aboutsummaryrefslogtreecommitdiff
path: root/jobs/TCPServerChecker.py
diff options
context:
space:
mode:
authorTom Ritter <tom@ritter.vg>2016-01-31 13:22:08 -0600
committerTom Ritter <tom@ritter.vg>2016-01-31 13:22:08 -0600
commit3bea3bae59e7404b286b5bf97a6270270bfadd6c (patch)
treec9d1d7cf76681420587198d09abda761912c47c4 /jobs/TCPServerChecker.py
parent1a8b46d940d3a4bc06700d15307191bb10008ea6 (diff)
Refactor lots of things to allow you to be notified every so often, instead of every single time.
Diffstat (limited to 'jobs/TCPServerChecker.py')
-rwxr-xr-xjobs/TCPServerChecker.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/jobs/TCPServerChecker.py b/jobs/TCPServerChecker.py
index 711047b..642e188 100755
--- a/jobs/TCPServerChecker.py
+++ b/jobs/TCPServerChecker.py
@@ -9,20 +9,24 @@ import JobSpawner
class TCPServerChecker(JobSpawner.JobSpawner):
servers = [
- #("example.com", 53, "example.com:tcpdns", JobBase.JobFrequency.MINUTE),
+ #("example.com", 53, "example.com:tcpdns", JobBase.JobFrequency.MINUTE, JobBase.JobFailureNotificationFrequency.EVERYTIME)
]
class ServerChecker(JobBase.JobBase):
- def __init__(self, ip, port, friendlyName, frequency):
+ def __init__(self, config, ip, port, friendlyName, frequency, failureNotificationFrequency):
+ self.config = config
self.ip = ip
self.port = port
self.friendlyName = friendlyName + "(" + self.ip + ":" + str(self.port) + ")"
self.frequency = frequency
+ self.failureNotificationFrequency = failureNotificationFrequency
def getName(self):
return str(self.__class__) + " for " + self.friendlyName
def executeEvery(self):
return self.frequency
+ def notifyOnFailureEvery(self):
+ return self.failureNotificationFrequency
def execute(self):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -30,12 +34,16 @@ class TCPServerChecker(JobSpawner.JobSpawner):
s.close()
return True
except:
- msg = "Could not hit server " + self.friendlyName
- logging.warn(msg)
- return self.sendEmail(msg, "")
+ self.failuremsg = "Could not hit server " + self.friendlyName
+ logging.warn(self.failuremsg)
+ return False
+ def onFailure(self):
+ return self.sendEmail(self.failuremsg, "")
+ def onStateChangeSuccess(self):
+ return self.sendEmail("Successfully hit " + self.friendlyName, "")
- def get_sub_jobs(self):
+ def get_sub_jobs(self, config):
for s in self.servers:
- yield self.ServerChecker(s[0], s[1], s[2], s[3])
+ yield self.ServerChecker(config, s[0], s[1], s[2], s[3], s[4])