Webhook script examples

Overview

Though Zabbix offers a large number of webhook integrations available out-of-the-box, you may want to create your own webhooks instead. This section provides examples of custom webhook scripts (used in the Script parameter). See webhook section for description of other webhook parameters.

Jira webhook (custom)

Webhook script examples - 图1

This script will create a JIRA issue and return some info on the created issue.

  1. try {
  2. Zabbix.Log(127, 'jira webhook script value='+value);
  3. var result = {
  4. 'tags': {
  5. 'endpoint': 'jira'
  6. }
  7. },
  8. params = JSON.parse(value),
  9. req = new CurlHttpRequest(),
  10. proxy = params.HTTPProxy;
  11. req.SetProxy(proxy);
  12. fields = {},
  13. resp;
  14. req.AddHeader('Content-Type: application/json');
  15. req.AddHeader('Authorization: Basic '+params.authentication);
  16. fields.summary = params.summary;
  17. fields.description = params.description;
  18. fields.project = {"key": params.project_key};
  19. fields.issuetype = {"id": params.issue_id};
  20. resp = req.Post('https://tsupport.zabbix.lan/rest/api/2/issue/',
  21. JSON.stringify({"fields": fields})
  22. );
  23. if (req.Status() != 201) {
  24. throw 'Response code: '+req.Status();
  25. }
  26. resp = JSON.parse(resp);
  27. result.tags.issue_id = resp.id;
  28. result.tags.issue_key = resp.key;
  29. } catch (error) {
  30. Zabbix.Log(127, 'jira issue creation failed json : '+JSON.stringify({"fields": fields}));
  31. Zabbix.Log(127, 'jira issue creation failed : '+error);
  32. result = {};
  33. }
  34. return JSON.stringify(result);

Slack webhook (custom)

This webhook will forward notifications from Zabbix to a Slack channel.

Webhook script examples - 图2

  1. var req = new CurlHttpRequest();
  2. params = JSON.parse(value);
  3. proxy = params.HTTPProxy;
  4. req.SetProxy(proxy);
  5. req.AddHeader('Content-Type: application/x-www-form-urlencoded');
  6. Zabbix.Log(127, 'webhook request value='+value);
  7. req.Post('https://hooks.slack.com/services/KLFDEI9KNL/ZNA76HGCF/h9MLKJMWoUcEAz8n',
  8. 'payload='+value
  9. );
  10. Zabbix.Log(127, 'response code: '+req.Status());
  11. return JSON.stringify({
  12. 'tags': {
  13. 'delivered': 'slack'
  14. }
  15. });