6 class NagiosObject(object):
7 trans = {'d2_coords': '2d_coords'}
9 def __init__(self, id, **kwargs):
11 self.kwords = kwargs.keys()
12 for key in self.kwords:
13 self.__setattr__(key, kwargs[key])
17 ret += "define %s {\n" % self.id
18 for key in self.kwords:
20 ret += " %s %s\n" % (self.trans[key], self.__getattribute__(key))
22 ret += " %s %s\n" % (key, self.__getattribute__(key))
26 class Host(NagiosObject):
27 def __init__(self, **kwargs):
28 NagiosObject.__init__(self, "host", **kwargs)
30 class HostGroup(NagiosObject):
31 def __init__(self, **kwargs):
32 NagiosObject.__init__(self, "hostgroup", **kwargs)
34 class Service(NagiosObject):
35 def __init__(self, **kwargs):
36 NagiosObject.__init__(self, "service", **kwargs)
38 class ServiceDependency(NagiosObject):
39 def __init__(self, **kwargs):
40 NagiosObject.__init__(self, "servicedependency", **kwargs)
42 class ServiceGroup(NagiosObject):
43 def __init__(self, **kwargs):
44 NagiosObject.__init__(self, "servicegroup", **kwargs)
48 for service in [('NET', "Network Services"),
49 ('SSH', "SSH Service"),
50 ('SSH806', "Auxiliary SSH Service"),
51 ('HTTP', "PlanetFlow HTTP"),
52 ('COTOP', "HTTP based COTOP"),
54 #('PLSOFT', "PlanetLab Software"),
55 #('MGMT', "Remote Management")]:
56 globalservices.append(ServiceGroup(servicegroup_name=service[0], alias=service[1]))
59 globalhost = [Host( name="planetlab-host",
64 max_check_attempts="10",
65 check_command="check-host-alive",
66 contact_groups="admins",
69 for obj in globalhost + globalservices:
72 plcdb = soltesz.dbLoad("l_plcsites")
73 netid2ip = soltesz.dbLoad("plcdb_netid2ip")
74 lb2hn = soltesz.dbLoad("plcdb_lb2hn")
77 shortname = site['abbreviated_name']
78 lb = site['login_base']
79 hg = HostGroup(hostgroup_name=lb, alias=shortname)
80 lat = site['latitude']
81 lon = site['longitude']
84 if lat is not None and lon is not None:
86 lon_x = int(180 + lon) * scale
87 lat_y = int(180 - (lat + 90)) * scale
89 if site['login_base'] in lb2hn:
90 nodes = lb2hn[site['login_base']] # plc.getSiteNodes2(site['login_base'])
100 hn = node['hostname']
101 if len(node['nodenetwork_ids']) == 0:
104 ip = netid2ip[node['nodenetwork_ids'][0]]
106 if lon_x is not -1 and lat_y is not -1:
107 coords="%s,%s" % (lon_x, lat_y)
111 h = Host(use="planetlab-host",
116 statusmap_image="icon-system.png",
121 s1 = Service(use="generic-service",
123 service_description="aSSH",
125 servicegroups="NET,SSH",
126 check_command="check_ssh!-t 120")
127 s2 = Service(use="generic-service",
129 service_description="bSSH806",
130 display_name="bSSH806",
131 servicegroups="NET,SSH806",
132 check_command="check_ssh!-p 806 -t 120")
133 s3 = Service(use="generic-service",
135 service_description="cHTTP",
136 display_name="cHTTP",
137 servicegroups="NET,HTTP",
138 check_command="check_http!-t 120")
139 s4 = Service(use="generic-service",
141 service_description="dCOTOP",
142 display_name="dCOTOP",
143 servicegroups="NET,COTOP",
144 check_command="check_http!-p 3120 -t 120")
146 sd1 = ServiceDependency(host_name=hn,
147 service_description="aSSH",
148 dependent_host_name=hn,
149 dependent_service_description="bSSH806",
150 execution_failure_criteria="w,u,c,p",)
152 sd2 = ServiceDependency(host_name=hn,
153 service_description="aSSH",
154 dependent_host_name=hn,
155 dependent_service_description="cHTTP",
156 execution_failure_criteria="w,u,c,p",)
158 sd3 = ServiceDependency(host_name=hn,
159 service_description="aSSH",
160 dependent_host_name=hn,
161 dependent_service_description="dCOTOP",
162 execution_failure_criteria="w,u,c,p",)
164 for service in [s1,s2,s3,s4,sd1,sd2,sd3]:
165 print service.toString()