From: Greg Price Date: Tue, 17 Mar 2009 00:26:21 +0000 (-0400) Subject: make outage-mail fully reusable X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/outage.git/commitdiff_plain/b19058747f2af71bd5d354b1e9cd678ee6ffb31c make outage-mail fully reusable svn path=/trunk/scripts/outage/; revision=2252 --- diff --git a/message-cdrom b/message-cdrom new file mode 100644 index 0000000..752363b --- /dev/null +++ b/message-cdrom @@ -0,0 +1,12 @@ +One of the four XVM host servers, %(host)s, failed at +about %(time)s and was rebooted. We're working to understand the cause. + +Your VM %%s was running on %(host)s. Because it was running from a CD, we +are unable to boot it up completely and have left it off until you +boot it yourself. + +We realize that this is an inconvenience for you, and we apologize for +the unexpected downtime. + +- %(sig)s +for the XVM team diff --git a/message-normal b/message-normal new file mode 100644 index 0000000..a0f0153 --- /dev/null +++ b/message-normal @@ -0,0 +1,10 @@ +One of the four XVM host servers, %(host)s, failed at +about %(time)s and was rebooted. We're working to understand the cause. + +Your VM %%s was running on %(host)s. We have restarted it. + +We realize that this is an inconvenience for you, and we apologize for +the unexpected downtime. + +- %(sig)s +for the XVM team diff --git a/outage-mail b/outage-mail index ed75737..93bb5a1 100644 --- a/outage-mail +++ b/outage-mail @@ -1,46 +1,69 @@ #!/usr/bin/python -import smtplib -from invirt.database import * -from email.mime.text import MIMEText - -sender = 'Greg Price ' -sendername = sender.split()[0] -host = 'arklay-mansion' +""" -message = """\ -One of the four XVM host servers, %s, failed tonight at -about 23:17 and was rebooted. We're working to understand the cause. +VM names on stdin. +""" -Your VM %%s was running on %s. We have restarted it. - -We realize that this is an inconvenience for you, and we apologize for -the unexpected downtime. - -- %s -for the XVM team -""" % (host, host, sendername) +import smtplib +import optparse +import sys +from email.mime.text import MIMEText -vms = "amd64-test brain-trust cluster-test david-vista debathena-livecd-build ecprice gradbook greg-ns1 greg-ns2 groovy htns iodine jsoltren latex liftm medkaz mhd mksvn niska polarix price-lenny price-test8 qren2 shawn-of-awesome staxowax tdc tdc-secure thesecrete tor transistor watmap".split() +from invirt import database -def send_mail(vm): - contact = Machine.query.filter_by(name=vm).first().contact +def send_mail(smtp, opts, message, vm): + contact = database.Machine.query.filter_by(name=vm).first().contact if '@' not in contact: contact += '@mit.edu' msg = MIMEText(message % vm) msg['To'] = contact msg['CC'] = 'XVM ' msg['Reply-To'] = 'XVM ' - msg['From'] = sender + msg['From'] = opts.from_addr msg['Subject'] = '[xvm] Unexpected reboot of your VM %s' % vm - s.sendmail(sender, + smtp.sendmail(opts.from_addr, [contact, 'xvm@mit.edu'], msg.as_string()) -connect() -s = smtplib.SMTP() -s.connect() +def main(argv): + parser = optparse.OptionParser( + usage = '%prog {-m message, -f from} [options]