我是SNMP的新手,但是我将使用SNMP和PYSNMP制作一些简单的监控应用程序
我想用我的自定义MIB监视我的代理(因为当我运行一些MIB时,它无法与PYSNMP一起工作),我已阅读PYSNMP文档,但它似乎无法帮助我,
您能告诉我,如何轻松制作自定义MIB PYSNMP?所以我可以在经理和代理方面使用它:))
谢谢
谢谢你的回答 我已经阅读过这些内容,但是我的mib仍然无法达到目标,
我想在我的分区上读取我的总磁盘,所以这是我的MIB代码:
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
# 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
我找到了:
iso.3.6.1.4.1.2021.9.1.6.1 = No Such Instance currently exists at this OID
谢谢
答案 0 :(得分:1)
使用PySNMP,您可以将MIB文本文件转换为Python代码,该代码为SNMP应用程序的管理员和代理端提供服务。使用smidump&进行转换。像这样的libsmi2pysnmp工具:
$ cat YOUR-MIB.txt | smidump -f python | libsmi2pysnmp > YOUR-MIB.py
请参阅PySNMP发行版以获取一些自动化脚本(tools / build-pysnmp-mib)。
一旦拥有了Pythonized MIB,Manager端就可以将其用于可视化目的(用单词表示OID,美化值)。代理应用程序可以通过添加可以访问您希望管理的主机系统上的值的叶对象来扩展Pythonized MIB。
这是similar question on Agent-side implementation和a blog post on PySNMP MIB conversion process
你真的需要同时实施Manager&代理商应用程序?