Rename data -> build.
[amitay/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.sqldb import StormCachingBuildFarm
21 import optparse
22 import smtplib
23 from email.MIMEText import MIMEText
24 import time
25
26 parser = optparse.OptionParser()
27 parser.add_option("--dry-run", help="Don't actually send any emails.", action="store_true")
28 (opts, args) = parser.parse_args()
29
30 buildfarm = StormCachingBuildFarm(timeout=40.0)
31
32 smtp = smtplib.SMTP()
33 smtp.connect()
34
35 hosts = buildfarm.hostdb.dead_hosts(7 * 86400)
36 for host in hosts:
37     if host.last_update:
38         last_update = time.strftime("%a %b %e %H:%M:%S %Y", time.gmtime(host.last_update))
39     else:
40         last_update = "a long time"
41
42     body = """
43 Your host %s has been part of the Samba Build farm, hosted
44 at http://build.samba.org.
45
46 Sadly however we have not heard from it since %s.
47
48 Could you see if something has changed recently, and examine the logs
49 (typically in ~build/build_farm/build.log and ~build/cron.err) to see
50 why we have not heard from your host?
51
52 If you no longer wish your host to participate in the Samba Build
53 Farm, then please let us know so we can remove its records.
54
55 You can see the summary for your host at:
56 http://build.samba.org/?function=View+Host;host=%s
57
58 Thanks,
59
60 The Build Farm administration team.
61
62 """ % (host.name, last_update, host.name)
63
64     msg = MIMEText(body)
65
66     # send an e-mail to the owner
67     msg["Subject"] ="Your build farm host %s appears dead" % host.name
68     msg["From"] = "\"Samba Build Farm\" <build@samba.org>"
69     msg["To"] = "\"%s\" <%s>" % host.owner
70     msg["Bcc"] = "\"Samba Build Farm\" <build@samba.org>"
71
72     if opts.dry_run:
73         print msg.as_string()
74     else:
75         smtp.sendmail(msg["From"], [msg["To"]], msg.as_string())
76         host.dead_mail_sent()
77 buildfarm.commit()
78 smtp.quit()