mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
BE: logging fix and comments why eve_PendingAlertEmail not cleared
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -75,7 +75,7 @@ def main ():
|
|||||||
updateState("Initializing", None, None, None, 0)
|
updateState("Initializing", None, None, None, 0)
|
||||||
|
|
||||||
# Open DB once and keep open
|
# Open DB once and keep open
|
||||||
# Opening / closing DB frequently actually casues more issues
|
# Opening/closing the DB frequently actually causes more issues
|
||||||
db = DB() # instance of class DB
|
db = DB() # instance of class DB
|
||||||
db.open()
|
db.open()
|
||||||
sql = db.sql # To-Do replace with the db class
|
sql = db.sql # To-Do replace with the db class
|
||||||
@@ -148,12 +148,14 @@ def main ():
|
|||||||
mylog('debug', [f'[MAIN] processScan: {processScan}'])
|
mylog('debug', [f'[MAIN] processScan: {processScan}'])
|
||||||
|
|
||||||
if processScan == True:
|
if processScan == True:
|
||||||
mylog('debug', "[MAIN] start processig scan results")
|
mylog('debug', "[MAIN] start processing scan results")
|
||||||
process_scan(db)
|
process_scan(db)
|
||||||
updateState("Scan processed", None, None, None, None, False)
|
updateState("Scan processed", None, None, None, None, False)
|
||||||
|
|
||||||
# --------
|
# ------------------------------------------------------------------------------
|
||||||
# Reporting
|
# Reporting
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# run plugins before notification processing (e.g. Plugins to discover device names)
|
# run plugins before notification processing (e.g. Plugins to discover device names)
|
||||||
pm.run_plugin_scripts('before_name_updates')
|
pm.run_plugin_scripts('before_name_updates')
|
||||||
|
|
||||||
@@ -181,19 +183,29 @@ def main ():
|
|||||||
notification = NotificationInstance(db)
|
notification = NotificationInstance(db)
|
||||||
notificationObj = notification.create(final_json, "")
|
notificationObj = notification.create(final_json, "")
|
||||||
|
|
||||||
# run all enabled publisher gateways
|
# ------------------------------------------------------------------------------
|
||||||
|
# Run all enabled publisher gateways (notification delivery)
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Design notes:
|
||||||
|
# - The eve_PendingAlertEmail flag is only cleared *after* a notification is sent.
|
||||||
|
# - If no notification is sent (HasNotifications == False), the flag stays set,
|
||||||
|
# meaning the event may still trigger alerts later depending on user settings
|
||||||
|
# (e.g. down-event reporting, delay timers, plugin conditions).
|
||||||
|
# - A pending flag means “still under evaluation,” not “missed.”
|
||||||
|
# It will clear automatically once its event is included in a sent alert.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
if notificationObj.HasNotifications:
|
if notificationObj.HasNotifications:
|
||||||
|
|
||||||
pm.run_plugin_scripts('on_notification')
|
pm.run_plugin_scripts('on_notification')
|
||||||
notification.setAllProcessed()
|
notification.setAllProcessed()
|
||||||
|
|
||||||
# clear pending email flag
|
# Only clear pending email flags and plugins_events once notifications are sent.
|
||||||
# and the plugin events
|
|
||||||
notification.clearPendingEmailFlag()
|
notification.clearPendingEmailFlag()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# If there are no notifications to process,
|
# If there are no notifications to process,
|
||||||
# we still need to clear all plugin events
|
# we still need to clear all plugin events to prevent database growth if
|
||||||
|
# no notification gateways are configured
|
||||||
notification.clearPluginEvents()
|
notification.clearPluginEvents()
|
||||||
mylog('verbose', ['[Notification] No changes to report'])
|
mylog('verbose', ['[Notification] No changes to report'])
|
||||||
|
|
||||||
|
|||||||
@@ -223,6 +223,15 @@ def get_notifications (db):
|
|||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
def skip_repeated_notifications (db):
|
def skip_repeated_notifications (db):
|
||||||
|
"""
|
||||||
|
Skips sending alerts for devices recently notified.
|
||||||
|
|
||||||
|
Clears `eve_PendingAlertEmail` for events linked to devices whose last
|
||||||
|
notification time is within their `devSkipRepeated` interval.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
db: Database object with `.sql.execute()` and `.commitDB()`.
|
||||||
|
"""
|
||||||
|
|
||||||
# Skip repeated notifications
|
# Skip repeated notifications
|
||||||
# due strfime : Overflow --> use "strftime / 60"
|
# due strfime : Overflow --> use "strftime / 60"
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ sys.path.extend([f"{INSTALL_PATH}/server"])
|
|||||||
# Register NetAlertX modules
|
# Register NetAlertX modules
|
||||||
import conf
|
import conf
|
||||||
from const import applicationPath, logPath, apiPath, reportTemplatesPath
|
from const import applicationPath, logPath, apiPath, reportTemplatesPath
|
||||||
from logger import mylog
|
from logger import mylog, Logger
|
||||||
from helper import generate_mac_links, \
|
from helper import generate_mac_links, \
|
||||||
removeDuplicateNewLines, \
|
removeDuplicateNewLines, \
|
||||||
timeNowTZ, \
|
timeNowTZ, \
|
||||||
@@ -46,6 +46,9 @@ class NotificationInstance:
|
|||||||
);
|
);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
# Make sure log level is initialized correctly
|
||||||
|
Logger(get_setting_value('LOG_LEVEL'))
|
||||||
|
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
# Method to override processing of notifications
|
# Method to override processing of notifications
|
||||||
|
|||||||
Reference in New Issue
Block a user