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

changes

parent 18fe90f4
No related branches found
No related tags found
1 merge request!288Resolve L2SS-446 "Extend snmp client to support mib files"
......@@ -4,44 +4,38 @@ from pysnmp.smi import builder, compiler
from pathlib import Path
import argparse
# import logging
# logging.basicConfig(level=logging.DEBUG, format = '%(asctime)s:%(levelname)s: %(message)s')
# logger = logging.getLogger("pymib")
from pysmi import debug
debug.setLogger(debug.Debug('compiler'))
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("mib_compiler")
def mib_compile(mib_list : list, src=None, dst=None):
def mib_compile(mib_list : list, src, dst):
fpath = str(Path().absolute()).replace("\\", "/")
if src is None:
src = f"{fpath}/mibs"
# "file://" prefix required for local files
src = "file://" + src
if dst is None:
dst = f"{fpath}/output_pymibs"
print(src, dst)
mibBuilder = builder.MibBuilder()
# set the path for the input .mib files
# f'file://{fpath}/mibs'
compiler.addMibCompiler(mibBuilder, sources=[src, ], destination=dst)
for i in mib_list:
# compile it
try:
mibBuilder.loadModules(i)
# logger.debug(f"Compiled \"{i}\"")
logger.debug(f"loaded {i}")
except Exception as e:
raise Exception(f"Something went wrong, try checking whether all the mib fills imported by the provided mib files are present (To do this enable debug options and scroll up) ") from e
if __name__ == "__main__":
out_path = f"{Path().absolute()}/output_pymibs"
abs_path = str(Path().absolute()).replace("\\", "/")
out_path = f"{abs_path}/output_pymibs"
in_path = f"{abs_path}/mibs"
parser = argparse.ArgumentParser(
description='Compiles .mib files in to the easy to load pysnmp format')
......@@ -52,9 +46,12 @@ if __name__ == "__main__":
help='sets the output directory for the compiled mibs. (default: '
'%(default)s)')
parser.add_argument(
'-s', '--source', type=str, required=False,
'-s', '--source', type=str, required=False, default=in_path,
help='sets the input directory to read the .mib files from (default: '
'%(default)s)')
parser.add_argument(
'-v', '--debug', dest='debug', action='store_true', default=False,
help='increase log output')
args = parser.parse_args()
......@@ -62,6 +59,10 @@ if __name__ == "__main__":
mibs = args.mibs
destination = args.destination
source = args.source
debug_option = args.debug
if debug_option:
debug.setLogger(debug.Debug('all'))
mib_compile(mib_list=mibs, src=source, dst=destination)
mib_compile(["TEST-MIB"], src=source, dst=destination)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment