X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/outage.git/blobdiff_plain/b19058747f2af71bd5d354b1e9cd678ee6ffb31c..eab5b7065ba411ccb0560dcf26b455f1a1312a06:/outage-mail diff --git a/outage-mail b/outage-mail index 93bb5a1..4731cb5 100644 --- a/outage-mail +++ b/outage-mail @@ -17,12 +17,22 @@ def send_mail(smtp, opts, message, vm): contact += '@mit.edu' msg = MIMEText(message % vm) msg['To'] = contact - msg['CC'] = 'XVM ' + msg['From'] = opts.from_addr msg['Reply-To'] = 'XVM ' + 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] Unexpected reboot of your VM %s' % vm + msg['Subject'] = ("xvm outage-mail summary (%d): %s" + % (len(messages), opts.subject)) smtp.sendmail(opts.from_addr, - [contact, 'xvm@mit.edu'], + ['xvm@mit.edu'], msg.as_string()) def main(argv): @@ -33,6 +43,11 @@ def main(argv): type = 'string', dest = 'message', help = 'filename with body of message') + parser.add_option('-s', '--subject', + type = 'string', + dest = 'subject', + default = '[xvm] Unexpected reboot of your VM %s', + help = 'subject line of message; %s for VM name') parser.add_option('-f', '--from', type = 'string', dest = 'from_addr', @@ -60,8 +75,10 @@ def main(argv): s = smtplib.SMTP() s.connect() + messages = [] for vm in vms: - send_mail(s, opts, message, vm) + messages.append(send_mail(s, opts, message, vm)) + send_summary(s, opts, messages) s.close()