Skip to content

Instantly share code, notes, and snippets.

@jayswan
Created November 25, 2014 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayswan/90d059c1c52c0903745c to your computer and use it in GitHub Desktop.
Save jayswan/90d059c1c52c0903745c to your computer and use it in GitHub Desktop.
Count Plixer log entries
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
print "Levels"
levels.pprint()
print
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