2018-07-08 21:25:29 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-06-30 11:19:49 +00:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import threading
|
2023-08-21 23:28:07 +00:00
|
|
|
from logging import info
|
2018-06-30 11:19:49 +00:00
|
|
|
|
|
|
|
import LibreNMS
|
|
|
|
|
2021-03-28 16:02:33 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="LibreNMS Service - manages polling and other periodic processes"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2021-10-28 13:22:15 +00:00
|
|
|
"-g",
|
|
|
|
"--group",
|
|
|
|
nargs="+",
|
|
|
|
type=int,
|
|
|
|
help="Set the poller group for this poller",
|
2021-03-28 16:02:33 +00:00
|
|
|
)
|
|
|
|
parser.add_argument("-v", "--verbose", action="count", help="Show verbose output.")
|
|
|
|
parser.add_argument("-d", "--debug", action="store_true", help="Show debug output.")
|
2023-08-21 23:28:07 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-o",
|
|
|
|
"--log-output",
|
|
|
|
action="store_true",
|
|
|
|
help="Log poller ouput to files. Warning: This could use significant disk space!",
|
|
|
|
)
|
2021-03-28 16:02:33 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"-m",
|
|
|
|
"--multiple",
|
|
|
|
action="store_true",
|
|
|
|
help="Allow multiple instances of the service.",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"-t",
|
|
|
|
"--timestamps",
|
|
|
|
action="store_true",
|
|
|
|
help="Include timestamps in the logs (not normally needed for syslog/journald",
|
|
|
|
)
|
2018-06-30 11:19:49 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.timestamps:
|
2021-03-28 16:02:33 +00:00
|
|
|
logging.basicConfig(
|
|
|
|
format="%(asctime)s %(threadName)s(%(levelname)s):%(message)s"
|
|
|
|
)
|
2018-06-30 11:19:49 +00:00
|
|
|
else:
|
2021-03-28 16:02:33 +00:00
|
|
|
logging.basicConfig(format="%(threadName)s(%(levelname)s):%(message)s")
|
2018-06-30 11:19:49 +00:00
|
|
|
|
|
|
|
if args.verbose:
|
|
|
|
logging.getLogger().setLevel(logging.INFO)
|
2021-09-27 19:24:25 +00:00
|
|
|
elif args.debug:
|
2018-06-30 11:19:49 +00:00
|
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
2021-09-27 19:24:25 +00:00
|
|
|
else:
|
|
|
|
logging.getLogger().setLevel(logging.WARNING)
|
2018-06-30 11:19:49 +00:00
|
|
|
|
|
|
|
info("Configuring LibreNMS service")
|
|
|
|
try:
|
|
|
|
service = LibreNMS.Service()
|
|
|
|
except Exception as e:
|
|
|
|
# catch any initialization errors and print the message instead of a stack trace
|
|
|
|
print(e)
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
service.config.single_instance = args.multiple
|
2023-08-21 23:28:07 +00:00
|
|
|
service.config.log_output = args.log_output
|
2018-06-30 11:19:49 +00:00
|
|
|
|
|
|
|
if args.group:
|
2021-10-28 13:22:15 +00:00
|
|
|
if isinstance(args.group, list):
|
|
|
|
service.config.group = args.group
|
|
|
|
else:
|
|
|
|
service.config.group = [args.group]
|
2018-06-30 11:19:49 +00:00
|
|
|
|
2021-03-28 16:02:33 +00:00
|
|
|
info(
|
|
|
|
"Entering main LibreNMS service loop on {}/{}...".format(
|
|
|
|
os.getpid(), threading.current_thread().name
|
|
|
|
)
|
|
|
|
)
|
2018-06-30 11:19:49 +00:00
|
|
|
service.start()
|