python snmp 自动化2在python中使用snmp

上传人:我*** 文档编号:135970166 上传时间:2020-06-21 格式:DOC 页数:32 大小:59KB
返回 下载 相关 举报
python snmp 自动化2在python中使用snmp_第1页
第1页 / 共32页
python snmp 自动化2在python中使用snmp_第2页
第2页 / 共32页
python snmp 自动化2在python中使用snmp_第3页
第3页 / 共32页
python snmp 自动化2在python中使用snmp_第4页
第4页 / 共32页
python snmp 自动化2在python中使用snmp_第5页
第5页 / 共32页
点击查看更多>>
资源描述

《python snmp 自动化2在python中使用snmp》由会员分享,可在线阅读,更多相关《python snmp 自动化2在python中使用snmp(32页珍藏版)》请在金锄头文库上搜索。

1、python snmp 自动化2在python中使用snmp python snmp 自动化2-在python中使用snmp#2012-02-23 磁针石#承接软件自动化实施与培训 验证码破解 软件破解 脚本开发 测试和python培训等#gtalk: ouyangchongwu# qq 博客:#版权所有,转载刊登请来函联系#自动化测试和python群组: http:/ qq group: 深圳自动化测试python群:#武冈深圳qq群: 都梁深圳湖南户外群:#参考资料为什么不使用pysnmp? Pysnmp是一个纯python的snmp模块,不过我们的mib文件,大概有20%的,Pysnmp

2、不能成功读取,报错如下:# build-pysnmp-mib-o fsp150cm-sa.mib.txt fsp150cm-sa.mibWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in

3、 smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: emp

4、ty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output

5、 at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule name seen in smidump output at CM-SA-MIBWARNING: empty MIBmodule na

6、me seen in smidump output at CM-SA-MIBTraceback (mostrecent call last): File /usr/bin/libsmi2pysnmp, line5, in pkg_resources.run_script(pysnmp=4.2.1,libsmi2pysnmp) File /usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py,line 489, in run_script File/usr/lib/python2.7/site-p

7、ackages/setuptools-0.6c11-py2.7.egg/pkg_resources.py,line 1214, in run_script File/usr/lib/python2.7/site-packages/pysnmp-4.2.1-py2.7.egg/EGG-INFO/scripts/libsmi2pysnmp,line 435, in File/usr/lib/python2.7/site-packages/pysnmp-4.2.1-py2.7.egg/EGG-INFO/scripts/libsmi2pysnmp,line 147, in _genTypeDef Ke

8、yError: syntaxsmidump -k -fpython fsp150cm-sa.mib | /usr/bin/libsmi2pysnmp failsmake sure you areusing libsmi version > 0.4.5 (or svn) 网上有篇netsnmp和pysnmp比较的评论:This isnt so muchan answer as much as me sharing my experience testing these libraries. I ran somesnmpwalk benchmarks on PySNMP 4.x and ne

9、t-snmp using pythonsmultiprocessing.Pool. Benchmarks were pretty dirty (basically scaled up thethread pool until I didnt get any performance gains), so reader be-ware.Heres some observations: netsnmps pythonbindings: * Could pull down 11958 oids/sec on thequad core test box. * Didnt consume a lot of

10、 CPU. Seemed to bewaiting on network I/O most of the time (keep reading). * Didnt support snmpbulkwalk,unfortunately. So this generates more network traffic and a single thread ofexecution tends to be slow. * It has some annoying MIB look upbehavior. I had to specify ifName instead of IF-MIB:ifName,

11、 which couldlead to some ambiguity. I also couldnt seem to find a way to control MIBlookups very well. * Threading will not work well. Even if youwant one thread of execution, run it in a separate process so you dont starveother threads. This library is thread safe, but not thread friendly. PySNMP4:

12、 * Came in at 5560 oids/sec on the same box. * Very CPU intensive. I attribute this tothe packet parsing being done in python. * MIB lookups I thought were really nice. * snmpwalks would leak some unrelated OIDs.For example, Id walk IF-MIB:ifXTable and at the end Id getIF-MIB:ifStackTable. IF-MIB du

13、mp. * Id almost certainly tailor a wrapper formy application instead of using this library directly. Specifically Id wrapall the error handling to use Exceptions. * Im not a big fan of writing/readingasynchronous code, so Id just ignore all the async bits and run big SNMPoperations in a separate pro

14、cess. Overall, Imreally kind of disappointed. Theres really not a best overalllibrary. Apart from the API and performance, PySNMP4 is great. Apart fromhaving some strange MIB/oid lookup handling behavior and not supporting manybulk operations, NetSNMPs python bindings were great. 可见pysnmp强在mib解析等方面,

15、性能方面不能和netsnmp媲美。既然我们的mib pysnmp无法解析,只好放弃,期待pysnmp尽快开发出自己的好的mib解析器。只有选择netsnmp。 为什么不使用subprocess? Subprocess会经常出现超时。 Python Get示例:单个get:print Get ntpClientEnabledoid = netsnmp.Varbind(1.3.6.1.4.1,2544.1.12.2.1.10.1.0)oidList = netsnmp.VarList(oid)resultList = netsnmp.snmpget(oid,Version=2,DestHost=172.

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 事务文书

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号