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

相关推荐
叫致寒吧8 小时前
Nginx基于域名的虚拟主机实操案例
运维·服务器·nginx
施努卡机器视觉9 小时前
SNK施努卡车门自动化安装
运维·自动化
咕噜签名-铁蛋9 小时前
云服务器与物理服务器、VPS的区别
运维·服务器
恒创科技HK9 小时前
香港服务器流量有限制和带宽有限制区别在哪?
运维·服务器·网络
wanhengidc9 小时前
机架式服务器有什么作用?
运维·服务器·web安全·智能手机·云计算
干啥都是小小白10 小时前
Linux C编程
linux·运维·服务器
司铭鸿10 小时前
化学式解析的算法之美:从原子计数到栈的巧妙运用
linux·运维·服务器·算法·动态规划·代理模式·哈希算法
❀͜͡傀儡师10 小时前
docker部署orion-ops一站式运维管理平台
运维·docker·github
last demo11 小时前
MariaDB 数据库管理
linux·运维·服务器·数据库·php·mariadb
z***438412 小时前
SQL server配置ODBC数据源(本地和服务器)
运维·服务器·github