fixed parsing, replaced non_workin instance_check with todo
This commit is contained in:
parent
713de159e7
commit
0b34a14d53
14 changed files with 63 additions and 36 deletions
|
|
@ -1,13 +1,17 @@
|
|||
from os.path import isfile
|
||||
import json
|
||||
import sys
|
||||
|
||||
from os.path import join
|
||||
from os import getcwd
|
||||
import imp
|
||||
from layouts import Layout
|
||||
from hostgroups import HostGroup
|
||||
import lib.services.ping
|
||||
from members import Member
|
||||
from periods import CronPeriod, DatePeriod, IntervalPeriod
|
||||
|
||||
from lib.services.service import Service
|
||||
print id(Service)
|
||||
from lib.processors.processor import Processor
|
||||
from lib.parsers.parser import Parser
|
||||
from lib.tasks.task import Task
|
||||
|
|
@ -17,10 +21,7 @@ MOD_PROCESSORS = "processors"
|
|||
MOD_PARSERS = "parsers"
|
||||
MOD_TASKS = "tasks"
|
||||
|
||||
sys.path.append("lib/" + MOD_SERVICES)
|
||||
sys.path.append("lib/" + MOD_PROCESSORS)
|
||||
sys.path.append("lib/" + MOD_PARSERS)
|
||||
sys.path.append("lib/" + MOD_TASKS)
|
||||
|
||||
|
||||
KEY_LAYOUTS = "layouts"
|
||||
KEY_HOSTGROUPS = "hostgroups"
|
||||
|
|
@ -143,6 +144,8 @@ class ConfigParser:
|
|||
return mods["class"]
|
||||
else:
|
||||
mod = __import__(clazz)
|
||||
#path = join("lib", modPart, clazz + ".py")
|
||||
#mod = imp.load_source(clazz, path)
|
||||
mods[clazz] = mod
|
||||
return mod
|
||||
|
||||
|
|
@ -153,19 +156,28 @@ class ConfigParser:
|
|||
for clazzItem in items:
|
||||
try:
|
||||
clazz = clazzItem["class"]
|
||||
path = "lib/" + modPart
|
||||
sys.path.append(path)
|
||||
mod = self._load_module(clazz, modPart)
|
||||
item = mod.create(**clazzItem)
|
||||
if class_check(item):
|
||||
item = mod.create(clazzItem)
|
||||
repl.append(item)
|
||||
else:
|
||||
self.log.w(" ignoring class " + clazzItem["class"] + "! It does not pass the class check!")
|
||||
#TODO: activate the crappy classcheck if answer is provided
|
||||
#http://stackoverflow.com/questions/17179440/
|
||||
self.log.d("warning: instance_check isn't working yet! TRUST_ALL = TRUE")
|
||||
#if class_check(item):
|
||||
# repl.append(item)
|
||||
#else:
|
||||
# self.log.w(" ignoring class " + clazzItem["class"] + "! It does not pass the class check!")
|
||||
except ImportError, err:
|
||||
self.log.w("could not import " + clazz + ": " + str(clazzItem) + "! reason")
|
||||
self.log.w(str(err))
|
||||
except KeyError:
|
||||
self.log.w("Key 'class' not in classItem " + str(clazzItem))
|
||||
except Exception:
|
||||
self.log.w("Error while replace: " + str(Exception))
|
||||
except KeyError, k:
|
||||
self.log.w("Key '" + str(k) + "' not in classItem " + str(clazzItem))
|
||||
except Exception, e:
|
||||
self.log.w("Error while replace: " + str(e))
|
||||
finally:
|
||||
if path in sys.path:
|
||||
del sys.path[sys.path.index(path)]
|
||||
del items[:]
|
||||
items.extend(repl)
|
||||
|
||||
|
|
@ -278,6 +290,7 @@ class FullConfigParser(ConfigParser):
|
|||
creator = parsePeriodList
|
||||
periods = self._create_raw_Object(self.jsonDict[KEY_PERIODS], "Period", creator)
|
||||
|
||||
|
||||
#2. import and replace
|
||||
items_func = lambda hostgroup: hostgroup.get_services()
|
||||
class_check = lambda service: isinstance(service, Service)
|
||||
|
|
@ -287,9 +300,14 @@ class FullConfigParser(ConfigParser):
|
|||
class_check = lambda processor: isinstance(processor, Processor)
|
||||
self.replace_with_import(hostgroups, MOD_PROCESSORS, items_func, class_check)
|
||||
|
||||
services = []
|
||||
for hg in hostgroups:
|
||||
services.extend(hg.get_services())
|
||||
|
||||
|
||||
items_func = lambda service: service.get_parser()
|
||||
class_check = lambda parser: isinstance(parser, Parser)
|
||||
self.replace_with_import(hostgroups.services, MOD_PARSERS, items_func, class_check)
|
||||
self.replace_with_import(services, MOD_PARSERS, items_func, class_check)
|
||||
|
||||
items_func = lambda member: member.get_tasks()
|
||||
class_check = lambda task: isinstance(task, Task)
|
||||
|
|
@ -300,9 +318,7 @@ class FullConfigParser(ConfigParser):
|
|||
id_get_func = lambda member: member.id
|
||||
self.replace_pointer(hostgroups, members, id_list_func, id_get_func)
|
||||
|
||||
services = []
|
||||
for hg in hostgroups:
|
||||
services.extend(hg.get_services())
|
||||
|
||||
id_list_func = lambda service: service.get_periods()
|
||||
id_get_func = lambda period: period.get_name()
|
||||
self.replace_pointer(services, periods, id_list_func, id_get_func)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class Period(object):
|
|||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
def getName(self):
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
def createJob(self, scheduler, jobInfo, func):
|
||||
|
|
|
|||
|
|
@ -11,3 +11,4 @@ class Parser:
|
|||
|
||||
def generate_parse_result(self, result):
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -8,3 +8,7 @@ from processor import Processor
|
|||
class Mongodb(Processor):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
||||
def create(kwargs):
|
||||
return Mongodb(**kwargs)
|
||||
|
|
@ -8,3 +8,6 @@ from processor import Processor
|
|||
class Syslog(Processor):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def create(kwargs):
|
||||
return Syslog(**kwargs)
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ from service import Service
|
|||
|
||||
class PingService(Service):
|
||||
def __init__(self, **kwargs):
|
||||
super(PingService, self).__init__(**kwargs)
|
||||
Service.__init__(self, **kwargs)
|
||||
|
||||
|
||||
def create(self, **kwargs):
|
||||
def create(kwargs):
|
||||
return PingService(**kwargs)
|
||||
|
|
@ -7,7 +7,7 @@ KEY_PERIODS = "periods"
|
|||
KEY_ARGS = "args"
|
||||
|
||||
|
||||
class Service:
|
||||
class Service(object):
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
self._args = {}
|
||||
|
|
@ -36,10 +36,10 @@ class Service:
|
|||
|
||||
self._periods = []
|
||||
if KEY_PERIODS in kwargs:
|
||||
self.addPeriods(kwargs[KEY_PERIODS])
|
||||
self.add_periods(kwargs[KEY_PERIODS])
|
||||
|
||||
self.errorcode = 0
|
||||
self.errormessage = "No Error!"
|
||||
self.errormessage = None
|
||||
|
||||
def add_arguments(self, args):
|
||||
for key, val in args.items():
|
||||
|
|
@ -51,7 +51,7 @@ class Service:
|
|||
def get_arguments(self):
|
||||
return self._args
|
||||
|
||||
def add_period(self, period):
|
||||
def add_periods(self, period):
|
||||
if period is not None:
|
||||
if isinstance(period, list):
|
||||
self._periods.extend(period)
|
||||
|
|
|
|||
|
|
@ -22,5 +22,5 @@ class ShellService(Service):
|
|||
self.command.call()
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
def create(kwargs):
|
||||
return ShellService(**kwargs)
|
||||
|
|
@ -52,5 +52,5 @@ class SnmpgetService(Service):
|
|||
# print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
def create(**kargs):
|
||||
def create(kargs):
|
||||
return SnmpgetService(**kwargs)
|
||||
|
|
@ -40,7 +40,7 @@ class SshService(Service):
|
|||
client.close()
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
def create(kwargs):
|
||||
return SshService(**kwargs)
|
||||
|
||||
# def main():
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ not use a parser.
|
|||
"""
|
||||
|
||||
import socket
|
||||
from lib.config.services import Service
|
||||
from service import Service
|
||||
|
||||
|
||||
class TcpconnectService(Service):
|
||||
def __init__(self, **kwargs):
|
||||
#Service.__init__(self, **kwargs)
|
||||
super(TcpconnectService, self).__init__(**kwargs)
|
||||
|
||||
args = self.get_arguments()
|
||||
|
|
@ -39,5 +41,5 @@ class TcpconnectService(Service):
|
|||
return
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
def create(kwargs):
|
||||
return TcpconnectService(**kwargs)
|
||||
|
|
@ -18,5 +18,5 @@ class EmailTask(Task):
|
|||
pass
|
||||
|
||||
|
||||
def creator(**taskDict):
|
||||
def creator(taskDict):
|
||||
return EmailTask(**taskDict)
|
||||
|
|
@ -18,5 +18,5 @@ class SmsTask(Task):
|
|||
pass
|
||||
|
||||
|
||||
def creator(**taskDict):
|
||||
def creator(taskDict):
|
||||
return SmsTask(**taskDict)
|
||||
|
|
@ -18,5 +18,6 @@ class XmppTask(Task):
|
|||
pass
|
||||
|
||||
|
||||
def creator(**taskDict):
|
||||
|
||||
def creator(taskDict):
|
||||
return XmppTask(taskDict)
|
||||
Loading…
Add table
Add a link
Reference in a new issue