I want to read all the objects from the MIB file that a manager has.
I developed one tool to get some data from a SNMP enabled agent. I want to enhance that tool by showing all the OIDs form the manager's MIB file.
I am using the NET-SNMP library.
I saw the following:
/usr/local/share/snmp/mibs/
folder and it contains many MIB files, but how can I form a list of the OIDs it has?
I went through the MIBs and saw the structures, but how do I get the OIDs of each and every object mentioned in the MIB files?
I want to list all the OIDs as follows:
SNMPv2-MIB::sysDescr.0 = .1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysObjectID.0 = .1.3.6.1.2.1.1.2.0
... etc
I want to scan all the MIB files and find all the OIDs from the files.
How do I do this?
Use snmptranslate-command from net-snmp library. Try it with the following paramenters:
-M "directory containing your MIB file"
-m ALL
-Pu
-Tso
After some problems I managed to generate the OIDs using the following command.
snmptranslate -Pu -Tz -M ~/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp:`pwd` -m module_name_NOT_file_name > module_name.oid
To pull the OIDs from a running SNMP server you might like to use the tool snmpwalk using the -Ci option . The tool comes with Net-SNMP.
The other two SO QAs show how you can do it without walking a running system:
"net-snmp sample code to parse MIB file and extract trap related information from it": The answer shows the top-level framework of a C parser which is based on top of the Net-SNMP library.
"Get oid's type (syntax) from MIB using Net-SNMP API": It is the specific function to handle an OID.
That is only the starting point. There is a lot of coding ahead from there.
Update: The another nice tool is the perl SNMP compiler packaged in SNMP::MIB::Compiler. With a script in perl you get all the MIB elements/components pulled into internal data structures and you can pick any information from there, either by looking into the structure tree or by dumping the tree and do a post-parsing on the dump.
Related
I find that with Net-SNMP, I can get the normal ifPhysAddress result .But when I use SNMP4J,I get some wrong result.How to fix it ?
The Net-SNMP result:
The snmp4j result:
That's absolutely normal.
NET-SNMP ships with a set of default MIB documents, so when it makes SNMP operations derived data types (like PhysAddress for ifPhysAddress) can be interpreted more accurately according to the MIB documents.
However, when you consume the raw SNMP4J library, MIB documents are not involved and the only way is to print out ifPhysAddress as the base type of OCTET STRING which is effectively raw bytes and garble characters.
If you like to achieve the same output like NET-SNMP, you can buy SNMP4J's MIB library or search for other alternative ways.
i want to send snmp trap using pysnmp library for database(postgresql). like when database goes down send a trap, similarly for when database goes up send another trap.
so now my question is how to define or create my own MIB file for the same in python.
thanks in advance
You may not absolutely require a MIB if all you want to do is to send SNMP TRAP. But I do not really know your requirements. Why do you think you need a MIB? Is it that you run some sort of NMS on the receiving side that requires MIB to analyse the event?
What you could do without MIB is to chose TRAP message contents that sufficiently describe the event using just OID-value pairs (e.g. required TRAP message contents + possibly OID-value pairs), then have the receiver of the TRAP analyse it accordingly.
If you still need a MIB, then you could just create one in your text editor. Take one of the existing MIBs as an example. You may test-compile it with mibdump.py to catch possible syntax errors. Once you are done, refer pysnmp to your TRAP object in the MIB so pysnmp which would compile and use it.
I looking for a way to monitor reads and writes to flash memory on an embedded board running buildroot.
problem is that cat /proc/diskstats only shows zeros in all columns (all the mtdblocks are there)
where else can I get that info? is there a missing package I need to add?
The topic of UBI statistics has been discussed recently on the linux-mtd mailing list, and a patch has been proposed: http://lists.infradead.org/pipermail/linux-mtd/2018-July/083030.html.
I have read several RFCs about the SNMP protocol, and they are usually written in cryptic and opaque style, so I have probably missed the proper information and I apologize in advance for what is probably a simple question...
I am unclear about what kind of error in a get command for instance would set the error and error index fields in the snmp get-response message. Since I have been using Net-SNMP to send commands (and the snmp simulator at demo.snmplabs.com), I have not been able to send improperly formatted messages to see what kind of response I would get. I have started writing my own SNMP test tool (in Visual Basic) just to be able to send improperly formatted messages but it will be a fair amount of work before I can use it as a validated test tool.
When sending requests for non-existing OIDs or with wrong data type, it appears that Net-SNMP handles the errors without needing error/error-index values.
Any suggestion appreciated
It should be possible to generate errors for SNMP GETs but perhaps easier to start with generating errors for SETs.
➜ snmpset -v 2c -c private demohost sysName.0 s "foo"
SNMPv2-MIB::sysName.0 = STRING: foo
In version below agent rejects the SET...
➜ snmpset -v 2c -c private demohost ucdDemoPublicString.0 s "TEST"
Error in packet.
Reason: noCreation (That table does not support row creation or that object can not ever be created)
Failed object: UCD-DEMO-MIB::ucdDemoPublicString.0
Use -d to see the packets back and forth.
With xperf I can generate a trace and get a "flat" listing of all files read like so:
xperf -on FileIO+FILE_IO+FILE_IO_INIT+FILENAME -stackwalk FileRead+FileWrite+FileDelete
xperf -start FileIOSession -heap -PidNewProcess "C:\Python27\x86\python.exe scratchy.py" -WaitForNewProcess -BufferSize 1024 -MinBuffers 128 -MaxBuffers 512 -stackwalk HeapAlloc+HeapRealloc -f ./tempheap.etl
xperf -stop FileIOSession -stop -d fileio.etl
xperf -i fileio.etl -o fio_output.txt -a filename
Unfortunately, the fio_output.txt file contains a list of every file imaginable that was accessed (from my web browser, IDE, etc). More frustratingly, if I manually open xperfview and open the File I/O Summary Table, I can see my process (python.exe in this case) and the one file it reads (for test purposes) but can't seem to find a way to output that same data on the CLI which is what I need--an unattended, automated method of generating file access info.
If you want to view this data then you should load the trace into WPA, open the file I/O table, and arrange the columns appropriately. Since you want to group by process you should have the process column first, then the orange bar, and then whatever data columns you want.
If you want to export the data to programmatically parse it then you should use wpaexporter.exe, new in WPT 8.1. See this blog post which I wrote describing how to do this:
https://randomascii.wordpress.com/2013/11/04/exporting-arbitrary-data-from-xperf-etl-files/
Using wpaexporter lets you decide exactly what data columns you want to export instead of being constrained by the limited set of trace processing actions that xperf.exe gives you.
I suspect you can get this data out from tracerpt.exe instead - I'd give that a try