whitespacing.... :)
This commit is contained in:
parent
2c40772796
commit
883e59a3d1
22 changed files with 66 additions and 109 deletions
|
|
@ -44,16 +44,14 @@ class HostGroup:
|
|||
def _to_config_dict(self, configDict):
|
||||
me = {}
|
||||
me["members"] = [member.nameid for member in self.get_members()]
|
||||
me["hosts"] = self.hosts
|
||||
me["hosts"] = self.hosts
|
||||
me["parents"] = [hg.get_name() for hg in self.get_parents()]
|
||||
#TODO implement delegation
|
||||
#me["services"] = [service._to_config_dict(configDict) for service in self.get_services()]
|
||||
#me["processors"] = [processor._to_config_dict(configDict) for processor in self.get_processors()]
|
||||
configDict["hostgroups"][self.get_name()] = me
|
||||
|
||||
|
||||
|
||||
def __add_internal(self,l,item):
|
||||
def __add_internal(self, l, item):
|
||||
if isinstance(item, list):
|
||||
l.extend(item)
|
||||
else:
|
||||
|
|
@ -92,7 +90,6 @@ class HostGroup:
|
|||
def get_members(self):
|
||||
return self.members
|
||||
|
||||
|
||||
def __str__(self):
|
||||
ret = "HostGroup: " + self.name + " threshold: " + str(self.threshold) + " parent: " + self.parent + "\n"
|
||||
ret += "members: {\n"
|
||||
|
|
|
|||
|
|
@ -116,4 +116,3 @@ def parseHostList(hosts, services, log):
|
|||
#replace host.service member by parsed HostService Objects
|
||||
host.services = hostServices
|
||||
return parsedHosts
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ class Layout:
|
|||
else:
|
||||
self._hostgroups = hostgroups
|
||||
|
||||
|
||||
def _to_config_dict(self, configDict):
|
||||
me = {}
|
||||
me["hostgroups"] = [hg.name for hg in self.get_hostgroups()]
|
||||
|
|
@ -25,7 +24,6 @@ class Layout:
|
|||
for hostgroup in self.get_hostgroups():
|
||||
hostgroup._to_config_dict(configDict)
|
||||
|
||||
|
||||
def get_name(self):
|
||||
return self._name
|
||||
|
||||
|
|
@ -35,7 +33,6 @@ class Layout:
|
|||
def get_hostgroups(self):
|
||||
return self._hostgroups
|
||||
|
||||
|
||||
def __str__(self):
|
||||
ret = "Layout: 'Name:" + str(self.name) + "', 'Enabled: " + str(self.enabled) + " "
|
||||
for group in self.hostgroups:
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ class Member:
|
|||
return ret
|
||||
|
||||
|
||||
|
||||
|
||||
class MemberFilter:
|
||||
def __init__(self, filter, Value):
|
||||
self.filter = filter
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from os.path import isfile
|
||||
import json
|
||||
import imp
|
||||
import sys
|
||||
|
||||
from layouts import Layout
|
||||
|
|
@ -8,13 +7,11 @@ from hostgroups import HostGroup
|
|||
from members import Member
|
||||
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
|
||||
|
||||
|
||||
MOD_SERVICES = "services"
|
||||
MOD_PROCESSORS = "processors"
|
||||
MOD_PARSERS = "parsers"
|
||||
|
|
@ -40,15 +37,14 @@ class ConfigurationException(Exception):
|
|||
return repr(self.msg)
|
||||
|
||||
|
||||
|
||||
class ConfigParser:
|
||||
def __init__(self, log):
|
||||
'''
|
||||
"""
|
||||
initializes a new ConfigParser Object
|
||||
|
||||
params:
|
||||
log: pre configured logger Object to post messages while parsing"
|
||||
'''
|
||||
"""
|
||||
self.log = log
|
||||
self.hostgroups = {}
|
||||
self.members = {}
|
||||
|
|
@ -65,12 +61,12 @@ class ConfigParser:
|
|||
layout._to_config_dict(configDict)
|
||||
|
||||
def _read_json_config(self, configFilename):
|
||||
'''
|
||||
"""
|
||||
reads the config File and returns a dictionary, while lowering the first keys
|
||||
|
||||
params:
|
||||
configFilename: the path under which the configuration file should be found
|
||||
'''
|
||||
"""
|
||||
if not isfile(configFilename):
|
||||
msg = "config file not found at " + str(configFilename)
|
||||
raise ConfigurationException(msg, self.log)
|
||||
|
|
@ -84,11 +80,11 @@ class ConfigParser:
|
|||
return json.loads(config)
|
||||
|
||||
def _get_as_list(self, configValue):
|
||||
'''
|
||||
"""
|
||||
In some cases the config permits to define a list or a single value.
|
||||
|
||||
returns the value as list
|
||||
'''
|
||||
"""
|
||||
return configValue if isinstance(configValue, list) else [configValue]
|
||||
|
||||
def _create_raw_Object(self, jsonDict, msgName, creator):
|
||||
|
|
@ -114,9 +110,9 @@ class ConfigParser:
|
|||
return layouts
|
||||
|
||||
def create_hostgroups_from_json(self, jsonHostGroups):
|
||||
'''
|
||||
"""
|
||||
creates Hostgroups from the jsonConfig
|
||||
'''
|
||||
"""
|
||||
hostgroups = []
|
||||
for hgName, hgValues in jsonHostGroups.items():
|
||||
try:
|
||||
|
|
@ -128,9 +124,9 @@ class ConfigParser:
|
|||
return hostgroups
|
||||
|
||||
def create_members_from_json(self, jsonMembers):
|
||||
'''
|
||||
"""
|
||||
creates Members from the jsonConfig
|
||||
'''
|
||||
"""
|
||||
members = []
|
||||
for memberName, memberValues in jsonMembers.items():
|
||||
try:
|
||||
|
|
@ -173,7 +169,6 @@ class ConfigParser:
|
|||
del items[:]
|
||||
items.extend(repl)
|
||||
|
||||
|
||||
def replace_pointer(self, objectList, replObjectList, id_list_func, id_get_func):
|
||||
for obj in objectList:
|
||||
replacements = []
|
||||
|
|
@ -186,12 +181,8 @@ class ConfigParser:
|
|||
del idList[:]
|
||||
idList.extend(replacements)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def parse_config(self, configFilename):
|
||||
'''
|
||||
"""
|
||||
parses the json configuration and returns a list of layouts,
|
||||
which contains all nessesary information of the config file.
|
||||
It will only parse nessesary Objects.
|
||||
|
|
@ -202,7 +193,7 @@ class ConfigParser:
|
|||
|
||||
params:
|
||||
configFilename: indicates which configuration file to parse
|
||||
'''
|
||||
"""
|
||||
|
||||
self.jsonDict = self._read_json_config(configFilename)
|
||||
|
||||
|
|
@ -215,7 +206,6 @@ class ConfigParser:
|
|||
for hgName in layout.get_hostgroups():
|
||||
hostgroupNames.add(hgName)
|
||||
|
||||
|
||||
jsonHostgroups = {}
|
||||
for hgName in hostgroupNames:
|
||||
if not hgName in self.jsonDict[KEY_HOSTGROUPS]:
|
||||
|
|
@ -244,8 +234,6 @@ class ConfigParser:
|
|||
self.members = self.create_members_from_json(jsonMembers)
|
||||
|
||||
|
||||
|
||||
|
||||
def parsePeriodList(name, values):
|
||||
if "date" in values:
|
||||
return DatePeriod(name, **values)
|
||||
|
|
@ -257,18 +245,13 @@ def parsePeriodList(name, values):
|
|||
comp = ["year", "month", "day", "week", "day_of_week", "hour", "minute", "second"]
|
||||
if len([i for i in comp if i in values]) > 0 :
|
||||
return CronPeriod(name, **values)
|
||||
|
||||
else:
|
||||
raise ConfigurationException("could not determine correct Period(" + repr(values)+").")
|
||||
|
||||
|
||||
|
||||
class FullConfigParser(ConfigParser):
|
||||
|
||||
|
||||
|
||||
def parse_config(self, configFilename):
|
||||
'''
|
||||
"""
|
||||
parses the json configuration and returns a list of layouts,
|
||||
which contains all nessesary information of the config file.
|
||||
parses the full config
|
||||
|
|
@ -279,7 +262,7 @@ class FullConfigParser(ConfigParser):
|
|||
|
||||
params:
|
||||
configFilename: indicates which configuration file to parse
|
||||
'''
|
||||
"""
|
||||
self.jsonDict = self._read_json_config(configFilename)
|
||||
|
||||
# first step
|
||||
|
|
@ -329,7 +312,3 @@ class FullConfigParser(ConfigParser):
|
|||
self.replace_pointer(layouts, hostgroups, id_list_func, id_get_func)
|
||||
|
||||
return layouts
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -67,7 +67,3 @@ class DatePeriod(Period):
|
|||
|
||||
def createJob(self, scheduler, jobInfo, func):
|
||||
return scheduler.add_date_job(func, self.date, jobInfo)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
class Parser:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ The MongoDB processor
|
|||
|
||||
from processor import Processor
|
||||
|
||||
|
||||
class Mongodb(Processor):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
'''
|
||||
"""
|
||||
Created on Jun 16, 2013
|
||||
|
||||
@author: rafael
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
class Processor:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
"""
|
||||
The snmpget service in pure Python.
|
||||
"""
|
||||
|
||||
# http://pysnmp.sourceforge.net/
|
||||
|
|
@ -41,7 +41,6 @@ class HttpService(Service):
|
|||
def needs_arguments(self):
|
||||
return True
|
||||
|
||||
|
||||
def execute(self):
|
||||
params = urllib.urlencode(self.params)
|
||||
if self.method is "get":
|
||||
|
|
@ -51,5 +50,6 @@ class HttpService(Service):
|
|||
|
||||
#print f.read()
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
return HttpService(**kwargs)
|
||||
|
|
@ -5,6 +5,7 @@ The ping service in pure Python.
|
|||
# http://code.activestate.com/recipes/409689-icmplib-library-for-creating-and-reading-icmp-pack/
|
||||
from service import Service
|
||||
|
||||
|
||||
class PingService(Service):
|
||||
def __init__(self, **kwargs):
|
||||
super(PingService, self).__init__(**kwargs)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ KEY_FAILS = "fails"
|
|||
KEY_PERIODS = "periods"
|
||||
KEY_ARGS = "args"
|
||||
|
||||
|
||||
class Service:
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
|
|
@ -88,7 +89,6 @@ class Service:
|
|||
def get_parser(self):
|
||||
return self._parser
|
||||
|
||||
|
||||
def add_parser(self, parser):
|
||||
if parser is not None:
|
||||
if isinstance(parser, list):
|
||||
|
|
@ -116,6 +116,5 @@ class Service:
|
|||
for parser in self.get_parser():
|
||||
result.append(self._parser._parse(executionResult))
|
||||
|
||||
|
||||
def handle_result(self, parseResult):
|
||||
pass
|
||||
|
|
@ -18,9 +18,9 @@ class ShellService(Service):
|
|||
def needs_arguments(self):
|
||||
return True
|
||||
|
||||
|
||||
def execute(self):
|
||||
self.command.call()
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
return ShellService(**kwargs)
|
||||
|
|
@ -51,5 +51,6 @@ class SnmpgetService(Service):
|
|||
# for name, val in varBinds:
|
||||
# print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
|
||||
|
||||
|
||||
def create(**kargs):
|
||||
return SnmpgetService(**kwargs)
|
||||
|
|
@ -39,6 +39,7 @@ class SshService(Service):
|
|||
print '... ' + line.strip('\n')
|
||||
client.close()
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
return SshService(**kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ class TcpconnectService(Service):
|
|||
else:
|
||||
raise Exception("There is no port set")
|
||||
|
||||
|
||||
def needs_arguments(self):
|
||||
return True
|
||||
|
||||
|
|
@ -39,5 +38,6 @@ class TcpconnectService(Service):
|
|||
sock.close()
|
||||
return
|
||||
|
||||
|
||||
def create(**kwargs):
|
||||
return TcpconnectService(**kwargs)
|
||||
|
|
@ -4,6 +4,7 @@ The email task.
|
|||
|
||||
from lib.tasks.task import Task
|
||||
|
||||
|
||||
class EmailTask(Task):
|
||||
def __init__(self, **kwargs):
|
||||
if not "type" in kwargs:
|
||||
|
|
@ -13,12 +14,9 @@ class EmailTask(Task):
|
|||
self.set_task_type(kwargs["type"])
|
||||
self.recipient = kwargs["args"]["rcpt"]
|
||||
|
||||
|
||||
|
||||
def execute_task(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def creator(**taskDict):
|
||||
return EmailTask(**taskDict)
|
||||
|
|
@ -4,6 +4,7 @@ The sms task.
|
|||
|
||||
from task import Task
|
||||
|
||||
|
||||
class SmsTask(Task):
|
||||
def __init__(self, **kwargs):
|
||||
if not "type" in kwargs:
|
||||
|
|
@ -13,12 +14,9 @@ class SmsTask(Task):
|
|||
self.set_task_type(kwargs["type"])
|
||||
self.recipient = kwargs["args"]["rcpt"]
|
||||
|
||||
|
||||
|
||||
def execute_task(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def creator(**taskDict):
|
||||
return SmsTask(**taskDict)
|
||||
|
|
@ -1,35 +1,36 @@
|
|||
'''
|
||||
"""
|
||||
Created on Jun 15, 2013
|
||||
|
||||
@author: Rafael Timmerberg
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
class Task:
|
||||
'''
|
||||
"""
|
||||
Base class for all built-in Tasks.
|
||||
'''
|
||||
"""
|
||||
|
||||
def set_task_type(self, taskType):
|
||||
'''
|
||||
"""
|
||||
sets the type of this task.
|
||||
|
||||
Be aware! this method can only get called once!
|
||||
|
||||
params:
|
||||
taskType: the type of this task
|
||||
'''
|
||||
"""
|
||||
if hasattr(self, "_taskType"):
|
||||
raise Exception("taskType is only allowed to set once!")
|
||||
self.taskType = taskType
|
||||
|
||||
def get_task_type(self):
|
||||
'''
|
||||
"""
|
||||
returns the type set by set_type_task
|
||||
'''
|
||||
"""
|
||||
return self._taskType
|
||||
|
||||
def execute_task(self, msg):
|
||||
'''
|
||||
"""
|
||||
this is the method tasks usually override.
|
||||
It gets called anytime the task should get executed
|
||||
|
||||
|
|
@ -37,11 +38,11 @@ class Task:
|
|||
|
||||
params:
|
||||
msg: the msg for this task
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def _execute(self,taskType, msg):
|
||||
'''
|
||||
def _execute(self, taskType, msg):
|
||||
"""
|
||||
internal method which gets called for any member in a hostgroup.
|
||||
It determines if it has an appropriate type by comparing taskType with get_task_type().
|
||||
Calls execute_task() if the type matches
|
||||
|
|
@ -52,9 +53,8 @@ class Task:
|
|||
|
||||
return:
|
||||
True if execute_task() is called succesfully, else False
|
||||
'''
|
||||
"""
|
||||
if self.get_task_type() == taskType:
|
||||
self.execute_task(msg)
|
||||
return True
|
||||
return False
|
||||
|
||||
|
|
@ -4,6 +4,7 @@ The xmpp task.
|
|||
|
||||
from task import Task
|
||||
|
||||
|
||||
class XmppTask(Task):
|
||||
def __init__(self, **kwargs):
|
||||
if not "type" in kwargs:
|
||||
|
|
@ -13,12 +14,9 @@ class XmppTask(Task):
|
|||
self.set_task_type(kwargs["type"])
|
||||
self.recipient = kwargs["args"]["rcpt"]
|
||||
|
||||
|
||||
|
||||
def execute_task(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def creator(**taskDict):
|
||||
return XmppTask(taskDict)
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/python2.7 -tt
|
||||
from zenmapCore.UmitConf import config_parser
|
||||
|
||||
__version__ = "0.4/TETRIS"
|
||||
__default_config__ = "./linspector.json"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue