mirror of
https://github.com/hansjone/netx.git
synced 2026-10-09 03:10:46 +08:00
fix(netx): derive ne_id from objectName ME{net_id}
When alarmkey does not contain a net_id, fall back to extracting ME{net_id} from objectName so alarms can join inventory correctly. Add regression coverage for the ME{} objectName pattern.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
626bb2b02e
commit
15d9cb5db3
2 changed files with 13 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import json
|
||||
import logging
|
||||
import hashlib
|
||||
import re
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
|
||||
|
|
@ -81,6 +82,13 @@ def _derive_ne_id_from_alarm(alarm: dict[str, Any]) -> str:
|
|||
parts = [p for p in alarm_key.split() if p]
|
||||
if len(parts) >= 2:
|
||||
return _s(parts[0])
|
||||
|
||||
# Fallback: some alarms encode net_id as ME{<net_id>} in objectName.
|
||||
object_name = _s(_pick(alarm, "objectName", "object-name"))
|
||||
if object_name:
|
||||
m = re.search(r"ME\{([^}]+)\}", object_name, flags=re.IGNORECASE)
|
||||
if m:
|
||||
return _s(m.group(1))
|
||||
return ""
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue