🔒DB lock v0.4 #685 + 🔔userNotifications

This commit is contained in:
jokob-sk
2024-06-01 20:05:15 +10:00
parent 2e9aa37cd2
commit de561e1ad0
29 changed files with 1932 additions and 1460 deletions

View File

@@ -3,6 +3,7 @@ import json
import uuid
import socket
import subprocess
import requests
from json2table import convert
# Register NetAlertX modules
@@ -181,6 +182,9 @@ class Notification_obj:
self.Text = final_text
self.HTML = final_html
# Notify frontend
write_notification("Report:" + self.GUID, "alert")
self.upsert()
return self
@@ -234,6 +238,39 @@ class Notification_obj:
self.save()
def write_notification(content, level="interrupt"):
NOTIFICATION_API_FILE = apiPath + 'user_notifications.json'
# Generate GUID
guid = str(uuid.uuid4())
# Generate timestamp
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Prepare notification dictionary
notification = {
'timestamp': timestamp,
'guid': guid,
'read': 0,
'level': level,
'content': content
}
# If file exists, load existing data, otherwise initialize as empty list
if os.path.exists(NOTIFICATION_API_FILE):
with open(NOTIFICATION_API_FILE, 'r') as file:
notifications = json.load(file)
else:
notifications = []
# Append new notification
notifications.append(notification)
# Write updated data back to file
with open(NOTIFICATION_API_FILE, 'w') as file:
json.dump(notifications, file, indent=4)
def clearPendingEmailFlag(self):
# Clean Pending Alert Events