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

相关推荐
软件资深者几秒前
免费的2026网刻工具, 轻松解决局域网电脑批量还原问题
运维·服务器·负载均衡
A-刘晨阳6 分钟前
K8S 部署 CoreDNS 之 DNS 域名获取
运维·云原生·容器·kubernetes·dns·coredns
爱内卷的学霸一枚10 分钟前
现代DevOps实践:从CI/CD到GitOps的深度技术解析
运维·ci/cd·devops
松涛和鸣12 分钟前
69、Linux字符设备驱动实战
linux·服务器·网络·arm开发·数据库·驱动开发
新缸中之脑14 分钟前
在Docker中运行OpenClaw
运维·docker·容器
女王大人万岁15 分钟前
Go语言JSON标准库(encoding/json):功能解析与实战指南
服务器·开发语言·后端·golang·json
cyber_两只龙宝24 分钟前
haproxy--使用socat工具实现对haproxy权重配置的热更新
linux·运维·负载均衡·haproxy·socat
“αβ”25 分钟前
IP协议内容补充
服务器·网络·网络协议·tcp/ip·智能路由器·nat·ip协议
zhang61839927 分钟前
Linux中不同服务器之间迁移python 虚拟环境-conda-pack
linux·运维·python
深圳市恒讯科技30 分钟前
2026新加坡服务器硬件防火墙配置推荐
运维·服务器·云计算