我尝试使用PYSNMP从Windows加载System32(HOST-Resources_MIB)中生成的自定义MIB文件
代码如下:
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]))
我收到一个与无法读取的主机对象标识符相关的错误:
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
MIB文件的开头如下所示:
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 }
似乎主机对象标识符是问题所在,但我找不到解决方案
是否存在允许pysnmp读取主机标识符的解决方法
1)待安装的模块
2)编译mib:
3)检查文件mymib.my是否存在:
相关问题 更多 >
编程相关推荐