From fc925d1d8227b6e4efb7cd39f2f190f18d45f95e Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Thu, 6 Oct 2022 03:08:16 +0200 Subject: [PATCH] Made the monitor interval optional and set 300 seconds to default. --- bin/linspector | 4 ++-- etc/monitors/network1/gateway.conf | 4 ++-- etc/monitors/network2/gateway.conf | 2 +- etc/monitors/test/test1.conf | 2 +- etc/monitors/test/test10.conf | 2 +- etc/monitors/test/test2.conf | 2 +- etc/monitors/test/test3.conf | 2 +- etc/monitors/test/test4.conf | 2 +- etc/monitors/test/test5.conf | 2 +- etc/monitors/test/test6.conf | 2 +- etc/monitors/test/test7.conf | 2 +- etc/monitors/test/test8.conf | 2 +- etc/monitors/test/test9.conf | 2 +- linspector/core/monitor.py | 13 +++++++++---- 14 files changed, 24 insertions(+), 19 deletions(-) diff --git a/bin/linspector b/bin/linspector index b6c8bb3..35ee331 100755 --- a/bin/linspector +++ b/bin/linspector @@ -35,9 +35,9 @@ from linspector.core.monitors import Monitors logger = logging.getLogger('linspector') -# i currently only increase the 3rd number because the goal is that 0.19 will become the first +# i currently only increase the 3rd number because the goal is that 0.20.* will become the first # stable version. -__version__ = '0.19.31.dev1' +__version__ = '0.19.32.dev1' __author__ = 'Johannes Findeisen ' diff --git a/etc/monitors/network1/gateway.conf b/etc/monitors/network1/gateway.conf index 3a16301..c8adc13 100644 --- a/etc/monitors/network1/gateway.conf +++ b/etc/monitors/network1/gateway.conf @@ -5,13 +5,13 @@ description = Cable Provider service = net.fritzboxuplink hosts = 192.168.0.1,192.168.23.24,@group1,@testgroup1 -; this only depends on the SLA you made with the product owner. -interval = 60 ; optional options when using notifications, plugins, services or tasks. btw. they still can be a required argument by ; a corresponding notification, plugin, service or task. they will need to check required args by themself and throw an ; exception if something fails. linspector never knows about required args: [args] +; this only depends on the SLA you made with the product owner. this option is optional. the default is 300 seconds. +interval = 60 ; notifications separated by ','. no whitespaces allowed. the case is not important. notifications = sms,emaiL ; values from main configuration can be overridden for each defined monitor diff --git a/etc/monitors/network2/gateway.conf b/etc/monitors/network2/gateway.conf index 5461957..7f6b3d6 100644 --- a/etc/monitors/network2/gateway.conf +++ b/etc/monitors/network2/gateway.conf @@ -1,10 +1,10 @@ [monitor] description = Cable Provider service = Net.FritzboxUplink -interval = 60 hosts = 192.168.1.1 [args] +interval = 60 notifications = email email_receivers = admin@example.com,fallback@example.com sms_receivers = +number1,+number2 diff --git a/etc/monitors/test/test1.conf b/etc/monitors/test/test1.conf index 03c8436..f6ca229 100644 --- a/etc/monitors/test/test1.conf +++ b/etc/monitors/test/test1.conf @@ -3,10 +3,10 @@ description = Test1 service = misc.dummy hosts = 192.168.10.10 -interval = 60 ; optional options [args] +interval = 60 ; 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 diff --git a/etc/monitors/test/test10.conf b/etc/monitors/test/test10.conf index 7c212c7..df5e30c 100644 --- a/etc/monitors/test/test10.conf +++ b/etc/monitors/test/test10.conf @@ -1,7 +1,7 @@ [monitor] description = Test10 service = misc.dummy -interval = 120 hosts = 192.168.10.10 [args] +interval = 120 diff --git a/etc/monitors/test/test2.conf b/etc/monitors/test/test2.conf index 4bc6b10..2869d7a 100644 --- a/etc/monitors/test/test2.conf +++ b/etc/monitors/test/test2.conf @@ -1,8 +1,8 @@ [monitor] description = Test2 service = misc.dummy -interval = 10 hosts = 192.168.10.10 [args] +interval = 10 test_dummy_arg = nothing diff --git a/etc/monitors/test/test3.conf b/etc/monitors/test/test3.conf index caf95cd..0533bf6 100644 --- a/etc/monitors/test/test3.conf +++ b/etc/monitors/test/test3.conf @@ -1,8 +1,8 @@ [monitor] description = Test3 service = misc.dummy -interval = 5 hosts = 192.168.10.10 [args] +interval = 5 foo = bar diff --git a/etc/monitors/test/test4.conf b/etc/monitors/test/test4.conf index 10d3042..b7256c6 100644 --- a/etc/monitors/test/test4.conf +++ b/etc/monitors/test/test4.conf @@ -1,7 +1,7 @@ [monitor] description = Test4 service = misc.dummy -interval = 50 hosts = 192.168.10.10 [args] +interval = 50 diff --git a/etc/monitors/test/test5.conf b/etc/monitors/test/test5.conf index 32122d3..fab5f84 100644 --- a/etc/monitors/test/test5.conf +++ b/etc/monitors/test/test5.conf @@ -1,7 +1,7 @@ [monitor] description = Test5 service = net.FritzboxUplink -interval = 62 hosts = 192.168.10.10 [args] +interval = 62 diff --git a/etc/monitors/test/test6.conf b/etc/monitors/test/test6.conf index 3c31d9a..668e91c 100644 --- a/etc/monitors/test/test6.conf +++ b/etc/monitors/test/test6.conf @@ -1,7 +1,7 @@ [monitor] description = Test6 service = misc.dummy -interval = 30 hosts = 192.168.10.10 [args] +interval = 30 diff --git a/etc/monitors/test/test7.conf b/etc/monitors/test/test7.conf index 7c1ae31..a8dd326 100644 --- a/etc/monitors/test/test7.conf +++ b/etc/monitors/test/test7.conf @@ -1,7 +1,7 @@ [monitor] description = Test7 service = misc.dummy -interval = 20 hosts = 192.168.10.10 [args] +interval = 20 diff --git a/etc/monitors/test/test8.conf b/etc/monitors/test/test8.conf index 5555ce8..0a97d42 100644 --- a/etc/monitors/test/test8.conf +++ b/etc/monitors/test/test8.conf @@ -1,7 +1,7 @@ [monitor] description = Test8 service = misc.dummy -interval = 15 hosts = 192.168.10.10 [args] +interval = 15 diff --git a/etc/monitors/test/test9.conf b/etc/monitors/test/test9.conf index b703f41..d5a622a 100644 --- a/etc/monitors/test/test9.conf +++ b/etc/monitors/test/test9.conf @@ -1,7 +1,7 @@ [monitor] description = Test9 service = misc.dummy -interval = 240 hosts = 192.168.10.10 [args] +interval = 240 diff --git a/linspector/core/monitor.py b/linspector/core/monitor.py index 2ec45da..7773984 100644 --- a/linspector/core/monitor.py +++ b/linspector/core/monitor.py @@ -14,14 +14,19 @@ from linspector.core.task import Task, TaskExecutor class Monitor: - def __init__(self, configuration, environment, identifier, log, monitor_configuration, notifications, services, tasks, kwargs): self.__args = kwargs self.__configuration = configuration self.__environment = environment self.__identifier = identifier - self.__interval = int(monitor_configuration.get('monitor', 'interval')) + if int(monitor_configuration.get('args', 'interval')): + self.__interval = int(monitor_configuration.get('args', 'interval')) + else: + # default interval is 5 minutes if not set in the monitor. + log('warning', 'no interval set in identifier ' + identifier + ' set to default ' + 'interval 300 seconds.') + self.__interval = 300 self.__log = log self.__monitor_configuration = monitor_configuration self.__notification_list = [] @@ -47,9 +52,9 @@ class Monitor: """ NONE job was not executed OK when everything is fine - WARNING when a job has errors but not the threshold overridden + WARNING when a job has errors but the threshold is not overridden RECOVER when a job recovers e.g. the threshold decrements (not implemented) - ERROR when a jobs threshold is overridden + ERROR when a jobs error threshold is overridden UNKNOWN when a job throws an exception which is not handled by the job itself (not implemented) """