Module: WPSessioniser
- Defined in:
- lib/wp-sessioniser.rb
Overview
WPSessioniser
Example Usage
file = File.open(“/var/log/apache/access.log”) visitors = WPSessioniser.parse(file)
Constant Summary collapse
- FORMAT =
Changing this string breaks parsing. I don’t know why.
'%h %l %u %t \"%r\" %>s %b \"{Referer}i\" \"%{User-Agent}i\"'- PARSER =
ApacheLogRegex.new(FORMAT)
Class Method Summary collapse
Class Method Details
.parse(file) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/wp-sessioniser.rb', line 29 def WPSessioniser.parse file visitors = Hash.new() file.each do |line| h = PARSER.parse! line #Ignore non-pages next if h["%r"] !~ /GET/ next if h["%r"] =~ /xmlrpc.php/ next if h["%r"] =~ /favicon.ico/ next if h["%r"] =~ /robots.txt/ next if h["%r"] =~ /\?sccss/ next if h["%r"] =~ /wp-admin/ next if h["%r"] =~ /wp-content/ next if h["%r"] =~ /wp-includes/ next if h["%r"] =~ /wp-json/ next if h["%r"] =~ /\/\/images/ next if h["%r"] =~ /\?plugin=/ page = h["%r"].delete('GET ', '').delete(' HTTP/1.1', '') if visitors.has_key? h["%h"] visitors[h["%h"]].push_hit page, h["%t"] else visitors[h["%h"]] = Visitor.new visitors[h["%h"]].push_hit page, h["%t"] end end return visitors end |