[Python] PYSNMP fails to read custom windows MIB

Discussão em 'Python' iniciado por Stack, Maio 21, 2025.

  1. Stack

    Stack Membro Participativo

    I try to load the custom MIB file generated in System32 (HOST-RESSOURCES_MIB) from Windows with PYSNMP.

    Code is the following:

    from pysnmp.hlapi import *
    from pysmi import debug as pysmi_debug
    pysmi_debug.setLogger(pysmi_debug.Debug('compiler'))

    errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
    CommunityData('public', mpModel=0),
    UdpTransportTarget(('localhost', 161)),
    ContextData(),
    ObjectType(ObjectIdentity('HOST-RESOURCES-MIB', 'hrSystemUptime', 0).addAsn1MibSource('file:C:/Users/Fusse/Desktop/SNMP/')))
    )

    if errorIndication:
    print(errorIndication)
    elif errorStatus:
    print('%s at %s' % (errorStatus.prettyPrint(),
    errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
    else:
    for varBind in varBinds:
    print(' = '.join([x.prettyPrint() for x in varBind]))


    I get an error related to the host object identifier which can't be read:

    2020-06-10 13:06:22,601 pysmi: current MIB borrower(s):
    2020-06-10 13:06:22,603 pysmi: trying source FileReader{"C:\Users\Fusse\Desktop\SNMP"}
    2020-06-10 13:06:22,651 pysmi: failing on error Unknown parent symbol: mib_2 at MIB HOST-RESOURCES-MIB from FileReader{"C:\Users\Fusse\Desktop\SNMP"}
    2020-06-10 13:06:22,651 pysmi: no HOST-RESOURCES-MIB found everywhere
    2020-06-10 13:06:22,651 pysmi: MIBs analyzed 0, MIBs failed 1
    2020-06-10 13:06:22,651 pysmi: MIBs parsed 0, MIBs failed 1
    2020-06-10 13:06:22,651 pysmi: MIBs built 0, MIBs failed 1
    2020-06-10 13:06:22,652 pysmi: MIBs available for borrowing 0, MIBs failed 1
    2020-06-10 13:06:22,652 pysmi: MIBs built 0, MIBs failed 1
    2020-06-10 13:06:22,652 pysmi: failing with problem MIBs HOST-RESOURCES-MIB


    The MIB file beginning is the following:

    HOST-RESOURCES-MIB DEFINITIONS ::= BEGIN

    IMPORTS
    DisplayString FROM RFC1213-MIB
    TimeTicks,
    OBJECT-TYPE,
    Counter, Gauge FROM RFC1155-SMI;

    host OBJECT IDENTIFIER ::= { mib-2 25 }


    hrSystem OBJECT IDENTIFIER ::= { host 1 }
    hrStorage OBJECT IDENTIFIER ::= { host 2 }
    hrDevice OBJECT IDENTIFIER ::= { host 3 }
    hrSWRun OBJECT IDENTIFIER ::= { host 4 }
    hrSWRunPerf OBJECT IDENTIFIER ::= { host 5 }
    hrSWInstalled OBJECT IDENTIFIER ::= { host 6 }


    Seems like the host OBJECT IDENTIFIER is the problem but I can't find the solution.

    Is there a workaround to allow pysnmp reading the host identifier ?

    Continue reading...

Compartilhe esta Página