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/JobBase.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'jobs/JobBase.py') diff --git a/jobs/JobBase.py b/jobs/JobBase.py index 78c8c71..6b47eb7 100755 --- a/jobs/JobBase.py +++ b/jobs/JobBase.py @@ -22,6 +22,10 @@ class JobFailureNotificationFrequency: EVERYDAY = "day" ONSTATECHANGE = "state_change" +class JobFailureCountMinimumBeforeNotification: + ONE = "one" + TWO = "two" + class JobBase(object): def __init__(self, config, *args): self.config = config @@ -47,6 +51,14 @@ class JobBase(object): """Returns True if the jobmanager should call 'onFailure' to alert the admin""" def shouldNotifyFailure(self, jobState): notifyFrequency = self.notifyOnFailureEvery() + minFailureCount = self.numberFailuresBeforeNotification() + + if minFailureCount == JobFailureCountMinimumBeforeNotification.ONE: + pass + elif minFailureCount == JobFailureCountMinimumBeforeNotification.TWO: + if jobState.CurrentStateSuccess: + return False + if notifyFrequency == JobFailureNotificationFrequency.EVERYTIME: return True elif notifyFrequency == JobFailureNotificationFrequency.EVERYFIVEMINUTES: @@ -94,6 +106,12 @@ class JobBase(object): def notifyOnFailureEvery(self): pass + """OVERRIDE ME + Returns a JobFailureCountMinimumBeforeNotification indicating how many + failures should occur before a notification email should be sent""" + def numberFailuresBeforeNotification(self): + pass + """OVERRIDE ME Executes the job's actions, and returns true to indicate the job succeeded.""" def execute(self): -- cgit v1.2.3