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-05-29 01:03:01 +02:00
|
|
|
from command import Command
|
2013-05-27 19:30:49 +02:00
|
|
|
|
2013-05-29 22:52:54 +02:00
|
|
|
def generateId():
|
|
|
|
|
i=0
|
|
|
|
|
while True:
|
|
|
|
|
yield i
|
|
|
|
|
i+=1
|
2013-05-16 23:03:00 +02:00
|
|
|
|
2013-05-27 01:44:28 +02:00
|
|
|
class JobInfo:
|
2013-05-29 22:52:54 +02:00
|
|
|
def __init__(self, hostgroupname, members, hosts, hostServices, threshold, parent=None):
|
2013-05-16 23:03:00 +02:00
|
|
|
self.members = members
|
2013-05-27 01:44:28 +02:00
|
|
|
self.hosts = hosts
|
2013-05-29 22:52:54 +02:00
|
|
|
self.hostServices = hostServices
|
2013-05-27 01:44:28 +02:00
|
|
|
self.threshold = threshold
|
|
|
|
|
self.parent = parent
|
2013-05-29 22:52:54 +02:00
|
|
|
self.name = generateId()
|
|
|
|
|
#self.name = hostgroupname + str([str("_" + s.service.name ) for s in hostServices])
|
2013-05-29 01:03:01 +02:00
|
|
|
self.jobs = []
|
2013-05-27 01:44:28 +02:00
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return self.name
|
|
|
|
|
|
2013-05-27 03:13:08 +02:00
|
|
|
def setLogger(self, log):
|
|
|
|
|
self.log = log
|
|
|
|
|
|
2013-05-29 01:03:01 +02:00
|
|
|
def appendJob(self, job):
|
|
|
|
|
self.jobs.append(job)
|
|
|
|
|
|
|
|
|
|
def getNextExecutionTime(self):
|
|
|
|
|
nextExecution = None
|
|
|
|
|
for job in self.jobs:
|
|
|
|
|
jobExec = job.trigger.get_next_fire_time()
|
|
|
|
|
if nextExecution is None or nextExecution > jobExec:
|
|
|
|
|
nextExecution = jobExec
|
|
|
|
|
return nextExecution
|
|
|
|
|
|
2013-05-27 03:13:08 +02:00
|
|
|
def handleCall(self):
|
2013-05-29 22:52:54 +02:00
|
|
|
self.log.d("handle call")
|
2013-05-29 23:16:51 +02:00
|
|
|
self.log.d(self.hostServices)
|
2013-05-29 23:39:16 +02:00
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
for hs in self.hostServices:
|
|
|
|
|
self.log.d(str(hs))
|
|
|
|
|
cmd=Command(hs.service.command, self.log)
|
|
|
|
|
cmd.call()
|
2013-05-29 23:51:12 +02:00
|
|
|
self.log.d(cmd.getAllOutput())
|
2013-05-29 23:39:16 +02:00
|
|
|
except Error:
|
|
|
|
|
self.log.d(Error)
|
2013-05-29 22:52:54 +02:00
|
|
|
|
|
|
|
|
|
2013-05-29 02:22:59 +02:00
|
|
|
#must find real service command stored in hosts...
|
|
|
|
|
#but because of error, mentioned in NOTES,ruff, there is no ping i.e.
|
|
|
|
|
|
|
|
|
|
#cmd = Command(service.command)
|
|
|
|
|
#self.log.d("executing command: " + str(command))
|
|
|
|
|
#cmd.call()
|
|
|
|
|
#return cmd
|
2013-05-29 01:03:01 +02:00
|
|
|
|