Added basic scheduler code.

This commit is contained in:
Johannes Findeisen 2022-09-29 22:21:31 +02:00
commit ca6b424473
3 changed files with 36 additions and 6 deletions

View file

@ -32,7 +32,7 @@ from linspector.core.environment import Environment
from linspector.core.linspector import Linspector
from linspector.core.monitors import Monitors
__version__ = '0.19.8'
__version__ = '0.19.9'
__author__ = 'Johannes Findeisen <you@hanez.org>'
logger = logging.getLogger('linspector')
@ -70,6 +70,7 @@ def main():
monitors = None
notifications = {}
plugins = {}
scheduler = {}
services = {}
tasks = {}
@ -123,7 +124,7 @@ def main():
logger.warning('[linspector] monitor initialization error: {0}'.format(err))
try:
linspector = Linspector(configuration, environment, monitors, plugins)
linspector = Linspector(configuration, environment, monitors, plugins, scheduler)
except Exception as err:
logger.critical('[linspector] core initialization error: {0}'.format(err))
sys.exit(1)

View file

@ -21,6 +21,11 @@ notifications = SMS
run_mode = cron
; members to send notifications to if something internally in Linspector went wrong.
members = superadmin@example.com,developers@example.com
; scheduler configuration
start_scheduler = true
max_threads = 3500
max_processes = 100
timezone = CET
; hostgroup parents; if the hostgroup "group1" is down, don't alert for the hosts in group2. see TODO.txt for more
; information.

View file

@ -7,21 +7,26 @@ import importlib
from logging import getLogger
#from apscheduler.schedulers.background import BackgroundScheduler
#from apscheduler.jobstores.memory import MemoryJobStore
#from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.executors.pool import ThreadPoolExecutor # , ProcessPoolExecutor
logger = getLogger('linspector')
def job_function(job):
job.handle_call()
class Linspector:
def __init__(self, configuration, environment, monitors, plugins):
def __init__(self, configuration, environment, monitors, plugins, scheduler):
self.__configuration = configuration
self.__environment = environment
self.__monitors = monitors
self.__plugin_list = None
self.__plugins = plugins
self.__scheduler = scheduler
# load plugins
logger.info('loading plugins...')
@ -36,6 +41,25 @@ class Linspector:
plugin = plugin_module.get(configuration, environment, self)
plugins[plugin_option.lower()] = plugin
jobstores = {
'memory': MemoryJobStore()
}
executors = {
'default': ThreadPoolExecutor(int(configuration.get_option('linspector',
'max_threads'))),
#'default': ProcessPoolExecutor(int(configuration.get_option('linspector',
# 'max_processes')))
}
job_defaults = {
'max_instances': 10000
}
self.__scheduler['linspector'] = BackgroundScheduler(jobstores=jobstores,
executors=executors,
job_defaults=job_defaults)
if configuration.get_option('linspector', 'start_scheduler') == 'true':
self.__scheduler['linspector'].start()
# this function is just for testing purposes and can be removed some day
def print_debug(self):
# example on how to access the monitor objects in monitors