This is an approach to generate dynamically a JSON representation of an OID tree (=an(y) SNMP MIB) using mibdump.py of python pysmi.
We will generate a flat list of OID objects (oid_catalog.json) + hierarchical json tree (oid_tree.json) with "."-separated nodes of RFC 1213 MIB.
$ pip install pysmi
# walk into and/or create a new directory you run the following command in
$ mibdump.py --destination-format=json --generate-mib-texts --build-index --mib-stub= RFC1213-MIB
NOTE: for some MIBs mibdump.py needs --mib-stub=
as argument to dump something.
Create a file converter.py in your working directory of step 1 with the content of the file below and execute:
$ python3 converter.py
Two new files oid_catalog.json and oid_tree.json should be created with a RFC 1213 tree representation of the MIB. The catalog file contains a flat list of all known oid-nodes it knows out of the *.json files we downloaded in step 1.
Feel free to modify and experiment with this code and share improvements.
{
"isLeaf": false,
"children": {
"1": {
"isLeaf": false,
"children": {
"3": {
"isLeaf": true,
"children": {
"6": {
"isLeaf": true,
"children": {
"1": {
"isLeaf": true,
"children": {
"2": {
"isLeaf": true,
"children": {
"1": {
"isLeaf": true,
"children": {
"1": {
"isLeaf": true,
"children": {
"1": {
"isLeaf": true,
"children": {},
"oidValue": "1.3.6.1.2.1.1.1",
"name": "sysDescr"
},
"2": {
"isLeaf": true,
"children": {},
"oidValue": "1.3.6.1.2.1.1.2",
"name": "sysObjectID"
},
"3": {
"isLeaf": true,
"children": {},
"oidValue": "1.3.6.1.2.1.1.3",
"name": "sysUpTime"
},
"4": {
"isLeaf": true,
"children": {},
"oidValue": "1.3.6.1.2.1.1.4",
"name": "sysContact"
}