From 927fff0c5ebd29ada2dba38e78c68156f306564f Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Tue, 18 Jun 2013 02:58:40 +0200 Subject: [PATCH] whitespacing.... :) --- lib/config/hostgroups.py | 11 +++----- lib/config/hosts.py | 3 +- lib/config/layouts.py | 7 ++--- lib/config/members.py | 4 +-- lib/config/parser.py | 55 ++++++++++++------------------------- lib/config/periods.py | 6 +--- lib/parsers/parser.py | 1 - lib/processors/mongodb.py | 4 +-- lib/processors/processor.py | 6 ++-- lib/service/snmpget.py | 5 ---- lib/services/http.py | 4 +-- lib/services/ping.py | 3 +- lib/services/service.py | 7 ++--- lib/services/shell.py | 4 +-- lib/services/snmpget.py | 3 +- lib/services/ssh.py | 1 + lib/services/tcpconnect.py | 6 ++-- lib/tasks/email.py | 4 +-- lib/tasks/sms.py | 6 ++-- lib/tasks/task.py | 30 ++++++++++---------- lib/tasks/xmpp.py | 4 +-- linspector | 1 - 22 files changed, 66 insertions(+), 109 deletions(-) delete mode 100644 lib/service/snmpget.py diff --git a/lib/config/hostgroups.py b/lib/config/hostgroups.py index 7135125..f6f6989 100644 --- a/lib/config/hostgroups.py +++ b/lib/config/hostgroups.py @@ -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: @@ -91,7 +89,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" @@ -140,4 +137,4 @@ def parseHostGroupList(hostgroups, hosts, members, periods, services, log): hostGroupPeriods = [p for p in periods if p.name in servicePeriods] hostGroup.services.append(HostGroupService(services, hostGroupPeriods)) parsedHostGroups.append(hostGroup) - return parsedHostGroups + return parsedHostGroups \ No newline at end of file diff --git a/lib/config/hosts.py b/lib/config/hosts.py index afffc90..f507b1a 100644 --- a/lib/config/hosts.py +++ b/lib/config/hosts.py @@ -115,5 +115,4 @@ def parseHostList(hosts, services, log): log.w("Service " + servicename + " not defined in host " + host.name) #replace host.service member by parsed HostService Objects host.services = hostServices - return parsedHosts - + return parsedHosts \ No newline at end of file diff --git a/lib/config/layouts.py b/lib/config/layouts.py index 7dfa1f1..c045869 100644 --- a/lib/config/layouts.py +++ b/lib/config/layouts.py @@ -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()] @@ -24,8 +23,7 @@ class Layout: configDict["layouts"][self.get_name()] = me 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: @@ -78,4 +75,4 @@ class LayoutList: ret += "Plugins: " + str(self.plugins) + "\n" for layout in self.layouts: ret += str(layout) + "\n" - return ret + return ret \ No newline at end of file diff --git a/lib/config/members.py b/lib/config/members.py index cfcf9c0..33f193d 100644 --- a/lib/config/members.py +++ b/lib/config/members.py @@ -27,8 +27,6 @@ class Member: for f in self.filters: ret += str(f) return ret - - class MemberFilter: @@ -56,4 +54,4 @@ def parseMemberList(members, filters, log): if not found: log.w("filter: " + filtername + " is not defined in member " + member.name) member.filters = mFilter - return parsedMembers + return parsedMembers \ No newline at end of file diff --git a/lib/config/parser.py b/lib/config/parser.py index 368f356..535f764 100644 --- a/lib/config/parser.py +++ b/lib/config/parser.py @@ -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: @@ -172,7 +168,6 @@ class ConfigParser: self.log.w("Error while replace: " + str(Exception)) del items[:] items.extend(repl) - def replace_pointer(self, objectList, replObjectList, id_list_func, id_get_func): for obj in objectList: @@ -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) @@ -214,8 +205,7 @@ class ConfigParser: for layout in layouts: 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 @@ -328,8 +311,4 @@ class FullConfigParser(ConfigParser): id_get_func = lambda hostgroup: hostgroup.get_name() self.replace_pointer(layouts, hostgroups, id_list_func, id_get_func) - return layouts - - - - \ No newline at end of file + return layouts \ No newline at end of file diff --git a/lib/config/periods.py b/lib/config/periods.py index 14c7651..237a8fc 100644 --- a/lib/config/periods.py +++ b/lib/config/periods.py @@ -66,8 +66,4 @@ class DatePeriod(Period): return ret def createJob(self, scheduler, jobInfo, func): - return scheduler.add_date_job(func, self.date, jobInfo) - - - - + return scheduler.add_date_job(func, self.date, jobInfo) \ No newline at end of file diff --git a/lib/parsers/parser.py b/lib/parsers/parser.py index 4c8feb4..977b284 100644 --- a/lib/parsers/parser.py +++ b/lib/parsers/parser.py @@ -1,4 +1,3 @@ - class Parser: def __init__(self): pass diff --git a/lib/processors/mongodb.py b/lib/processors/mongodb.py index 1f3bf07..62eda3b 100644 --- a/lib/processors/mongodb.py +++ b/lib/processors/mongodb.py @@ -4,7 +4,7 @@ The MongoDB processor from processor import Processor + class Mongodb(Processor): def __init__(self): - pass - \ No newline at end of file + pass \ No newline at end of file diff --git a/lib/processors/processor.py b/lib/processors/processor.py index df61b44..988f696 100644 --- a/lib/processors/processor.py +++ b/lib/processors/processor.py @@ -1,8 +1,10 @@ -''' +""" Created on Jun 16, 2013 @author: rafael -''' +""" + + class Processor: def __init__(self): pass \ No newline at end of file diff --git a/lib/service/snmpget.py b/lib/service/snmpget.py deleted file mode 100644 index c36c477..0000000 --- a/lib/service/snmpget.py +++ /dev/null @@ -1,5 +0,0 @@ -""" -The snmpget service in pure Python. -""" - -# http://pysnmp.sourceforge.net/ \ No newline at end of file diff --git a/lib/services/http.py b/lib/services/http.py index 35ec6d2..a23c42b 100644 --- a/lib/services/http.py +++ b/lib/services/http.py @@ -40,7 +40,6 @@ class HttpService(Service): def needs_arguments(self): return True - def execute(self): params = urllib.urlencode(self.params) @@ -50,6 +49,7 @@ class HttpService(Service): f = urllib.urlopen(self.protocol + "://" + self._host + ":" + self.port + self.path, params) #print f.read() - + + def create(**kwargs): return HttpService(**kwargs) \ No newline at end of file diff --git a/lib/services/ping.py b/lib/services/ping.py index fcfa0d3..fc07cc1 100644 --- a/lib/services/ping.py +++ b/lib/services/ping.py @@ -5,10 +5,11 @@ 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) def create(self, **kwargs): - return PingService(**kwargs) + return PingService(**kwargs) \ No newline at end of file diff --git a/lib/services/service.py b/lib/services/service.py index 81b3015..4d6d339 100644 --- a/lib/services/service.py +++ b/lib/services/service.py @@ -6,6 +6,7 @@ KEY_FAILS = "fails" KEY_PERIODS = "periods" KEY_ARGS = "args" + class Service: def __init__(self, **kwargs): @@ -87,8 +88,7 @@ class Service: def get_parser(self): return self._parser - - + def add_parser(self, parser): if parser is not None: if isinstance(parser, list): @@ -115,7 +115,6 @@ class Service: result = [] for parser in self.get_parser(): result.append(self._parser._parse(executionResult)) - def handle_result(self, parseResult): - pass + pass \ No newline at end of file diff --git a/lib/services/shell.py b/lib/services/shell.py index f17255b..59ad5e8 100644 --- a/lib/services/shell.py +++ b/lib/services/shell.py @@ -17,10 +17,10 @@ class ShellService(Service): def needs_arguments(self): return True - def execute(self): self.command.call() - + + def create(**kwargs): return ShellService(**kwargs) \ No newline at end of file diff --git a/lib/services/snmpget.py b/lib/services/snmpget.py index e7fcc9d..bf516fb 100644 --- a/lib/services/snmpget.py +++ b/lib/services/snmpget.py @@ -50,6 +50,7 @@ class SnmpgetService(Service): # else: # for name, val in varBinds: # print('%s = %s' % (name.prettyPrint(), val.prettyPrint())) - + + def create(**kargs): return SnmpgetService(**kwargs) \ No newline at end of file diff --git a/lib/services/ssh.py b/lib/services/ssh.py index c95ee44..dc82884 100644 --- a/lib/services/ssh.py +++ b/lib/services/ssh.py @@ -39,6 +39,7 @@ class SshService(Service): print '... ' + line.strip('\n') client.close() + def create(**kwargs): return SshService(**kwargs) diff --git a/lib/services/tcpconnect.py b/lib/services/tcpconnect.py index d17322c..1548698 100644 --- a/lib/services/tcpconnect.py +++ b/lib/services/tcpconnect.py @@ -18,7 +18,6 @@ class TcpconnectService(Service): self.port = args["port"] else: raise Exception("There is no port set") - def needs_arguments(self): return True @@ -38,6 +37,7 @@ class TcpconnectService(Service): sock.close() return - + + def create(**kwargs): - return TcpconnectService(**kwargs) + return TcpconnectService(**kwargs) \ No newline at end of file diff --git a/lib/tasks/email.py b/lib/tasks/email.py index 33975ea..4453b4a 100644 --- a/lib/tasks/email.py +++ b/lib/tasks/email.py @@ -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: @@ -12,13 +13,10 @@ class EmailTask(Task): raise Exception("typeDict " + str(kwargs) + " has nor arguments!") self.set_task_type(kwargs["type"]) self.recipient = kwargs["args"]["rcpt"] - - def execute_task(self, msg): pass - def creator(**taskDict): return EmailTask(**taskDict) \ No newline at end of file diff --git a/lib/tasks/sms.py b/lib/tasks/sms.py index 6fff896..407f542 100644 --- a/lib/tasks/sms.py +++ b/lib/tasks/sms.py @@ -4,6 +4,7 @@ The sms task. from task import Task + class SmsTask(Task): def __init__(self, **kwargs): if not "type" in kwargs: @@ -12,13 +13,10 @@ class SmsTask(Task): raise Exception("typeDict " + str(kwargs) + " has no arguments!") self.set_task_type(kwargs["type"]) self.recipient = kwargs["args"]["rcpt"] - - def execute_task(self, msg): pass - def creator(**taskDict): - return SmsTask(**taskDict) + return SmsTask(**taskDict) \ No newline at end of file diff --git a/lib/tasks/task.py b/lib/tasks/task.py index 78d8736..12d2269 100644 --- a/lib/tasks/task.py +++ b/lib/tasks/task.py @@ -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 - \ No newline at end of file + return False \ No newline at end of file diff --git a/lib/tasks/xmpp.py b/lib/tasks/xmpp.py index 2a5ecfe..694b766 100644 --- a/lib/tasks/xmpp.py +++ b/lib/tasks/xmpp.py @@ -4,6 +4,7 @@ The xmpp task. from task import Task + class XmppTask(Task): def __init__(self, **kwargs): if not "type" in kwargs: @@ -12,13 +13,10 @@ class XmppTask(Task): raise Exception("typeDict " + str(kwargs) + " has nor arguments!") self.set_task_type(kwargs["type"]) self.recipient = kwargs["args"]["rcpt"] - - def execute_task(self, msg): pass - def creator(**taskDict): return XmppTask(taskDict) \ No newline at end of file diff --git a/linspector b/linspector index 8f1f377..dbbfb89 100755 --- a/linspector +++ b/linspector @@ -1,5 +1,4 @@ #!/usr/bin/python2.7 -tt -from zenmapCore.UmitConf import config_parser __version__ = "0.4/TETRIS" __default_config__ = "./linspector.json"