Permalink
Browse files

cleanup patch from Dan Larsson

  • Loading branch information...
1 parent 49f7e0f commit 0b7e34c8296ba938df0e526afdd624464ff6121b Julien Vehent committed Jan 13, 2012
Showing with 7 additions and 4 deletions.
  1. +7 −4 postscreen_stats.py
View
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# Parses the postscreen logs and display stats
-# jvehent - 20111106
+# jvehent - 20120113
import re
import time
@@ -38,15 +38,16 @@ def usage():
def gen_unix_ts(syslog_date):
ts = 0
unix_ts = 0
+ now_ts = datetime.datetime.now()
# add the year
syslog_date = str(YEAR) + " " + syslog_date
ts = time.strptime(syslog_date, '%Y %b %d %H:%M:%S')
unix_ts = time.mktime(ts)
# check if the unix_ts is not in the future
- if unix_ts > time.mktime(NOW.timetuple()):
+ if unix_ts > time.mktime(now_ts.timetuple()):
print "Time is in the future... what the heck ?"
- print "Are you really parsing logs from " + YEAR + " ?"
+ print "Are you really parsing logs from " + str(YEAR) + " ?"
sys.exit()
else:
return unix_ts
@@ -327,6 +328,7 @@ def action_filter(self,filter):
# if client was blocked at any point, add its country to the count
if ( GEOLOC > 0 and
+ ip_list[client].geoloc > 0 and
(ip_list[client].actions["BLACKLISTED"] > 0
or ip_list[client].actions["DNSBL"] > 0
or ip_list[client].actions["PREGREET"] > 0
@@ -407,4 +409,5 @@ def action_filter(self,filter):
for i in range(20):
if i < len(sorted_countries):
country,clients = sorted_countries[i]
- print clients, country, "(" + str(Decimal(clients)/total_blocked*100) + "%)"
+ cpercent = "(%5.2f%%)" % float(Decimal(clients)/total_blocked*100)
+ print "%4d" % clients, cpercent, country

0 comments on commit 0b7e34c

Please sign in to comment.