|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
|
|
|
|
import re, argparse, os
|
|
|
|
import re, argparse, os
|
|
|
|
|
|
|
|
|
|
|
|
def show_sorted(dictionary):
|
|
|
|
def show_sorted(dictionary):
|
|
|
@ -28,6 +30,7 @@ urls = {}
|
|
|
|
extensions = {}
|
|
|
|
extensions = {}
|
|
|
|
|
|
|
|
|
|
|
|
total_digits = 10
|
|
|
|
total_digits = 10
|
|
|
|
|
|
|
|
current_lines = 0
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
ignore_extensions = options['extensions'].split(',')
|
|
|
|
ignore_extensions = options['extensions'].split(',')
|
|
|
@ -39,6 +42,7 @@ for logpath in options['logfiles']:
|
|
|
|
log = open(logpath, 'r')
|
|
|
|
log = open(logpath, 'r')
|
|
|
|
|
|
|
|
|
|
|
|
for line in log:
|
|
|
|
for line in log:
|
|
|
|
|
|
|
|
try:
|
|
|
|
ip, hostname, dash, datetime, timezone, method, uri, version, status, size, referer, useragent = line.split(' ', 11)
|
|
|
|
ip, hostname, dash, datetime, timezone, method, uri, version, status, size, referer, useragent = line.split(' ', 11)
|
|
|
|
datetime = datetime[1:]
|
|
|
|
datetime = datetime[1:]
|
|
|
|
date = datetime.split(':')[0]
|
|
|
|
date = datetime.split(':')[0]
|
|
|
@ -75,31 +79,36 @@ for logpath in options['logfiles']:
|
|
|
|
files[filename] += 1
|
|
|
|
files[filename] += 1
|
|
|
|
urls[uri] += 1
|
|
|
|
urls[uri] += 1
|
|
|
|
extensions[extension] += 1
|
|
|
|
extensions[extension] += 1
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
print "Corrupt log line at line %d, contents: %s" % (current_lines + 1, line[:-1])
|
|
|
|
|
|
|
|
|
|
|
|
print "Top days:"
|
|
|
|
current_lines += 1
|
|
|
|
show_sorted(days)
|
|
|
|
|
|
|
|
print ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print "Top requested hostnames:"
|
|
|
|
if current_lines % 1000 == 0:
|
|
|
|
show_sorted(hosts)
|
|
|
|
print "Processed %d lines." % current_lines
|
|
|
|
print ""
|
|
|
|
except IOError:
|
|
|
|
|
|
|
|
print "Could not find file %s, ignored entry." % logpath
|
|
|
|
|
|
|
|
|
|
|
|
print "Top files:"
|
|
|
|
print "Top days:"
|
|
|
|
show_sorted(files)
|
|
|
|
show_sorted(days)
|
|
|
|
print ""
|
|
|
|
print ""
|
|
|
|
|
|
|
|
|
|
|
|
print "Top extensions:"
|
|
|
|
print "Top requested hostnames:"
|
|
|
|
show_sorted(extensions)
|
|
|
|
show_sorted(hosts)
|
|
|
|
print ""
|
|
|
|
print ""
|
|
|
|
|
|
|
|
|
|
|
|
print "Top referers:"
|
|
|
|
print "Top files:"
|
|
|
|
show_sorted(referers)
|
|
|
|
show_sorted(files)
|
|
|
|
print ""
|
|
|
|
print ""
|
|
|
|
|
|
|
|
|
|
|
|
print "Top URLs:"
|
|
|
|
print "Top extensions:"
|
|
|
|
show_sorted(urls)
|
|
|
|
show_sorted(extensions)
|
|
|
|
print ""
|
|
|
|
print ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print "Top referers:"
|
|
|
|
|
|
|
|
show_sorted(referers)
|
|
|
|
|
|
|
|
print ""
|
|
|
|
|
|
|
|
|
|
|
|
except IOError:
|
|
|
|
print "Top URLs:"
|
|
|
|
print "Could not find file %s, ignored entry." % logpath
|
|
|
|
show_sorted(urls)
|
|
|
|
|
|
|
|
print ""
|
|
|
|