From 29d1ab59f9d12a0edc0cce7a1d38057536b90d85 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 16 Jan 2020 12:55:34 -0500 Subject: [PATCH] Add runner for sending error results over XMPP --- _runners/handle_minion_data.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 _runners/handle_minion_data.py diff --git a/_runners/handle_minion_data.py b/_runners/handle_minion_data.py new file mode 100644 index 0000000..222a70e --- /dev/null +++ b/_runners/handle_minion_data.py @@ -0,0 +1,29 @@ +import subprocess + +import salt.modules.xmpp + + +def xmpp_errors(recipient, data): + error = False + changes = False + + with open('/tmp/whatever', 'w') as f: + f.write(repr(data['return'])) + f.write(str(type(data['return']))) + + if isinstance(data['return'], dict): + error = not all(result['result'] for result in data['return'].values()) + changes = any(result['changes'] for result in data['return'].values()) + else: + error = not data['success'] + + if error or changes: + msg = subprocess.check_output( + ["salt-run", "jobs.lookup_jid", data['jid']]) + + salt.modules.xmpp.send_msg( + recipient, msg.decode(), + jid='salt@adamgoldsmith.name', + password="aewae2goh1Tee2Imahhe8iceika5aoph") + + return error