From e2ab9709c135fa841819129bf65cecda9b72d630 Mon Sep 17 00:00:00 2001 From: "Rafael.Timmerberg" Date: Wed, 19 Jun 2013 01:56:04 +0200 Subject: [PATCH] just cleanup --- lib/config/parser.py | 103 ++----------------------------------------- linspector.json | 2 +- 2 files changed, 4 insertions(+), 101 deletions(-) diff --git a/lib/config/parser.py b/lib/config/parser.py index 0fd1d45..27fd23f 100644 --- a/lib/config/parser.py +++ b/lib/config/parser.py @@ -1,12 +1,9 @@ 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 @@ -51,10 +48,10 @@ class ConfigParser: self.members = {} self.periods = {} self.layouts = {} - self._loadedMods={MOD_SERVICES:{}, MOD_PROCESSORS:{}, MOD_TASKS:{}} + self._loadedMods={MOD_SERVICES: {}, MOD_PROCESSORS: {}, MOD_TASKS: {}, MOD_PARSERS: {}} def _create_new_config_dict(self): - return {"members": {}, "periods":{}, "hostgroups":{}, "layouts":{}, "core":{}} + return {"members": {}, "periods": {}, "hostgroups": {}, "layouts": {}, "core": {}} def create_config(self, config): configDict = self._create_new_config_dict() @@ -80,13 +77,6 @@ class ConfigParser: self.log.i("reading Config: " + configFilename) 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): items = [] @@ -98,45 +88,7 @@ class ConfigParser: self.log.w("ignoring " + msgName + ": " + key + "! reason:") self.log.w(str(Exception)) return items - - def create_layouts_from_json(self, jsonLayouts): - layouts = [] - for lName, lValues in jsonLayouts.items(): - try: - layout = Layout(lName, **lValues) - layouts.append(layout) - except ConfigurationException: - self.log.w("ignoring Layout " + lName + "! reason:") - self.log.w(str(Exception)) - return layouts - def create_hostgroups_from_json(self, jsonHostGroups): - """ - creates Hostgroups from the jsonConfig - """ - hostgroups = [] - for hgName, hgValues in jsonHostGroups.items(): - try: - hostgroup = HostGroup(hgName, **hgValues) - hostgroups.append(hostgroup) - except ConfigurationException: - self.log.w("ignoring hostgroup: " + hgName + "!") - self.log.w("reason: " + str(Exception)) - return hostgroups - - def create_members_from_json(self, jsonMembers): - """ - creates Members from the jsonConfig - """ - members = [] - for memberName, memberValues in jsonMembers.items(): - try: - member = memberName(memberName, **memberValues) - members.append(member) - except ConfigurationException: - self.log.w("ignoring member: " + memberName + "!") - self.log.w("reason: " + str(Exception)) - return members def _load_module(self, clazz, modPart): mods = self._loadedMods[modPart] @@ -194,56 +146,7 @@ class ConfigParser: 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. - Parsing will be done in 3 steps: - 1. get raw Config Objects by just passing the values defined inside the config - 2. replace references by objects - 3. do sanity checks - - params: - configFilename: indicates which configuration file to parse - """ - - self.jsonDict = self._read_json_config(configFilename) - - jsonLayouts = self.jsonDict[KEY_LAYOUTS] - #layouts = self._create_raw_Object(jsonLayouts, "Layouts", lambda name, vals: Layout(name, **vals)) - layouts = self.create_layouts_from_json(jsonLayouts) - - hostgroupNames = set() - 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]: - self.log.w("Hostgroup " + hgName + " not found!") - for layout in layouts: - if hgName in layout.hostgroups: - del layout.hostgroups[layout.hostgroups.index(hgName)] - jsonHostgroups[hgName] = self.jsonDict[KEY_HOSTGROUPS][hgName] - - self.hostgroups = self.create_hostgroups_from_json(jsonHostgroups) - - memberNames = set() - for layout in layouts: - for memberName in layout.get_members(): - memberNames.add(memberName) - - jsonMembers = {} - for memberName in memberNames: - if not memberName in self.jsonDict[KEY_MEMBERS]: - self.log.w("Member " + memberName + " not found!") - for hostgroup in self.hostgroups: - if memberName in hostgroup.members: - del hostgroup.members[hostgroup.members.index(memberName)] - jsonMembers[memberName] = self.jsonDict[KEY_HOSTGROUPS][memberName] - - self.members = self.create_members_from_json(jsonMembers) + pass def parsePeriodList(name, values): diff --git a/linspector.json b/linspector.json index 1eae12e..b1f464e 100644 --- a/linspector.json +++ b/linspector.json @@ -5,7 +5,7 @@ "comment": "The Linspector Admin", "tasks":[{ "class": "email", "type": "warning", "args":{ "rcpt": "admin@systems.hanez.org" }}, { "class": "sms", "type": "critical", "args":{ "rcpt": "+49112" }}, - { "class": "xmpp", "type": "critical", "args":{ "rcpt": "admin@jabber.hanez.org" }}] + { "class": "xmpp", "type": "critical", "arfixed parsing, replaced non_workin instance_check with gs":{ "rcpt": "admin@jabber.hanez.org" }}] }, "hanez":{ "name": "Johannes Findeisen",