Some more error handling and logging.

This commit is contained in:
Johannes Findeisen 2022-10-06 03:24:16 +02:00
commit a2fe8e8196
2 changed files with 11 additions and 6 deletions

View file

@ -1,4 +1,4 @@
; requireed options ; required options
[monitor] [monitor]
description = Test1 description = Test1
service = misc.dummy service = misc.dummy
@ -6,7 +6,7 @@ hosts = 192.168.10.10
; optional options ; optional options
[args] [args]
interval = 60 interval = 13
; the start is to schedule the execution of the monitor in at a date in the future. this is helpful to configure ; the start is to schedule the execution of the monitor in at a date in the future. this is helpful to configure
; linspector before a host is up and running. ; linspector before a host is up and running.
start_date = 2025-01-01 00:00:00 start_date = 2022-01-01 00:00:00

View file

@ -12,8 +12,13 @@ from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor
def job_function(monitor): def job_function(monitor, log):
monitor.handle_call() try:
log('debug', 'executing job_function for monitor: ' + monitor.get_identifier())
monitor.handle_call()
except Exception as err:
log('warning', 'execution failed for job_function for monitor: ' +
monitor.get_identifier() + ' error: ' + str(err))
class Linspector: class Linspector:
@ -99,7 +104,7 @@ class Linspector:
scheduler_job = scheduler['linspector'].add_job(job_function, 'interval', scheduler_job = scheduler['linspector'].add_job(job_function, 'interval',
start_date=new_start_date, start_date=new_start_date,
seconds=interval, timezone=timezone, seconds=interval, timezone=timezone,
args=[monitors.get(monitor)]) args=[monitors.get(monitor), log])
monitor_job.set_job(scheduler_job) monitor_job.set_job(scheduler_job)
self.__jobs.append(monitor_job) self.__jobs.append(monitor_job)