added job handling... a bit... :)
This commit is contained in:
parent
93a3d626d8
commit
0616ea4701
5 changed files with 77 additions and 36 deletions
|
|
@ -12,7 +12,8 @@ from periods import CronPeriod, DatePeriod, IntervalPeriod
|
||||||
from lib.services.service import Service
|
from lib.services.service import Service
|
||||||
from lib.processors.processor import Processor
|
from lib.processors.processor import Processor
|
||||||
from lib.parsers.parser import Parser
|
from lib.parsers.parser import Parser
|
||||||
from lib.tasks.task import Task
|
from lib.tasks.task import Task
|
||||||
|
from argparse import Namespace
|
||||||
|
|
||||||
MOD_SERVICES = "services"
|
MOD_SERVICES = "services"
|
||||||
MOD_PROCESSORS = "processors"
|
MOD_PROCESSORS = "processors"
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
This is what job_function needs as parameter for each job to successfully
|
This is what job_function needs as parameter for each job to successfully
|
||||||
execute.
|
execute.
|
||||||
"""
|
"""
|
||||||
|
from datetime import datetime
|
||||||
from lib.core.command import Command
|
|
||||||
|
|
||||||
|
|
||||||
def generateId():
|
def generateId():
|
||||||
i = 0
|
i = 0
|
||||||
|
|
@ -12,15 +10,17 @@ def generateId():
|
||||||
yield i
|
yield i
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
class Job:
|
||||||
class JobInfo:
|
|
||||||
def __init__(self, service):
|
def __init__(self, service):
|
||||||
self.service = service
|
self.service = service
|
||||||
self.name = generateId()
|
self.jobInfos = []
|
||||||
self.job = None
|
self.hostThreshold = {}
|
||||||
|
for host in service.get_hostgroup().get_hosts():
|
||||||
|
self.hostThreshold[host] = service.get_threshold()
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "JobInfo " + str(self.name)
|
return str(self.__dict__)
|
||||||
|
|
||||||
def set_logger(self, log):
|
def set_logger(self, log):
|
||||||
self.log = log
|
self.log = log
|
||||||
|
|
@ -31,8 +31,33 @@ class JobInfo:
|
||||||
def handle_call(self):
|
def handle_call(self):
|
||||||
self.log.d("handle call")
|
self.log.d("handle call")
|
||||||
self.log.d(self.service)
|
self.log.d(self.service)
|
||||||
try:
|
|
||||||
|
|
||||||
self.service._execute()
|
for host in self.service.get_hostgroup().get_hosts():
|
||||||
except Exception, e:
|
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()
|
||||||
|
|
||||||
|
except Exception, e:
|
||||||
self.log.d(e)
|
self.log.d(e)
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
self.executionSuccess = successful
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,25 +105,40 @@ class Service(object):
|
||||||
def needs_arguments(self):
|
def needs_arguments(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _execute(self):
|
def set_execution_successful(self, successful):
|
||||||
self.pre_execute()
|
self.executionSuccessful = successful
|
||||||
result = {}
|
|
||||||
for host in self.get_hostgroup().get_hosts():
|
|
||||||
result[host] = self.execute(host)
|
|
||||||
|
|
||||||
parseResult = self.parse_result(result)
|
def was_execution_successful(self):
|
||||||
self.handle_result(parseResult)
|
return self.executionSuccessful
|
||||||
|
|
||||||
|
def _execute(self, host):
|
||||||
|
try:
|
||||||
|
|
||||||
|
self.set_execution_successful(True)
|
||||||
|
self.pre_execute(host)
|
||||||
|
|
||||||
|
result = self.execute(host)
|
||||||
|
parseResult = self.parse_result(result)
|
||||||
|
self.post_execute(parseResult)
|
||||||
|
return parseResult
|
||||||
|
except Exception, e:
|
||||||
|
self.set_execution_successful(False)
|
||||||
|
self._threshold -= 1
|
||||||
|
raise e
|
||||||
|
|
||||||
def execute(self, host):
|
def execute(self, host):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def pre_execute(self):
|
def pre_execute(self, host):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def parse_result(self, executionResult):
|
def parse_result(self, executionResult):
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for parser in self.get_parser():
|
for parser in self.get_parser():
|
||||||
result.append(parser.parse(executionResult))
|
result.append(parser.parse(executionResult))
|
||||||
|
|
||||||
def handle_result(self, parseResult):
|
return result
|
||||||
|
|
||||||
|
def post_execute(self, parseResult):
|
||||||
pass
|
pass
|
||||||
15
linspector
15
linspector
|
|
@ -7,11 +7,10 @@ import argparse
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
from lib.core.job import JobInfo
|
|
||||||
from lib.core.logger import Logger
|
from lib.core.logger import Logger
|
||||||
from lib.config.parser import FullConfigParser
|
from lib.config.parser import FullConfigParser
|
||||||
from apscheduler.scheduler import Scheduler
|
from apscheduler.scheduler import Scheduler
|
||||||
from lib.core.job import JobInfo
|
from lib.core.job import Job
|
||||||
|
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
import tornado.web
|
import tornado.web
|
||||||
|
|
@ -84,12 +83,12 @@ def main():
|
||||||
for hostgroup in layout.get_hostgroups():
|
for hostgroup in layout.get_hostgroups():
|
||||||
for service in hostgroup.get_services():
|
for service in hostgroup.get_services():
|
||||||
for period in service.get_periods():
|
for period in service.get_periods():
|
||||||
jobInfo = JobInfo(service)
|
job = Job(service)
|
||||||
job = period.createJob(scheduler, jobInfo, handleJob)
|
schedulerJob = period.createJob(scheduler, job, handleJob)
|
||||||
if job is not None:
|
if schedulerJob is not None:
|
||||||
jobInfo.set_job(job)
|
job.set_job(schedulerJob)
|
||||||
jobInfo.set_logger(log)
|
job.set_logger(log)
|
||||||
jobs.append(jobInfo)
|
jobs.append(job)
|
||||||
application = tornado.web.Application([
|
application = tornado.web.Application([
|
||||||
(r"/", MainHandler),
|
(r"/", MainHandler),
|
||||||
(r"/jobs", JoblistHandler, dict(jobs=scheduler.get_jobs()))
|
(r"/jobs", JoblistHandler, dict(jobs=scheduler.get_jobs()))
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"comment": "Security Inspector",
|
"comment": "Security Inspector",
|
||||||
"tasks": [
|
"tasks": [
|
||||||
{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}},
|
{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}},
|
||||||
{"class":"email", "type": "do", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}}
|
{"class":"email", "type": "donut", "args": {"rcpt": "homer_j_simpson@burnscorp.sp"}}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -26,18 +26,19 @@
|
||||||
"class": "ping",
|
"class": "ping",
|
||||||
"fails": {"donut": 2000},
|
"fails": {"donut": 2000},
|
||||||
"periods": ["doh"],
|
"periods": ["doh"],
|
||||||
"threshold": 500
|
"threshold": 50
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"class": "ping",
|
"class": "ping",
|
||||||
"fails": {"donut": 2000},
|
"fails": {"donut": 1000},
|
||||||
"periods": ["doh"],
|
"periods": ["doh"],
|
||||||
"threshold": 500
|
"threshold": 100
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"class": "tcpconnect",
|
"class": "tcpconnect",
|
||||||
"args": {"port": 23232},
|
"args": {"port": 23232},
|
||||||
"periods": ["moes_time", "marges_birthday"],
|
"periods": ["moes_time", "marges_birthday"],
|
||||||
|
"fails": {"donut": 0},
|
||||||
"threshold": 0,
|
"threshold": 0,
|
||||||
"comment": "my personal reminder, hehe"
|
"comment": "my personal reminder, hehe"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue