From 21c684bfbc5202b463967d77a927ccafb670f132 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Mon, 21 Aug 2023 01:48:57 +0200 Subject: [PATCH] Masses of deletions and cleanups. (0.23.2) --- bin/linspector | 6 +- etc.local/linspector.conf | 2 +- linspector/environment.py | 24 ++--- linspector/monitor.py | 21 ++-- linspector/plugins/httpd.py | 2 +- linspector/services/misc/dummy.py | 2 +- linspector/services/misc/random.py | 2 +- .../services/vendor/avm/is_connected.py | 2 +- linspector/task.py | 99 +------------------ linspector/tasks/csv.py | 4 +- linspector/tasks/file.py | 4 +- linspector/tasks/mariadb.py | 4 +- 12 files changed, 36 insertions(+), 136 deletions(-) diff --git a/bin/linspector b/bin/linspector index 205c2e3..8ead2cb 100755 --- a/bin/linspector +++ b/bin/linspector @@ -1,7 +1,7 @@ #!/usr/bin/python3 -d """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ # TODO: VERY IMPORTANT! IMPLEMENT ERROR HANDLING ALL THE WAY...!!! @@ -19,7 +19,7 @@ from linspector.environment import Environment from linspector.linspector import Linspector from linspector.monitors import Monitors -__version__ = '0.23.1' +__version__ = '0.23.2' __author__ = 'Johannes Findeisen ' @@ -115,7 +115,7 @@ def linspector(): task = task_module.create(configuration, environment, log) tasks[task_name] = task else: - log.warning('initialization task: {0} failed! seems it does not exist.'.format(task_name)) + log.warning('initialization of task: {0} failed! seems it does not exist.'.format(task_name)) except Exception as err: log.warning('task initialization error: {0}'.format(err)) diff --git a/etc.local/linspector.conf b/etc.local/linspector.conf index dd42cfc..256f667 100644 --- a/etc.local/linspector.conf +++ b/etc.local/linspector.conf @@ -17,7 +17,7 @@ log_level = INFO ; logfile to use logfile = /home/hanez/code/linspector/linspector/log/linspector.log ; number of logfiles to keep (default: 10) -logfile_count = 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 diff --git a/linspector/environment.py b/linspector/environment.py index 794ad6a..ef6e28f 100644 --- a/linspector/environment.py +++ b/linspector/environment.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ @@ -20,20 +20,20 @@ class Environment: return self._env[key] else: self._log.warning('environment var "' + key + '" not found! could be that it is ' - 'set later at runtime. if you ' - 'encounter any errors executing ' - 'linspector, something is wrong ' - 'in the logic of the code. please ' - 'consider reporting this as a ' - 'bug! btw. a WARNING is not an ' - 'ERROR! linspector should work ' - 'even with missing environment ' - 'variables.') + 'set later at runtime. if you ' + 'encounter any errors executing ' + 'linspector, something is wrong ' + 'in the logic of the code. please ' + 'consider reporting this as a ' + 'bug! btw. a WARNING is not an ' + 'ERROR! linspector should work ' + 'even with missing environment ' + 'variables.') return None def set_env_var(self, key, value): if self._env[key]: - self._log('warning', _name_, 'environment var "' + key + - ' existed and was overwritten!') + self._log('warning', __name__, 'environment var "' + key + + ' existed and was overwritten!') self._env[key] = value diff --git a/linspector/monitor.py b/linspector/monitor.py index 58e4783..a5d2b9a 100644 --- a/linspector/monitor.py +++ b/linspector/monitor.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ import configparser @@ -72,11 +72,8 @@ class Monitor: RECOVER when a job recovers e.g. the threshold decrements (not implemented): 2 ERROR when a jobs error threshold is overridden: 3 UNKNOWN when a job throws an exception which is not handled by the job itself (not - implemented) :4 - self.status = "NONE" - self.last_execution = None + implemented): 4 """ - try: if configuration.get_option('linspector', 'notifications') or \ monitor_configuration.get('monitor', 'notifications'): @@ -124,15 +121,15 @@ class Monitor: self._result = self._services[self._service].execute(self._identifier, self, self._service, **self._args) - #print(self._tasks) + self._log.debug(self._tasks) for task in self._tasks: self._tasks[task].execute() - #print("task: " + task) - #print("identifier: " + self._identifier) - #print("service: " + self._service) - #print("status: " + self._result['status']) - #print("message: " + self._result['message']) - #print("json: " + str(self._result)) + self._log.debug("task: " + task) + self._log.debug("identifier: " + self._identifier) + self._log.debug("service: " + self._service) + self._log.debug("status: " + self._result['status']) + self._log.debug("message: " + self._result['message']) + self._log.debug("json: " + str(self._result)) except Exception as err: self._log.error(err) diff --git a/linspector/plugins/httpd.py b/linspector/plugins/httpd.py index 4d29cae..8f43ade 100644 --- a/linspector/plugins/httpd.py +++ b/linspector/plugins/httpd.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ import json diff --git a/linspector/services/misc/dummy.py b/linspector/services/misc/dummy.py index 91c8c10..f3e55b3 100644 --- a/linspector/services/misc/dummy.py +++ b/linspector/services/misc/dummy.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ from linspector.service import Service diff --git a/linspector/services/misc/random.py b/linspector/services/misc/random.py index 3912b8e..5d27c3b 100644 --- a/linspector/services/misc/random.py +++ b/linspector/services/misc/random.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ import hashlib diff --git a/linspector/services/vendor/avm/is_connected.py b/linspector/services/vendor/avm/is_connected.py index f139736..63225cb 100644 --- a/linspector/services/vendor/avm/is_connected.py +++ b/linspector/services/vendor/avm/is_connected.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ from fritzconnection.lib.fritzstatus import FritzStatus diff --git a/linspector/task.py b/linspector/task.py index 29d7637..e0987b3 100644 --- a/linspector/task.py +++ b/linspector/task.py @@ -1,16 +1,8 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ -from queue import Queue -from threading import Thread - -from linspector.singleton import Singleton - -KEY_TYPE = "type" -KEY_ARGS = "args" -KEY_CLASS = "class" class Task: @@ -19,92 +11,3 @@ class Task: self._configuration = configuration self._environment = environment self._log = log - - if KEY_ARGS in kwargs: - self.add_arguments(kwargs[KEY_ARGS]) - elif self.needs_arguments(): - raise Exception("Error: needs arguments but none provided!") - - if KEY_CLASS in kwargs: - self.name = kwargs[KEY_CLASS] - else: - self.name = self.__class__ - - self._type = None - if KEY_TYPE in kwargs: - self._type = kwargs[KEY_TYPE] - - def get_task_type(self): - return str(self._type) - - def get_config_name(self): - return str(self.name) - - def add_arguments(self, args): - for key, val in args.items(): - self._args[key] = val - - def get_arguments(self): - return self._args - - # def set_member(self, member): - # self.member = member - - def needs_arguments(self): - return False - - def execute(self, job): - try: - self.execute(job) - except Exception as e: - # logger.debug("Task execute failed!!!") - raise e - - -# i believe the singleton pattern is not required here because all tasks are stored as singleton in -# a dict already, and they can be executed directly in the equivalent monitor. need to discover this -# when tasks are being implemented. this is from the old version of Linspector... -# UPDATE: i see that task runners should be executed as separate threads, so maybe they should be -# singleton here to not instantiate more than one instance inside each task. don't know actually... -@Singleton -class TaskRunner: - def __init__(self, configuration, environment, log): - self._configuration = configuration - self._environment = environment - self._log = log - self.queue = Queue() - self.task_infos = [] - task_thread = Thread(target=self._run_worker_thread) - self._instant_end = False - self._running = True - task_thread.daemon = True - task_thread.start() - - def _run_worker_thread(self): - while self.is_running() or not self.is_instant_end(): - - try: - msg, task = self.queue.get() - if task: - self._log.debug('starting task execution...') - # task.execute(msg) - self.queue.task_done() - - except Exception as err: - self._log.error('error ' + str(err)) - - def is_instant_end(self): - return self._instant_end - - def is_running(self): - return self._running - - def stop(self): - self._running = False - - def stop_immediately(self): - self._running = False - self._instant_end = True - - def schedule_task(self, msg, task): - self.queue.put((msg, task)) diff --git a/linspector/tasks/csv.py b/linspector/tasks/csv.py index eedf8d0..5ca6a89 100644 --- a/linspector/tasks/csv.py +++ b/linspector/tasks/csv.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ from linspector.task import Task @@ -14,4 +14,4 @@ def create(configuration, environment, log): class CSVTask(Task): def execute(self): - print("Hello from CSV Task...") + self._log.debug("Hello from CSV Task...") diff --git a/linspector/tasks/file.py b/linspector/tasks/file.py index 8160d97..285dbc5 100644 --- a/linspector/tasks/file.py +++ b/linspector/tasks/file.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ from linspector.task import Task @@ -14,4 +14,4 @@ def create(configuration, environment, log): class FileTask(Task): def execute(self): - print("Hello from File Task...") + self._log.debug("Hello from File Task...") diff --git a/linspector/tasks/mariadb.py b/linspector/tasks/mariadb.py index bdd1591..9ba811f 100644 --- a/linspector/tasks/mariadb.py +++ b/linspector/tasks/mariadb.py @@ -1,6 +1,6 @@ """ This file is part of Linspector (https://linspector.org/) -Copyright (c) 2022 Johannes Findeisen . All Rights Reserved. +Copyright (c) 2022-2023 Johannes Findeisen . All Rights Reserved. See LICENSE (MIT license). """ from linspector.task import Task @@ -14,4 +14,4 @@ def create(configuration, environment, log): class MariaDBTask(Task): def execute(self): - print("Hello from MariaDB Task...") + self._log.debug("Hello from MariaDB Task...")