alertmanager: python发送报警信息到alert manager

一,代码:

import requests
import json

def send_alert(url,summary,description):
    data = [{
        "labels":{
            "job":"mysql",
            "alertname": summary,
            "severity": "critical"
        },
        "annotations":{
            "description": description
        },
    }]
    headers = {'Content-Type': 'application/json'}
    jsons = json.dumps(data)
    response = requests.post(url=url, headers=headers, data=jsons)
    print(response)
    if response.status_code ==200:
        print("Alert sent successfully.")
    else:
        print("Failed to send alert.")


url="http://127.0.0.1:9093/api/v2/alerts"
summary="服务器host报错1"
description="报错信息:abcd"
send_alert(url,summary,description)

 

posted @   刘宏缔的架构森林  阅读(26)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
历史上的今天:
2022-11-05 php:在linux上用sudo提升权限(centos 8 / PHP 7.4.2)
点击右上角即可分享
微信分享提示