diff options
author | Tom Ritter <tom@ritter.vg> | 2016-01-31 13:22:08 -0600 |
---|---|---|
committer | Tom Ritter <tom@ritter.vg> | 2016-01-31 13:22:08 -0600 |
commit | 3bea3bae59e7404b286b5bf97a6270270bfadd6c (patch) | |
tree | c9d1d7cf76681420587198d09abda761912c47c4 /jobs/HTTPServerChecker.py | |
parent | 1a8b46d940d3a4bc06700d15307191bb10008ea6 (diff) |
Refactor lots of things to allow you to be notified every so often, instead of every single time.
Diffstat (limited to 'jobs/HTTPServerChecker.py')
-rwxr-xr-x | jobs/HTTPServerChecker.py | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/jobs/HTTPServerChecker.py b/jobs/HTTPServerChecker.py index ec8eda1..ec2a9d6 100755 --- a/jobs/HTTPServerChecker.py +++ b/jobs/HTTPServerChecker.py @@ -8,29 +8,37 @@ import JobSpawner class HTTPServerChecker(JobSpawner.JobSpawner):
servers = [
- #("http://example.com", JobBase.JobFrequency.MINUTE),
- #("https://exampletwo.com", JobBase.JobFrequency.MINUTE)
+ #("http://example.com", JobBase.JobFrequency.MINUTE, JobBase.JobFailureNotificationFrequency.EVERYTIME),
+ #("https://exampletwo.com", JobBase.JobFrequency.MINUTE, JobBase.JobFailureNotificationFrequency.EVERYTIME)
]
class ServerChecker(JobBase.JobBase):
- def __init__(self, url, frequency):
+ def __init__(self, config, url, frequency, failureNotificationFrequency):
+ self.config = config
self.url = url
self.frequency = frequency
+ self.failureNotificationFrequency = failureNotificationFrequency
def getName(self):
return str(self.__class__) + " for " + self.url
def executeEvery(self):
return self.frequency
+ def notifyOnFailureEvery(self):
+ return self.failureNotificationFrequency
def execute(self):
try:
requests.get(self.url)
return True
except:
- msg = "Could not hit server " + self.url
- logging.warn(msg)
- return self.sendEmail(msg, "")
+ self.failuremsg = "Could not hit server " + self.url
+ logging.warn(self.failuremsg)
+ return False
+ def onFailure(self):
+ return self.sendEmail(self.failuremsg, "")
+ def onStateChangeSuccess(self):
+ return self.sendEmail("Successfully hit " + self.url, "")
- def get_sub_jobs(self):
+ def get_sub_jobs(self, config):
for s in self.servers:
- yield self.ServerChecker(s[0], s[1])
+ yield self.ServerChecker(config, s[0], s[1], s[2])
|