whitespaces at night...

This commit is contained in:
Johannes Findeisen 2013-06-19 03:26:25 +02:00
commit c463f2473d
11 changed files with 28 additions and 40 deletions

View file

@ -1,4 +1,3 @@
class HostGroupException(Exception): class HostGroupException(Exception):
def __init__(self, msg): def __init__(self, msg):
self.msg = msg self.msg = msg
@ -6,10 +5,12 @@ class HostGroupException(Exception):
def __str__(self): def __str__(self):
return repr(self.msg) return repr(self.msg)
class HostGroupMissingArgumentException(HostGroupException): class HostGroupMissingArgumentException(HostGroupException):
def __init__(self, missingArgument, hostgroupName): def __init__(self, missingArgument, hostgroupName):
super(HostGroupMissingArgumentException, self).__init__("no " + missingArgument + " defined for Hostgroup " + hostgroupName) super(HostGroupMissingArgumentException, self).__init__("no " + missingArgument + " defined for Hostgroup " + hostgroupName)
class HostGroup: class HostGroup:
def __init__(self, name, **kwargs): def __init__(self, name, **kwargs):
self.name = name self.name = name

View file

@ -10,7 +10,7 @@ from members import Member
from periods import CronPeriod, DatePeriod, IntervalPeriod from periods import CronPeriod, DatePeriod, IntervalPeriod
from lib.services.service import Service from lib.services.service import Service
print id(Service) #print id(Service)
from lib.processors.processor import Processor from lib.processors.processor import Processor
from lib.parsers.parser import Parser from lib.parsers.parser import Parser
from lib.tasks.task import Task from lib.tasks.task import Task
@ -20,14 +20,13 @@ MOD_PROCESSORS = "processors"
MOD_PARSERS = "parsers" MOD_PARSERS = "parsers"
MOD_TASKS = "tasks" MOD_TASKS = "tasks"
KEY_LAYOUTS = "layouts" KEY_LAYOUTS = "layouts"
KEY_HOSTGROUPS = "hostgroups" KEY_HOSTGROUPS = "hostgroups"
KEY_MEMBERS = "members" KEY_MEMBERS = "members"
KEY_PERIODS = "periods" KEY_PERIODS = "periods"
KEY_CORE = "core" KEY_CORE = "core"
class ConfigurationException(Exception): class ConfigurationException(Exception):
def __init__(self, msg, log): def __init__(self, msg, log):
log.e(msg) log.e(msg)
@ -42,15 +41,14 @@ class ConfigParser:
""" """
initializes a new ConfigParser Object initializes a new ConfigParser Object
params: :param log: pre configured logger Object to post messages while parsing"
log: pre configured logger Object to post messages while parsing"
""" """
self.log = log self.log = log
self.hostgroups = {} self.hostgroups = {}
self.members = {} self.members = {}
self.periods = {} self.periods = {}
self.layouts = {} self.layouts = {}
self._loadedMods={MOD_SERVICES: {}, MOD_PROCESSORS: {}, MOD_TASKS: {}, MOD_PARSERS: {}} self._loadedMods = {MOD_SERVICES: {}, MOD_PROCESSORS: {}, MOD_TASKS: {}, MOD_PARSERS: {}}
def _create_new_config_dict(self): def _create_new_config_dict(self):
return {"members": {}, "periods": {}, "hostgroups": {}, "layouts": {}, "core": {}} return {"members": {}, "periods": {}, "hostgroups": {}, "layouts": {}, "core": {}}
@ -64,14 +62,13 @@ class ConfigParser:
""" """
reads the config File and returns a dictionary, while lowering the first keys reads the config File and returns a dictionary, while lowering the first keys
params: :param configFilename: the path under which the configuration file should be found
configFilename: the path under which the configuration file should be found
""" """
if not isfile(configFilename): if not isfile(configFilename):
msg = "config file not found at " + str(configFilename) msg = "config file not found at " + str(configFilename)
raise ConfigurationException(msg, self.log) raise ConfigurationException(msg, self.log)
self.configfilename = configFilename self.configFilename = configFilename
with open(configFilename) as cfgFile: with open(configFilename) as cfgFile:
config = cfgFile.read() config = cfgFile.read()
@ -102,6 +99,7 @@ class ConfigParser:
def _load_module(self, clazz, modPart): def _load_module(self, clazz, modPart):
""" """
imports and caches a module. imports and caches a module.
:param clazz: the filename of the module (i.e email, ping...) :param clazz: the filename of the module (i.e email, ping...)
:param modPart: the folder of the module. (i.e services, parsers...) :param modPart: the folder of the module. (i.e services, parsers...)
:return: the imported/cached module, or throws an error if it couldn't find it :return: the imported/cached module, or throws an error if it couldn't find it
@ -121,6 +119,7 @@ class ConfigParser:
""" """
replaces configuration dicts with their objects by importing and creating it in the first step. replaces configuration dicts with their objects by importing and creating it in the first step.
In the second step the original list of json config dicts gets replaced by the loaded objects In the second step the original list of json config dicts gets replaced by the loaded objects
:param objList: the list of objects which is iterated on :param objList: the list of objects which is iterated on
:param modPart: the folder from the module (i.e tasks, parsers) :param modPart: the folder from the module (i.e tasks, parsers)
:param items_func: function to get a pointer on the list of json-config-objects to replace. Takes one argument and :param items_func: function to get a pointer on the list of json-config-objects to replace. Takes one argument and
@ -166,6 +165,7 @@ class ConfigParser:
def replace_pointer(self, objectList, replObjectList, id_list_func, id_get_func): def replace_pointer(self, objectList, replObjectList, id_list_func, id_get_func):
""" """
replaces objects from the config by ids. replaces objects from the config by ids.
:param objectList: the list of objects to be iterated on :param objectList: the list of objects to be iterated on
:param replObjectList: the list of objects to replace :param replObjectList: the list of objects to replace
:param id_list_func: function taking one argument as object and should return a list of config ids to replace :param id_list_func: function taking one argument as object and should return a list of config ids to replace
@ -205,15 +205,14 @@ class FullConfigParser(ConfigParser):
def parse_config(self, configFilename): def parse_config(self, configFilename):
""" """
parses the json configuration and returns a list of layouts, parses the json configuration and returns a list of layouts,
which contains all nessesary information of the config file. which contains all necessary information of the config file.
parses the full config parses the full config
Parsing will be done in 3 steps: Parsing will be done in 3 steps:
1. get raw Config Objects by just passing the values defined inside the config 1. get raw Config Objects by just passing the values defined inside the config
2. replace references by objects, import services, tasks, parsers and processors 2. replace references by objects, import services, tasks, parsers and processors
3. do sanity checks 3. do sanity checks
params: :param configFilename: the configuration file to parse
configFilename: indicates which configuration file to parse
""" """
self.jsonDict = self._read_json_config(configFilename) self.jsonDict = self._read_json_config(configFilename)
@ -230,7 +229,6 @@ class FullConfigParser(ConfigParser):
creator = parsePeriodList creator = parsePeriodList
periods = self._create_raw_Object(self.jsonDict[KEY_PERIODS], "Period", creator) periods = self._create_raw_Object(self.jsonDict[KEY_PERIODS], "Period", creator)
#2. import and replace #2. import and replace
items_func = lambda hostgroup: hostgroup.get_services() items_func = lambda hostgroup: hostgroup.get_services()
class_check = lambda service: isinstance(service, Service) class_check = lambda service: isinstance(service, Service)
@ -244,7 +242,6 @@ class FullConfigParser(ConfigParser):
for hg in hostgroups: for hg in hostgroups:
services.extend(hg.get_services()) services.extend(hg.get_services())
items_func = lambda service: service.get_parser() items_func = lambda service: service.get_parser()
class_check = lambda parser: isinstance(parser, Parser) class_check = lambda parser: isinstance(parser, Parser)
self.replace_with_import(services, MOD_PARSERS, items_func, class_check) self.replace_with_import(services, MOD_PARSERS, items_func, class_check)
@ -258,7 +255,6 @@ class FullConfigParser(ConfigParser):
id_get_func = lambda member: member.id id_get_func = lambda member: member.id
self.replace_pointer(hostgroups, members, id_list_func, id_get_func) self.replace_pointer(hostgroups, members, id_list_func, id_get_func)
id_list_func = lambda service: service.get_periods() id_list_func = lambda service: service.get_periods()
id_get_func = lambda period: period.get_name() id_get_func = lambda period: period.get_name()
self.replace_pointer(services, periods, id_list_func, id_get_func) self.replace_pointer(services, periods, id_list_func, id_get_func)

