diff --git a/bin/linspector b/bin/linspector index 275dc0c..e82bcca 100755 --- a/bin/linspector +++ b/bin/linspector @@ -155,8 +155,9 @@ def main(): core, hostgroup) scheduler_job = period.createJob(scheduler, job, handle_job, start_date=new_start_date) - scheduler_job.misfire_grace_time = 2 + if scheduler_job is not None: + scheduler_job.misfire_grace_time = 2 job.set_job(scheduler_job) jobs.append(job) diff --git a/linspector/config/members.py b/linspector/config/members.py index 2009fbd..5a22fa9 100644 --- a/linspector/config/members.py +++ b/linspector/config/members.py @@ -44,6 +44,11 @@ class Member: raise MemberMissingArgumentException(tmp, name) self.add_tasks(kwargs[tmp]) + tmp = "parent" + self.parent = None + if tmp in kwargs: + self.parent = kwargs[tmp] + def __add_internal(self, l, item): if isinstance(item, list): l.extend(item) @@ -59,6 +64,12 @@ class Member: def get_tasks(self): return self.__tasks + def has_parent(self): + return self.parent is not None + + def get_parent(self): + return self.parent + def __str__(self): ret = "Member: " + self.name + " Tasks: " for t in self.tasks: diff --git a/linspector/core/interface.py b/linspector/core/interface.py index 29326ce..c30972d 100644 --- a/linspector/core/interface.py +++ b/linspector/core/interface.py @@ -41,6 +41,9 @@ class LinspectorInterface(object): for job in self.jobs: self.jobHex.append(job.hex_string()) + def get_config(self): + return self._config + def get_job_hex_strings(self): return self.jobHex @@ -74,6 +77,9 @@ class LinspectorInterface(object): #d["Last Escalation"] = None return d + def add_job(self, job): + self.jobs.append(job) + def get_job_list(self): job_list = [] for job in self.jobs: diff --git a/linspector/frontends/lish.py b/linspector/frontends/lish.py index d497d50..644f69f 100644 --- a/linspector/frontends/lish.py +++ b/linspector/frontends/lish.py @@ -54,7 +54,8 @@ class LishFrontend(Frontend): run = True while run: try: - commander.cmdloop(GREEN + "Lish - Linspector interactive shell (" + __version__ + ")" + END) + print(GREEN + "Lish - Linspector interactive shell (" + __version__ + ")" + END) + commander.cmdloop() except KeyboardInterrupt, ki: run = False except Exception, err: @@ -220,8 +221,6 @@ class NewLish(CmdWrapper): - - class Job(CmdWrapper): def __init__(self, interface): diff --git a/linspector/transactions/BaseTransaction.py b/linspector/transactions/BaseTransaction.py new file mode 100644 index 0000000..3ccfafd --- /dev/null +++ b/linspector/transactions/BaseTransaction.py @@ -0,0 +1,9 @@ +__author__ = 'rafael' + + +class BaseTransaction(object): + def __init__(self, linspectorInterface: + self.interface = linspectorInterface + + def transact(self): + pass \ No newline at end of file diff --git a/linspector/transactions/HostgroupHostTransaction.py b/linspector/transactions/HostgroupHostTransaction.py new file mode 100644 index 0000000..15943e9 --- /dev/null +++ b/linspector/transactions/HostgroupHostTransaction.py @@ -0,0 +1,44 @@ +from linspector.transactions import HostgroupTransaction +from linspector.core.job import LinspectorJob + +__author__ = 'rafael' + +def handle_job(job): + job.handle_call() + + +class HostgroupHostTransaction(HostgroupTransaction): + def __init__(self, linspectorInterface, hostgroup, host): + super(HostgroupHostTransaction).__init__(linspectorInterface, hostgroup) + self.host = host + +class HostgroupAddHostTransaction(HostgroupHostTransaction): + def __init__(self, linspectorInterface, hostgroup, host): + super(HostgroupHostTransaction).__init__(linspectorInterface, hostgroup, host) + + + + def transact(self): + hostgroup = self.interface.get_config().get_hostgroup_by_name(self.hostgroup) + if hostgroup is not None: + hostgroup.add_host(self.host) + for service in hostgroup.get_services(): + for host in hostgroup.get_hosts(): + for period in service.get_periods(): + + job = LinspectorJob(service, + host, + hostgroup.get_members(), + None, + hostgroup) + scheduler_job = period.createJob(self.scheduler, job, handle_job) + if scheduler_job is not None: + scheduler_job.misfire_grace_time = 2 + job.set_job(scheduler_job) + self.interface.add_job(job) + + + else: + raise Exception("could not find hostgroup %s" % self.hostgroup ) + + diff --git a/linspector/transactions/HostgroupTransaction.py b/linspector/transactions/HostgroupTransaction.py new file mode 100644 index 0000000..fd21829 --- /dev/null +++ b/linspector/transactions/HostgroupTransaction.py @@ -0,0 +1,9 @@ +from cherrypy.test.test_session import host +from linspector.transactions import BaseTransaction + +__author__ = 'rafael' + +class HostgroupTransaction(BaseTransaction): + def __init__(self, linspectorInterface, hostgroup): + super(HostgroupTransaction, self).__init__(linspectorInterface) + self.hostgroup = hostgroup \ No newline at end of file diff --git a/linspector/transactions/__init__.py b/linspector/transactions/__init__.py new file mode 100644 index 0000000..f399501 --- /dev/null +++ b/linspector/transactions/__init__.py @@ -0,0 +1 @@ +__author__ = 'rafael'