Add optional temperature support to SNMP checker

- New temperature_oid config parameter
- Temperature published as integer via MQTT
- Auto-creates Home Assistant temperature sensor via MQTT Discovery

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-26 17:47:01 +01:00
parent c72117e6e1
commit 10fad0d9f3
3 changed files with 47 additions and 3 deletions

View File

@@ -19,16 +19,22 @@ class SnmpChecker(BaseChecker):
port = self.config.get("port", 161)
community = self.config.get("community", "public")
oid = self.config.get("oid", "1.3.6.1.2.1.1.1.0") # sysDescr
temperature_oid = self.config.get("temperature_oid")
timeout_val = self.config.get("timeout", 5)
start = time.time()
try:
with Slim() as slim:
# Build list of OIDs to query
oids = [ObjectType(ObjectIdentity(oid))]
if temperature_oid:
oids.append(ObjectType(ObjectIdentity(temperature_oid)))
error_indication, error_status, error_index, var_binds = await slim.get(
community,
host,
port,
ObjectType(ObjectIdentity(oid)),
*oids,
timeout=timeout_val,
retries=1
)
@@ -48,12 +54,23 @@ class SnmpChecker(BaseChecker):
response_time=None
)
else:
values = {str(oid): str(val) for oid, val in var_binds}
details = {str(oid): str(val) for oid, val in var_binds}
# Extract temperature if configured
if temperature_oid:
for oid_key, val in var_binds:
if str(oid_key) == temperature_oid:
try:
details["temperature"] = int(val)
except (ValueError, TypeError):
pass # Ignore if not a valid integer
break
return CheckResult(
success=True,
message="SNMP response OK",
response_time=response_time,
details=values
details=details
)
except Exception as e:
return CheckResult(