View file

@ -3,6 +3,7 @@ from subprocess import Popen
from subprocess import CalledProcessError from subprocess import CalledProcessError
from datetime import datetime as dt from datetime import datetime as dt
class Command: class Command:
def __init__(self, command, log): def __init__(self, command, log):
self.command = command self.command = command

View file

@ -17,7 +17,6 @@ class Logger():
:param logfile: the file where to log. Logs are rotated by default. :param logfile: the file where to log. Logs are rotated by default.
:param logfileLevel: the LoggingLevel for the file Logger. (DEBUG default) :param logfileLevel: the LoggingLevel for the file Logger. (DEBUG default)
""" """
logfile = path.expanduser(logfile) logfile = path.expanduser(logfile)
if not path.exists(path.dirname(logfile)): if not path.exists(path.dirname(logfile)):
os.makedirs(path.dirname(logfile)) os.makedirs(path.dirname(logfile))

View file

@ -11,4 +11,3 @@ class Parser:
def generate_parse_result(self, result): def generate_parse_result(self, result):
pass pass

View file

@ -1,7 +1,5 @@
""" """
Created on Jun 16, 2013 The processor class for postprocessing polled data.
@author: rafael
""" """

View file

@ -9,5 +9,6 @@ class Syslog(Processor):
def __init__(self): def __init__(self):
pass pass
def create(kwargs): def create(kwargs):
return Syslog(**kwargs) return Syslog(**kwargs)

