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

相关推荐
极地星光1 天前
版本发布流程手册:Release分支规范与Bug分级标准全解析
运维
三坛海会大神5551 天前
Linux服务器资源自动监控与报警脚本详解
linux·运维·服务器
CookieCrusher1 天前
数据泄露危机逼近:五款电脑加密软件为企业筑起安全防线
运维·数据库·windows·安全·文件加密·数据防泄漏·dlp
小薛博客1 天前
17、DevOps持续集成、持续部署
运维·ci/cd·devops
霍格沃兹软件测试开发1 天前
Browser Use:打造你的浏览器自动化助手
运维·自动化
fuyongliang1231 天前
linux Nginx服务配置介绍,和配置流程
运维·服务器·网络
UNbuff_01 天前
Linux bzip2 命令使用说明
linux·运维·服务器
小马哥编程1 天前
DNS解析中的服务器协作机制
服务器·git·github
IOT-Power1 天前
Ubuntu下把 SD 卡格式化为 FAT32
linux·运维·ubuntu
嫩萝卜头儿1 天前
虚拟地址空间:从概念到内存管理的底层逻辑
linux·服务器·网络