简体   繁体   English

如何在PySNMP中实现自定义MIB?

[英]How do I implement a custom MIB in PySNMP?

I already have the MIB text file (do I need to make this into a .py file somehow??). 我已经有了MIB文本文件(我是否需要以某种方式将其转换为.py文件?)。 I am trying to use PySNMP (not net-snmp). 我正在尝试使用PySNMP(不是net-snmp)。 I have been able to connect to my device and print out some info, but the info was not very helpful (just ObjectName, ObjectIdentifier, etc). 我已经能够连接到我的设备并打印出一些信息,但信息不是很有用(只是ObjectName,ObjectIdentifier等)。 I want to be able to communicate with the device (send commands to change and read values), but all of the tutorials I have seen seem to be of little help. 我希望能够与设备通信(发送命令来更改和读取值),但我看到的所有教程似乎都没什么帮助。 Does anyone know how I can use my custom MIB to effectively communicate with my device? 有谁知道如何使用我的自定义MIB与我的设备进行有效通信? Any good sites I am missing? 我遗失的任何好网站? http://pysnmp.sourceforge.net/ is ok, but I need something else... http://pysnmp.sourceforge.net/没关系,但我需要别的......

To use MIBs with pysnmp you should first convert your MIB into pysnmp format (which is a collection of Python objects). 要将MIB与pysnmp一起使用,首先应将MIB转换为pysnmp格式(这是Python对象的集合)。 The conversion is done with the pysnmp/tools/build-pysnmp-mib shell script in the following manner: 使用pysnmp / tools / build-pysnmp-mib shell脚本以下列方式完成转换:

$ sh build-pysnmp-mib -h
build-pysnmp-mib: illegal option -- h
Convert MIB text file into PySNMP-compliant module, see http://pysnmp.sf.net.
Usage: build-pysnmp-mib [-o pysnmp-mib-file ] [ mib-text-file ]

Make sure you also have libsmi installed (pysnmp scripts use the smidump tool from libsmi distribution). 确保你也安装了libsmi(pysnmp脚本使用libsmi发行版的smidump工具)。

Unless you put your new pysnmp MIB file into pysnmp/smi/mibs/ (which is not a good idea), you would also have to point pysnmp to the location where your own MIBs are. 除非你将新的pysnmp MIB文件放入pysnmp / smi / mibs /(这不是一个好主意),否则你还必须将pysnmp指向你自己的MIB所在的位置。 This could be done as explained here . 这可以按照此处的说明完成。

Once you are done with the MIB, you can use it from your scripts as explained here . 一旦你与MIB做,你可以作为解释的从你的脚本中使用它在这里

You could make a quick check how your new MIB works by invoking pysnmpget/pysnmpset tools shipped with the pysnmp-apps package. 您可以通过调用pysnmp-apps软件包附带的pysnmpget / pysnmpset工具快速检查新MIB的工作原理。

BTW, chances are that the MIB you need to work with is already converted into pysnmp format and distributed with the pysnmp-mibs package. 顺便说一下,您需要使用的MIB已经转换为pysnmp格式并与pysnmp-mibs包一起分发。

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

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