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设置:

相关推荐
不染尘.几秒前
UDP客户服务器模型和UDP协议
服务器·网络·网络协议·计算机网络·udp
太行山有西瓜汁4 分钟前
达梦DTS工具:批量导出与导入DDL脚本完整指南
运维·服务器·数据库
蓝晶之心13 分钟前
Linux rsync ssh方式数据备份
linux·运维·服务器
fengyehongWorld37 分钟前
Linux sudo命令
linux·运维·服务器
WG_1744 分钟前
Linux:缓冲区_glibc封装
linux·运维·服务器
番知了1 小时前
Ubuntu 22.04 常用命令清单
linux·运维·ubuntu
旺仔Sec1 小时前
2026年河北省职业院校技能大赛“网络系统管理”(高职组)网络构建样题
运维·服务器·网络
FF-Studio1 小时前
Ubuntu 24.04 磁盘爆满“灵异“事件:Btrfs, Snapper 与删不掉的空间
linux·运维·人工智能·ubuntu
爱尔兰极光1 小时前
计算机网络--网络层
运维·服务器·计算机网络
Neolnfra1 小时前
Xshell SSH 连接故障排查
运维·服务器·网络·ssh·xshell·运程连接