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×tamp={timestamp}&sign={sign}" data = {'msgtype': 'text', 'text': { 'content': Alarm_content,}} req =requests.post(url, json=data) print(req) print(req.text)
zabbix设置:
{ALERT.SUBJECT}
和 {ALERT.MESSAGE}
是 Zabbix 触发器动作中常用的宏变量,用于在告警通知中显示告警的主题和内容。这些变量会在告警发生时自动填充具体的告警信息。
- {ALERT.SUBJECT}:通常表示告警的主题或标题。例如,它可能包含告警的严重性、触发器名称或主机名称等信息。
- {ALERT.MESSAGE}:表示告警的详细消息,通常包含有关告警事件的描述、触发条件以及其他相关信息。