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.processors.processor import Processor
|
||||
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_PROCESSORS = "processors"
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@
|
|||
This is what job_function needs as parameter for each job to successfully
|
||||
execute.
|
||||
"""
|
||||
|
||||
from lib.core.command import Command
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
def generateId():
|
||||
i = 0
|
||||
|
|
@ -12,16 +10,18 @@ def generateId():
|
|||
yield i
|
||||
i += 1
|
||||
|
||||
|
||||
class JobInfo:
|
||||
class Job:
|
||||
def __init__(self, service):
|
||||
self.service = service
|
||||
self.name = generateId()
|
||||
self.job = None
|
||||
self.jobInfos = []
|
||||
self.hostThreshold = {}
|
||||
for host in service.get_hostgroup().get_hosts():
|
||||
self.hostThreshold[host] = service.get_threshold()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return "JobInfo " + str(self.name)
|
||||
|
||||
return str(self.__dict__)
|
||||
|
||||
def set_logger(self, log):
|
||||
self.log = log
|
||||
|
||||
|
|
@ -31,8 +31,33 @@ class JobInfo:
|
|||
def handle_call(self):
|
||||
self.log.d("handle call")
|
||||
self.log.d(self.service)
|
||||
try:
|
||||
|
||||
self.service._execute()
|
||||
except Exception, e:
|
||||
self.log.d(e)
|
||||
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()
|
||||
|
||||
except Exception, 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):
|
||||
return False
|
||||
|
||||
def _execute(self):
|
||||
self.pre_execute()
|
||||
result = {}
|
||||
for host in self.get_hostgroup().get_hosts():
|
||||
result[host] = self.execute(host)
|
||||
def set_execution_successful(self, successful):
|
||||
self.executionSuccessful = successful
|
||||
|
||||
parseResult = self.parse_result(result)
|
||||
self.handle_result(parseResult)
|
||||
def was_execution_successful(self):
|
||||
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):
|
||||
pass
|
||||
|
||||
def pre_execute(self):
|
||||
def pre_execute(self, host):
|
||||
pass
|
||||
|
||||
def parse_result(self, executionResult):
|
||||
|
||||
result = []
|
||||
for parser in self.get_parser():
|
||||
result.append(parser.parse(executionResult))
|
||||
|
||||
def handle_result(self, parseResult):
|
||||
pass
|
||||
return result
|
||||
|
||||
def post_execute(self, parseResult):
|
||||
pass
|
||||
|
|
|
|||
15
linspector
15
linspector
|
|
@ -7,11 +7,10 @@ import argparse
|
|||
import time
|
||||
import logging
|
||||
import subprocess as sp
|
||||
from lib.core.job import JobInfo
|
||||
from lib.core.logger import Logger
|
||||
from lib.config.parser import FullConfigParser
|
||||
from apscheduler.scheduler import Scheduler
|
||||
from lib.core.job import JobInfo
|
||||
from lib.core.job import Job
|
||||
|
||||
import tornado.ioloop
|
||||
import tornado.web
|
||||
|
|
@ -84,12 +83,12 @@ def main():
|
|||
for hostgroup in layout.get_hostgroups():
|
||||
for service in hostgroup.get_services():
|
||||
for period in service.get_periods():
|
||||
jobInfo = JobInfo(service)
|
||||
job = period.createJob(scheduler, jobInfo, handleJob)
|
||||
if job is not None:
|
||||
jobInfo.set_job(job)
|
||||
jobInfo.set_logger(log)
|
||||
jobs.append(jobInfo)
|
||||
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()))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
"comment": "Security Inspector",
|
||||
"tasks": [
|
||||
{"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",
|
||||
"fails": {"donut": 2000},
|
||||
"periods": ["doh"],
|
||||
"threshold": 500
|
||||
"threshold": 50
|
||||
},
|
||||
{
|
||||
"class": "ping",
|
||||
"fails": {"donut": 2000},
|
||||
"fails": {"donut": 1000},
|
||||
"periods": ["doh"],
|
||||
"threshold": 500
|
||||
"threshold": 100
|
||||
},
|
||||
{
|
||||
"class": "tcpconnect",
|
||||
"args": {"port": 23232},
|
||||
"periods": ["moes_time", "marges_birthday"],
|
||||
"fails": {"donut": 0},
|
||||
"threshold": 0,
|
||||
"comment": "my personal reminder, hehe"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue