简体   繁体   English

pysnmp-从NET-SNMP-EXTEND-MIB扩展脚本获取输出?

[英]pysnmp - get output from NET-SNMP-EXTEND-MIB extend script?

How can I properly invoke an SNMP extend script by MIB with pysnmp 4.3? 如何使用pysnmp 4.3通过MIB正确调用SNMP扩展脚本?

I have this entry in the remote server's snmpd.conf file: 我在远程服务器的snmpd.conf文件中有此条目:

extend check_fd_wap /app/users/nagios_checks/check_fd_wap.sh

which in turn can be invoked by: 依次可以由以下方式调用:

snmpwalk -t 60 -v2c -c greendale remoteserver 'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."check_fd_wap"'
NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."check_fd_wap" = STRING: { "sys_inuse" : 32640, "proc_data" : {  "ssl-mmsib" : { "proc_used" : 22, "proc_limit" : 200000 } , (...) }

In pysnmp I'm trying to invoke MIB NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."check_fd_wap" using the sample code: 在pysnmp中,我尝试使用示例代码来调用MIB NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."check_fd_wap"

errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
        CommunityData(community, mpModel=1),
        UdpTransportTarget((hostname, port)),
        ContextData(),
        ObjectType(ObjectIdentity('NET-SNMP-EXTEND-MIB','nsExtendOutput1Line','check_fd_wap')))
)

for varBind in varBinds:
    print(' = '.join([x.prettyPrint() for x in varBind]))

However, this fails with the 'DisplayString' failed to cast value OctetString error message: 但是,此操作失败,并且'DisplayString' failed to cast value OctetString错误消息:

raise SmiError('MIB object %r having type %r failed to cast value %r: %s' % (self.__args[0].prettyPrint(), self.__args[0].getMibNode().getSyntax().__class__.__name__, self.__args[1], sys.exc_info()[1]))
;SmiError: MIB object u'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.check_fd_wap' having type 'DisplayString' failed to cast value OctetString('{ "sys_inuse" (...)"" at DisplayString

However, calling it with the translated OID works fine ( '.1.3.6.1.4.1.8072.1.3.2.3.1.1.12.99.104.101.99.107.95.102.100.95.119.97.112' ). 但是,使用转换后的OID调用可以正常工作( '.1.3.6.1.4.1.8072.1.3.2.3.1.1.12.99.104.101.99.107.95.102.100.95.119.97.112' )。

SNMPv2-SMI::enterprises.8072.1.3.2.3.1.1.12.99.104.101.99.107.95.102.100.95.119.97.112 = { "sys_inuse" : 31110, "proc_data" : {  "ssl-mmsib" : { "proc_used" : 19, "proc_limit" : 200000 } } }

What is the reason for this error? 此错误的原因是什么?

Also, if I invoke the getCmd with the full MIB NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.check_fd_wap as one argument, I get the error: 另外,如果我使用完整的MIB NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.check_fd_wap作为一个参数调用getCmd, MIB NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.check_fd_wap收到错误消息:

pysnmp.smi.error.NoSuchObjectError: NoSuchObjectError({'str': 'Can\'t resolve node name ::(\'NET-SNMP-EXTEND-MIB::nsExtendOutput1Line\', \'"check_fd_wap"\') at <pysnmp.smi.view.MibViewController instance at 0x2989638>'})

Is it possible to invoke the SNMP get with the full MIB in one string? 是否可以在一个字符串中调用带有完整MIB的SNMP get?

This failure: 此失败:

'DisplayString' failed to cast value OctetString

happens when pysnmp receives a response from SNMP Agent for requested OID 当pysnmp从SNMP代理收到请求的OID的响应时

1.3.6.1.4.1.8072.1.3.2.3.1.1.12.99.104.101.99.107.95.102.100.95.119.97.112

(which corresponds to NET-SNMP-EXTEND-MIB::nsExtendOutput1Line.check_fd_wap MIB object) and then it tried to convert response value ( { "sys_inuse" : 32640, "proc... ) into human-friendly DisplayString representation. At that point pysnmp failed but the exact cause is not included in your report for some reason. (它对应于NET-SNMP-EXTEND-MIB :: nsExtendOutput1Line.check_fd_wap MIB对象),然后尝试将响应值( {“ sys_inuse”:32640,“ proc ...” )转换为人类友好的DisplayString表示形式。 pysnmp点失败,但是由于某种原因,确切原因未包含在您的报告中。

I am guessing that response string sent by your SNMP Agent may accidentally exceed the length of 255 characters (which is a constraint of DisplayString type ). 我猜测您的SNMP代理发送的响应字符串可能会意外超过255个字符的长度(这是DisplayString type约束 )。

Formally correct solution is to make SNMP Agent response for that MIB object fitting 255 ASCII characters to satisfy DisplayString type limits. 形式上正确的解决方案是针对适合255个ASCII字符的MIB对象做出SNMP代理响应,以满足DisplayString类型的限制。

Alternatively, you could disable MIB lookup for response values in pysnmp by passing lookupMib=False keyword argument to getCmd() function. 另外,您可以通过将lookupMib = False关键字参数传递给getCmd()函数来禁用pysnmp中的MIB查找响应值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM