2 - def __init__(self, name, members="", hosts="", services="", threshold="", parent="", comment=""):
11
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
33
35 return "HostgroupService { " + str([str(s) for s in self.services]) + ", " + str([p.name for p in self.periods]) + "}"
36
37
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