-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
29 lines (23 loc) · 1020 Bytes
/
Copy pathapi.py
File metadata and controls
29 lines (23 loc) · 1020 Bytes
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
from flask import Flask, request, jsonify
from executor import execute_runbook
app = Flask(__name__)
@app.route("/incident", methods=["POST"])
def handle_incident():
data = request.json
# Alertmanager formatı
if "alerts" in data:
for alert in data["alerts"]:
incident_type = alert.get("labels", {}).get("alertname")
container = alert.get("annotations", {}).get("container", "unknown")
if incident_type:
execute_runbook(incident_type, {"container": container})
return jsonify({"status": "executed"}), 200
# Manuel format
incident_type = data.get("incident_type")
context = data.get("context", {})
if not incident_type or not context.get("container"):
return jsonify({"error": "incident_type and context.container required"}), 400
execute_runbook(incident_type, context)
return jsonify({"status": "executed", "incident": incident_type}), 200
if __name__ == "__main__":
app.run(port=5000, debug=True)