Skip to content
Snippets Groups Projects
Commit fd7ecb8e authored by Taya Snijder's avatar Taya Snijder
Browse files

added named_value support

parent 3e8f6d64
Branches
Tags
1 merge request!288Resolve L2SS-446 "Extend snmp client to support mib files"
......@@ -111,7 +111,7 @@ class SNMP_client(CommClient):
def load_mib(mib_name):
mibBuilder = builder.MibBuilder()
mibBuilder.loadModule(mib_name)
class snmp_attribute:
......@@ -200,19 +200,39 @@ class snmp_attribute:
varBinds = varBinds[0]
for varBind in varBinds:
# class 'DisplayString' doesnt want to play along for whatever reason
if "DisplayString" in str(type(varBind[1])):
vals.append(varBind[1].prettyPrint())
elif type(varBind[1]) == hlapi.IpAddress:
# Get all the types. Custom and base. Custom types are merely wrapped base types.
varbind_types = varBind[1].__class__.__bases__ + (type(varBind[1]),)
snmp_type = None
for i in varbind_types:
if i in snmp_to_numpy_dict.keys():
snmp_type = i
if snmp_type is None:
TypeError(f"Error: did not find a valid snmp type. Got: {varbind_types}, expected one of: {snmp_to_numpy_dict.keys()}")
if snmp_type == hlapi.IpAddress:
# IpAddress values get printed as their raw value but in hex (7F 20 20 01 for 127.0.0.1 for example)
vals.append(varBind[1].prettyPrint())
elif snmp_type == hlapi.Integer32 and self.dtype == str:
# Integers can have 'named values', Where a value can be translated to a specific name. A dict basically
# Example: {1: "other", 2: "invalid", 3: "dynamic", 4: "static",}
if varBind[1].namedValues == {}:
# An empty dict {} means no namedValue's are present.
vals.append(snmp_to_numpy_dict[snmp_type](varBind[1]))
else:
# append the named values string instead of the raw number.
vals.append(varBind[1].prettyPrint())
else:
# convert from the funky pysnmp types to numpy types and then append
vals.append(snmp_to_numpy_dict[type(varBind[1])](varBind[1]))
vals.append(snmp_to_numpy_dict[snmp_type](varBind[1]))
if self.is_scalar:
vals = vals[0]
return vals
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment