5 class NagiosObject(object):
6 trans = {'d2_coords': '2d_coords'}
8 def __init__(self, id, **kwargs):
10 self.kwords = kwargs.keys()
11 for key in self.kwords:
12 self.__setattr__(key, kwargs[key])
16 ret += "define %s {\n" % self.id
17 for key in self.kwords:
19 ret += " %s %s\n" % (self.trans[key], self.__getattribute__(key))
21 ret += " %s %s\n" % (key, self.__getattribute__(key))
25 class Host(NagiosObject):
26 def __init__(self, **kwargs):
27 NagiosObject.__init__(self, "host", **kwargs)
29 class HostGroup(NagiosObject):
30 def __init__(self, **kwargs):
31 NagiosObject.__init__(self, "hostgroup", **kwargs)
33 class Service(NagiosObject):
34 def __init__(self, **kwargs):
35 NagiosObject.__init__(self, "service", **kwargs)
37 class ServiceDependency(NagiosObject):
38 def __init__(self, **kwargs):
39 NagiosObject.__init__(self, "servicedependency", **kwargs)
41 class ServiceGroup(NagiosObject):
42 def __init__(self, **kwargs):
43 NagiosObject.__init__(self, "servicegroup", **kwargs)
47 for service in [('NET', "Network Services"),
48 ('SSH', "SSH Service"),
49 ('SSH806', "Auxiliary SSH Service"),
50 ('HTTP', "PlanetFlow HTTP"),
51 ('COTOP', "HTTP based COTOP"),
53 #('PLSOFT', "PlanetLab Software"),
54 #('MGMT', "Remote Management")]:
55 globalservices.append(ServiceGroup(servicegroup_name=service[0], alias=service[1]))
58 globalhost = [Host( name="planetlab-host",
63 max_check_attempts="10",
64 check_command="check-host-alive",
65 contact_groups="admins",
68 for obj in globalhost + globalservices:
71 plcdb = database.dbLoad("l_plcsites")
72 netid2ip = database.dbLoad("plcdb_netid2ip")
73 lb2hn = database.dbLoad("plcdb_lb2hn")
76 shortname = site['abbreviated_name']
77 lb = site['login_base']
78 hg = HostGroup(hostgroup_name=lb, alias=shortname)
79 lat = site['latitude']
80 lon = site['longitude']
83 if lat is not None and lon is not None:
85 lon_x = int(180 + lon) * scale
86 lat_y = int(180 - (lat + 90)) * scale
88 if site['login_base'] in lb2hn:
89 nodes = lb2hn[site['login_base']]
100 if len(node['nodenetwork_ids']) == 0:
103 ip = netid2ip[node['nodenetwork_ids'][0]]
105 if lon_x is not -1 and lat_y is not -1:
106 coords="%s,%s" % (lon_x, lat_y)
110 h = Host(use="planetlab-host",
115 statusmap_image="icon-system.png",
120 s1 = Service(use="generic-service",
122 service_description="aSSH",
124 servicegroups="NET,SSH",
125 check_command="check_ssh!-t 120")
126 s2 = Service(use="generic-service",
128 service_description="bSSH806",
129 display_name="bSSH806",
130 servicegroups="NET,SSH806",
131 check_command="check_ssh!-p 806 -t 120")
132 s3 = Service(use="generic-service",
134 service_description="cHTTP",
135 display_name="cHTTP",
136 servicegroups="NET,HTTP",
137 check_command="check_http!-t 120")
138 s4 = Service(use="generic-service",
140 service_description="dCOTOP",
141 display_name="dCOTOP",
142 servicegroups="NET,COTOP",
143 check_command="check_http!-p 3120 -t 120")
145 sd1 = ServiceDependency(host_name=hn,
146 service_description="aSSH",
147 dependent_host_name=hn,
148 dependent_service_description="bSSH806",
149 execution_failure_criteria="w,u,c,p",)
151 sd2 = ServiceDependency(host_name=hn,
152 service_description="aSSH",
153 dependent_host_name=hn,
154 dependent_service_description="cHTTP",
155 execution_failure_criteria="w,u,c,p",)
157 sd3 = ServiceDependency(host_name=hn,
158 service_description="aSSH",
159 dependent_host_name=hn,
160 dependent_service_description="dCOTOP",
161 execution_failure_criteria="w,u,c,p",)
163 for service in [s1,s2,s3,s4,sd1,sd2,sd3]:
164 print service.toString()