updated python scripts
This commit is contained in:
parent
351dab96dc
commit
cd4e14a8dd
@ -48,6 +48,7 @@ def set_config(url, verify, apikey, config):
|
||||
req = Request(method="POST",
|
||||
url=fullurl,
|
||||
data=json.dumps(config).encode())
|
||||
req.add_header("Content-Type", "application/json")
|
||||
req.add_header("X-API-Key", apikey)
|
||||
try:
|
||||
res = urlopen(req, context=get_context(verify))
|
||||
|
@ -3,7 +3,7 @@
|
||||
import sys
|
||||
import subprocess
|
||||
import json
|
||||
import salt.modules.smtp
|
||||
from salt.modules.smtp import send_msg
|
||||
|
||||
|
||||
'''
|
||||
@ -16,9 +16,8 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
|
||||
error = False
|
||||
changes = False
|
||||
|
||||
try:
|
||||
if type(data['return']) is dict:
|
||||
for _, result in data['return'].iteritems():
|
||||
for _, result in data['return'].items():
|
||||
if not result['result']:
|
||||
error = True
|
||||
break
|
||||
@ -26,10 +25,9 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
|
||||
changes = True
|
||||
break
|
||||
else:
|
||||
if "success" in data.keys():
|
||||
if not data['success']:
|
||||
error = True
|
||||
except KeyError:
|
||||
sys.exit()
|
||||
|
||||
if error or changes:
|
||||
js = subprocess.check_output(["salt-run", "--out=json",
|
||||
@ -42,17 +40,23 @@ def email_errors(fromaddr, toaddrs, subject, data_str, smtp_server):
|
||||
name = outdata[nodename][i]["name"]
|
||||
comment = outdata[nodename][i]["comment"].rstrip('\n')
|
||||
data = "%s- %s / %s\n" % (body, name, comment)
|
||||
salt.modules.smtp.send_msg(recipient=toaddrs, message=data,
|
||||
subject=subject, sender=fromaddr,
|
||||
server=smtp_server, use_ssl=False)
|
||||
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,
|
||||
subject=subject, sender=fromaddr,
|
||||
server=smtp_server, use_ssl=False)
|
||||
send_msg(recipient=toaddrs,
|
||||
message=data,
|
||||
subject=subject,
|
||||
sender=fromaddr,
|
||||
server=smtp_server,
|
||||
use_ssl=False)
|
||||
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user