mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-04 01:01:35 -07: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": []}
|
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.
|
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
|
return False
|
||||||
|
|
||||||
# Rule 5: Default - overwrite if current value empty
|
# 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):
|
def get_overwrite_sql_clause(field_name, source_column, plugin_settings):
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ FIELD_SPECS = {
|
|||||||
"empty_values": ["", "null", "(unknown)", "(Unknown)"],
|
"empty_values": ["", "null", "(unknown)", "(Unknown)"],
|
||||||
"priority": ["ARPSCAN", "NEWDEV", "N/A"],
|
"priority": ["ARPSCAN", "NEWDEV", "N/A"],
|
||||||
"default_value": "0.0.0.0",
|
"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_prefix=source_prefix,
|
||||||
plugin_settings=plugin_settings,
|
plugin_settings=plugin_settings,
|
||||||
field_value=new_value,
|
field_value=new_value,
|
||||||
|
allow_override_if_changed=spec.get("allow_override_if_changed", False)
|
||||||
):
|
):
|
||||||
# Build UPDATE dynamically
|
# Build UPDATE dynamically
|
||||||
update_cols = [f"{field} = ?"]
|
update_cols = [f"{field} = ?"]
|
||||||
|
|||||||
Reference in New Issue
Block a user