added some logic for jobsprocessing, magically somehow not working...
This commit is contained in:
parent
f3c33a3964
commit
e60890268f
5 changed files with 65 additions and 37 deletions
|
|
@ -71,23 +71,24 @@ class DatePeriod(Period):
|
||||||
|
|
||||||
def parsePeriodList(periodlist, log):
|
def parsePeriodList(periodlist, log):
|
||||||
periods = []
|
periods = []
|
||||||
log.i(periodlist)
|
#log.d("values of periodslist: " + str(periodlist.items()))
|
||||||
for name, values in periodlist.items():
|
for name, values in periodlist.items():
|
||||||
|
|
||||||
if "date" in values:
|
if "date" in values:
|
||||||
periods.append(DatePeriod(name, **values))
|
periods.append(DatePeriod(name, **values))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for i in ["weeks", "days", "hours", "minutes", "seconds", "start_date"]:
|
comp = ["weeks", "days", "hours", "minutes", "seconds", "start_date"]
|
||||||
if i in values:
|
if len([i for i in comp if i in values]) > 0 :
|
||||||
periods.append(IntervalPeriod(name, **values))
|
periods.append(IntervalPeriod(name, **values))
|
||||||
break
|
break
|
||||||
|
|
||||||
for i in ["year", "month", "day", "week", "day_of_week", "hour", "minute", "second"]:
|
comp = ["year", "month", "day", "week", "day_of_week", "hour", "minute", "second"]
|
||||||
if i in values:
|
if len([i for i in comp if i in values]) > 0 :
|
||||||
periods.append(CronPeriod(name, **values))
|
periods.append(CronPeriod(name, **values))
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
log.w("ignoring Period: " + str(name))
|
log.w("ignoring Period: " + str(name))
|
||||||
log.w("reason: could not determine PeriodType: " + str(values))
|
log.w("reason: could not determine PeriodType: " + str(values))
|
||||||
|
|
||||||
return periods
|
return periods
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,40 @@
|
||||||
import subprocess
|
import subprocess as sp
|
||||||
|
from subprocess import CalledProcessError
|
||||||
|
from datetime import datetime as dt
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
def __init__(self, command):
|
def __init__(self, command):
|
||||||
self.command = command
|
self.command = command
|
||||||
self.output = ""
|
self.output = ""
|
||||||
self.error = ""
|
self.error = ""
|
||||||
|
self.retcode = 0
|
||||||
|
self.commandStart=0
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.command
|
return self.command
|
||||||
|
|
||||||
def hasProcessed(self):
|
def call(self):
|
||||||
return self.output != "" and self.error != ""
|
'''
|
||||||
|
self.commandStart = dt.now()
|
||||||
def doProcess(self):
|
"called at: "
|
||||||
process = subprocess.Popen([self.command], stdout=subprocess.PIPE)
|
process = sp.Popen(stdout=PIPE, *popenargs, **kwargs)
|
||||||
self.output, self.error = process.communicate()
|
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):
|
def getOutput(self):
|
||||||
if not self.hasProcessed():
|
|
||||||
self.doProcess()
|
|
||||||
return self.output
|
return self.output
|
||||||
|
|
||||||
def getError(self):
|
def getError(self):
|
||||||
if not self.hasProcessed():
|
return self.error
|
||||||
self.doProcess()
|
|
||||||
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.
|
execute.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import subprocess
|
from command import Command
|
||||||
|
|
||||||
|
|
||||||
class JobInfo:
|
class JobInfo:
|
||||||
|
|
@ -14,6 +14,7 @@ class JobInfo:
|
||||||
self.threshold = threshold
|
self.threshold = threshold
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.name = hostgroupname + "_" + service.name
|
self.name = hostgroupname + "_" + service.name
|
||||||
|
self.jobs = []
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
@ -21,8 +22,21 @@ class JobInfo:
|
||||||
def setLogger(self, log):
|
def setLogger(self, log):
|
||||||
self.log = 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):
|
def handleCall(self):
|
||||||
#p = subprocess.Popen("df -h", stdout=subprocess.PIPE, shell=True)
|
print "calling command " + str(service.command)
|
||||||
#(output, err) = p.communicate()
|
cmd = Command(service.command)
|
||||||
#print output
|
self.log.d("executing command: " + str(command))
|
||||||
pass
|
cmd.call()
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,11 @@ def parseArgs():
|
||||||
|
|
||||||
|
|
||||||
def handleJob(jobInfo):
|
def handleJob(jobInfo):
|
||||||
jobInfo.handleCall()
|
print "handlejobInfo"
|
||||||
print str(jobInfo)
|
print str(jobInfo)
|
||||||
|
print "executing: " + str(jobInfo.service.command)
|
||||||
|
jobInfo.handleCall()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -90,4 +93,4 @@ def main():
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
|
|
@ -213,9 +213,7 @@
|
||||||
"threshold": 10,
|
"threshold": 10,
|
||||||
"services":
|
"services":
|
||||||
{
|
{
|
||||||
"load": ["twentyfourseven"],
|
"ping": ["do_every_x_times"]
|
||||||
"discusage":["twentyfourseven"],
|
|
||||||
"ping": ["do_every_x_times"]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue