zammad-service.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. #zammad-service
  3. # -*- encoding: utf-8; py-indent-offset: 4 -*-
  4. # This script if for service-notifications to zammad
  5. # Place this in ~/local/share/check_mk/notifications as your site-user.
  6. # Add the url to send the notifications to as first parameter.
  7. import os
  8. import requests
  9. import sys
  10. def build_context():
  11. return {
  12. var[7:]: value
  13. for (var, value) in os.environ.items()
  14. if var.startswith("NOTIFY_")
  15. }
  16. def build_message(ctx):
  17. data = {
  18. 'event_id': (None, ctx.get('SERVICEPROBLEMID', '')),
  19. 'host': (None, ctx.get('HOSTNAME', '')),
  20. 'hostip': (None, ctx.get('HOSTADDRESS', '')),
  21. 'service': (None, ctx.get('SERVICEDESC', '')),
  22. 'state': (None, ctx.get('SERVICESTATE', '')),
  23. 'text': (None, ctx.get('SERVICEOUTPUT', '')),
  24. }
  25. return data
  26. def main():
  27. ctx = build_context()
  28. response = requests.post(ctx.get("PARAMETER_1"), files=build_message(ctx), verify=False)
  29. if __name__ == "__main__":
  30. try:
  31. main()
  32. except Exception as e:
  33. sys.stderr.write("Unhandled exception: %s\n" % e)
  34. sys.exit(2)