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

相关推荐
测试修炼手册9 小时前
[测试工具] 用 Codex 做测试实战:从需求分析到自动化用例落地
运维·自动化·需求分析
米高梅狮子9 小时前
03.网络类服务实践
linux·运维·服务器·网络·kubernetes·centos·openstack
June`9 小时前
网络编程时内核究竟做了什么???
linux·服务器·网络
原来是猿9 小时前
腾讯云服务器端口开放完全指南
服务器·网络·腾讯云
你的保护色10 小时前
【无标题】
java·服务器·网络
Elnaij10 小时前
Linux系统与系统编程(9)——自设计shell与基础IO
linux·服务器
IpdataCloud10 小时前
稳定的企业级IP数据接口怎么选?可用性指标+离线库高可用方案
运维·网络·tcp/ip
WebGIS开发10 小时前
地信职业百科②:GIS运维
运维·gis·就业·转行
淘矿人10 小时前
Claude辅助DevOps实践
java·大数据·运维·人工智能·算法·bug·devops
JiaWen技术圈10 小时前
nginx 安全响应头 介绍
运维·nginx·安全