-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
48 lines (36 loc) · 1.4 KB
/
app.py
File metadata and controls
48 lines (36 loc) · 1.4 KB
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
45
46
47
48
from pathlib import Path
from flask import Flask, jsonify, render_template, current_app, request
from dashboard_data import clear_alerts_collection, get_dashboard_payload
BASE_DIR = Path(__file__).resolve().parent
app = Flask(
__name__,
template_folder=str(BASE_DIR / "templates"),
static_folder=str(BASE_DIR / "static"),
)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/api/dashboard")
def dashboard_api():
try:
limit = request.args.get("limit")
next_token = request.args.get("next")
try:
limit_value = int(limit) if limit is not None else None
except ValueError:
limit_value = None
data = get_dashboard_payload(limit=limit_value, next_token=next_token)
return jsonify(data)
except Exception as exc: # pragma: no cover - defensive logging
current_app.logger.exception("Failed to build dashboard payload: %s", exc)
return jsonify({"error": str(exc)}), 500
@app.route("/api/alerts/clear", methods=["POST"])
def clear_alerts():
try:
data = clear_alerts_collection()
return jsonify(data)
except Exception as exc: # pragma: no cover - defensive logging
current_app.logger.exception("Failed to clear TAXII data: %s", exc)
return jsonify({"error": str(exc)}), 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000, debug=True)