Package linspector :: Package lib :: Package config :: Module hostgroups
[hide private]
[frames] | no frames]

Source Code for Module linspector.lib.config.hostgroups

1 -class HostGroup:
2 - def __init__(self, name, members="", hosts="", services="", threshold="", parent="", comment=""):
3 self.name = name 4 self.interval = 0 5 self.members = members 6 self.hosts = hosts 7 self.services = services 8 self.threshold = threshold 9 self.parent = parent 10 self.comment = comment
11
12 - def __str__(self):
13 ret = "HostGroup: " + self.name + " threshold: " + str(self.threshold) + " parent: " + self.parent + "\n" 14 ret += "members: {\n" 15 for itm in self.members: 16 ret += str(itm) + "\n" 17 ret += "}\n" 18 ret += "hosts: {\n" 19 for itm in self.hosts: 20 ret += str(itm) + "\n" 21 ret += "}\n" 22 ret += "services: {\n" 23 for itm in self.services: 24 ret += str(itm) + "\n" 25 ret += "}\n" 26 return ret
27 28
29 -class HostGroupService:
30 - def __init__(self, services, periods):
31 self.services = services 32 self.periods = periods
33
34 - def __str__(self):
35 return "HostgroupService { " + str([str(s) for s in self.services]) + ", " + str([p.name for p in self.periods]) + "}"
36 37
38 -def parseHostGroupList(hostgroups, hosts, members, periods, services, log):
39 parsedHostGroups = [] 40 for hgname, hgValues in hostgroups.items(): 41 hostGroup = HostGroup(hgname) 42 hostGroup.members = [m for m in members if m.nameid in hgValues['members']] 43 hostGroup.hosts = [h for h in hosts if h.name in hgValues['hosts']] 44 hostGroup.threshold = hgValues['threshold'] 45 if 'parent' in hgValues: 46 hostGroup.parent = hgValues['parent'] 47 hostGroup.services = [] 48 for serviceName, servicePeriods in hgValues['services'].items(): 49 services = [] 50 for host in hosts: 51 service = host.getHostServiceByName(serviceName) 52 if service is not None: 53 services.append(service) 54 else: 55 log.w("could not find HostService(" +str(serviceName) + ") for host " + host.name) 56 hostGroupPeriods = [p for p in periods if p.name in servicePeriods] 57 hostGroup.services.append(HostGroupService(services, hostGroupPeriods)) 58 parsedHostGroups.append(hostGroup) 59 return parsedHostGroups
60