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_741768852 小时前
使用docker的小例子
运维·docker·容器
学习3人组2 小时前
CentOS 中配置 OpenJDK以及多版本管理
linux·运维·centos
厨 神3 小时前
vmware中的ubuntu系统扩容分区
linux·运维·ubuntu
Karoku0663 小时前
【网站架构部署与优化】web服务与http协议
linux·运维·服务器·数据库·http·架构
geek_Chen013 小时前
虚拟机共享文件夹开启后mnt/hgfs/下无sharefiles? --已解决
linux·运维·服务器
(⊙o⊙)~哦3 小时前
linux 解压缩
linux·运维·服务器
最新小梦5 小时前
Docker日志管理
运维·docker·容器
鸡鸭扣6 小时前
虚拟机:3、(待更)WSL2安装Ubuntu系统+实现GPU直通
linux·运维·ubuntu
友友马6 小时前
『 Linux 』HTTP(一)
linux·运维·服务器·网络·c++·tcp/ip·http
千禧年@6 小时前
微服务以及注册中心
java·运维·微服务