diff --git a/.gitignore b/.gitignore index a7f2154..136a379 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ # Linspector -etc.local/ +etc.test.* log/*.log -log/*.log.* -tmp.py # ---> Python # Byte-compiled / optimized / DLL files diff --git a/Makefile b/Makefile index e047933..43de542 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ run: PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector -s ./etc rundev: - PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector -s ./etc.local + PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector -s ./etc.test.local daemon: PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VRESION)/site-packages/ bin/linspector -d ./etc diff --git a/bin/linspector b/bin/linspector index 02d5fa3..bca1e2a 100755 --- a/bin/linspector +++ b/bin/linspector @@ -17,7 +17,7 @@ from linspector.linspector import Linspector from linspector.monitors import Monitors from loguru import logger -__version__ = '0.21' +__version__ = '0.21.1' __author__ = 'Johannes Findeisen ' @@ -61,23 +61,48 @@ def main(): services = {} tasks = {} + logger.remove() + default_log_format = '[{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}] [{elapsed}] [{level}] [linspector] ' \ + '[{name}:{function}:{line}]: {message}' + log_level = "INFO" + logger.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, format=default_log_format, level=log_level) + try: configuration = Configuration(args.configuration_path, logger) except Exception as err: logger.error('configuration error: {0}'.format(err)) sys.exit(1) - logger.remove() - log_level = "ERROR" if configuration.get_option('linspector', 'log_level'): - log_level = configuration.get_option('linspector', 'log_level') + logger.remove() + log_format = default_log_format + if configuration.get_option('linspector', 'log_format'): + log_format = configuration.get_option('linspector', 'log_format') + + if configuration.get_option('linspector', 'log_level'): + log_level = configuration.get_option('linspector', 'log_level') + + logger.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, format=log_format, level=log_level) - logger.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, level=log_level) - # log.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, format="{time} [{level}]: {message}", level="INFO") - # log.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO") if configuration.get_option('linspector', 'logfile'): + logfile_count = '10' + if configuration.get_option('linspector', 'logfile_count'): + logfile_count = configuration.get_option('linspector', 'logfile_count') + + logfile_format = default_log_format + if configuration.get_option('linspector', 'logfile_format'): + logfile_format = configuration.get_option('linspector', 'logfile_format') + + logfile_level = log_level + if configuration.get_option('linspector', 'logfile_level'): + logfile_level = configuration.get_option('linspector', 'logfile_level') + + logfile_size = '1MB' + if configuration.get_option('linspector', 'logfile_size'): + logfile_size = configuration.get_option('linspector', 'logfile_size') + logger.add(configuration.get_option('linspector', 'logfile'), backtrace=True, diagnose=True, enqueue=True, - level=configuration.get_option('linspector', 'logfile_level')) + format=logfile_format, level=logfile_level, retention=int(logfile_count), rotation=logfile_size) environment = Environment(logger) diff --git a/etc/linspector.conf b/etc/linspector.conf index a82fa1e..c81af7d 100644 --- a/etc/linspector.conf +++ b/etc/linspector.conf @@ -1,35 +1,33 @@ [linspector] default_interval = 300 +minimum_interval = 10 delta_range = 10 -error_receivers = admin@example.com -log_file_count = 20 -log_file_size = 1 -log_file_size_bytes = 100000 -log_level = info + +start_scheduler = true +scheduler_mode = thread max_processes = 1 max_threads = 2048 -minimum_interval = 10 -notifications = email pid_file = /var/run/user/1000/linspector.pid + +; log format. this overrides the default configured in the code +log_format = [{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}] [{elapsed}] [{level}] [linspector] [{name}:{function}:{line}]: {message} +; log level for stderr logging (default: INFO) +log_level = INFO +; logfile to use +logfile = /home/hanez/code/linspector/linspector/log/linspector.log +; number of logfiles to keep (default: 10) +logfile_count = 5 +; logfile format. this overrides the default configured in the code +;logfile_format = [{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}] [{elapsed}] [{level}] [linspector] [{name}:{function}:{line}]: {message} +; log level for file based logging +logfile_level = DEBUG +; size of logfiles (default: 1MB) +logfile_size = 10MB + +notifications = plugins = -run_mode = cron -scheduler_mode = thread -start_scheduler = true -tasks = mariadb -timezone = CET +tasks = -[hostgroupparents] - -[hostgroups] - -[membergroups] - -[monitorgroups] - -[notifications] - -[plugins] - -[services] - -[tasks] +; timezone can be set to a remote timezone to make monitors run at the remote time. this is optional. the local +; timezone is set by default. this can be overridden in each monitor. +;timezone = UTC diff --git a/etc/monitors/network1/gateway.conf b/etc/monitors/network1/gateway.conf index 8d3a1c4..2e1ac69 100644 --- a/etc/monitors/network1/gateway.conf +++ b/etc/monitors/network1/gateway.conf @@ -3,8 +3,10 @@ title = Uplink Status description = Cable Provider Uplink Status service = vendor.avm.is_connected host = 192.168.1.1 -interval = 60 +interval = 5 +; the timezone can be set to the zone of the monitor target host to run at the remote time. this is optional. the +; default is the local system timezone. +;timezone = UTC [args] -host = 192.168.1.1 password = PASSWORD diff --git a/etc/monitors/network2/gateway.conf b/etc/monitors/network2/gateway.conf index 8a72f92..bbc7283 100644 --- a/etc/monitors/network2/gateway.conf +++ b/etc/monitors/network2/gateway.conf @@ -1,9 +1,9 @@ [monitor] title = Uplink Status -description = DSL Provider Uplink Status +description = Cable Provider Uplink Status service = vendor.avm.is_connected host = 192.168.2.1 -interval = 5 +interval = 13 [args] password = PASSWORD diff --git a/files/receipes.py b/files/receipts.py similarity index 83% rename from files/receipes.py rename to files/receipts.py index a0a5a97..185deb1 100644 --- a/files/receipes.py +++ b/files/receipts.py @@ -1,3 +1,5 @@ +# some python receipts for different stuff + # get system timezone name # https://stackoverflow.com/questions/1111056/get-time-zone-information-of-the-system-in-python import datetime diff --git a/linspector/configuration.py b/linspector/configuration.py index 5c41f0b..9238405 100644 --- a/linspector/configuration.py +++ b/linspector/configuration.py @@ -9,15 +9,15 @@ import os # TODO: check for all required configuration options and set defaults if needed. do this only for -# options in the "linspector" section of linspector.ini. +# options in the "linspector" section of linspector.conf. class Configuration: def __init__(self, configuration_path, log): self.__configuration = configparser.ConfigParser() self.__configuration_path = configuration_path self.__log = log - # print('[linspector] reading configuration file: ' + configuration_path + - # '/linspector.conf') + log.info('message=reading configuration configfile=' + configuration_path + + '/linspector.conf') if os.path.isfile(configuration_path + '/linspector.conf'): try: self.__configuration.read(configuration_path + '/linspector.conf', 'utf-8') diff --git a/linspector/linspector.py b/linspector/linspector.py index 61c5a7a..46e8470 100644 --- a/linspector/linspector.py +++ b/linspector/linspector.py @@ -99,11 +99,12 @@ class Linspector: if configuration.get_option('linspector', 'timezone'): timezone = configuration.get_option('linspector', 'timezone') - if monitors.get(monitor).get_monitor_configuration_option('args', 'timezone'): - timezone = monitors.get(monitor).get_monitor_configuration_option('args', + if monitors.get(monitor).get_monitor_configuration_option('monitor', 'timezone'): + timezone = monitors.get(monitor).get_monitor_configuration_option('monitor', 'timezone') else: - timezone = 'UTC' + # set to local system timezone by as default + timezone = datetime.datetime.now(datetime.timezone.utc).astimezone().tzname() # add cron and one time run jobs to Linspector. not only "interval" jobs should be # supported.