mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
🔒DB lock v0.4 #685 + 🔔userNotifications
This commit is contained in:
@@ -173,6 +173,7 @@ def main ():
|
||||
pluginsState = run_plugin_scripts(db, all_plugins, 'on_notification', pluginsState)
|
||||
notification.setAllProcessed()
|
||||
notification.clearPendingEmailFlag()
|
||||
|
||||
|
||||
|
||||
else:
|
||||
|
||||
@@ -287,7 +287,7 @@ def importConfigs (db, all_plugins):
|
||||
|
||||
|
||||
# save the newly discovered plugins as options and default values
|
||||
conf.LOADED_PLUGINS = ccd('LOADED_PLUGINS', loaded_plugins_prefixes , c_d, 'Loaded plugins', 'text.multiselect', str(all_plugins_prefixes), 'General')
|
||||
conf.LOADED_PLUGINS = ccd('LOADED_PLUGINS', loaded_plugins_prefixes , c_d, 'Loaded plugins', 'text.multiselect', str(sorted(all_plugins_prefixes)), 'General')
|
||||
|
||||
mylog('none', ['[Config] Number of Plugins to load: ', len(loaded_plugins_prefixes)])
|
||||
mylog('none', ['[Config] Plugins to load: ', loaded_plugins_prefixes])
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user