-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
44 lines (36 loc) · 1.29 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
Author: llody [email protected]
Date: 2024-05-29 16:54:49
LastEditors: llody [email protected]
LastEditTime: 2024-05-30 10:40:38
FilePath: \K8S\组件包\云原生监控\prometheus-llody\weixin_robot\main.py
Description: 微信机器人通知
'''
import os
import sys
import json
import Alert
import argparse
from flask import Flask, request
from flask_json import FlaskJSON, as_json
from gevent import pywsgi
app = Flask(__name__)
FlaskJSON(app)
@app.route('/alertinfo', methods=['POST'])
@as_json
def alert_data():
data = request.get_data()
json_re = json.loads(data) # 解析接收到的数据为JSON
Alert.send_alert(json_re, args.key)
return json_re
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Run the alert notification service.")
parser.add_argument("-p", "--port", type=int, default=os.getenv('PORT', 5000), help="The service port")
parser.add_argument("-k", "--key", type=str, default=os.getenv('KEY', 'default_key'), help="The webhook url key")
args = parser.parse_args()
if not args.port or not args.key:
parser.print_help()
sys.exit(1)
print("Weixin robot 启动成功,正在监听端口:{}".format(args.port))
server = pywsgi.WSGIServer(('0.0.0.0', args.port), app)
server.serve_forever()