2018-07-08 17:25:29 -04:00
|
|
|
#!/usr/bin/env python3
|
2018-06-30 06:19:49 -05:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
|
|
|
|
import LibreNMS
|
|
|
|
|
|
|
|
from logging import info
|
|
|
|
|
2021-03-28 18:02:33 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description="LibreNMS Service - manages polling and other periodic processes"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2021-10-29 00:22:15 +11:00
|
|
|
"-g",
|
|
|
|
"--group",
|
|
|
|
nargs="+",
|
|
|
|
type=int,
|
|
|
|
help="Set the poller group for this poller",
|
2021-03-28 18:02:33 +02:00
|
|
|
)
|
|
|
|
parser.add_argument("-v", "--verbose", action="count", help="Show verbose output.")
|
|
|
|
parser.add_argument("-d", "--debug", action="store_true", help="Show debug output.")
|
|
|
|
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 06:19:49 -05:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.timestamps:
|
2021-03-28 18:02:33 +02:00
|
|
|
logging.basicConfig(
|
|
|
|
format="%(asctime)s %(threadName)s(%(levelname)s):%(message)s"
|
|
|
|
)
|
2018-06-30 06:19:49 -05:00
|
|
|
else:
|
2021-03-28 18:02:33 +02:00
|
|
|
logging.basicConfig(format="%(threadName)s(%(levelname)s):%(message)s")
|
2018-06-30 06:19:49 -05:00
|
|
|
|
|
|
|
if args.verbose:
|
|
|
|
logging.getLogger().setLevel(logging.INFO)
|
2021-09-27 21:24:25 +02:00
|
|
|
elif args.debug:
|
2018-06-30 06:19:49 -05:00
|
|
|
logging.getLogger().setLevel(logging.DEBUG)
|
2021-09-27 21:24:25 +02:00
|
|
|
else:
|
|
|
|
logging.getLogger().setLevel(logging.WARNING)
|
2018-06-30 06:19:49 -05: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
|
|
|
|
|
|
|
|
if args.group:
|
2021-10-29 00:22:15 +11:00
|
|
|
if isinstance(args.group, list):
|
|
|
|
service.config.group = args.group
|
|
|
|
else:
|
|
|
|
service.config.group = [args.group]
|
2018-06-30 06:19:49 -05:00
|
|
|
|
2021-03-28 18:02:33 +02:00
|
|
|
info(
|
|
|
|
"Entering main LibreNMS service loop on {}/{}...".format(
|
|
|
|
os.getpid(), threading.current_thread().name
|
|
|
|
)
|
|
|
|
)
|
2018-06-30 06:19:49 -05:00
|
|
|
service.start()
|