Skip to content
Snippets Groups Projects
Commit bc77b4a8 authored by Taya Snijder's avatar Taya Snijder
Browse files

updated README, cleaned up code, added ability to add multiple sources including web addresses

parent 1d9e6c5e
No related branches found
No related tags found
1 merge request!288Resolve L2SS-446 "Extend snmp client to support mib files"
#MIB Compiler #MIB Compiler
The MIB compiler script 'compiles' .mib files to a custom python representation that pysnmp can load immediately. The MIB compiler script 'compiles' .mib files to a custom python representation that pysnmp can load immediately.
In order to compile scripts there must be a valid mib file in the source directory as well as any potential imported files. In order to compile scripts there must be a valid mib file in the source directory as well as any potential imported files.
You can find out which mib files need to be imported by opening the file and looking at the `IMPORTS` section, where imported mib files are listed. These mibs may also have subsequent mib files that need to be imported. Alternatively these imports may also be found in the verbose debug log. You can find out which mib files need to be imported by opening the file and looking at the `IMPORTS` section, where imported mib files are listed.
These mibs may also have subsequent mib files that need to be imported. Alternatively these imports may also be found in the verbose debug log.
This script will also generate pymib files for all the imported mib files.
`--mibs`: A list of mib files that need to be compiled. `--mibs`: A list of mib files that need to be compiled.
`--destination`: The output folder for the compiled mibs. This argument is optional. The default destination folder is `~/output_pymibs` `--destination`: The output folder for the compiled mibs. This argument is optional. The default destination folder is `~/output_pymibs`
`--source`: The source folder from where the mib files are sourced. This argument is optional. The default source folder is `~/mibs` `--source`: A list of source folders and addresses from where the mib files are sourced. This argument is optional. The default source folder is `~/mibs`
It can be useful to also list a web address as source, as there exist various sites that host mib files.
`--debug`: enable verbose debugging. Useful for figuring out errors. `--debug`: enable verbose debugging. Useful for figuring out errors.
example usage:
To source the mib TEST-MIB from the default `/mibs` location
`python3 mib_compiler.py --mibs TEST-MIB`
To source the mib TEST-MIB from the default `/mibs` location but to a custom output folder
`python3 mib_compiler.py --mibs TEST-MIB --destination home/user/output`
To source te mib TEST-MIB and all its imports from the path `home/user/mibs` and web address `http://www.net-snmp.org/docs/mibs/`
`python3 mib_compiler.py --mibs TEST-MIB --source home/user/mibs http://www.net-snmp.org/docs/mibs/`
...@@ -13,14 +13,10 @@ def mib_compile(mib_list : list, src, dst): ...@@ -13,14 +13,10 @@ def mib_compile(mib_list : list, src, dst):
fpath = str(Path().absolute()).replace("\\", "/") fpath = str(Path().absolute()).replace("\\", "/")
# "file://" prefix required for local files
src = "file://" + src
mibBuilder = builder.MibBuilder() mibBuilder = builder.MibBuilder()
# set the path for the input .mib files # set the compiler, the source path and set the www.net-snmp.org site as mib source as well.
# f'file://{fpath}/mibs' compiler.addMibCompiler(mibBuilder, sources=src, destination=dst)
compiler.addMibCompiler(mibBuilder, sources=[src, ], destination=dst)
for i in mib_list: for i in mib_list:
# compile it # compile it
...@@ -46,8 +42,8 @@ if __name__ == "__main__": ...@@ -46,8 +42,8 @@ if __name__ == "__main__":
help='sets the output directory for the compiled mibs. (default: ' help='sets the output directory for the compiled mibs. (default: '
'%(default)s)') '%(default)s)')
parser.add_argument( parser.add_argument(
'-s', '--source', type=str, required=False, default=in_path, '-s', '--source', type=str, required=False, nargs='+', default=in_path,
help='sets the input directory to read the .mib files from (default: ' help='sets the input paths or addresses to read the .mib files from (default: '
'%(default)s)') '%(default)s)')
parser.add_argument( parser.add_argument(
'-v', '--debug', dest='debug', action='store_true', default=False, '-v', '--debug', dest='debug', action='store_true', default=False,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment