fix: handle "null" string values in SNMP parsing
Some devices (e.g., AirOS 8.7.14) return the literal string "null" for unavailable metrics like UCD CPU stats. Added explicit handling in parse_integer/1 and parse_float/1 to return nil for "null" strings, preventing ArgumentError when attempting binary_to_integer conversion.
This commit is contained in:
parent
1f07b3b640
commit
dd0b29aefb
2 changed files with 11 additions and 0 deletions
|
|
@ -1,6 +1,14 @@
|
|||
CHANGELOG - towerops-web
|
||||
========================
|
||||
|
||||
2026-02-11 - fix: handle "null" string values in SNMP parsing
|
||||
- File: lib/towerops/snmp/profiles/base.ex (parse_integer/1, parse_float/1)
|
||||
Added explicit handling for "null" string values before attempting integer/float
|
||||
conversion. Some devices (e.g., AirOS 8.7.14) return the literal string "null"
|
||||
for unavailable metrics like UCD CPU stats, which caused ArgumentError when
|
||||
parse_integer/parse_float tried to convert them. Now returns nil, which gets
|
||||
coerced to 0 by the || 0 fallback in the calling code.
|
||||
|
||||
2026-02-11 - fix: deduplicate sensors with leading-dot OID differences
|
||||
- File: lib/towerops/snmp/profiles/dynamic.ex (deduplicate_by_oid/1)
|
||||
Normalized OIDs by stripping leading dots when grouping for deduplication.
|
||||
|
|
|
|||
|
|
@ -1434,11 +1434,14 @@ defmodule Towerops.Snmp.Profiles.Base do
|
|||
|
||||
defp parse_integer(value) when is_integer(value), do: value
|
||||
defp parse_integer(""), do: nil
|
||||
defp parse_integer("null"), do: nil
|
||||
defp parse_integer(value) when is_binary(value), do: String.to_integer(value)
|
||||
defp parse_integer(_), do: nil
|
||||
|
||||
defp parse_float(value) when is_float(value), do: value
|
||||
defp parse_float(value) when is_integer(value), do: value / 1.0
|
||||
defp parse_float(""), do: nil
|
||||
defp parse_float("null"), do: nil
|
||||
defp parse_float(value) when is_binary(value), do: String.to_float(value)
|
||||
defp parse_float(_), do: nil
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue