added job handling...
This commit is contained in:
parent
cabf6a96a3
commit
3447dbe03f
4 changed files with 44 additions and 56 deletions
|
|
@ -11,14 +11,12 @@ def generateId():
|
|||
yield i
|
||||
i += 1
|
||||
|
||||
|
||||
class Job:
|
||||
def __init__(self, service):
|
||||
def __init__(self, service, host):
|
||||
self.service = service
|
||||
self.host = host
|
||||
self.jobInfos = []
|
||||
self.hostThreshold = {}
|
||||
for host in service.get_hostgroup().get_hosts():
|
||||
self.hostThreshold[host] = service.get_threshold()
|
||||
self.jobThreshold = 0
|
||||
|
||||
def __str__(self):
|
||||
return str(self.__dict__)
|
||||
|
|
@ -29,21 +27,36 @@ class Job:
|
|||
def set_job(self, job):
|
||||
self.job = job
|
||||
|
||||
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
|
||||
|
||||
def handle_call(self):
|
||||
self.log.d("handle call")
|
||||
self.log.d(self.service)
|
||||
try:
|
||||
jobInfo = JobInfo(self.host, self.service)
|
||||
result = self.service._execute(self.host)
|
||||
jobInfo.set_result(result)
|
||||
jobInfo.set_successfull(self.service.was_execution_successful())
|
||||
jobInfo.set_execution_end()
|
||||
|
||||
for host in self.service.get_hostgroup().get_hosts():
|
||||
try:
|
||||
jobInfo = JobInfo(host, self.service)
|
||||
result = self.service._execute(host)
|
||||
jobInfo.set_result(result)
|
||||
jobInfo.set_successfull(self.service.was_execution_successful())
|
||||
jobInfo.set_execution_end()
|
||||
self.handle_threshold(self.service.get_threshold(), self.service.was_execution_successful())
|
||||
|
||||
except Exception, e:
|
||||
self.log.d(e)
|
||||
|
||||
self.jobInfos.append(jobInfo)
|
||||
|
||||
|
||||
except Exception, e:
|
||||
self.log.d(e)
|
||||
|
||||
class JobInfo:
|
||||
def __init__(self, host, service):
|
||||
|
|
@ -59,4 +72,6 @@ class JobInfo:
|
|||
self.executionEnd = datetime.now()
|
||||
|
||||
def set_execution_successful(self, successful):
|
||||
self.executionSuccess = successful
|
||||
self.executionSuccess = successful
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ class Service(object):
|
|||
self.add_arguments(kwargs[KEY_ARGS])
|
||||
elif self.needs_arguments():
|
||||
raise Exception("Error: needs arguments but none provided!")
|
||||
|
||||
self._host = None
|
||||
|
||||
|
||||
self._parser = []
|
||||
if KEY_PARSER in kwargs:
|
||||
|
|
@ -86,12 +85,6 @@ class Service(object):
|
|||
def get_comment(self):
|
||||
return self._comment
|
||||
|
||||
def set_host(self, host):
|
||||
self._host = host
|
||||
|
||||
def get_host(self):
|
||||
return self._host
|
||||
|
||||
def get_parser(self):
|
||||
return self._parser
|
||||
|
||||
|
|
|
|||
|
|
@ -23,17 +23,18 @@ class TcpconnectService(Service):
|
|||
def needs_arguments(self):
|
||||
return True
|
||||
|
||||
def execute(self, log):
|
||||
def execute(self, host):
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
except socket.error, msg:
|
||||
log.w("%s\n" % msg[1])
|
||||
|
||||
#log.w("%s\n" % msg[1])
|
||||
self.errorcode = 1
|
||||
|
||||
try:
|
||||
sock.connect((self.host, self.port))
|
||||
except socket.error, msg:
|
||||
log.w("%s\n" % msg[1])
|
||||
#log.w("%s\n" % msg[1])
|
||||
self.errorcode = 2
|
||||
|
||||
sock.close()
|
||||
|
|
|
|||
37
linspector
37
linspector
|
|
@ -12,8 +12,6 @@ from lib.config.parser import FullConfigParser
|
|||
from apscheduler.scheduler import Scheduler
|
||||
from lib.core.job import Job
|
||||
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
|
||||
|
||||
def parseArgs():
|
||||
|
|
@ -49,20 +47,6 @@ def handleJob(jobInfo):
|
|||
jobInfo.handle_call()
|
||||
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
def get(self):
|
||||
self.write("Linspector: (<a href='/jobs'>jobs</a>)")
|
||||
|
||||
|
||||
class JoblistHandler(tornado.web.RequestHandler):
|
||||
def initialize(self, jobs):
|
||||
self.jobs = jobs
|
||||
|
||||
def get(self):
|
||||
self.write("Linspector Job List:<br/>")
|
||||
for job in self.jobs:
|
||||
self.write("Job: " + str(job) + "<br/>")
|
||||
|
||||
|
||||
def main():
|
||||
args = parseArgs()
|
||||
|
|
@ -82,20 +66,15 @@ def main():
|
|||
if layout.is_enabled():
|
||||
for hostgroup in layout.get_hostgroups():
|
||||
for service in hostgroup.get_services():
|
||||
for period in service.get_periods():
|
||||
job = Job(service)
|
||||
schedulerJob = period.createJob(scheduler, job, handleJob)
|
||||
if schedulerJob is not None:
|
||||
job.set_job(schedulerJob)
|
||||
job.set_logger(log)
|
||||
jobs.append(job)
|
||||
application = tornado.web.Application([
|
||||
(r"/", MainHandler),
|
||||
(r"/jobs", JoblistHandler, dict(jobs=scheduler.get_jobs()))
|
||||
])
|
||||
for host in hostgroup.get_hosts():
|
||||
for period in service.get_periods():
|
||||
job = Job(service, host)
|
||||
schedulerJob = period.createJob(scheduler, job, handleJob)
|
||||
if schedulerJob is not None:
|
||||
job.set_job(schedulerJob)
|
||||
job.set_logger(log)
|
||||
jobs.append(job)
|
||||
|
||||
application.listen(8888)
|
||||
tornado.ioloop.IOLoop.instance().start()
|
||||
|
||||
while True:
|
||||
#Todo: implement user handle
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue