Create universal.py
taylor_socfortress committed
Jul 10, 2023 at 16:43 UTC
747052cf0a2cf4a64897f78363d791300c41f9f3
1 file changed
+41
backend/app/services/Graylog/universal.py
new
+41
@@ -0,0 +1,41 @@
1
+from app.models.agents import (
2
+ AgentMetadata,
3
+ agent_metadata_schema,
4
+ agent_metadatas_schema,
5
+)
6
+from app import db
7
+from datetime import datetime
8
+import requests
9
+from loguru import logger
10
+from app.models.connectors import connector_factory, Connector, GraylogConnector
11
+
12
+
13
+class UniversalService:
14
+ """
15
+ A service class that encapsulates the logic for polling messages from Graylog.
16
+ """
17
+
18
+ def __init__(self) -> None:
19
+ self.collect_graylog_details("Graylog")
20
+
21
+ def collect_graylog_details(self, connector_name: str):
22
+ """
23
+ Collects the details of the Graylog connector.
24
+
25
+ Args:
26
+ connector_name (str): The name of the Graylog connector.
27
+
28
+ Returns:
29
+ tuple: A tuple containing the connection URL, username, and password.
30
+ """
31
+ connector_instance = connector_factory.create(connector_name, connector_name)
32
+ connection_successful = connector_instance.verify_connection()
33
+ if connection_successful:
34
+ connection_details = Connector.get_connector_info_from_db(connector_name)
35
+ return (
36
+ connection_details.get("connector_url"),
37
+ connection_details.get("connector_username"),
38
+ connection_details.get("connector_password"),
39
+ )
40
+ else:
41
+ return None, None, None