如何制作自定义MIB PYSNMP [英] How to make custom MIB PYSNMP

查看:440
本文介绍了如何制作自定义MIB PYSNMP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SNMP的新手,但是我将使用SNMP和PYSNMP制作一些简单的监视应用程序

Im newbie in SNMP, but I'm going to make some simple monitoring apps using SNMP and PYSNMP

我想用我的自定义MIB监视我的代理(因为当我运行某些MIB时,它不能与PYSNMP一起使用),我已经阅读了PYSNMP文档,但似乎无济于事,

I want to monitor my agent with my custom MIB (because when i run some MIB, it can not work with PYSNMP), I've read PYSNMP documentation, but it seems can not help me,

您能告诉我,如何轻松制作自定义MIB PYSNMP吗?这样我就可以在经理和代理商端使用它了:)

Can you show me , how to make custom MIB PYSNMP easyly? so i can use it both in manager and agent side :)

谢谢

感谢您的回答 我已经读过这些话了,但是我的mib仍然无法达到目标,

thank you for your answer I've already read those tuts, but my mib still can not hit the target,

我想读取我的分区上的Total Disk,所以这是我的MIB代码:

I want read my Total Disk on my partition , so here is my MIB CODE :

DISKTOTAL-MIB DEFINITIONS ::= BEGIN

IMPORTS
        OBJECT-TYPE, Integer32, NOTIFICATION-TYPE
                     FROM SNMPv2-SMI
;

internet OBJECT IDENTIFIER ::= { iso(1) org(3) dod(6) 1 }
enterprises OBJECT IDENTIFIER ::= { internet private(4) 1 }
ucdavis OBJECT IDENTIFIER ::= { enterprises 2021 }
diskcheck OBJECT IDENTIFIER ::= { ucdavis 9 }
snmpdiskcheck OBJECT IDENTIFIER ::= { diskcheck 1 }
totaldisk OBJECT IDENTIFIER ::= { snmpdiskcheck 6 }

diskTotal OBJECT-TYPE
    SYNTAX Integer32
    MAX-ACCESS read-only
    STATUS current
    DESCRIPTION "Total size of disk on partition."
    ::= { totaldisk 1 }

END

生成此代码后,这是我在py中的MIB

after generating this code, here is my MIB in py

# PySNMP SMI module. Autogenerated from smidump -f python DISKTOTAL-MIB
# by libsmi2pysnmp-0.1.3 at Wed Jul  3 01:30:48 2013,
# Python version sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)

# Imports

( Integer, ObjectIdentifier, OctetString, ) = mibBuilder.importSymbols("ASN1", "Integer", "ObjectIdentifier", "OctetString")
( NamedValues, ) = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues")
( ConstraintsIntersection, ConstraintsUnion, SingleValueConstraint, ValueRangeConstraint, ValueSizeConstraint, ) = mibBuilder.importSymbols("ASN1-REFINEMENT", "ConstraintsIntersection", "ConstraintsUnion", "SingleValueConstraint", "ValueRangeConstraint", "ValueSizeConstraint")
( Bits, Integer32, Integer32, MibIdentifier, NotificationType, MibScalar, MibTable, MibTableRow, MibTableColumn, TimeTicks, ) = mibBuilder.importSymbols("SNMPv2-SMI", "Bits", "Integer32", "Integer32", "MibIdentifier", "NotificationType", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "TimeTicks")

# Objects

internet = MibIdentifier((1, 3, 6, 1))
enterprises = MibIdentifier((1, 3, 6, 1, 4, 1))
ucdavis = MibIdentifier((1, 3, 6, 1, 4, 1, 2021))
diskcheck = MibIdentifier((1, 3, 6, 1, 4, 1, 2021, 9))
snmpdiskcheck = MibIdentifier((1, 3, 6, 1, 4, 1, 2021, 9, 1))
totaldisk = MibIdentifier((1, 3, 6, 1, 4, 1, 2021, 9, 1, 6))
diskTotal = MibScalar((1, 3, 6, 1, 4, 1, 2021, 9, 1, 6, 1), Integer32()).setMaxAccess("readonly")
if mibBuilder.loadTexts: diskTotal.setDescription("Total size of disk on partition.")

# Augmentions

# Exports

# Objects
mibBuilder.exportSymbols("DISKTOTAL-MIB", internet=internet, enterprises=enterprises, ucdavis=ucdavis, diskcheck=diskcheck, snmpdiskcheck=snmpdiskcheck, totaldisk=totaldisk, diskTotal=diskTotal)

但是,当我尝试致电snmpget时: snmpget -v 2c -c public localhost .1.3.6.1.4.1.2021.9.1.6.1

But, when i tried to call snmpget : snmpget -v 2c -c public localhost .1.3.6.1.4.1.2021.9.1.6.1

我发现了:

iso.3.6.1.4.1.2021.9.1.6.1 = No Such Instance currently exists at this OID

谢谢

推荐答案

使用PySNMP,您可以将MIB文本文件转换为Python代码,该代码可同时为SNMP应用程序的Manager和Agent端提供服务.转换是使用Smidump&像这样的libsmi2pysnmp工具:

With PySNMP you have MIB text file converted into Python code which serves both Manager and Agent sides of your SNMP app. The conversion is performed with the smidump & libsmi2pysnmp tools like this:

$ cat YOUR-MIB.txt | smidump -f python | libsmi2pysnmp > YOUR-MIB.py

请参阅PySNMP分发以获取一些自动化脚本(tools/build-pysnmp-mib).

See PySNMP distribution for a little automation script (tools/build-pysnmp-mib).

一旦有了Python化的MIB,管理器端就可以将其用于可视化目的(用文字表示OID,修饰值).代理应用程序可以通过添加对您要管理的主机系统上的值具有访问权限的叶对象来扩展Python化的MIB.

Once you have a Pythonized MIB, Manager side can use it for visualization purposes (represent OIDs in words, prettify values). Agent application can extend Pythonized MIB by adding leaf objects that have access to the values on the host system you wish to manage.

这是与代理端实施类似的问题类似的问题

Here's a similar question on Agent-side implementation and a blog post on PySNMP MIB conversion process

您是否真的需要同时实现Manager&代理程式应用程式?

Do you really need to implement both Manager & Agent Apps?

这篇关于如何制作自定义MIB PYSNMP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