Improve SNMP discovery item context
This commit is contained in:
@@ -87,6 +87,7 @@ def _monitorable_items(discovered: DiscoveredSnmpDevice) -> list[SnmpDiscoveryIt
|
||||
group="Device Health",
|
||||
label="Device uptime",
|
||||
unit="seconds",
|
||||
current_value=_format_duration(discovered.uptime_seconds),
|
||||
)
|
||||
)
|
||||
items.extend(
|
||||
@@ -96,6 +97,7 @@ def _monitorable_items(discovered: DiscoveredSnmpDevice) -> list[SnmpDiscoveryIt
|
||||
group=item.group,
|
||||
label=item.label,
|
||||
unit=item.unit,
|
||||
current_value=item.current_value,
|
||||
)
|
||||
for item in discovered.health_items
|
||||
)
|
||||
@@ -109,6 +111,7 @@ def _monitorable_items(discovered: DiscoveredSnmpDevice) -> list[SnmpDiscoveryIt
|
||||
item_type="interface_status",
|
||||
group=group,
|
||||
label=f"{interface.label} status",
|
||||
current_value=_interface_status_value(interface.admin_status, interface.oper_status),
|
||||
),
|
||||
SnmpDiscoveryItemRead(
|
||||
item_id=f"{item_prefix}.traffic",
|
||||
@@ -116,6 +119,7 @@ def _monitorable_items(discovered: DiscoveredSnmpDevice) -> list[SnmpDiscoveryIt
|
||||
group=group,
|
||||
label=f"{interface.label} traffic",
|
||||
unit="bps",
|
||||
current_value="Rate after first check",
|
||||
),
|
||||
SnmpDiscoveryItemRead(
|
||||
item_id=f"{item_prefix}.errors",
|
||||
@@ -127,3 +131,22 @@ def _monitorable_items(discovered: DiscoveredSnmpDevice) -> list[SnmpDiscoveryIt
|
||||
]
|
||||
)
|
||||
return items
|
||||
|
||||
|
||||
def _format_duration(seconds: int | None) -> str | None:
|
||||
if seconds is None:
|
||||
return None
|
||||
days = seconds // 86_400
|
||||
hours = (seconds % 86_400) // 3_600
|
||||
minutes = (seconds % 3_600) // 60
|
||||
if days:
|
||||
return f"{days}d {hours}h"
|
||||
if hours:
|
||||
return f"{hours}h {minutes}m"
|
||||
return f"{minutes}m"
|
||||
|
||||
|
||||
def _interface_status_value(admin_status: str | None, oper_status: str | None) -> str | None:
|
||||
if admin_status and oper_status:
|
||||
return f"admin {admin_status}, oper {oper_status}"
|
||||
return admin_status or oper_status
|
||||
|
||||
Reference in New Issue
Block a user