mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
0e952b9c98
* 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
72 lines
2.0 KiB
Python
Executable File
72 lines
2.0 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
"""
|
|
This is a Bootstrap script for wrapper.py, in order to retain compatibility with earlier LibreNMS setups
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import logging
|
|
from argparse import ArgumentParser
|
|
|
|
import LibreNMS
|
|
import LibreNMS.wrapper as wrapper
|
|
|
|
WRAPPER_TYPE = "discovery"
|
|
DEFAULT_WORKERS = 1
|
|
|
|
"""
|
|
Take the amount of threads we want to run in parallel from the commandline
|
|
if None are given or the argument was garbage, fall back to default
|
|
"""
|
|
usage = (
|
|
"usage: %(prog)s [options] <amount_of_workers> (Default: {}"
|
|
"(Do not set too high, or you will get an OOM)".format(DEFAULT_WORKERS)
|
|
)
|
|
description = "Spawn multiple discovery.php processes in parallel."
|
|
parser = ArgumentParser(usage=usage, description=description)
|
|
parser.add_argument(dest="amount_of_workers", default=DEFAULT_WORKERS)
|
|
parser.add_argument(
|
|
"-d",
|
|
"--debug",
|
|
dest="debug",
|
|
action="store_true",
|
|
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__)))
|
|
if not config:
|
|
logger = logging.getLogger(__name__)
|
|
logger.critical("Could not run {} wrapper. Missing config".format(WRAPPER_TYPE))
|
|
sys.exit(1)
|
|
log_dir = config["log_dir"]
|
|
log_file = os.path.join(log_dir, WRAPPER_TYPE + "_wrapper.log")
|
|
logger = LibreNMS.logger_get_logger(log_file, debug=args.debug)
|
|
|
|
try:
|
|
amount_of_workers = int(args.amount_of_workers)
|
|
except (IndexError, ValueError):
|
|
amount_of_workers = DEFAULT_WORKERS
|
|
logger.warning(
|
|
"Bogus number of workers given. Using default number ({}) of workers.".format(
|
|
amount_of_workers
|
|
)
|
|
)
|
|
|
|
wrapper.wrapper(
|
|
WRAPPER_TYPE,
|
|
amount_of_workers=amount_of_workers,
|
|
config=config,
|
|
log_dir=log_dir,
|
|
modules=args.modules or "",
|
|
_debug=args.debug,
|
|
)
|