2013-05-16 23:03:00 +02:00
|
|
|
"""
|
2013-05-27 20:27:57 +02:00
|
|
|
This is what job_function needs as parameter for each job to successfully
|
2013-05-16 23:03:00 +02:00
|
|
|
execute.
|
|
|
|
|
"""
|
2013-08-14 20:36:35 +02:00
|
|
|
|
2013-07-02 23:30:31 +02:00
|
|
|
from datetime import datetime
|
2013-05-30 04:20:35 +02:00
|
|
|
|
2013-08-13 22:48:51 +02:00
|
|
|
|
2013-05-29 22:52:54 +02:00
|
|
|
def generateId():
|
2013-05-30 04:20:35 +02:00
|
|
|
i = 0
|
2013-05-29 22:52:54 +02:00
|
|
|
while True:
|
2013-05-30 04:20:35 +02:00
|
|
|
yield i
|
|
|
|
|
i += 1
|
|
|
|
|
|
2013-08-14 20:36:35 +02:00
|
|
|
|
2013-07-02 23:30:31 +02:00
|
|
|
class Job:
|
2013-08-14 00:39:45 +02:00
|
|
|
def __init__(self, service, host):
|
2013-06-21 02:20:58 +02:00
|
|
|
self.service = service
|
2013-08-14 00:39:45 +02:00
|
|
|
self.host = host
|
2013-07-02 23:30:31 +02:00
|
|
|
self.jobInfos = []
|
2013-08-14 00:39:45 +02:00
|
|
|
self.jobThreshold = 0
|
2013-07-02 23:30:31 +02:00
|
|
|
|
2013-05-27 01:44:28 +02:00
|
|
|
def __str__(self):
|
2013-07-02 23:30:31 +02:00
|
|
|
return str(self.__dict__)
|
|
|
|
|
|
2013-06-21 02:20:58 +02:00
|
|
|
def set_logger(self, log):
|
2013-05-27 03:13:08 +02:00
|
|
|
self.log = log
|
2013-06-21 02:20:58 +02:00
|
|
|
|
|
|
|
|
def set_job(self, job):
|
|
|
|
|
self.job = job
|
|
|
|
|
|
2013-08-14 00:39:45 +02:00
|
|
|
def handle_threshold(self, serviceThreshold, executionSucessful):
|
|
|
|
|
if executionSucessful:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
self.jobThreshold += 1
|
|
|
|
|
|
|
|
|
|
if self.jobThreshold >= serviceThreshold:
|
|
|
|
|
self.handle_alarm(self.jobThreshold-serviceThreshold)
|
|
|
|
|
|
|
|
|
|
def handle_alarm(self, threholdOffset):
|
|
|
|
|
pass
|
|
|
|
|
|
2013-06-21 02:20:58 +02:00
|
|
|
def handle_call(self):
|
2013-05-29 22:52:54 +02:00
|
|
|
self.log.d("handle call")
|
2013-06-21 02:20:58 +02:00
|
|
|
self.log.d(self.service)
|
2013-08-14 00:39:45 +02:00
|
|
|
try:
|
|
|
|
|
jobInfo = JobInfo(self.host, self.service)
|
|
|
|
|
result = self.service._execute(self.host)
|
|
|
|
|
jobInfo.set_result(result)
|
2013-08-14 20:36:35 +02:00
|
|
|
jobInfo.set_execution_successful(self.service.was_execution_successful())
|
2013-08-14 00:39:45 +02:00
|
|
|
jobInfo.set_execution_end()
|
2013-07-02 00:19:20 +02:00
|
|
|
|
2013-08-14 00:39:45 +02:00
|
|
|
self.handle_threshold(self.service.get_threshold(), self.service.was_execution_successful())
|
2013-07-02 23:30:31 +02:00
|
|
|
|
2013-08-14 00:39:45 +02:00
|
|
|
self.jobInfos.append(jobInfo)
|
|
|
|
|
|
|
|
|
|
except Exception, e:
|
|
|
|
|
self.log.d(e)
|
2013-07-02 23:30:31 +02:00
|
|
|
|
2013-08-14 20:36:35 +02:00
|
|
|
|
2013-07-02 23:30:31 +02:00
|
|
|
class JobInfo:
|
|
|
|
|
def __init__(self, host, service):
|
|
|
|
|
self.id = generateId()
|
|
|
|
|
self.host = host
|
|
|
|
|
self.service = service
|
|
|
|
|
self.executionBegin = datetime.now()
|
|
|
|
|
|
|
|
|
|
def set_result(self, result):
|
|
|
|
|
self.result = result
|
|
|
|
|
|
|
|
|
|
def set_execution_end(self):
|
|
|
|
|
self.executionEnd = datetime.now()
|
|
|
|
|
|
|
|
|
|
def set_execution_successful(self, successful):
|
2013-08-14 20:36:35 +02:00
|
|
|
self.executionSuccess = successful
|