From a2fe8e819616d6c9dfb1b3b9adb242e66be4c8d8 Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Thu, 6 Oct 2022 03:24:16 +0200 Subject: [PATCH] Some more error handling and logging. --- etc/monitors/test/test1.conf | 6 +++--- linspector/core/linspector.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/etc/monitors/test/test1.conf b/etc/monitors/test/test1.conf index f6ca229..b3cff6c 100644 --- a/etc/monitors/test/test1.conf +++ b/etc/monitors/test/test1.conf @@ -1,4 +1,4 @@ -; requireed options +; required options [monitor] description = Test1 service = misc.dummy @@ -6,7 +6,7 @@ hosts = 192.168.10.10 ; optional options [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 ; linspector before a host is up and running. -start_date = 2025-01-01 00:00:00 +start_date = 2022-01-01 00:00:00 diff --git a/linspector/core/linspector.py b/linspector/core/linspector.py index 966b12a..1cb2d2b 100644 --- a/linspector/core/linspector.py +++ b/linspector/core/linspector.py @@ -12,8 +12,13 @@ from apscheduler.jobstores.memory import MemoryJobStore from apscheduler.executors.pool import ThreadPoolExecutor, ProcessPoolExecutor -def job_function(monitor): - monitor.handle_call() +def job_function(monitor, log): + 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: @@ -99,7 +104,7 @@ class Linspector: scheduler_job = scheduler['linspector'].add_job(job_function, 'interval', start_date=new_start_date, seconds=interval, timezone=timezone, - args=[monitors.get(monitor)]) + args=[monitors.get(monitor), log]) monitor_job.set_job(scheduler_job) self.__jobs.append(monitor_job)