Lot of task execution refactoring. (0.23.0)
This commit is contained in:
parent
681475f274
commit
1ef835cfe6
10 changed files with 37 additions and 54 deletions
|
|
@ -8,6 +8,7 @@ See LICENSE (MIT license).
|
|||
# Only exit execution on critical core errors. Do not exit when monitors are failing on
|
||||
# configuration and execution, but log these errors.
|
||||
import argparse
|
||||
import importlib
|
||||
import signal
|
||||
import sys
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ from linspector.environment import Environment
|
|||
from linspector.linspector import Linspector
|
||||
from linspector.monitors import Monitors
|
||||
|
||||
__version__ = '0.22.0'
|
||||
__version__ = '0.23.0'
|
||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||
|
||||
|
||||
|
|
@ -101,6 +102,23 @@ def linspector():
|
|||
|
||||
environment = Environment(log)
|
||||
|
||||
try:
|
||||
if configuration.get_option('linspector', 'tasks'):
|
||||
log.info(configuration.get_option('linspector', 'tasks'))
|
||||
|
||||
task_list = configuration.get_option('linspector', 'tasks')
|
||||
task_list = task_list.split(',')
|
||||
for task_name in task_list:
|
||||
task_package = 'linspector.tasks.' + task_name
|
||||
if importlib.util.find_spec(task_package) is not None:
|
||||
task_module = importlib.import_module(task_package)
|
||||
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))
|
||||
except Exception as err:
|
||||
log.warning('task initialization error: {0}'.format(err))
|
||||
|
||||
try:
|
||||
monitors = Monitors(configuration, environment, log, notifications, services, tasks)
|
||||
except Exception as err:
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ logfile_size = 10MiB
|
|||
|
||||
notifications =
|
||||
plugins =
|
||||
tasks =
|
||||
tasks = mariadb,csv,file
|
||||
|
||||
; timezone can be set to a remote timezone to make monitors run at the remote time. this can be overridden in each
|
||||
; monitor configuration.
|
||||
|
|
|
|||
|
|
@ -63,8 +63,6 @@ class Monitor:
|
|||
self._service = 'misc.dummy'
|
||||
|
||||
self._services = services
|
||||
self._task = None
|
||||
self._task_list = [] # put tasks for the dedicated job here.
|
||||
self._tasks = tasks
|
||||
|
||||
"""
|
||||
|
|
@ -117,20 +115,6 @@ class Monitor:
|
|||
service = service_module.create(configuration, environment, log)
|
||||
self._services[monitor_configuration.get('monitor', 'service').lower()] = service
|
||||
|
||||
if self._configuration.get_option('linspector', 'tasks'):
|
||||
self._log.info(self._configuration.get_option('linspector', 'tasks'))
|
||||
|
||||
task_list = self._configuration.get_option('linspector', 'tasks')
|
||||
|
||||
self._task_list = task_list.split(',')
|
||||
self._log.info(self._task_list)
|
||||
for task in self._task_list:
|
||||
if self._task is None:
|
||||
task_package = 'linspector.tasks.' + task
|
||||
task_module = importlib.import_module(task_package)
|
||||
self._task = task_module.create(self._configuration, self._environment,
|
||||
self._log)
|
||||
|
||||
def execute(self):
|
||||
self._log.debug('identifier=' + self._identifier + ' object=' + str(self))
|
||||
self._log.debug('identifier=' + self._identifier + ' message=handle call to service')
|
||||
|
|
@ -139,15 +123,16 @@ class Monitor:
|
|||
try:
|
||||
self._result = self._services[self._service].execute(self._identifier, self,
|
||||
self._service, **self._args)
|
||||
if self._task is not None:
|
||||
self._task.execute()
|
||||
|
||||
print("task: " + str(self._task))
|
||||
print("identifier: " + self._identifier)
|
||||
print("service: " + self._service)
|
||||
print("status: " + self._result['status'])
|
||||
print("message: " + self._result['message'])
|
||||
print("json: " + str(self._result))
|
||||
#print(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))
|
||||
|
||||
except Exception as err:
|
||||
self._log.error(err)
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@ def create(configuration, environment, log):
|
|||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class CSVTask(Task):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
|
||||
def execute(self):
|
||||
print("Hello from CSV Task...")
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ def create(configuration, environment, log):
|
|||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class FileTask(Task):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
|
||||
def execute(self):
|
||||
print("Hello from File Task...")
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@ def create(configuration, environment, log):
|
|||
|
||||
# TODO: check for all required configuration options and set defaults if needed.
|
||||
class MariaDBTask(Task):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
|
||||
def execute(self):
|
||||
print("Hello from MariaDB Task...")
|
||||
|
|
|
|||
|
|
@ -14,6 +14,4 @@ def create(configuration, environment, log):
|
|||
class RedisTask(Task):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -14,6 +14,4 @@ def create(configuration, environment, log):
|
|||
class SplunkTask(Task):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -14,6 +14,4 @@ def create(configuration, environment, log):
|
|||
class SQLiteTask(Task):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -14,6 +14,4 @@ def create(configuration, environment, log):
|
|||
class SyslogTask(Task):
|
||||
def __init__(self, configuration, environment, log):
|
||||
super().__init__(configuration, environment, log)
|
||||
self._configuration = configuration
|
||||
self._environment = environment
|
||||
self._log = log
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue