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 @ 2024-11-05 14:59  刘宏缔的架构森林  阅读(9)  评论(0编辑  收藏  举报