Create graylog.py
taylor_socfortress committed
Jul 10, 2023 at 16:40 UTC
b262db52227a8b6873e3f72765d166e97488638d
1 file changed
+85
backend/app/routes/graylog.py
new
+85
@@ -0,0 +1,85 @@
1
+from flask import Blueprint, jsonify, request
2
+from loguru import logger
3
+from app.models.connectors import Connector, WazuhManagerConnector
4
+
5
+from app.services.Graylog.messages import MessagesService
6
+from app.services.Graylog.metrics import MetricsService
7
+from app.services.Graylog.index import IndexService
8
+from app.services.Graylog.inputs import InputsService
9
+from app.services.WazuhManager.wazuhmanager import WazuhManagerService
10
+
11
+bp = Blueprint("graylog", __name__)
12
+
13
+
14
+@bp.route("/graylog/messages", methods=["GET"])
15
+def get_messages():
16
+ """
17
+ Endpoint to collect the latest 10 messages from Graylog.
18
+
19
+ Returns:
20
+ json: A JSON response containing the list of all the messages.
21
+ """
22
+ service = MessagesService()
23
+ messages = service.collect_messages()
24
+ return messages
25
+
26
+
27
+@bp.route("/graylog/metrics", methods=["GET"])
28
+def get_metrics():
29
+ """
30
+ Endpoint to collect Graylog metrics.
31
+
32
+ Returns:
33
+ json: A JSON response containing the list of all metrics
34
+ """
35
+ service = MetricsService()
36
+ uncommitted_journal_size = service.collect_uncommitted_journal_size()
37
+ metrics = service.collect_throughput_metrics()
38
+ return jsonify(
39
+ {"uncommitted_journal_size": uncommitted_journal_size, "metrics": metrics}
40
+ )
41
+
42
+
43
+@bp.route("/graylog/indices", methods=["GET"])
44
+def get_indices():
45
+ """
46
+ Endpoint to collect Graylog indices.
47
+
48
+ Returns:
49
+ json: A JSON response containing the list of all indices
50
+ """
51
+ service = IndexService()
52
+ indices = service.collect_indices()
53
+ return indices
54
+
55
+
56
+@bp.route("/graylog/indices/<index_name>/delete", methods=["DELETE"])
57
+def delete_index(index_name):
58
+ """
59
+ Endpoint to delete a Graylog index.
60
+
61
+ Args:
62
+ index_name (str): The name of the index to be deleted.
63
+
64
+ Returns:
65
+ json: A JSON response containing the result of the deletion.
66
+ """
67
+ service = IndexService()
68
+ result = service.delete_index(index_name)
69
+ return result
70
+
71
+
72
+@bp.route("/graylog/inputs", methods=["GET"])
73
+def get_inputs():
74
+ """
75
+ Endpoint to collect Graylog inputs.
76
+
77
+ Returns:
78
+ json: A JSON response containing the list of all inputs
79
+ """
80
+ service = InputsService()
81
+ running_inputs = service.collect_running_inputs()
82
+ configured_inputs = service.collect_configured_inputs()
83
+ return jsonify(
84
+ {"running_inputs": running_inputs, "configured_inputs": configured_inputs}
85
+ )