From 3e85f1d0d48f0fb65a83af6ce3fb4b6a08f0bb1a Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 28 Dec 2016 13:59:43 -0600 Subject: Create an option that lets you require two failures before alerting. --- jobs/HTTPServerChecker.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'jobs/HTTPServerChecker.py') diff --git a/jobs/HTTPServerChecker.py b/jobs/HTTPServerChecker.py index 9336588..8f0e88f 100755 --- a/jobs/HTTPServerChecker.py +++ b/jobs/HTTPServerChecker.py @@ -8,17 +8,18 @@ import JobSpawner class HTTPServerChecker(JobSpawner.JobSpawner): servers = [ - #("http://example.com", JobBase.JobFrequency.MINUTE, JobBase.JobFailureNotificationFrequency.EVERYTIME), - #("https://exampletwo.com", JobBase.JobFrequency.MINUTE, JobBase.JobFailureNotificationFrequency.EVERYTIME) + #("http://example.com", JobBase.JobFrequency.MINUTE, JobBase.JobFailureNotificationFrequency.EVERYTIME, JobBase.JobFailureCountMinimumBeforeNotification.ONE), + #("https://exampletwo.com", JobBase.JobFrequency.MINUTE, JobBase.JobFailureNotificationFrequency.EVERYTIME, JobBase.JobFailureCountMinimumBeforeNotification.ONE) ] class ServerChecker(JobBase.JobBase): - def __init__(self, config, url, frequency, failureNotificationFrequency): + def __init__(self, config, url, frequency, failureNotificationFrequency, failuresBeforeNotification): self.config = config self.url = url self.frequency = frequency self.failureNotificationFrequency = failureNotificationFrequency - super(HTTPServerChecker.ServerChecker, self).__init__(config, url, frequency, failureNotificationFrequency) + self.failuresBeforeNotification = failuresBeforeNotification + super(HTTPServerChecker.ServerChecker, self).__init__(config, url, frequency, failureNotificationFrequency, failuresBeforeNotification) def getName(self): return str(self.__class__) + " for " + self.url @@ -26,6 +27,8 @@ class HTTPServerChecker(JobSpawner.JobSpawner): return self.frequency def notifyOnFailureEvery(self): return self.failureNotificationFrequency + def numberFailuresBeforeNotification(self): + return self.failuresBeforeNotification def execute(self): try: i = requests.get(self.url) @@ -44,5 +47,5 @@ class HTTPServerChecker(JobSpawner.JobSpawner): def get_sub_jobs(self, config): for s in self.servers: - yield self.ServerChecker(config, s[0], s[1], s[2]) + yield self.ServerChecker(config, s[0], s[1], s[2], s[3]) -- cgit v1.2.3