just cleanup
This commit is contained in:
parent
07a2ffae51
commit
fdcce34ff7
2 changed files with 4 additions and 101 deletions
|
|
@ -1,12 +1,9 @@
|
||||||
from os.path import isfile
|
from os.path import isfile
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from os.path import join
|
|
||||||
from os import getcwd
|
|
||||||
import imp
|
import imp
|
||||||
from layouts import Layout
|
from layouts import Layout
|
||||||
from hostgroups import HostGroup
|
from hostgroups import HostGroup
|
||||||
import lib.services.ping
|
|
||||||
from members import Member
|
from members import Member
|
||||||
from periods import CronPeriod, DatePeriod, IntervalPeriod
|
from periods import CronPeriod, DatePeriod, IntervalPeriod
|
||||||
|
|
||||||
|
|
@ -51,10 +48,10 @@ class ConfigParser:
|
||||||
self.members = {}
|
self.members = {}
|
||||||
self.periods = {}
|
self.periods = {}
|
||||||
self.layouts = {}
|
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):
|
def _create_new_config_dict(self):
|
||||||
return {"members": {}, "periods":{}, "hostgroups":{}, "layouts":{}, "core":{}}
|
return {"members": {}, "periods": {}, "hostgroups": {}, "layouts": {}, "core": {}}
|
||||||
|
|
||||||
def create_config(self, config):
|
def create_config(self, config):
|
||||||
configDict = self._create_new_config_dict()
|
configDict = self._create_new_config_dict()
|
||||||
|
|
@ -80,13 +77,6 @@ class ConfigParser:
|
||||||
self.log.i("reading Config: " + configFilename)
|
self.log.i("reading Config: " + configFilename)
|
||||||
return json.loads(config)
|
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):
|
def _create_raw_Object(self, jsonDict, msgName, creator):
|
||||||
items = []
|
items = []
|
||||||
|
|
@ -98,45 +88,7 @@ class ConfigParser:
|
||||||
self.log.w("ignoring " + msgName + ": " + key + "! reason:")
|
self.log.w("ignoring " + msgName + ": " + key + "! reason:")
|
||||||
self.log.w(str(Exception))
|
self.log.w(str(Exception))
|
||||||
return items
|
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):
|
def _load_module(self, clazz, modPart):
|
||||||
mods = self._loadedMods[modPart]
|
mods = self._loadedMods[modPart]
|
||||||
|
|
@ -194,56 +146,7 @@ class ConfigParser:
|
||||||
idList.extend(replacements)
|
idList.extend(replacements)
|
||||||
|
|
||||||
def parse_config(self, configFilename):
|
def parse_config(self, configFilename):
|
||||||
"""
|
pass
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def parsePeriodList(name, values):
|
def parsePeriodList(name, values):
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
"comment": "The Linspector Admin",
|
"comment": "The Linspector Admin",
|
||||||
"tasks":[{ "class": "email", "type": "warning", "args":{ "rcpt": "admin@systems.hanez.org" }},
|
"tasks":[{ "class": "email", "type": "warning", "args":{ "rcpt": "admin@systems.hanez.org" }},
|
||||||
{ "class": "sms", "type": "critical", "args":{ "rcpt": "+49112" }},
|
{ "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":{
|
"hanez":{
|
||||||
"name": "Johannes Findeisen",
|
"name": "Johannes Findeisen",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue