Masses of deletions and cleanups. (0.23.2)
This commit is contained in:
parent
9500b91c2d
commit
21c684bfbc
12 changed files with 36 additions and 136 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/python3 -d
|
#!/usr/bin/python3 -d
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
# TODO: VERY IMPORTANT! IMPLEMENT ERROR HANDLING ALL THE WAY...!!!
|
# 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.linspector import Linspector
|
||||||
from linspector.monitors import Monitors
|
from linspector.monitors import Monitors
|
||||||
|
|
||||||
__version__ = '0.23.1'
|
__version__ = '0.23.2'
|
||||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -115,7 +115,7 @@ def linspector():
|
||||||
task = task_module.create(configuration, environment, log)
|
task = task_module.create(configuration, environment, log)
|
||||||
tasks[task_name] = task
|
tasks[task_name] = task
|
||||||
else:
|
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:
|
except Exception as err:
|
||||||
log.warning('task initialization error: {0}'.format(err))
|
log.warning('task initialization error: {0}'.format(err))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ log_level = INFO
|
||||||
; logfile to use
|
; logfile to use
|
||||||
logfile = /home/hanez/code/linspector/linspector/log/linspector.log
|
logfile = /home/hanez/code/linspector/linspector/log/linspector.log
|
||||||
; number of logfiles to keep (default: 10)
|
; 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. 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}
|
;logfile_format = [{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}] [{elapsed}] [{level}] [linspector] [{name}:{function}:{line}]: {message}
|
||||||
; log level for file based logging
|
; log level for file based logging
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -20,20 +20,20 @@ class Environment:
|
||||||
return self._env[key]
|
return self._env[key]
|
||||||
else:
|
else:
|
||||||
self._log.warning('environment var "' + key + '" not found! could be that it is '
|
self._log.warning('environment var "' + key + '" not found! could be that it is '
|
||||||
'set later at runtime. if you '
|
'set later at runtime. if you '
|
||||||
'encounter any errors executing '
|
'encounter any errors executing '
|
||||||
'linspector, something is wrong '
|
'linspector, something is wrong '
|
||||||
'in the logic of the code. please '
|
'in the logic of the code. please '
|
||||||
'consider reporting this as a '
|
'consider reporting this as a '
|
||||||
'bug! btw. a WARNING is not an '
|
'bug! btw. a WARNING is not an '
|
||||||
'ERROR! linspector should work '
|
'ERROR! linspector should work '
|
||||||
'even with missing environment '
|
'even with missing environment '
|
||||||
'variables.')
|
'variables.')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def set_env_var(self, key, value):
|
def set_env_var(self, key, value):
|
||||||
if self._env[key]:
|
if self._env[key]:
|
||||||
self._log('warning', _name_, 'environment var "' + key +
|
self._log('warning', __name__, 'environment var "' + key +
|
||||||
' existed and was overwritten!')
|
' existed and was overwritten!')
|
||||||
|
|
||||||
self._env[key] = value
|
self._env[key] = value
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
import configparser
|
import configparser
|
||||||
|
|
@ -72,11 +72,8 @@ class Monitor:
|
||||||
RECOVER when a job recovers e.g. the threshold decrements (not implemented): 2
|
RECOVER when a job recovers e.g. the threshold decrements (not implemented): 2
|
||||||
ERROR when a jobs error threshold is overridden: 3
|
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
|
UNKNOWN when a job throws an exception which is not handled by the job itself (not
|
||||||
implemented) :4
|
implemented): 4
|
||||||
self.status = "NONE"
|
|
||||||
self.last_execution = None
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if configuration.get_option('linspector', 'notifications') or \
|
if configuration.get_option('linspector', 'notifications') or \
|
||||||
monitor_configuration.get('monitor', 'notifications'):
|
monitor_configuration.get('monitor', 'notifications'):
|
||||||
|
|
@ -124,15 +121,15 @@ class Monitor:
|
||||||
self._result = self._services[self._service].execute(self._identifier, self,
|
self._result = self._services[self._service].execute(self._identifier, self,
|
||||||
self._service, **self._args)
|
self._service, **self._args)
|
||||||
|
|
||||||
#print(self._tasks)
|
self._log.debug(self._tasks)
|
||||||
for task in self._tasks:
|
for task in self._tasks:
|
||||||
self._tasks[task].execute()
|
self._tasks[task].execute()
|
||||||
#print("task: " + task)
|
self._log.debug("task: " + task)
|
||||||
#print("identifier: " + self._identifier)
|
self._log.debug("identifier: " + self._identifier)
|
||||||
#print("service: " + self._service)
|
self._log.debug("service: " + self._service)
|
||||||
#print("status: " + self._result['status'])
|
self._log.debug("status: " + self._result['status'])
|
||||||
#print("message: " + self._result['message'])
|
self._log.debug("message: " + self._result['message'])
|
||||||
#print("json: " + str(self._result))
|
self._log.debug("json: " + str(self._result))
|
||||||
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self._log.error(err)
|
self._log.error(err)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
from linspector.service import Service
|
from linspector.service import Service
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
from fritzconnection.lib.fritzstatus import FritzStatus
|
from fritzconnection.lib.fritzstatus import FritzStatus
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,8 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
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:
|
class Task:
|
||||||
|
|
@ -19,92 +11,3 @@ class Task:
|
||||||
self._configuration = configuration
|
self._configuration = configuration
|
||||||
self._environment = environment
|
self._environment = environment
|
||||||
self._log = log
|
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))
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
from linspector.task import Task
|
from linspector.task import Task
|
||||||
|
|
@ -14,4 +14,4 @@ def create(configuration, environment, log):
|
||||||
class CSVTask(Task):
|
class CSVTask(Task):
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
print("Hello from CSV Task...")
|
self._log.debug("Hello from CSV Task...")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
from linspector.task import Task
|
from linspector.task import Task
|
||||||
|
|
@ -14,4 +14,4 @@ def create(configuration, environment, log):
|
||||||
class FileTask(Task):
|
class FileTask(Task):
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
print("Hello from File Task...")
|
self._log.debug("Hello from File Task...")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This file is part of Linspector (https://linspector.org/)
|
This file is part of Linspector (https://linspector.org/)
|
||||||
Copyright (c) 2022 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
See LICENSE (MIT license).
|
See LICENSE (MIT license).
|
||||||
"""
|
"""
|
||||||
from linspector.task import Task
|
from linspector.task import Task
|
||||||
|
|
@ -14,4 +14,4 @@ def create(configuration, environment, log):
|
||||||
class MariaDBTask(Task):
|
class MariaDBTask(Task):
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
print("Hello from MariaDB Task...")
|
self._log.debug("Hello from MariaDB Task...")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue