added some logic for jobsprocessing, magically somehow not working...
This commit is contained in:
parent
a51e24c85d
commit
f7c5cd65cc
5 changed files with 65 additions and 37 deletions
|
|
@ -1,28 +1,40 @@
|
|||
import subprocess
|
||||
|
||||
import subprocess as sp
|
||||
from subprocess import CalledProcessError
|
||||
from datetime import datetime as dt
|
||||
|
||||
class Command:
|
||||
def __init__(self, command):
|
||||
self.command = command
|
||||
self.output = ""
|
||||
self.error = ""
|
||||
self.retcode = 0
|
||||
self.commandStart=0
|
||||
|
||||
def __str__(self):
|
||||
return self.command
|
||||
|
||||
def hasProcessed(self):
|
||||
return self.output != "" and self.error != ""
|
||||
|
||||
def doProcess(self):
|
||||
process = subprocess.Popen([self.command], stdout=subprocess.PIPE)
|
||||
def call(self):
|
||||
'''
|
||||
self.commandStart = dt.now()
|
||||
"called at: "
|
||||
process = sp.Popen(stdout=PIPE, *popenargs, **kwargs)
|
||||
self.output, self.error = process.communicate()
|
||||
|
||||
self.retcode = process.poll()
|
||||
'''
|
||||
try:
|
||||
print self.command
|
||||
self.output=sp.check_output(self.command.split(),stderr=sp.STDOUT)
|
||||
|
||||
except CalledProcessError:
|
||||
self.error=CalledProcessError.output
|
||||
self.retcode = CalledProcessError.returncode
|
||||
|
||||
def getOutput(self):
|
||||
if not self.hasProcessed():
|
||||
self.doProcess()
|
||||
return self.output
|
||||
|
||||
def getError(self):
|
||||
if not self.hasProcessed():
|
||||
self.doProcess()
|
||||
return self.error
|
||||
return self.error
|
||||
|
||||
def getReturnCode(self):
|
||||
return self.retcode
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ This is what job_function needs as parameter for each job to successfully
|
|||
execute.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
from command import Command
|
||||
|
||||
|
||||
class JobInfo:
|
||||
|
|
@ -14,6 +14,7 @@ class JobInfo:
|
|||
self.threshold = threshold
|
||||
self.parent = parent
|
||||
self.name = hostgroupname + "_" + service.name
|
||||
self.jobs = []
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
@ -21,8 +22,21 @@ class JobInfo:
|
|||
def setLogger(self, log):
|
||||
self.log = log
|
||||
|
||||
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
|
||||
|
||||
def handleCall(self):
|
||||
#p = subprocess.Popen("df -h", stdout=subprocess.PIPE, shell=True)
|
||||
#(output, err) = p.communicate()
|
||||
#print output
|
||||
pass
|
||||
print "calling command " + str(service.command)
|
||||
cmd = Command(service.command)
|
||||
self.log.d("executing command: " + str(command))
|
||||
cmd.call()
|
||||
return cmd
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue