pysnmp does not show the data like snmpwalk does

49 views Asked by At

i'm trying to fetch the hrstorage and hrDevice using pysnmp. this is the code I'm using in pysnmp:

def snmp_walk_v2c(ip, community_string, snmp_list):
    parsed_dict = {}
    for obj in snmp_list:
        snmp_data = nextCmd(SnmpEngine(),
                          CommunityData(community_string, mpModel=1),
                          UdpTransportTarget((ip, 161), timeout=3),
                          ContextData(),
                          ObjectType(ObjectIdentity(obj['mib_file'], obj['object_table'])),
                          lexicographicMode=False,
                          lookupNames=True, lookupValues=True)
        obj_data = []
        for (errorIndication, errorStatus, errorIndex, varBinds) in snmp_data: 
            if errorIndication:
                print(f"SNMP Walk Error: {errorIndication}")
                break
            elif errorStatus:
                print(f"SNMP Walk Error: {errorStatus.prettyPrint()}")
                break
            else:
                for varBind in varBinds:
                    print(f"Data: {varBind.prettyPrint()}")
                    obj_data.append(str(varBind))

        parsed_dict[obj['name']] = obj_data
        parsed_dict['ip'] = ip
    
    # print(parsed_dict)
    
    json_message = json.dumps(parsed_dict)

and for the snmp list, I'm using this:

dt_lst = [
    {'name': 'hrstorage', 'oid': '1.3.6.1.2.1.25.2', 'mib_file': 'HOST-RESOURCES-MIB', 'object_table': 'hrStorageTable'},
    {'name': 'hrDevice', 'oid': '1.3.6.1.2.1.25.3', 'mib_file': 'HOST-RESOURCES-MIB', 'object_table': 'hrDevice'},
]

now when I do this, I get this data for hrdevice's hrdevicetype:

Data: HOST-RESOURCES-MIB::hrDeviceType.196608 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.196609 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.196610 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.196611 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.196612 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.196613 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.196614 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.196615 = HOST-RESOURCES-MIB::hrDeviceTypes.3
Data: HOST-RESOURCES-MIB::hrDeviceType.262145 = HOST-RESOURCES-MIB::hrDeviceTypes.4
Data: HOST-RESOURCES-MIB::hrDeviceType.262146 = HOST-RESOURCES-MIB::hrDeviceTypes.4
Data: HOST-RESOURCES-MIB::hrDeviceType.786432 = HOST-RESOURCES-MIB::hrDeviceTypes.12

but when I do it using snmpwalk I get the following data:

HOST-RESOURCES-MIB::hrDeviceType.196608 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.196609 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.196610 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.196611 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.196612 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.196613 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.196614 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.196615 = OID: HOST-RESOURCES-TYPES::hrDeviceProcessor
HOST-RESOURCES-MIB::hrDeviceType.262145 = OID: HOST-RESOURCES-TYPES::hrDeviceNetwork
HOST-RESOURCES-MIB::hrDeviceType.262146 = OID: HOST-RESOURCES-TYPES::hrDeviceNetwork
HOST-RESOURCES-MIB::hrDeviceType.786432 = OID: HOST-RESOURCES-TYPES::hrDeviceCoprocessor

I want the actual value like snmpwalk which I'm not getting with pysnmp, what is the issue and what can I do to solve it. this also applies for hrdevice's hrfsType and hrstorage's hrstorageType

0

There are 0 answers