Last active
December 15, 2015 21:09
-
-
Save danielrichman/5323661 to your computer and use it in GitHub Desktop.
Summarise exim4 email failures
This file contains hidden or 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
#!/usr/bin/python | |
import glob | |
import gzip | |
import datetime | |
logfiles = glob.glob("/var/log/exim4/mainlog*") | |
time_format = "%Y-%m-%d %H:%M:%S" | |
def all_lines(): | |
for filename in logfiles: | |
if ".gz" in filename: | |
f = gzip.open(filename) | |
else: | |
f = open(filename) | |
for line in f: | |
yield line | |
f.close() | |
days = {} | |
for line in all_lines(): | |
split = line.split() | |
when = " ".join(split[0:2]) | |
if len(split) > 3 and split[3] == '**': | |
day = datetime.datetime.strptime(when, time_format).date() | |
if day not in days: | |
days[day] = {} | |
failures = days[day] | |
local_part, domain = split[4].split("@") | |
if domain not in failures: | |
failures[domain] = 0 | |
failures[domain] += 1 | |
print "Outgoing email hard failure summary" | |
for day, failures in sorted(days.items()): | |
print day | |
for domain, times in sorted(failures.items(), key=lambda (d, t): -t): | |
print " ", str(times).rjust(5), domain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment