feat: Enhance plugin configurations and improve MAC normalization

This commit is contained in:
Jokob @NetAlertX
2026-01-21 01:58:52 +00:00
parent 3ee21ac830
commit 478b018fa5
34 changed files with 1117 additions and 63 deletions

View File

@@ -44,7 +44,7 @@ from models.user_events_queue_instance import UserEventsQueueInstance # noqa: E
from models.event_instance import EventInstance # noqa: E402 [flake8 lint suppression]
# Import tool logic from the MCP/tools module to reuse behavior (no blueprints)
from plugin_helper import is_mac # noqa: E402 [flake8 lint suppression]
from plugin_helper import is_mac, normalize_mac # noqa: E402 [flake8 lint suppression]
# is_mac is provided in mcp_endpoint and used by those handlers
# mcp_endpoint contains helper functions; routes moved into this module to keep a single place for routes
from messaging.in_app import ( # noqa: E402 [flake8 lint suppression]
@@ -469,33 +469,28 @@ def api_device_field_lock(mac, payload=None):
if not field_name:
return jsonify({"success": False, "error": "fieldName is required"}), 400
# Validate that the field can be locked
source_field = field_name + "Source"
allowed_tracked_fields = {
"devMac", "devName", "devLastIP", "devVendor", "devFQDN",
"devSSID", "devParentMAC", "devParentPort", "devParentRelType", "devVlan"
}
if field_name not in allowed_tracked_fields:
return jsonify({"success": False, "error": f"Field '{field_name}' cannot be locked"}), 400
device_handler = DeviceInstance()
normalized_mac = normalize_mac(mac)
try:
# When locking: set source to LOCKED
# When unlocking: check current value and let plugins take over
new_source = "LOCKED" if should_lock else "NEWDEV"
result = device_handler.updateDeviceColumn(mac, source_field, new_source)
if result.get("success"):
action = "locked" if should_lock else "unlocked"
return jsonify({
"success": True,
"message": f"Field {field_name} {action}",
"fieldName": field_name,
"locked": should_lock
})
if should_lock:
result = device_handler.lockDeviceField(normalized_mac, field_name)
action = "locked"
else:
return jsonify(result), 400
result = device_handler.unlockDeviceField(normalized_mac, field_name)
action = "unlocked"
response = dict(result)
response["fieldName"] = field_name
response["locked"] = should_lock
if response.get("success"):
response.setdefault("message", f"Field {field_name} {action}")
return jsonify(response)
if "does not support" in response.get("error", ""):
response["error"] = f"Field '{field_name}' cannot be {action}"
return jsonify(response), 400
except Exception as e:
mylog("none", f"Error locking field {field_name} for {mac}: {str(e)}")
return jsonify({"success": False, "error": str(e)}), 500