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