Show make "test" as -1 if no test failed but make return non zero
[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 hostdb
21 import smtplib
22 from email.MIMEText import MIMEText
23 import os
24 import time
25
26 db = hostdb.HostDatabase(os.path.join(os.path.dirname(__file__), "hostdb.sqlite"))
27 dry_run = False
28
29 hosts = db.dead_hosts(7 * 86400)
30 for host in hosts:
31     db.sent_dead_mail(host.name)
32
33     if host.last_update:
34         last_update = time.strftime ("%a %b %e %H:%M:%S %Y", time.gmtime(host.last_update))
35     else:
36         last_update = "a long time"
37
38     body = """
39 Your host %s has been part of the Samba Build farm, hosted
40 at http://build.samba.org.
41
42 Sadly however we have not heard from it since %s.
43
44 Could you see if something has changed recently, and examine the logs
45 (typically in ~build/build_farm/build.log and ~build/cron.err) to see
46 why we have not heard from your host?
47
48 If you no longer wish your host to participate in the Samba Build
49 Farm, then please let us know so we can remove its records.
50
51 You can see the summary for your host at:
52 http://build.samba.org/?function=View+Host;host=%s
53
54 Thanks,
55
56 The Build Farm administration team.
57
58 """ % (host.name, last_update, host.name)
59
60     msg = MIMEText(body)
61
62     # send an e-mail to the owner
63     msg["Subject"] ="Your build farm host %s appears dead" % host.name
64     msg["From"] = "\"Samba Build Farm\" <build@samba.org>"
65     msg["To"] = "\"%s\" <%s>" % host.owner
66
67     if dry_run:
68         print msg.as_string()
69     else:
70         s = smtplib.Connection()
71         s.connect()
72         s.send(msg["From"], [msg["To"]], msg.as_string())
73         s.quit()