Created
November 25, 2014 16:29
-
-
Save jayswan/90d059c1c52c0903745c to your computer and use it in GitHub Desktop.
Count Plixer log entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from operator import itemgetter | |
import sys | |
FILENAME = sys.argv[1] | |
class SimpleCounter(defaultdict): | |
""" Scrutinizer ships with Python 2.6 and doesn't have the Counter object | |
from collections. This is a simple version of it. | |
""" | |
def most_common(self): | |
return sorted(self.iteritems(), key=itemgetter(1), reverse=True) | |
def pprint(self): | |
for k,v in self.most_common(): | |
print '%-10i %s' % (v,k) | |
modules = SimpleCounter(int) | |
levels = SimpleCounter(int) | |
ips = SimpleCounter(int) | |
def main(): | |
with open(FILENAME) as f: | |
for line in f: | |
fields = line.split() | |
module = fields[3] | |
level = fields[5] | |
ip = fields[7] | |
msg_text = fields[8:] | |
modules[module] += 1 | |
levels[level] += 1 | |
ips[ip] += 1 | |
print "Modules" | |
modules.pprint() | |
print "Levels" | |
levels.pprint() | |
print "IPs" | |
ips.pprint() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment