updated runners

This commit is contained in:
Paul 2021-01-17 17:44:58 +01:00
parent 4d6b8dd50d
commit 736d270364

View File

@ -5,10 +5,12 @@ import subprocess
import json import json
import salt.modules.smtp import salt.modules.smtp
''' '''
For use with salt reactor For use with salt reactor
''' '''
def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server): def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
data = eval(data_str) data = eval(data_str)
error = False error = False
@ -30,10 +32,10 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
sys.exit() sys.exit()
if error or changes: if error or changes:
_js = subprocess.check_output(["salt-run", "--out=json", js = subprocess.check_output(["salt-run", "--out=json",
"jobs.lookup_jid", data['jid']]) "jobs.lookup_jid", data['jid']])
body = "JobId is %s\n" % (data['jid']) body = f"JobId is data['jid']\n"
outdata = json.loads(_js) outdata = json.loads(js)
nodename = outdata.keys()[0] nodename = outdata.keys()[0]
for i in outdata[nodename]: for i in outdata[nodename]:
if not outdata[nodename][i]["result"]: if not outdata[nodename][i]["result"]:
@ -43,8 +45,10 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
salt.modules.smtp.send_msg(recipient=toaddrs, message=data, salt.modules.smtp.send_msg(recipient=toaddrs, message=data,
subject=subject, sender=fromaddr, subject=subject, sender=fromaddr,
server=smtp_server, use_ssl=False) server=smtp_server, use_ssl=False)
return True return True
def email_auth(fromaddr, toaddrs, subject, data_str, smtp_server): def email_auth(fromaddr, toaddrs, subject, data_str, smtp_server):
data = eval(data_str) data = eval(data_str)
salt.modules.smtp.send_msg(recipient=toaddrs, message=data, salt.modules.smtp.send_msg(recipient=toaddrs, message=data,