基于官方网络snmp绑定的快速pythonicsnmp库
easysnmp的Python项目详细描述
简介
简单snmp是官方的分支Net-SNMP Python Bindings 但是试图给图书馆带来一个更像Python的界面支票 为了更多 有关SNMP的信息
此模块提供一个功能齐全的SNMP客户端API,支持所有 SNMP协议的方言
为什么是另一个图书馆?
- original Net-SNMP Python library 是一个很好的起点,但很不象话,缺乏适当的 单元测试和文档。
- PySNMP是用纯python编写的 因此有着巨大的性能冲击。在一些简短的测试中,我 估计net snmp python绑定和easy snmp都是 速度快了4倍多。此外,pysnmp的 pythonic接口比官方的net snmp绑定。
- 许多其他的图书馆 Snimpy很遗憾 基于pysnmp,因此它们遭受相同的性能损失。
快速启动
使用Easy SNMP库的方法主要有两种。
第一种是使用最适合的会话对象 当您计划从 来源。
fromeasysnmpimportSession# Create an SNMP session to be used for all our requestssession=Session(hostname='localhost',community='public',version=2)# You may retrieve an individual OID using an SNMP GETlocation=session.get('sysLocation.0')# You may also specify the OID as a tuple (name, index)# Note: the index is specified as a string as it can be of other types than# just a regular integercontact=session.get(('sysContact','0'))# And of course, you may use the numeric OID toodescription=session.get('.1.3.6.1.2.1.1.1.0')# Set a variable using an SNMP SETsession.set('sysLocation.0','The SNMP Lab')# Perform an SNMP walksystem_items=session.walk('system')# Each returned item can be used normally as its related type (str or int)# but also has several extended attributes with SNMP-specific informationforiteminsystem_items:print'{oid}.{oid_index} {snmp_type} = {value}'.format(oid=item.oid,oid_index=item.oid_index,snmp_type=item.snmp_type,value=item.value)
您也可以通过其简单的接口使用easy snmp 对于一次性操作,您希望在 请求:
fromeasysnmpimportsnmp_get,snmp_set,snmp_walk# Grab a single piece of information using an SNMP GETsnmp_get('sysDescr.0',hostname='localhost',community='public',version=1)# Perform an SNMP SET to update datasnmp_set('sysLocation.0','My Cool Place',hostname='localhost',community='public',version=1)# Perform an SNMP walksnmp_walk('system',hostname='localhost',community='public',version=1)
文件
请查看Easy SNMP documentation at Read the Docs。这包括安装 各种操作系统的说明。
您可以按如下方式生成文档:
# Install Sphinx pip install sphinx # You may optionally export the READTHEDOCS environment variable to build docs # on systems where you haven't built the C interface exportREADTHEDOCS=1# Build the documentation into static HTML pages cd docs make html
致谢
我要感谢以下参与这个项目的人 可能:
- giovanni marzot:原作者
- sciencelogic,llc:发起了这项技术的初步开发 模块
- wes hardaker和net snmp编码器:为他们的辛勤工作和 奉献精神
运行测试
您可以按如下方式运行单元测试:
git clone https://github.com/fgimian/painter.git cd painter python setup.py test
许可证
Easy SNMP是在bsd许可证下发布的。请看 LICENSE 文件以获取更多详细信息。
版权
此库的原始版本版权所有(C)2006 G.S.Marzot。 保留所有权利。
这个程序是免费软件;你可以重新发布和/或修改它 与net snmp本身的术语相同。
版权所有(C)2006斯巴达,公司保留所有权利。这个程序是 自由软件;你可以在同一版本下重新发布和/或修改它 术语为net snmp本身。