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

相关推荐
m0_737302581 天前
火山引擎专有宿主机DDH,物理独占筑牢合规防线
服务器
2501_945837431 天前
火山引擎hfr3i高主频实例,4.0GHz睿频突破性能上限
服务器
墨客希1 天前
systemd + cgroups v2 限制agent资源消耗
运维
wangqiaowq1 天前
llama.cpp + llama-server 的安装部署验证
运维·服务器·llama
m0_737539371 天前
Mariadb 服务器
服务器·数据库·mariadb
wheeldown1 天前
【Linux TCP Socket 实战】 从单客户端到多客户端回声服务器
linux·服务器·tcp/ip
0思必得01 天前
[Web自动化] 爬虫基础
运维·爬虫·python·selenium·自动化·html
looking_for__1 天前
【Linux】网络基础
linux·服务器·网络
克里斯蒂亚诺更新1 天前
vue展示node express调用python解析tdms
服务器·python·express
南棱笑笑生1 天前
20260127让天启AIO-3576Q38开发板跑Rockchip瑞芯微原厂的Buildroot【linux-6.1内核】【使用天启Firefly的DTS】
linux·运维·elasticsearch·rockchip