When PySNMP's nextCmd() iterates over the table I am working with, it outputs by column, rather than by row. This has proven difficult when trying to save the data into an Object. For example, I will see every value from the alarmID column before moving on to the next column.
So far, I've only created a print statement to output and see how the values are structured. I've been trying to think of a way to solve this, and my mind tends to take me to recursion, but it's something I haven't tried implementing yet.
Here is the function I am working with:
def query_alarm_table(device):
manufacturer = Manufacturer(device.manufacturer)
for (errorIndication, errorStatus, errorIndex, varBinds) in nextCmd(
SnmpEngine(),
CommunityData("public"),
UdpTransportTarget((device.ip_address, device.snmp_port_number)),
ContextData(),
ObjectType(ObjectIdentity(manufacturer.alarm_table)),
lexicographicMode=False,
):
if errorIndication:
print(errorIndication)
break
elif errorStatus:
print("%s at %s" % (errorStatus.prettyPrint(), errorIndex and varBinds[int(errorIndex) - 1][0] or "?",))
break
else:
for oid, raw_value in varBinds:
print(f'oid: {oid} --- raw_value: {raw_value}')
This above function is properly iterating over the table. But I am unsure of how to work with the data as if it were a single row and put it into an Object within my database.