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

Comparison of the usage of EXISTS and IN in MySQL

1. Usage: (1) EXISTS usage select a.batchName,a.p...

Samba server configuration under Centos7 (actual combat)

Samba Overview Samba is a free software that impl...

Remote Desktop Connection between Windows and Linux

When it comes to remote desktop connection to Lin...

Solution to mysql ERROR 1045 (28000) problem

I encountered mysql ERROR 1045 and spent a long t...

25 Examples of Using Circular Elements in Web Design

Today, this post lists some great examples of circ...

JavaScript to achieve mouse tailing effect

Mouse effects require the use of setTimeout to ge...

Ubuntu Server Installation Tutorial in Vmware

This article shares with you the Ubuntu server ve...

How to use Docker container to access host network

Recently, a system was deployed, using nginx as a...

Copy the contents of one file to the end of another file in linux

Problem description: For example, the content of ...

Example analysis of mysql shared lock and exclusive lock usage

This article uses examples to illustrate the usag...

Share JS four fun hacker background effect codes

Table of contents Example 1 Example 2 Example 3 E...