finished creation of parser, needs some bugfixes
This commit is contained in:
parent
56906b9ebc
commit
3f8a9cdec4
3 changed files with 52 additions and 39 deletions
|
|
@ -41,9 +41,6 @@ class ConfigurationException(Exception):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ConfigParser:
|
class ConfigParser:
|
||||||
def __init__(self, log):
|
def __init__(self, log):
|
||||||
'''
|
'''
|
||||||
|
|
@ -152,7 +149,6 @@ class ConfigParser:
|
||||||
return __import__(clazz)
|
return __import__(clazz)
|
||||||
|
|
||||||
def replace_with_import(self, objList, modPart, items_func, class_check):
|
def replace_with_import(self, objList, modPart, items_func, class_check):
|
||||||
loadedModules = {}
|
|
||||||
for obj in objList:
|
for obj in objList:
|
||||||
repl = []
|
repl = []
|
||||||
items = items_func(obj)
|
items = items_func(obj)
|
||||||
|
|
@ -175,8 +171,22 @@ class ConfigParser:
|
||||||
del items[:]
|
del items[:]
|
||||||
items.extend(repl)
|
items.extend(repl)
|
||||||
|
|
||||||
|
|
||||||
|
def replace_pointer(self, objectList, replObjectList, id_list_func, id_get_func):
|
||||||
|
for obj in objectList:
|
||||||
|
replacements = []
|
||||||
|
idList = id_list_func(obj)
|
||||||
|
for id in idList:
|
||||||
|
repl = [o for o in replObjectList if id == id_get_func(o)]
|
||||||
|
if len(repl) == 1:
|
||||||
|
replacements.append(repl[0])
|
||||||
|
|
||||||
|
del idList[:]
|
||||||
|
idList.extend(replacements)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parse_config(self, configFilename):
|
def parse_config(self, configFilename):
|
||||||
'''
|
'''
|
||||||
|
|
@ -232,6 +242,8 @@ class ConfigParser:
|
||||||
self.members = self.create_members_from_json(jsonMembers)
|
self.members = self.create_members_from_json(jsonMembers)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parsePeriodList(name, values):
|
def parsePeriodList(name, values):
|
||||||
if "date" in values:
|
if "date" in values:
|
||||||
return DatePeriod(name, **values)
|
return DatePeriod(name, **values)
|
||||||
|
|
@ -297,26 +309,25 @@ class FullConfigParser(ConfigParser):
|
||||||
items_func = lambda member: member.get_tasks()
|
items_func = lambda member: member.get_tasks()
|
||||||
class_check = lambda task: isinstance(task, Task)
|
class_check = lambda task: isinstance(task, Task)
|
||||||
self.replace_with_import(members, MOD_TASKS, items_func, class_check)
|
self.replace_with_import(members, MOD_TASKS, items_func, class_check)
|
||||||
|
|
||||||
|
#replace object pointer
|
||||||
|
id_list_func = lambda hostgroup: hostgroup.get_members()
|
||||||
|
id_get_func = lambda member: member.id
|
||||||
|
self.replace_pointer(hostgroups, members, id_list_func, id_get_func)
|
||||||
|
|
||||||
|
services = []
|
||||||
for hg in hostgroups:
|
for hg in hostgroups:
|
||||||
replmembers = []
|
services.extend(hg.get_services())
|
||||||
memberNames = hg.get_members()
|
id_list_func = lambda service: service.get_periods()
|
||||||
for membername in memberNames:
|
id_get_func = lambda period: period.get_name()
|
||||||
member = [m for m in members if m.id == membername]
|
self.replace_pointer(services, periods, id_list_func, id_get_func)
|
||||||
if len(member) == 1:
|
|
||||||
replmembers.append(member[0])
|
id_list_func = lambda layout: layout.get_hostgroups()
|
||||||
|
id_get_func = lambda hostgroup: hostgroup.get_name()
|
||||||
del hg.get_members()[:]
|
self.replace_pointer(layouts, hostgroups, id_list_func, id_get_func)
|
||||||
hg.add_members(replmembers)
|
|
||||||
|
return layouts
|
||||||
replParents = []
|
|
||||||
parentNames = hg.get_parents()
|
|
||||||
for parentname in parentNames:
|
|
||||||
parent = [p for p in hostgroups if p.get_name() == parentname]
|
|
||||||
if len(parent) == 1:
|
|
||||||
replParents.append(parent[0])
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -4,8 +4,6 @@ The snmpget service in pure Python.
|
||||||
|
|
||||||
#from pysnmp.entity.rfc3413.oneliner import cmdgen
|
#from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||||
from service import Service
|
from service import Service
|
||||||
from Cython.Compiler.Naming import kwds_cname
|
|
||||||
from wx.lib.pubsub.core import kwargs
|
|
||||||
|
|
||||||
|
|
||||||
class SnmpgetService(Service):
|
class SnmpgetService(Service):
|
||||||
|
|
|
||||||
28
linspector
28
linspector
|
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/python2.7 -tt
|
#!/usr/bin/python2.7 -tt
|
||||||
|
from zenmapCore.UmitConf import config_parser
|
||||||
|
|
||||||
__version__ = "0.4/TETRIS"
|
__version__ = "0.4/TETRIS"
|
||||||
__default_config__ = "./linspector.json"
|
__default_config__ = "./linspector.json"
|
||||||
|
|
@ -9,7 +10,7 @@ import logging
|
||||||
import subprocess as sp
|
import subprocess as sp
|
||||||
from lib.core.job import JobInfo
|
from lib.core.job import JobInfo
|
||||||
from lib.core.logger import Logger
|
from lib.core.logger import Logger
|
||||||
from lib.config.parser import ConfigParser
|
from lib.config.parser import FullConfigParser
|
||||||
from apscheduler.scheduler import Scheduler
|
from apscheduler.scheduler import Scheduler
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -53,19 +54,22 @@ def main():
|
||||||
log.i("parsed arguments")
|
log.i("parsed arguments")
|
||||||
|
|
||||||
if args.action == "start":
|
if args.action == "start":
|
||||||
jobs = []
|
configParser = FullConfigParser(log)
|
||||||
scheduler = Scheduler()
|
config = configParser.parse_config(args.config)
|
||||||
scheduler.start()
|
|
||||||
|
#jobs = []
|
||||||
|
#scheduler = Scheduler()
|
||||||
|
#scheduler.start()
|
||||||
|
|
||||||
log.i("starting linspector: reading config... (" + args.config + ")")
|
#log.i("starting linspector: reading config... (" + args.config + ")")
|
||||||
config_parser = ConfigParser(log)
|
#config_parser = ConfigParser(log)
|
||||||
config = config_parser.parse_config(args.config)
|
#config = config_parser.parse_config(args.config)
|
||||||
log.d("parsed config: " + str(config))
|
#log.d("parsed config: " + str(config))
|
||||||
|
|
||||||
while True:
|
#while True:
|
||||||
time.sleep(10)
|
# time.sleep(10)
|
||||||
for job in jobs:
|
# for job in jobs:
|
||||||
log.d(str(job))
|
# log.d(str(job))
|
||||||
|
|
||||||
elif args.action == "stop":
|
elif args.action == "stop":
|
||||||
log.i("stopping linspector is currently unsupported")
|
log.i("stopping linspector is currently unsupported")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue