mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-01-29 09:01:22 -05:00
feat: authoritative plugin fields - fix devLastIP
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -74,7 +74,7 @@ def get_plugin_authoritative_settings(plugin_prefix):
|
||||
return {"set_always": [], "set_empty": []}
|
||||
|
||||
|
||||
def can_overwrite_field(field_name, current_value, current_source, plugin_prefix, plugin_settings, field_value):
|
||||
def can_overwrite_field(field_name, current_value, current_source, plugin_prefix, plugin_settings, field_value, allow_override_if_changed=False):
|
||||
"""
|
||||
Determine if a plugin can overwrite a field.
|
||||
|
||||
@@ -121,7 +121,14 @@ def can_overwrite_field(field_name, current_value, current_source, plugin_prefix
|
||||
return False
|
||||
|
||||
# Rule 5: Default - overwrite if current value empty
|
||||
return current_value in empty_values
|
||||
if current_value in empty_values:
|
||||
return True
|
||||
|
||||
# Rule 6: Optional override flag to allow overwrite if value changed (devLastIP)
|
||||
if allow_override_if_changed and field_value != current_value:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_overwrite_sql_clause(field_name, source_column, plugin_settings):
|
||||
|
||||
@@ -121,6 +121,7 @@ FIELD_SPECS = {
|
||||
"empty_values": ["", "null", "(unknown)", "(Unknown)"],
|
||||
"priority": ["ARPSCAN", "NEWDEV", "N/A"],
|
||||
"default_value": "0.0.0.0",
|
||||
"allow_update_if_changed": True,
|
||||
},
|
||||
|
||||
# ==========================================================
|
||||
@@ -304,6 +305,7 @@ def update_devices_data_from_scan(db):
|
||||
plugin_prefix=source_prefix,
|
||||
plugin_settings=plugin_settings,
|
||||
field_value=new_value,
|
||||
allow_override_if_changed=spec.get("allow_override_if_changed", False)
|
||||
):
|
||||
# Build UPDATE dynamically
|
||||
update_cols = [f"{field} = ?"]
|
||||
|
||||
Reference in New Issue
Block a user