Browse Source

Add 'notifications/zammad-service.py'

Michael Honkoop 1 week ago
parent
commit
74e3e04af9
1 changed files with 37 additions and 0 deletions
  1. 37 0
      notifications/zammad-service.py

+ 37 - 0
notifications/zammad-service.py

@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+#zammad-service
+
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+
+import os
+import requests
+import sys
+
+def build_context():
+    return {
+        var[7:]: value
+        for (var, value) in os.environ.items()
+        if var.startswith("NOTIFY_")
+    }
+
+def build_message(ctx):
+    data = {
+        'event_id': (None, ctx.get('SERVICEPROBLEMID', '')),
+        'host': (None, ctx.get('HOSTNAME', '')),
+        'hostip': (None, ctx.get('HOSTADDRESS', '')),
+        'service': (None, ctx.get('SERVICEDESC', '')),
+        'state': (None, ctx.get('SERVICESTATE', '')),
+        'text':  (None, ctx.get('SERVICEOUTPUT', '')),
+        }
+    return data
+
+def main():
+    ctx = build_context()
+    response =  requests.post(ctx.get("PARAMETER_1"), files=build_message(ctx), verify=False)
+    
+if __name__ == "__main__":
+    try:
+        main()
+    except Exception as e:
+        sys.stderr.write("Unhandled exception: %s\n" % e)
+        sys.exit(2)