mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add module support for wrapper script calls (#14055)
* Add module support for wrapper script calls The scripts poller.php and discovery.php offer a module option (-m), which may be used to specify specific modules for polling/discovery, possibly for special (and then faster) testing or for example rediscovering the fdb table (on all hosts). Until now, this was not possible with the python wrapper scripts. Now they support a '-m' option, where comma separated module names may be passed. This will currently only work with poller and discovery, though. * Replace single quotation signs with double ones (empty strings only) * Fix more code lines (quotation signs, indentation) Also 'reduced' if-else-clause size at end of LibreNMS/wrapper.py (do not call method at each branch, instead prepare a value for modules) * Add commas after last parameter of dict+methode Also an additional comment sign before # * Fix two leftover single quot. signs … * doc: Add documentation for module support
This commit is contained in:
@ -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,
|
||||
)
|
||||
|
@ -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,
|
||||
)
|
||||
|
@ -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`
|
||||
|
@ -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,
|
||||
)
|
||||
|
Reference in New Issue
Block a user