diff --git a/states/_modules/syncthing.py b/states/_modules/syncthing.py index 1a5ae66..23c2ea5 100644 --- a/states/_modules/syncthing.py +++ b/states/_modules/syncthing.py @@ -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)) diff --git a/states/_runners/process_minion_data.py b/states/_runners/process_minion_data.py index 42ad0b4..2a89b03 100755 --- a/states/_runners/process_minion_data.py +++ b/states/_runners/process_minion_data.py @@ -3,7 +3,7 @@ import sys import subprocess import json -import salt.modules.smtp +from salt.modules.smtp import send_msg ''' @@ -16,20 +16,18 @@ 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(): - if not result['result']: - error = True - break - if result['changes']: - changes = True - break - else: + if type(data['return']) is dict: + for _, result in data['return'].items(): + if not result['result']: + error = True + break + if result['changes']: + 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