View file

@ -2,7 +2,7 @@
The email task. The email task.
""" """
from lib.tasks.task import Task from task import Task
class EmailTask(Task): class EmailTask(Task):

View file

@ -1,7 +1,5 @@
""" """
Created on Jun 15, 2013 The task class.
@author: Rafael Timmerberg
""" """
@ -16,8 +14,7 @@ class Task:
Be aware! this method can only get called once! Be aware! this method can only get called once!
params: :param taskType: the type of this task
taskType: the type of this task
""" """
if hasattr(self, "_taskType"): if hasattr(self, "_taskType"):
raise Exception("taskType is only allowed to set once!") raise Exception("taskType is only allowed to set once!")
@ -25,7 +22,7 @@ class Task:
def get_task_type(self): def get_task_type(self):
""" """
returns the type set by set_type_task :return: the type set by set_type_task
""" """
return self._taskType return self._taskType
@ -36,8 +33,7 @@ class Task:
default does nothing default does nothing
params: :param msg: the msg for this task
msg: the msg for this task
""" """
pass pass
@ -47,12 +43,10 @@ class Task:
It determines if it has an appropriate type by comparing taskType with get_task_type(). It determines if it has an appropriate type by comparing taskType with get_task_type().
Calls execute_task() if the type matches Calls execute_task() if the type matches
params: :param taskType: the type of the fail which is compared with get_task_type()
taskType: the type of the fail which is compared with get_task_type() :param msg: the error message
msg: the error message
return: :return: True if execute_task() is called succesfully, else False
True if execute_task() is called succesfully, else False
""" """
if self.get_task_type() == taskType: if self.get_task_type() == taskType:
self.execute_task(msg) self.execute_task(msg)

View file

@ -18,6 +18,5 @@ class XmppTask(Task):
pass pass
def create(taskDict): def create(taskDict):
return XmppTask(**taskDict) return XmppTask(**taskDict)