Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 67 lines (50 sloc) 1.647 kb
cf93080 Magnus Hagander Make the aggregator write it's log to the database instead of just
authored
1 #!/usr/bin/env python
2 # vim: ai ts=4 sts=4 sw=4
3 """PostgreSQL Planet Aggregator
4
5 This file contains the functions to email a report of failed fetches
6 by reading the aggregator log table in the database.
7
8 Current version just sends a single summary report. A future enhancement
9 could be to send reports directly to individual blog owners.
10
11 Copyright (C) 2009 PostgreSQL Global Development Group
12 """
13
14 import psycopg2
15 import smtplib
16 import email.Message
17 import ConfigParser
18
19 class LogChecker(object):
20 def __init__(self, cfg, db):
21 self.cfg = cfg
22 self.db = db
23
24 def Check(self):
25 c = self.db.cursor()
e9cc3ee Magnus Hagander Aggregate log reports and don't report on transient errors
authored
26 c.execute("""
27 SELECT name,info,count(*) as num FROM planet.aggregatorlog
cf93080 Magnus Hagander Make the aggregator write it's log to the database instead of just
authored
28 INNER JOIN planet.feeds ON feed=feeds.id
29 WHERE success='f' AND ts > CURRENT_TIMESTAMP-'24 hours'::interval
e9cc3ee Magnus Hagander Aggregate log reports and don't report on transient errors
authored
30 GROUP BY name,info
31 HAVING count(*) > %s
32 ORDER BY num,name;
33 """ % self.cfg.get('notify','minerrors'))
34
cf93080 Magnus Hagander Make the aggregator write it's log to the database instead of just
authored
35 if c.rowcount > 0:
36 s = """
37 One or more of the blogs fetched in the past 24 hours caused an error
38 as listed below.
39
40 """
41 last = ""
e9cc3ee Magnus Hagander Aggregate log reports and don't report on transient errors
authored
42 for name,info,num in c:
43 s += "(%3s times) %s (%s)\n" % (num, name, info)
cf93080 Magnus Hagander Make the aggregator write it's log to the database instead of just
authored
44
45 s += "\n\n"
46
47 toAddr = self.cfg.get('notify','mailto')
48 fromAddr = self.cfg.get('notify','mailfrom')
49
50 msg = email.Message.Message()
51 msg['To'] = toAddr
52 msg['From'] = fromAddr
53 msg['Subject'] = 'Planet PostgreSQL error summary'
54 msg.set_payload(s)
55
56
57 smtp = smtplib.SMTP('127.0.0.1')
58 smtp.sendmail(fromAddr, toAddr, msg.as_string())
59 smtp.quit()
60
61
62 if __name__=="__main__":
63 c = ConfigParser.ConfigParser()
64 c.read('planet.ini')
65 LogChecker(c, psycopg2.connect(c.get('planet','db'))).Check()
66
Something went wrong with that request. Please try again.