Zabbix configuration DingTalk alarm function implementation code

Zabbix configuration DingTalk alarm function implementation code

need

Configuring DingTalk alarms in Zabbix is ​​similar to configuring DingTalk alarms in Prometheus. However, Zabbix’s alerts through DingTalk are implemented through Python scripts. Prometheus is implemented through the binary package of DingTalk.

For the settings of DingTalk, please refer to another blog post of mine (Configure DingTalk Alerts with Prometheus): https://knight.blog.csdn.net/article/details/105583741

We will now mainly explain the settings and implementation of Zabbix

DingTalk Webhook Code Implementation

vim /usr/local/zabbix/share/zabbix/alertscripts/dingding.py

#!/usr/bin/env python
#coding:utf-8
 
import requests,json,sys,os,datetime
webhook="https://oapi.dingtalk.com/robot/send?access_token=6e5bcfee12bc6fa7f3c6bd16b7d6c333d86266cecadd3fe5e77a29cedae9f9" #Description: Here, change the value of the webhook of the robot you created to user=sys.argv[1]
text=sys.argv[3]
data={
  "msgtype": "text",
  "text": {
    "content": text
  },
  "at": {
    "atMobiles": [
      user
    ],
    "isAtAll": False
  }
}
headers = {'Content-Type': 'application/json'}
x=requests.post(url=webhook,data=json.dumps(data),headers=headers)
if os.path.exists("/tmp/dingding.log"):
  f=open("/tmp/dingding.log","a+")
else:
  f=open("/tmp/dingding.log","w+")
f.write("\n"+"--"*30)
if x.json()["errcode"] == 0:
  f.write("\n"+str(datetime.datetime.now())+" "+str(user)+" "+"Sent successfully"+"\n"+str(text))
  f.close()
else:
  f.write("\n"+str(datetime.datetime.now()) + " " + str(user) + " " + "Failed to send" + "\n" + str(text))
  f.close()

Execute it:

chmod +x dingding.py # add execution permission python dingding.py ab "test"

Let's see if DingTalk can receive the alarm (remember to add the server's public IP to the whitelist of DingTalk)

The configuration of Zabbix is ​​as follows:

(1) Configure the alarm media type:

Configuration--->Alarm media type, the script parameters are as follows:

{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}

The screenshots are as follows:

(2) Configuration action

Configure--->Action--->Create Action, and copy the "Operation" and recovery operation content of the WeChat alarm or email alarm.

(3) Finally configure the user

Configuration--->User--->Alarm Media, just add DingTalk. The recipient needs to write his or her own phone number.

The configuration of Zabbix is ​​complete. Let's take a look at the warning effect diagram

Summarize

This is the end of this article about Zabbix configuration DingTalk alarm. For more relevant Zabbix configuration DingTalk alarm content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Installation and configuration method of Zabbix Agent on Linux platform
  • Zabbix monitors the process of Linux system services
  • Use of Zabbix Api in Linux shell environment
  • How to install Zabbix monitoring in Linux
  • How to set up Zabbix to monitor Linux hosts
  • Detailed examples of Zabbix remote command execution
  • Detailed explanation of zabbix executing scripts or instructions on remote hosts
  • Detailed explanation of Zabbix installation and deployment practices
  • Zabbix monitors Linux hosts based on snmp

<<:  WeChat applet component development: Visual movie seat selection function

>>:  mysql 8.0.18 mgr installation and its switching function

Recommend

Analysis of examples of using anti-shake and throttling in Vue components

Be careful when listening for events that are tri...

Let IE support CSS3 Media Query to achieve responsive web design

Today's screen resolutions range from as smal...

Detailed explanation of MySQL sql_mode query and setting

1. Execute SQL to view select @@session.sql_mode;...

Solve the problem of garbled data in MySQL database migration

Under the instructions of my leader, I took over ...

Nginx service 500: Internal Server Error one of the reasons

500 (Internal Server Error) The server encountere...

Detailed explanation of Linux command file overwrite and file append

1. The difference between the command > and &g...

Analysis of the process of building a cluster environment with Apache and Tomcat

In fact, it is not difficult to build an Apache c...

Common properties of frameset (dividing frames and windows)

A frame is a web page screen divided into several ...

How to set the memory size of Docker tomcat

When installing Tomcat in Docker, Tomcat may over...

A simple example of using Vue3 routing VueRouter4

routing vue-router4 keeps most of the API unchang...

A brief discussion on the role of Vue3 defineComponent

Table of contents defineComponent overload functi...

Priority analysis of and or queries in MySQL

This may be an issue that is easily overlooked. F...

Solve the mobile terminal jump problem (CSS transition, target pseudo-class)

Preface Many friends who have just come into cont...