More debug
[build-farm.git] / mail-dead-hosts.py
1 #!/usr/bin/python
2 # Samba.org buildfarm
3 # Copyright (C) 2008 Andrew Bartlett <abartlet@samba.org>
4 # Copyright (C) 2008-2010 Jelmer Vernooij <jelmer@samba.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 from buildfarm import (
21     hostdb,
22     open_hostdb,
23     )
24 import smtplib
25 from email.MIMEText import MIMEText
26 import time
27
28 db = open_hostdb()
29 dry_run = False
30
31 hosts = db.dead_hosts(7 * 86400)
32 for host in hosts:
33     db.sent_dead_mail(host.name)
34
35     if host.last_update:
36         last_update = time.strftime ("%a %b %e %H:%M:%S %Y", time.gmtime(host.last_update))
37     else:
38         last_update = "a long time"
39
40     body = """
41 Your host %s has been part of the Samba Build farm, hosted
42 at http://build.samba.org.
43
44 Sadly however we have not heard from it since %s.
45
46 Could you see if something has changed recently, and examine the logs
47 (typically in ~build/build_farm/build.log and ~build/cron.err) to see
48 why we have not heard from your host?
49
50 If you no longer wish your host to participate in the Samba Build
51 Farm, then please let us know so we can remove its records.
52
53 You can see the summary for your host at:
54 http://build.samba.org/?function=View+Host;host=%s
55
56 Thanks,
57
58 The Build Farm administration team.
59
60 """ % (host.name, last_update, host.name)
61
62     msg = MIMEText(body)
63
64     # send an e-mail to the owner
65     msg["Subject"] ="Your build farm host %s appears dead" % host.name
66     msg["From"] = "\"Samba Build Farm\" <build@samba.org>"
67     msg["To"] = "\"%s\" <%s>" % host.owner
68
69     if dry_run:
70         print msg.as_string()
71     else:
72         s = smtplib.Connection()
73         s.connect()
74         s.send(msg["From"], [msg["To"]], msg.as_string())
75         s.quit()