基于官方网络snmp绑定的快速pythonicsnmp库

easysnmp的Python项目详细描述


Build StatusCoverage StatusJoin the chat at https://gitter.im/easysnmp/LobbyLicense

Easy SNMP Logo

艺术作品由Open Clip Art Library

简介

简单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 文件以获取更多详细信息。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用数据库中的值填充p:selectOneMenu   Java/Junit中的异步单元测试一个非常简单但不成功的例子   在Debian上使用Java连接到MySQL   java测试时如何恢复表中的一条记录/行?   java如何将重点放在jbutton上而不是放在另一个jbutton上?   java我可以从HPROF文件中获取JVM标志吗?   java如何使用自定义比较器在2个集合上保留   java让stringTokenizer将一行文本拆分为预定义变量的最佳方法是什么   Kotlin Android/Java字符串日期时间格式,API21   exchange server EWS Java Api自动发现不工作   netbeans是Java新手,似乎无法修复错误;应为类、接口或枚举。274062   我正在尝试将一些scala代码转换为Java8,以创建新的Lambda和并行集合   流中的分配api(java)   用于串行通信的java Python字节数组