You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.7 KiB
Python

9 months ago
# -*- coding: utf-8 -*-
import requests
import brotli
import datetime
import socket
def push_metrics(hostname, workline, application, alert_value, receivers, create_time, text):
headers = {
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIyMDk5LTEyLTMxVDIzOjU5OjU5WiIsImlhdCI6MTY0OTk2MDU3OCwicHJpbmNpcGFsIjoibGl1emlxaWFuZyIsIndvcmtsaW5lIjoiQuS8muWRmOS4muWKoSJ9.NYXj0Lg4Ljh5DLO5N-BL_510XJ16jUSJzLowOOqTMjU',
'Content-Type': 'application/json',
}
create_time = "" + str(create_time) + ""
message = f'{text}'
print(message)
json_data = {
"level": 5,
"title": "小川服务报警",
'receivers': receivers,
'application': application,
'metric': '5分钟pod重启率>30%',
'alarm_value': "30%",
'metric_value': alarm_value,
'source': 'prometheus',
'create_time': create_time,
'message': message,
'interval': 300,
'check_times': 1,
'workline': workline,
'auto_recover': 1,
'hostname': hostname,
'status': "resolved"
}
try:
result = requests.post('http://devops.cc.xunlei.cn:8097/v1/generic_alarm', headers=headers, json=json_data)
print(result.content.decode('utf-8'), result.status_code)
except Exception as e:
print(e)
if __name__ == '__main__':
workline = "xiaochuan"
hostname = socket.gethostname()
recievers = "sunhong,18101243983"
current_time = datetime.datetime.now()
create_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
text = "review 服务5xx每秒超过100"
alarm_value = 0
application = "review"
push_metrics(workline, hostname, application, alarm_value, recievers, create_time, text)