diff --git a/LibreNMS/wrapper.py b/LibreNMS/wrapper.py index 7fae1fc0fb..9c7bbecb0c 100644 --- a/LibreNMS/wrapper.py +++ b/LibreNMS/wrapper.py @@ -44,6 +44,7 @@ import logging import os import queue +import re import sys import threading import time @@ -229,6 +230,7 @@ def poll_worker( log_dir, # Type: str wrapper_type, # Type: str debug, # Type: bool + modules="", # Type: string ): """ This function will fork off single instances of the php process, record @@ -279,6 +281,9 @@ def poll_worker( wrappers[wrapper_type]["executable"], ) command = "/usr/bin/env php {} -h {}".format(executable, device_id) + if modules is not None and len(str(modules).strip()): + module_str = re.sub("\s", "", str(modules).strip()) + command = command + " -m {}".format(module_str) if debug: command = command + " -d" exit_code, output = command_runner( @@ -327,6 +332,7 @@ def wrapper( config, # Type: dict log_dir, # Type: str _debug=False, # Type: bool + **kwargs, # Type: dict, may contain modules ): # -> None """ Actual code that runs various php scripts, in single node mode or distributed poller mode @@ -495,6 +501,7 @@ def wrapper( "log_dir": log_dir, "wrapper_type": wrapper_type, "debug": _debug, + "modules": kwargs.get("modules", ""), }, ) worker.setDaemon(True) @@ -615,6 +622,12 @@ if __name__ == "__main__": default=False, help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.", ) + parser.add_argument( + "-m", + "--modules", + default="", + help="Enable passing of a module string, modules are separated by comma", + ) parser.add_argument( dest="wrapper", @@ -628,6 +641,7 @@ if __name__ == "__main__": args = parser.parse_args() debug = args.debug + modules = args.modules or "" wrapper_type = args.wrapper amount_of_workers = args.threads @@ -654,4 +668,16 @@ if __name__ == "__main__": ) ) - wrapper(wrapper_type, amount_of_workers, config, log_dir, _debug=debug) + if wrapper_type in ["discovery", "poller"]: + modules_validated = modules + else: + modules_validated = "" # ignore module parameter + + wrapper( + wrapper_type, + amount_of_workers, + config, + log_dir, + _debug=debug, + modules=modules_validated, + ) diff --git a/discovery-wrapper.py b/discovery-wrapper.py index bb9920f9e9..839c397461 100755 --- a/discovery-wrapper.py +++ b/discovery-wrapper.py @@ -33,6 +33,13 @@ parser.add_argument( default=False, help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.", ) +parser.add_argument( + "-m", + "--modules", + dest="modules", + default="", + help="Enable passing of a module string, modules are separated by comma", +) args = parser.parse_args() config = LibreNMS.get_config_data(os.path.dirname(os.path.realpath(__file__))) @@ -59,5 +66,6 @@ wrapper.wrapper( amount_of_workers=amount_of_workers, config=config, log_dir=log_dir, + modules=args.modules or "", _debug=args.debug, ) diff --git a/doc/Support/Discovery Support.md b/doc/Support/Discovery Support.md index 3f622729e1..a5b9faa58d 100644 --- a/doc/Support/Discovery Support.md +++ b/doc/Support/Discovery Support.md @@ -48,6 +48,10 @@ If you need to debug the output of discovery-wrapper.py then you can add `-d` to the end of the command - it is NOT recommended to do this in cron. +You also may use `-m` to pass a list of comma-separated modules. +Please refer to [Command options](#command-options) of discovery.php. +Example: `/opt/librenms/discovery-wrapper.py 1 -m bgp-peers` + If you want to switch back to discovery.php then you can replace: `33 */6 * * * librenms /opt/librenms/discovery-wrapper.py 1 >> /dev/null 2>&1` diff --git a/poller-wrapper.py b/poller-wrapper.py index 85f3a1f240..4c6dc4c2ce 100755 --- a/poller-wrapper.py +++ b/poller-wrapper.py @@ -33,6 +33,13 @@ parser.add_argument( default=False, help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.", ) +parser.add_argument( + "-m", + "--modules", + dest="modules", + default="", + help="Enable passing of a module string, modules are separated by comma", +) args = parser.parse_args() config = LibreNMS.get_config_data(os.path.dirname(os.path.realpath(__file__))) @@ -59,5 +66,6 @@ wrapper.wrapper( amount_of_workers=amount_of_workers, config=config, log_dir=log_dir, + modules=args.modules or "", _debug=args.debug, )