def apflog(msg, level='Notice', echo=True): """Wraps the APF.log function. Messages are logged as 'master'.""" APF.log(str(msg), level=level, echo=echo) if level in ['error']: subject = "[APF] An Error has occured" sendmail(subject, msg, to=['*****@*****.**']) if level in ['Crit', 'Alert', 'Emerg']: subject = "[APF] An Error has occured" sendmail(subject, msg, to=['*****@*****.**','*****@*****.**'])
def sendmail(subject, body, to=['*****@*****.**']): APF.log("Sending error message to" + str(to)) me = "APF <*****@*****.**>" msg = MIMEMultipart() msg["Subject"] = subject msg["From"] = me msg["To"] = ', '.join(to) msg.attach(MIMEText(body + "\n")) user_msg = "Script was being run by user %s" % getpass.getuser() msg.attach(MIMEText(user_msg)) s = smtplib.SMTP('localhost') s.sendmail(me, to, msg.as_string()) s.quit()
def apflog(msg, level='Notice', echo=True): """Wraps the APF.log function. Messages are logged as 'master'.""" APF.log(str(msg), level=level, echo=echo) if level in ['error']: subject = "[APF] An Error has occured" sendmail(subject, msg, to=['*****@*****.**']) if level in ['Crit', 'Alert', 'Emerg']: subject = "[APF] An Error has occured" sendmail(subject, msg, to=[ '*****@*****.**', '[email protected] ', '*****@*****.**' ])
def sendmail(subject, body, to=['*****@*****.**']): APF.log("Sending error message to" + str(to)) me = "APF <*****@*****.**>" msg = MIMEMultipart() msg["Subject"] = subject msg["From"] = me msg["To"] = ', '.join(to) msg.attach(MIMEText(body)) user_msg = "Script was being run by user %s" % getpass.getuser() msg.attach(MIMEText(user_msg)) s = smtplib.SMTP('localhost') s.sendmail(me, to, msg.as_string()) s.quit()