Moved databases from tasks to own concept because they need persistent connections. Tasks do now allow this. (0.24.0)
This commit is contained in:
parent
21c684bfbc
commit
52b0c6b509
9 changed files with 62 additions and 28 deletions
|
|
@ -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.2'
|
__version__ = '0.24.0'
|
||||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -48,6 +48,7 @@ def parse_args():
|
||||||
|
|
||||||
def linspector():
|
def linspector():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
databases = {}
|
||||||
monitors = {}
|
monitors = {}
|
||||||
notifications = {}
|
notifications = {}
|
||||||
plugins = {}
|
plugins = {}
|
||||||
|
|
@ -103,24 +104,40 @@ def linspector():
|
||||||
environment = Environment(log)
|
environment = Environment(log)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if configuration.get_option('linspector', 'tasks'):
|
if configuration.get_option('linspector', 'databases'):
|
||||||
log.info(configuration.get_option('linspector', 'tasks'))
|
log.info('Loading databases: ' + configuration.get_option('linspector', 'databases'))
|
||||||
|
database_list = configuration.get_option('linspector', 'databases')
|
||||||
|
database_list = database_list.split(',')
|
||||||
|
for database_name in database_list:
|
||||||
|
database_package = 'linspector.databases.' + database_name
|
||||||
|
if importlib.util.find_spec(database_package) is not None:
|
||||||
|
database_module = importlib.import_module(database_package)
|
||||||
|
database_object = database_module.create(configuration, environment, log)
|
||||||
|
databases[database_name] = database_object
|
||||||
|
else:
|
||||||
|
log.warning('initialization of database: {0} failed! seems it does not exist.'.
|
||||||
|
format(database_name))
|
||||||
|
except Exception as err:
|
||||||
|
log.warning('database initialization error: {0}'.format(err))
|
||||||
|
|
||||||
|
try:
|
||||||
|
if configuration.get_option('linspector', 'tasks'):
|
||||||
|
log.info('Loading tasks: ' + configuration.get_option('linspector', 'tasks'))
|
||||||
task_list = configuration.get_option('linspector', 'tasks')
|
task_list = configuration.get_option('linspector', 'tasks')
|
||||||
task_list = task_list.split(',')
|
task_list = task_list.split(',')
|
||||||
for task_name in task_list:
|
for task_name in task_list:
|
||||||
task_package = 'linspector.tasks.' + task_name
|
task_package = 'linspector.tasks.' + task_name
|
||||||
if importlib.util.find_spec(task_package) is not None:
|
if importlib.util.find_spec(task_package) is not None:
|
||||||
task_module = importlib.import_module(task_package)
|
task_module = importlib.import_module(task_package)
|
||||||
task = task_module.create(configuration, environment, log)
|
task_object = task_module.create(configuration, environment, log)
|
||||||
tasks[task_name] = task
|
tasks[task_name] = task_object
|
||||||
else:
|
else:
|
||||||
log.warning('initialization of 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))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
monitors = Monitors(configuration, environment, log, notifications, services, tasks)
|
monitors = Monitors(configuration, databases, environment, log, notifications, services, tasks)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
log.warning('monitor initialization error: {0}'.format(err))
|
log.warning('monitor initialization error: {0}'.format(err))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,13 @@ logfile_level = DEBUG
|
||||||
; size of logfiles (default: 1MB)
|
; size of logfiles (default: 1MB)
|
||||||
logfile_size = 10MB
|
logfile_size = 10MB
|
||||||
|
|
||||||
|
databases = mariadb
|
||||||
|
|
||||||
notifications =
|
notifications =
|
||||||
|
|
||||||
plugins =
|
plugins =
|
||||||
|
|
||||||
tasks = mariadb
|
tasks =
|
||||||
|
|
||||||
; timezone can be set to a remote timezone to make monitors run at the remote time. this can be overridden in each
|
; timezone can be set to a remote timezone to make monitors run at the remote time. this can be overridden in each
|
||||||
; monitor configuration.
|
; monitor configuration.
|
||||||
|
|
|
||||||
13
linspector/database.py
Normal file
13
linspector/database.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
"""
|
||||||
|
This file is part of Linspector (https://linspector.org/)
|
||||||
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
|
See LICENSE (MIT license).
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Database:
|
||||||
|
def __init__(self, configuration, environment, log, **kwargs):
|
||||||
|
self._args = {}
|
||||||
|
self._configuration = configuration
|
||||||
|
self._environment = environment
|
||||||
|
self._log = log
|
||||||
0
linspector/databases/__init__.py
Normal file
0
linspector/databases/__init__.py
Normal file
16
linspector/databases/mariadb.py
Normal file
16
linspector/databases/mariadb.py
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
"""
|
||||||
|
This file is part of Linspector (https://linspector.org/)
|
||||||
|
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
||||||
|
See LICENSE (MIT license).
|
||||||
|
"""
|
||||||
|
from linspector.database import Database
|
||||||
|
|
||||||
|
|
||||||
|
def create(configuration, environment, log):
|
||||||
|
return MariaDBDatabase(configuration, environment, log)
|
||||||
|
|
||||||
|
|
||||||
|
class MariaDBDatabase(Database):
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
self._log.debug("Hello from MariaDB Database...")
|
||||||
|
|
@ -8,10 +8,11 @@ import importlib
|
||||||
|
|
||||||
|
|
||||||
class Monitor:
|
class Monitor:
|
||||||
def __init__(self, configuration, environment, identifier, log, monitor_configuration,
|
def __init__(self, configuration, databases, environment, identifier, log,
|
||||||
notifications, services, tasks, kwargs):
|
monitor_configuration, notifications, services, tasks, kwargs):
|
||||||
self._args = kwargs
|
self._args = kwargs
|
||||||
self._configuration = configuration
|
self._configuration = configuration
|
||||||
|
self._databases = databases
|
||||||
self._enabled = True
|
self._enabled = True
|
||||||
self._environment = environment
|
self._environment = environment
|
||||||
self._host = monitor_configuration.get('monitor', 'host')
|
self._host = monitor_configuration.get('monitor', 'host')
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,9 @@ from linspector.monitor import Monitor
|
||||||
# if a new monitor is added at runtime it needs to be checked manually by running a "reload" command
|
# if a new monitor is added at runtime it needs to be checked manually by running a "reload" command
|
||||||
# to lish which walks thrue all scheduled jobs and when an unknown monitor is found, schedule it.
|
# to lish which walks thrue all scheduled jobs and when an unknown monitor is found, schedule it.
|
||||||
class Monitors:
|
class Monitors:
|
||||||
def __init__(self, configuration, environment, log, notifications, services, tasks):
|
def __init__(self, configuration, databases, environment, log, notifications, services, tasks):
|
||||||
self._configuration = configuration
|
self._configuration = configuration
|
||||||
|
self._databases = databases
|
||||||
self._environment = environment
|
self._environment = environment
|
||||||
self._log = log
|
self._log = log
|
||||||
self._notifications = notifications
|
self._notifications = notifications
|
||||||
|
|
@ -57,6 +58,7 @@ class Monitors:
|
||||||
# create Monitor() object and copy monitor_configuration for each instance because
|
# create Monitor() object and copy monitor_configuration for each instance because
|
||||||
# they else refer to the same object? copy.deepcopy(monitor_configuration)???
|
# they else refer to the same object? copy.deepcopy(monitor_configuration)???
|
||||||
self._monitors[identifier] = Monitor(self._configuration,
|
self._monitors[identifier] = Monitor(self._configuration,
|
||||||
|
self._databases,
|
||||||
self._environment,
|
self._environment,
|
||||||
identifier,
|
identifier,
|
||||||
self._log,
|
self._log,
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
"""
|
|
||||||
This file is part of Linspector (https://linspector.org/)
|
|
||||||
Copyright (c) 2022-2023 Johannes Findeisen <you@hanez.org>. All Rights Reserved.
|
|
||||||
See LICENSE (MIT license).
|
|
||||||
"""
|
|
||||||
from linspector.task import Task
|
|
||||||
|
|
||||||
|
|
||||||
def create(configuration, environment, log):
|
|
||||||
return MariaDBTask(configuration, environment, log)
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed.
|
|
||||||
class MariaDBTask(Task):
|
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
self._log.debug("Hello from MariaDB Task...")
|
|
||||||
|
|
@ -2,7 +2,7 @@ APScheduler==3.10.4
|
||||||
CherryPy==18.8.0
|
CherryPy==18.8.0
|
||||||
asyncssh==2.13.2
|
asyncssh==2.13.2
|
||||||
fastapi==0.101.1
|
fastapi==0.101.1
|
||||||
fritzconnection==1.13.0
|
fritzconnection==1.13.1
|
||||||
loguru==0.7.0
|
loguru==0.7.0
|
||||||
paramiko==3.3.1
|
paramiko==3.3.1
|
||||||
pydantic==2.2.1
|
pydantic==2.2.1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue