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】
运维·docker·容器
文言一心7 小时前
LINUX离线升级 Python 至 3.11.9 操作手册
linux·运维·python
北邮刘老师8 小时前
A3C Network:智能体互联网的层次化视图
运维·服务器·网络
XRJ040618xrj8 小时前
如何在Linux中根据物理网卡建立虚拟网卡
linux·服务器·网络
空中楼阁,梦幻泡影9 小时前
LoRA 详细解析,使用LoRA 方式对模型进行微调详细操作指南
运维·服务器·人工智能·机器学习·语言模型
晚风吹长发9 小时前
初步了解Linux中的动静态库及其制作和使用
linux·运维·服务器·数据结构·c++·后端·算法
Le_ee9 小时前
dc4打靶报告
运维·服务器·网络
yeflx10 小时前
解决Ubuntu22.04宿主机docker容器中nvidia-smi偶发失效问题
运维·docker·容器
4t4run10 小时前
28、Linux 系统定时任务
linux·运维·服务器
~黄夫人~10 小时前
Ansible 自动化运维:从 “手动输密码” 到 “一键免密管理”
linux·运维·自动化·ansible