More logging adjustments and improvements. (0.21.1)

This commit is contained in:
Johannes Findeisen 2023-02-24 01:45:15 +01:00
commit 4f30af83db
9 changed files with 75 additions and 49 deletions

4
.gitignore vendored
View file

@ -1,8 +1,6 @@
# Linspector
etc.local/
etc.test.*
log/*.log
log/*.log.*
tmp.py
# ---> Python
# Byte-compiled / optimized / DLL files

View file

@ -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

View file

@ -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 <you@hanez.org>'
@ -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)

View file

@ -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 = <green>[{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}]</green> <yellow>[{elapsed}]</yellow> <magenta>[{level}]</magenta> <blue>[linspector]</blue> <cyan>[{name}:{function}:{line}]</cyan><red>:</red> {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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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')

View file

@ -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.