49681356311c5edb4c83a0a2dade301d04c5193e
[invirt/scripts/outage.git] / outage-mail
1 import smtplib
2 from invirt.database import *
3 from email.mime.text import MIMEText
4
5 message = """One of the four XVM servers, aperture-science, spontaneously rebooted
6 today at around 2:55 today. As of now, we're not sure what the cause of
7 this was.
8
9 Your VM %s was running on aperture-science. We have restarted it.
10
11 We realize that this is an inconvenience for you, and we apologize for
12 the unexpected downtime.
13
14 - Evan
15 for the XVM team"""
16
17 vms = "nforrest0 remus ghost-of-golezan tabbott 6470 dh moo mclamb dt-web htns uav-team x lsmb twopi what esg panache gardiner mailman-acl jack-o-tron knowledge ephialtes ocaml happy-go-lucky maridia cochese ocelot ecprice bibix groovy r privoxy thebes intrepid-paravirt-test qren2 quentin woodrow prolix oculus shinnyih gkovacs".split()
18
19 def send_mail(vm):
20     contact = Machine.query.filter_by(name=vm).first().contact
21     if '@' not in contact:
22         contact += '@mit.edu'
23     msg = MIMEText(message % vm)
24     msg['To'] = contact
25     msg['CC'] = 'XVM <xvm@mit.edu>'
26     msg['Reply-To'] = 'XVM <xvm@mit.edu>'
27     msg['From'] = 'Evan Broder <broder@mit.edu>'
28     msg['Subject'] = '[xvm] Unexpected reboot of your VM %s' % vm
29     s.sendmail('Evan Broder <broder@mit.edu>',
30         [contact, 'xvm@mit.edu'],
31         msg.as_string())
32
33 connect()
34 s = smtplib.SMTP()
35 s.connect()
36
37 for vm in vms:
38     send_mail(vm)
39
40 s.close()