Class: IISAccessLogParser::Entry

Inherits:
Struct
  • Object
show all
Defined in:
lib/iis-access-log-parser.rb,
lib/iis-access-log-parser.rb

Overview

Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) sc-status sc-substatus sc-win32-status time-taken

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#client_ipObject

Returns the value of attribute client_ip

Returns:

  • (Object)

    the current value of client_ip



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def client_ip
  @client_ip
end

#dateObject

Returns the value of attribute date

Returns:

  • (Object)

    the current value of date



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def date
  @date
end

#methodObject

Returns the value of attribute method

Returns:

  • (Object)

    the current value of method



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def method
  @method
end

#otherObject

Returns the value of attribute other

Returns:

  • (Object)

    the current value of other



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def other
  @other
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def port
  @port
end

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def query
  @query
end

#server_ipObject

Returns the value of attribute server_ip

Returns:

  • (Object)

    the current value of server_ip



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def server_ip
  @server_ip
end

#statusObject

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def status
  @status
end

#substatusObject

Returns the value of attribute substatus

Returns:

  • (Object)

    the current value of substatus



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def substatus
  @substatus
end

#time_takenObject

Returns the value of attribute time_taken

Returns:

  • (Object)

    the current value of time_taken



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def time_taken
  @time_taken
end

#urlObject

Returns the value of attribute url

Returns:

  • (Object)

    the current value of url



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def url
  @url
end

#user_agentObject

Returns the value of attribute user_agent

Returns:

  • (Object)

    the current value of user_agent



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def user_agent
  @user_agent
end

#usernameObject

Returns the value of attribute username

Returns:

  • (Object)

    the current value of username



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def username
  @username
end

#win32_statusObject

Returns the value of attribute win32_status

Returns:

  • (Object)

    the current value of win32_status



6
7
8
# File 'lib/iis-access-log-parser.rb', line 6

def win32_status
  @win32_status
end

Class Method Details

.from_string(line) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/iis-access-log-parser.rb', line 8

def self.from_string(line)
	# 2011-06-20 00:00:00 83.222.242.43 GET /SharedControls/getListingThumbs.aspx img=48,13045,27801,25692,35,21568,21477,21477,10,18,46,8&premium=0|1|0|0|0|0|0|0|0|0|0|0&h=100&w=125&pos=175&scale=true 80 - 92.20.10.104 Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+6.1;+Trident/4.0;+GTB6.6;+SLCC2;+.NET+CLR+2.0.50727;+.NET+CLR+3.5.30729;+.NET+CLR+3.0.30729;+Media+Center+PC+6.0;+aff-kingsoft-ciba;+.NET4.0C;+MASN;+AskTbSTC/5.8.0.12304) 200 0 0 609

	x, date, server_ip, method, url, query, port, username, client_ip, user_agent, status, substatus, win32_status, time_taken, y, other = *line.match(/^([^ ]* [^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)($| )(.*)/)
	raise ArgumentError, "bad format: '#{line}'" unless x

	date = Time.parse(date + ' UTC')

	server_ip = IP.new(server_ip)
	client_ip = IP.new(client_ip)

	port = port.to_i
	status = status.to_i
	substatus = substatus.to_i
	win32_status = win32_status.to_i

	time_taken = time_taken.to_f / 1000

	query = nil if query == '-'
	username = nil if username == '-'
	user_agent = nil if user_agent == '-'

	user_agent.tr!('+', ' ') unless user_agent.nil?

	self.new(date, server_ip, method, url, query, port, username, client_ip, user_agent, status, substatus, win32_status, time_taken, other)
end