mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
@@ -12,12 +12,12 @@ from logger import mylog, Logger
|
||||
from helper import (
|
||||
generate_mac_links,
|
||||
removeDuplicateNewLines,
|
||||
timeNowTZ,
|
||||
write_file,
|
||||
get_setting_value,
|
||||
get_timezone_offset,
|
||||
)
|
||||
from messaging.in_app import write_notification
|
||||
from utils.datetime_utils import timeNowDB, get_timezone_offset
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@@ -71,15 +71,15 @@ class NotificationInstance:
|
||||
else:
|
||||
self.HasNotifications = True
|
||||
|
||||
self.GUID = str(uuid.uuid4())
|
||||
self.DateTimeCreated = timeNowTZ()
|
||||
self.DateTimePushed = ""
|
||||
self.Status = "new"
|
||||
self.JSON = JSON
|
||||
self.Text = ""
|
||||
self.HTML = ""
|
||||
self.PublishedVia = ""
|
||||
self.Extra = Extra
|
||||
self.GUID = str(uuid.uuid4())
|
||||
self.DateTimeCreated = timeNowDB()
|
||||
self.DateTimePushed = ""
|
||||
self.Status = "new"
|
||||
self.JSON = JSON
|
||||
self.Text = ""
|
||||
self.HTML = ""
|
||||
self.PublishedVia = ""
|
||||
self.Extra = Extra
|
||||
|
||||
if self.HasNotifications:
|
||||
# if not notiStruc.json['data'] and not notiStruc.text and not notiStruc.html:
|
||||
@@ -113,9 +113,9 @@ class NotificationInstance:
|
||||
mail_html = mail_html.replace("<NEW_VERSION>", newVersionText)
|
||||
|
||||
# Report "REPORT_DATE" in Header & footer
|
||||
timeFormated = timeNowTZ().strftime("%Y-%m-%d %H:%M")
|
||||
mail_text = mail_text.replace("<REPORT_DATE>", timeFormated)
|
||||
mail_html = mail_html.replace("<REPORT_DATE>", timeFormated)
|
||||
timeFormated = timeNowDB()
|
||||
mail_text = mail_text.replace('<REPORT_DATE>', timeFormated)
|
||||
mail_html = mail_html.replace('<REPORT_DATE>', timeFormated)
|
||||
|
||||
# Report "SERVER_NAME" in Header & footer
|
||||
mail_text = mail_text.replace("<SERVER_NAME>", socket.gethostname())
|
||||
@@ -226,7 +226,7 @@ class NotificationInstance:
|
||||
# Updates the Published properties
|
||||
def updatePublishedVia(self, newPublishedVia):
|
||||
self.PublishedVia = newPublishedVia
|
||||
self.DateTimePushed = timeNowTZ()
|
||||
self.DateTimePushed = timeNowDB()
|
||||
self.upsert()
|
||||
|
||||
# create or update a notification
|
||||
@@ -284,17 +284,15 @@ class NotificationInstance:
|
||||
|
||||
# Clear the Pending Email flag from all events and devices
|
||||
def clearPendingEmailFlag(self):
|
||||
# Clean Pending Alert Events
|
||||
self.db.sql.execute(
|
||||
"""
|
||||
|
||||
# Clean Pending Alert Events
|
||||
self.db.sql.execute("""
|
||||
UPDATE Devices SET devLastNotification = ?
|
||||
WHERE devMac IN (
|
||||
SELECT eve_MAC FROM Events
|
||||
WHERE eve_PendingAlertEmail = 1
|
||||
)
|
||||
""",
|
||||
(timeNowTZ(),),
|
||||
)
|
||||
""", (timeNowDB(),))
|
||||
|
||||
self.db.sql.execute("""
|
||||
UPDATE Events SET eve_PendingAlertEmail = 0
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from const import logPath
|
||||
from logger import mylog
|
||||
from utils.datetime_utils import timeNowDB
|
||||
|
||||
|
||||
class UserEventsQueueInstance:
|
||||
@@ -78,3 +80,44 @@ class UserEventsQueueInstance:
|
||||
mylog("minimal", ["[UserEventsQueueInstance] Processed event: ", event])
|
||||
|
||||
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