问题
Im newbie in SNMP, but I'm going to make some simple monitoring apps using SNMP and 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,
Can you show me , how to make custom MIB PYSNMP easyly? so i can use it both in manager and agent side :)
Thank you
thank you for your answer I've already read those tuts, but my mib still can not hit the target,
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
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)
But, when i tried to call snmpget :
snmpget -v 2c -c public localhost .1.3.6.1.4.1.2021.9.1.6.1
I found :
iso.3.6.1.4.1.2021.9.1.6.1 = No Such Instance currently exists at this OID
thank you
回答1:
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
See PySNMP distribution for a little automation script (tools/build-pysnmp-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
Do you really need to implement both Manager & Agent Apps?
来源:https://stackoverflow.com/questions/17413123/how-to-make-custom-mib-pysnmp