fix: normalize OID format for sysObjectID matching

LibreNMS uses leading dot format (.1.3.6.1...) but SNMP returns
OIDs without leading dot (1.3.6.1...). Normalize by prepending
dot to sys_object_id before matching, and use starts_with instead
of contains for more accurate prefix matching.
This commit is contained in:
Graham McIntire 2026-01-17 18:18:38 -06:00
parent 007adcc489
commit 6c6b68f8fb
No known key found for this signature in database

View file

@ -170,12 +170,17 @@ defmodule Towerops.DeviceProfiles do
defp match_rule?(%DetectionRule{rule_type: "sysObjectID"} = rule, system_info) do
sys_object_id = Map.get(system_info, :sys_object_id, "")
# Normalize OID - prepend dot if not present for pattern matching
# LibreNMS uses ".1.3.6.1..." format, SNMP returns "1.3.6.1..." format
normalized_oid = if String.starts_with?(sys_object_id, "."), do: sys_object_id, else: "." <> sys_object_id
cond do
rule.pattern && rule.pattern != "" ->
String.contains?(sys_object_id, rule.pattern)
String.starts_with?(normalized_oid, rule.pattern)
rule.value && rule.value != "" ->
sys_object_id == rule.value
normalized_value = if String.starts_with?(rule.value, "."), do: rule.value, else: "." <> rule.value
normalized_oid == normalized_value
true ->
false