mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
BE: LangStrings /graphql + /logs endpoint, utils chores
Some checks failed
docker / docker_dev (push) Has been cancelled
Some checks failed
docker / docker_dev (push) Has been cancelled
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
# Register NetAlertX directories
|
||||
INSTALL_PATH="/app"
|
||||
@@ -8,6 +9,7 @@ sys.path.extend([f"{INSTALL_PATH}/server"])
|
||||
# Register NetAlertX modules
|
||||
from const import pluginsPath, logPath, applicationPath, reportTemplatesPath
|
||||
from logger import mylog
|
||||
from utils.datetime_utils import timeNowDB
|
||||
|
||||
class UserEventsQueueInstance:
|
||||
"""
|
||||
@@ -81,5 +83,43 @@ class UserEventsQueueInstance:
|
||||
|
||||
return removed
|
||||
|
||||
def add_event(self, action):
|
||||
"""
|
||||
Append an action to the execution queue log file.
|
||||
|
||||
Args:
|
||||
action (str): Description of the action to queue.
|
||||
|
||||
Returns:
|
||||
tuple: (success: bool, message: str)
|
||||
success - True if the event was successfully added.
|
||||
message - Log message describing the result.
|
||||
"""
|
||||
timestamp = timeNowDB()
|
||||
# Generate GUID
|
||||
guid = str(uuid.uuid4())
|
||||
|
||||
if not action or not isinstance(action, str):
|
||||
msg = "[UserEventsQueueInstance] Invalid or missing action"
|
||||
mylog('none', [msg])
|
||||
|
||||
return False, msg
|
||||
|
||||
try:
|
||||
with open(self.log_file, "a") as f:
|
||||
f.write(f"[{timestamp}]|{guid}|{action}\n")
|
||||
|
||||
msg = f'[UserEventsQueueInstance] Action "{action}" added to the execution queue.'
|
||||
mylog('minimal', [msg])
|
||||
|
||||
return True, msg
|
||||
|
||||
except Exception as e:
|
||||
msg = f"[UserEventsQueueInstance] ERROR Failed to write to {self.log_file}: {e}"
|
||||
mylog('none', [msg])
|
||||
|
||||
return False, msg
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user