zabbix4.0 实现钉钉告警

python 复制代码
 cat /etc/zabbix/zabbix_server.conf | grep "alert"

ll /usr/lib/zabbix/alertscripts

钉钉机器人接入文档: 自定义机器人接入 - 钉钉开放平台

钉钉告警文件放在/usr/lib/zabbix/alertscripts/dingding2.py中

复制代码
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import requests
import time
import hmac
import hashlib
import base64
import urllib.parse
import sys

filename = sys.argv[1].strip()
filename2 = sys.argv[2].strip()

# 将三个参数组合在一起,并过滤掉空行
Alarm_content = "\n".join([line for line in [filename, filename2,] if line])



timestamp = str(round(time.time() * 1000))
secret = 'Sxxxxxxxxxxxxxx0'
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
url=f"https://oapi.dingtalk.com/robot/send?access_token=ev&timestamp={timestamp}&sign={sign}"
data = {'msgtype': 'text',
        'text': { 'content': Alarm_content,}}

req =requests.post(url, json=data)
print(req)
print(req.text)

zabbix设置:

相关推荐
❀͜͡傀儡师7 分钟前
docker部署PruneMate
运维·docker·容器
咕噜签名-铁蛋8 分钟前
云服务器地域选择:从技术架构到业务增长的战略决策
服务器
k***921620 分钟前
Linux救援模式是什么,如何使用
linux·运维·服务器
oMcLin28 分钟前
Systemd 深度解析:理解并掌握 Linux 的现代启动系统
linux·运维·服务器
深耕AI1 小时前
【Docker使用】从拉取到运行
运维·docker·容器
蒜丶1 小时前
openEuler 22.03 修改 ssh 22 端口
运维·ssh
小明_GLC1 小时前
关于在window系统安装虚拟机出现不兼容的问题:如何禁用Hyper-V
运维·安装冲突
不屈的铝合金1 小时前
MySQL 数据库服务多实例部署指南
运维·数据库·mysql·多实例部署·维度隔离
The Mr.Nobody2 小时前
如何配置群晖网盘客户端Synology Drive Client
服务器
学习者0072 小时前
NE相关知识之------路由知识
运维·服务器