BE+FE: refactor totals retrieval + LUCIRPC old field name

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2026-02-10 07:39:11 +11:00
parent cedbd59897
commit e899f657c5
10 changed files with 142 additions and 72 deletions

View File

@@ -5,7 +5,7 @@ import ipaddress
from helper import get_setting_value, check_IP_format
from utils.datetime_utils import timeNowDB, normalizeTimeStamp
from logger import mylog, Logger
from const import vendorsPath, vendorsPathNewest, sql_generateGuid
from const import vendorsPath, vendorsPathNewest, sql_generateGuid, NULL_EQUIVALENTS
from models.device_instance import DeviceInstance
from scan.name_resolution import NameResolver
from scan.device_heuristics import guess_icon, guess_type
@@ -97,7 +97,7 @@ FIELD_SPECS = {
"devName": {
"scan_col": "scanName",
"source_col": "devNameSource",
"empty_values": ["", "null", "(unknown)", "(name not found)"],
"empty_values": NULL_EQUIVALENTS,
"default_value": "(unknown)",
"priority": ["NSLOOKUP", "AVAHISCAN", "NBTSCAN", "DIGSCAN", "ARPSCAN", "DHCPLSS", "NEWDEV", "N/A"],
},
@@ -108,7 +108,7 @@ FIELD_SPECS = {
"devLastIP": {
"scan_col": "scanLastIP",
"source_col": "devLastIPSource",
"empty_values": ["", "null", "(unknown)", "(Unknown)"],
"empty_values": NULL_EQUIVALENTS,
"priority": ["ARPSCAN", "NEWDEV", "N/A"],
"default_value": "0.0.0.0",
"allow_override_if_changed": True,
@@ -120,7 +120,7 @@ FIELD_SPECS = {
"devVendor": {
"scan_col": "scanVendor",
"source_col": "devVendorSource",
"empty_values": ["", "null", "(unknown)", "(Unknown)"],
"empty_values": NULL_EQUIVALENTS,
"priority": ["VNDRPDT", "ARPSCAN", "NEWDEV", "N/A"],
},
@@ -131,7 +131,7 @@ FIELD_SPECS = {
"devSyncHubNode": {
"scan_col": "scanSyncHubNode",
"source_col": None,
"empty_values": ["", "null"],
"empty_values": NULL_EQUIVALENTS,
"priority": None,
},
@@ -141,7 +141,7 @@ FIELD_SPECS = {
"devSite": {
"scan_col": "scanSite",
"source_col": None,
"empty_values": ["", "null"],
"empty_values": NULL_EQUIVALENTS,
"priority": None,
},
@@ -151,7 +151,7 @@ FIELD_SPECS = {
"devVlan": {
"scan_col": "scanVlan",
"source_col": "devVlanSource",
"empty_values": ["", "null"],
"empty_values": NULL_EQUIVALENTS,
"priority": None,
},
@@ -161,7 +161,7 @@ FIELD_SPECS = {
"devType": {
"scan_col": "scanType",
"source_col": None,
"empty_values": ["", "null"],
"empty_values": NULL_EQUIVALENTS,
"priority": None,
},
@@ -171,14 +171,14 @@ FIELD_SPECS = {
"devParentMAC": {
"scan_col": "scanParentMAC",
"source_col": "devParentMACSource",
"empty_values": ["", "null"],
"empty_values": NULL_EQUIVALENTS,
"priority": ["SNMPDSC", "UNIFIAPI", "UNFIMP", "NEWDEV", "N/A"],
},
"devParentPort": {
"scan_col": "scanParentPort",
"source_col": None,
"empty_values": ["", "null"],
"empty_values": NULL_EQUIVALENTS,
"priority": ["SNMPDSC", "UNIFIAPI", "UNFIMP", "NEWDEV", "N/A"],
},
@@ -188,7 +188,7 @@ FIELD_SPECS = {
"devSSID": {
"scan_col": "scanSSID",
"source_col": None,
"empty_values": ["", "null"],
"empty_values": NULL_EQUIVALENTS,
"priority": ["SNMPDSC", "UNIFIAPI", "UNFIMP", "NEWDEV", "N/A"],
},
}
@@ -708,16 +708,16 @@ def create_new_devices(db):
raw_name = str(scanName).strip() if scanName else ""
raw_vendor = str(scanVendor).strip() if scanVendor else ""
raw_ip = str(scanLastIP).strip() if scanLastIP else ""
if raw_ip.lower() in ("null", "(unknown)"):
if raw_ip.lower() in NULL_EQUIVALENTS:
raw_ip = ""
raw_ssid = str(scanSSID).strip() if scanSSID else ""
if raw_ssid.lower() in ("null", "(unknown)"):
if raw_ssid.lower() in NULL_EQUIVALENTS:
raw_ssid = ""
raw_parent_mac = str(scanParentMAC).strip() if scanParentMAC else ""
if raw_parent_mac.lower() in ("null", "(unknown)"):
if raw_parent_mac.lower() in NULL_EQUIVALENTS:
raw_parent_mac = ""
raw_parent_port = str(scanParentPort).strip() if scanParentPort else ""
if raw_parent_port.lower() in ("null", "(unknown)"):
if raw_parent_port.lower() in NULL_EQUIVALENTS:
raw_parent_port = ""
# Handle NoneType

View File

@@ -18,6 +18,7 @@ from utils.datetime_utils import timeNowDB
from logger import mylog, Logger
from messaging.reporting import skip_repeated_notifications
from messaging.in_app import update_unread_notifications_count
from const import NULL_EQUIVALENTS, NULL_EQUIVALENTS_SQL
# Make sure log level is initialized correctly
@@ -222,7 +223,7 @@ def insert_events(db):
FROM Devices, CurrentScan
WHERE devMac = scanMac
AND scanLastIP IS NOT NULL
AND scanLastIP NOT IN ('', 'null', '(unknown)', '(Unknown)')
AND scanLastIP NOT IN ({NULL_EQUIVALENTS_SQL})
AND scanLastIP <> COALESCE(devPrimaryIPv4, '')
AND scanLastIP <> COALESCE(devPrimaryIPv6, '')
AND scanLastIP <> COALESCE(devLastIP, '') """)