From a1ab1b1661aae61ed4a12fe00110c065b5463aee Mon Sep 17 00:00:00 2001 From: Johannes Findeisen Date: Wed, 19 Jun 2013 23:55:56 +0200 Subject: [PATCH] some deletions --- lib/config/hosts.py | 118 ----------------------------------------- lib/config/services.py | 20 ------- lib/config/tasks.py | 16 ------ 3 files changed, 154 deletions(-) delete mode 100644 lib/config/hosts.py delete mode 100644 lib/config/services.py delete mode 100644 lib/config/tasks.py diff --git a/lib/config/hosts.py b/lib/config/hosts.py deleted file mode 100644 index f507b1a..0000000 --- a/lib/config/hosts.py +++ /dev/null @@ -1,118 +0,0 @@ -import re - - -class Host: - def __init__(self, name="", host="", parent="", services=None, comment=""): - self.name = name - self.host = host - self.parent = parent - self.services = services - self.comment = comment - - def getHostServiceByName(self, serviceName): - for hostService in self.services: - if serviceName == hostService.service.name: - return hostService - return None - - def __str__(self): - ret = "Host('Name: " + self.name + "', 'Access: " + self.host + "', " - if self.parent != "": - ret += "'Parent: " + self.parent + "', " - ret += "'HostServices: {" - for s in self.services: - ret += str(s) + "\n" - ret += "}" - return ret - - -class HostService: - def __init__(self, service, warning="", critical=""): - self.service = service - self.warning = warning - self.critical = critical - - def setCommand(self, command): - self.service.command = command - - def getCommand(self): - return self.service.command - - def __str__(self): - - ret = "HostService : " + str(self.service) - if self.warning: - ret += "warning: " + str(self.warning) - if self.critical: - ret += "critical: " + str(self.critical) - return ret - - -def parseHostList(hosts, services, log): - """ - parse the HostList and replace any command as necessary - """ - #precompiled regexPattern which finds replacements in service strings - pattern = re.compile("@(\w+)") - #get a List of Host Objects and leave services unparsed for this moment - parsedHosts = [Host(name, **values) for name, values in hosts.items()] - #predefined dict to cache service replacements by name - serviceReplacements = {} - for host in parsedHosts: - #list to store HostService Objects - hostServices = [] - #lets start to parse the Service Dict. - for servicename, serviceParams in host.services.items(): - #bool to check if the service is defined. - found = False - #to a real iteration. just pick the right service - for service in services: - if service.name != servicename: - continue - #indicate we found a service - found = True - #check to see if we already regexed our service command - if service.name not in serviceReplacements: - serviceReplacements[service.name] = pattern.findall(service.command) - for params in serviceParams: - #copy replacements from service command - replacements = serviceReplacements[service.name][:] - #for every Host.service.parameter we need a new HostService Object - hostService = HostService(service.clone()) - #check if the ServiceParameter contain warnings or critical values - if 'warning' in params: - hostService.warning = params['warning'] - del params['warning'] - if 'critical' in params: - hostService.critical = params['critical'] - del params['critical'] - #any remainig parm should be a replacement - for parm in params: - if parm not in replacements: - log.w("undefined parameter: " + parm + " in host " + host.name + " from service " + service.name) - continue - #replace our ServiceCommand with the parameter_value (search, replacement, string) - hostService.setCommand(re.sub('@' + parm, params[parm], hostService.getCommand())) - replacements.remove(parm) - #host will not be inside ServiceParameters, so check this also - if 'host' in replacements: - log.d("replacing host in " + hostService.getCommand()) - comm = re.sub('@host', host.host, hostService.getCommand()) - hostService.setCommand(comm) - log.d("new Command: " +comm) - log.d("set in hostService: " + str(hostService)) - replacements.remove('host') - #replacements should be empty now. - #If not we cannot use this command as some values are missing - if len(replacements) > 0: - log.w("Hostservice " + servicename + " from host " + host.name + " is ignored because of missing replacements: " + str( - replacements)) - else: - #anything ok! add to our valid hostServices - hostServices.append(hostService) - #we could't find the service defined in this host. Service ignored! - if not found: - log.w("Service " + servicename + " not defined in host " + host.name) - #replace host.service member by parsed HostService Objects - host.services = hostServices - return parsedHosts \ No newline at end of file diff --git a/lib/config/services.py b/lib/config/services.py deleted file mode 100644 index 9232a5a..0000000 --- a/lib/config/services.py +++ /dev/null @@ -1,20 +0,0 @@ -class Service: - def __init__(self, name="", command="", comment="", parser=""): - self.name = name - self.command = command - self.comment = comment - self.parser = parser - self.hostgroup = None - - def set_hostgroup(self, hostgroup): - self.hostgroup = hostgroup - - def __str__(self): - return "Service('Name: " + self.name + "', 'Command: " + self.command + ", 'Parser: " + self.parser + "')" - - def clone(self): - return Service(self.name, self.command, self.comment) - - -def serviceList(services): - return [Service(name=key, **values) for key, values in services.items()] diff --git a/lib/config/tasks.py b/lib/config/tasks.py deleted file mode 100644 index 1907563..0000000 --- a/lib/config/tasks.py +++ /dev/null @@ -1,16 +0,0 @@ -class Task: - def __init__(self, name="", command="", priority=0, comment=""): - self.name = name - self.command = command - self.priority = priority - self.comment = comment - - def __str__(self): - return "Task('Name: " + self.name + "', 'Command: " + self.command + "', 'Priority: " + str(self.priority) + "')" - - def clone(self): - return Task(self.name, self.command, self.priority, self.comment) - - -def parseTaskList(tasks): - return [Task(name, **values) for name, values in tasks.items()] \ No newline at end of file