mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
BE/PLG: TZ timestamp work #1251
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ from dateutil import parser
|
||||
INSTALL_PATH="/app"
|
||||
sys.path.extend([f"{INSTALL_PATH}/server"])
|
||||
|
||||
from helper import timeNowTZ, get_setting_value, check_IP_format
|
||||
from helper import timeNowDB, timeNowTZ, get_setting_value, check_IP_format
|
||||
from logger import mylog, Logger
|
||||
from const import vendorsPath, vendorsPathNewest, sql_generateGuid
|
||||
from models.device_instance import DeviceInstance
|
||||
@@ -56,7 +56,7 @@ def exclude_ignored_devices(db):
|
||||
#-------------------------------------------------------------------------------
|
||||
def update_devices_data_from_scan (db):
|
||||
sql = db.sql #TO-DO
|
||||
startTime = timeNowTZ().astimezone().isoformat()
|
||||
startTime = timeNowDB()
|
||||
|
||||
# Update Last Connection
|
||||
mylog('debug', '[Update Devices] 1 Last Connection')
|
||||
@@ -371,7 +371,7 @@ def print_scan_stats(db):
|
||||
#-------------------------------------------------------------------------------
|
||||
def create_new_devices (db):
|
||||
sql = db.sql # TO-DO
|
||||
startTime = timeNowTZ()
|
||||
startTime = timeNowDB()
|
||||
|
||||
# Insert events for new devices from CurrentScan (not yet in Devices)
|
||||
|
||||
@@ -536,7 +536,7 @@ def update_devices_names(pm):
|
||||
if isinstance(last_checked, str):
|
||||
try:
|
||||
last_checked = parser.parse(last_checked)
|
||||
except Exception as e:
|
||||
except (ValueError, TypeError) as e:
|
||||
mylog('none', f'[Update Device Name] Could not parse last_checked timestamp: {last_checked!r} ({e})')
|
||||
last_checked = None
|
||||
elif not isinstance(last_checked, datetime.datetime):
|
||||
@@ -544,7 +544,6 @@ def update_devices_names(pm):
|
||||
|
||||
# Collect and normalize valid state update timestamps for name-related plugins
|
||||
state_times = []
|
||||
latest_state = None
|
||||
|
||||
for p in name_plugins:
|
||||
state_updated = pm.plugin_states.get(p, {}).get("stateUpdated")
|
||||
@@ -561,13 +560,15 @@ def update_devices_names(pm):
|
||||
mylog('none', f'[Update Device Name] Failed to parse timestamp for {p}: {state_updated!r} ({e})')
|
||||
else:
|
||||
mylog('none', f'[Update Device Name] Unexpected timestamp type for {p}: {type(state_updated)}')
|
||||
# Determine the latest valid timestamp safely
|
||||
try:
|
||||
if state_times:
|
||||
latest_state = max(state_times)
|
||||
except Exception as e:
|
||||
mylog('none', f'[Update Device Name] Failed to determine latest timestamp, using fallback ({e})')
|
||||
latest_state = state_times[-1] if state_times else None
|
||||
|
||||
# Determine the latest valid timestamp safely (after collecting all timestamps)
|
||||
latest_state = None
|
||||
try:
|
||||
if state_times:
|
||||
latest_state = max(state_times)
|
||||
except (ValueError, TypeError) as e:
|
||||
mylog('none', f'[Update Device Name] Failed to determine latest timestamp, using fallback ({e})')
|
||||
latest_state = state_times[-1] if state_times else None
|
||||
|
||||
|
||||
# Skip if no plugin state changed since last check
|
||||
@@ -672,7 +673,7 @@ def update_devices_names(pm):
|
||||
|
||||
# --- Step 3: Log last checked time ---
|
||||
# After resolving names, update last checked
|
||||
pm.name_plugins_checked = timeNowTZ().astimezone().isoformat()
|
||||
pm.name_plugins_checked = timeNowDB()
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Updates devPresentLastScan for parent devices based on the presence of their NICs
|
||||
|
||||
@@ -12,7 +12,7 @@ sys.path.extend([f"{INSTALL_PATH}/server"])
|
||||
import conf
|
||||
from const import *
|
||||
from logger import mylog
|
||||
from helper import timeNowTZ, get_setting_value
|
||||
from helper import get_setting_value
|
||||
|
||||
# Load MAC/device-type/icon rules from external file
|
||||
MAC_TYPE_ICON_PATH = Path(f"{INSTALL_PATH}/back/device_heuristics_rules.json")
|
||||
|
||||
@@ -6,7 +6,7 @@ sys.path.extend([f"{INSTALL_PATH}/server"])
|
||||
|
||||
import conf
|
||||
from scan.device_handling import create_new_devices, print_scan_stats, save_scanned_devices, exclude_ignored_devices, update_devices_data_from_scan
|
||||
from helper import timeNowTZ, get_setting_value
|
||||
from helper import timeNowDB, get_setting_value
|
||||
from db.db_helper import print_table_schema
|
||||
from logger import mylog, Logger
|
||||
from messaging.reporting import skip_repeated_notifications
|
||||
@@ -128,7 +128,7 @@ def create_sessions_snapshot (db):
|
||||
#-------------------------------------------------------------------------------
|
||||
def insert_events (db):
|
||||
sql = db.sql #TO-DO
|
||||
startTime = timeNowTZ()
|
||||
startTime = timeNowDB()
|
||||
|
||||
# Check device down
|
||||
mylog('debug','[Events] - 1 - Devices down')
|
||||
@@ -191,7 +191,7 @@ def insert_events (db):
|
||||
def insertOnlineHistory(db):
|
||||
sql = db.sql # TO-DO: Implement sql object
|
||||
|
||||
scanTimestamp = timeNowTZ()
|
||||
scanTimestamp = timeNowDB()
|
||||
|
||||
# Query to fetch all relevant device counts in one go
|
||||
query = """
|
||||
|
||||
Reference in New Issue
Block a user