当前位置:   article > 正文

zabbix7.0(6.4以上)钉钉告警脚本_zabbix6.4 钉钉机器人告警

zabbix6.4 钉钉机器人告警

一、有关钉钉机器人的配置不再赘述

        我是因为把zabbix从6.0升级到7.0之后,发现之前的脚本不能用了

二、因为zabbix更改了函数名,比如curlhttprequest更改为httprequest造成的

三、媒介类型配置如下图

四、脚本如下

  1. var dingding = {
  2. key: null,
  3. message: null,
  4. msgtype: "markdown",
  5. proxy: null,
  6. to: null,
  7. subject: null,
  8. sendMessage: function () {
  9. var params = {
  10. msgtype: "markdown",
  11. markdown: {
  12. title: "告警信息⚠️",
  13. text: dingding.message
  14. },
  15. disable_web_page_preview: true,
  16. disable_notification: false
  17. },
  18. data,
  19. response,
  20. request = new HttpRequest(),
  21. url = 'https://oapi.dingtalk.com/robot/send?access_token=' + dingding.key;
  22. if (dingding.proxy) {
  23. request.setProxy(dingding.proxy);
  24. }
  25. request.addHeader('Content-Type: application/json');
  26. data = JSON.stringify(params);
  27. // Remove replace() function if you want to see the exposed key in the log file.
  28. Zabbix.Log( 4,"[dingding Webhook] URL: " + url.replace(dingding.key, "<BOT KEY>"));
  29. Zabbix.Log(4, "[dingding Webhook] params: " + data);
  30. response = request.post(url, data);
  31. Zabbix.Log(4, "[dingding Webhook] HTTP code: " + request.getStatus());
  32. try {
  33. response = JSON.parse(response);
  34. } catch (error) {
  35. response = null;
  36. }
  37. if (request.getStatus() !== 200 || response.errcode !== 0) {
  38. if (typeof response.errmsg === "string") {
  39. throw response.errmsg;
  40. } else {
  41. throw "Unknown error. Check debug log for more information.";
  42. }
  43. }
  44. },
  45. };
  46. try {
  47. var params = JSON.parse(value);
  48. if (typeof params.Key === "undefined") {
  49. throw 'Incorrect value is given for parameter "Key": parameter is missing';
  50. }
  51. dingding.key = params.Key;
  52. if (params.HTTPProxy) {
  53. dingding.proxy = params.HTTPProxy;
  54. }
  55. dingding.to = params.To;
  56. dingding.message = params.Subject + "\n" + params.Message;
  57. dingding.sendMessage();
  58. return "OK";
  59. } catch (error) {
  60. Zabbix.Log(4, "[dingding Webhook] notification failed: " + error);
  61. throw "Sending failed: " + error + ".";
  62. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/898489
推荐阅读
相关标签
  

闽ICP备14008679号