X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/outage.git/blobdiff_plain/5537f3877fdae638164e06ad45b4f88e27c5093b..eab5b7065ba411ccb0560dcf26b455f1a1312a06:/outage-mail diff --git a/outage-mail b/outage-mail index 4968135..4731cb5 100644 --- a/outage-mail +++ b/outage-mail @@ -1,40 +1,86 @@ -import smtplib -from invirt.database import * -from email.mime.text import MIMEText - -message = """One of the four XVM servers, aperture-science, spontaneously rebooted -today at around 2:55 today. As of now, we're not sure what the cause of -this was. - -Your VM %s was running on aperture-science. We have restarted it. +#!/usr/bin/python +""" -We realize that this is an inconvenience for you, and we apologize for -the unexpected downtime. +VM names on stdin. +""" -- Evan -for the XVM team""" +import smtplib +import optparse +import sys +from email.mime.text import MIMEText -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() +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['From'] = opts.from_addr msg['Reply-To'] = 'XVM ' - msg['From'] = 'Evan Broder ' - msg['Subject'] = '[xvm] Unexpected reboot of your VM %s' % vm - s.sendmail('Evan Broder ', - [contact, 'xvm@mit.edu'], + msg['Subject'] = opts.subject % vm + smtp.sendmail(opts.from_addr, + [contact], msg.as_string()) + return msg.as_string() + +def send_summary(smtp, opts, messages): + msg = MIMEText('\n\n\n'.join(messages)) + msg['To'] = 'xvm@mit.edu' + msg['From'] = opts.from_addr + msg['Subject'] = ("xvm outage-mail summary (%d): %s" + % (len(messages), opts.subject)) + smtp.sendmail(opts.from_addr, + ['xvm@mit.edu'], + msg.as_string()) + +def main(argv): + parser = optparse.OptionParser( + usage = '%prog {-m message, -f from} [options]