3 class NagiosObject(object):
4 trans = {'d2_coords': '2d_coords'}
6 def __init__(self, id, **kwargs):
8 self.kwords = kwargs.keys()
9 for key in self.kwords:
10 self.__setattr__(key, kwargs[key])
14 ret += "define %s {\n" % self.id
15 for key in self.kwords:
17 ret += " %s %s\n" % (self.trans[key], self.__getattribute__(key))
19 ret += " %s %s\n" % (key, self.__getattribute__(key))
23 class Host(NagiosObject):
24 def __init__(self, **kwargs):
25 NagiosObject.__init__(self, "host", **kwargs)
27 class HostGroup(NagiosObject):
28 def __init__(self, **kwargs):
29 NagiosObject.__init__(self, "hostgroup", **kwargs)
31 class HostEscalation(NagiosObject):
32 def __init__(self, **kwargs):
33 NagiosObject.__init__(self, "hostescalation", **kwargs)
35 class Contact(NagiosObject):
36 def __init__(self, **kwargs):
37 NagiosObject.__init__(self, "contact", **kwargs)
39 class ContactGroup(NagiosObject):
40 def __init__(self, **kwargs):
41 NagiosObject.__init__(self, "contactgroup", **kwargs)
43 class Service(NagiosObject):
44 def __init__(self, **kwargs):
45 NagiosObject.__init__(self, "service", **kwargs)
47 class ServiceDependency(NagiosObject):
48 def __init__(self, **kwargs):
49 NagiosObject.__init__(self, "servicedependency", **kwargs)
51 class ServiceEscalation(NagiosObject):
52 def __init__(self, **kwargs):
53 NagiosObject.__init__(self, "serviceescalation", **kwargs)
55 class ServiceGroup(NagiosObject):
56 def __init__(self, **kwargs):
57 NagiosObject.__init__(self, "servicegroup", **kwargs)
59 def getContactsAndContactGroupsFor(lb, type, email_list):
62 for person in email_list:
63 c1 = Contact(contact_name=person,
64 host_notifications_enabled=1,
65 service_notifications_enabled=1,
66 host_notification_period="24x7",
67 service_notification_period="24x7",
68 host_notification_options="d,r,s",
69 service_notification_options="c,r",
70 host_notification_commands="notify-by-email",
71 service_notification_commands="notify-by-email",
73 contact_list.append(c1)
75 cg1 = ContactGroup(contactgroup_name="%s-%s" % (lb,type),
76 alias="%s-%s" % (lb,type),
77 members=",".join(email_list))
79 contact_list.append(cg1)
85 for service in [('NET', "Network Services"),
86 ('SSH', "SSH Service"),
87 ('SSH806', "Auxiliary SSH Service"),
88 ('HTTP', "PlanetFlow HTTP"),
89 ('COTOP', "HTTP based COTOP"),
91 #('PLSOFT', "PlanetLab Software"),
92 #('MGMT', "Remote Management")]:
93 globalservices.append(ServiceGroup(servicegroup_name=service[0], alias=service[1]))
96 globalhost = [Host( name="planetlab-host",
101 max_check_attempts="6",
102 check_command="check-host-alive",
103 contact_groups="admins",
106 for obj in globalhost + globalservices:
109 from monitor.wrapper import plccache
111 plcdb = plccache.l_sites
112 netid2ip = plccache.d_from_l(plccache.plc.api.GetInterfaces(), 'interface_id')
113 lb2hn = plccache.plcdb_lb2hn
115 sites = plccache.plc.api.GetSites([10243, 22, 10247, 138, 139, 10050, 10257, 18, 20,
116 21, 10134, 24, 10138, 10141, 30, 31, 33, 10279, 41, 29, 10193, 10064, 81,
117 10194, 10067, 87, 10208, 10001, 233, 157, 10100, 10107])
120 shortname = site['abbreviated_name']
121 lb = site['login_base']
122 hg = HostGroup(hostgroup_name=lb, alias=shortname)
123 lat = site['latitude']
124 lon = site['longitude']
127 if lat is not None and lon is not None:
129 lon_x = int(180 + lon) * scale
130 lat_y = int(180 - (lat + 90)) * scale
132 if site['login_base'] in lb2hn:
133 nodes = lb2hn[site['login_base']]
142 # NOTE: do duplcate groups create duplicate emails?
143 cl1 = getContactsAndContactGroupsFor(lb, "techs", plccache.plc.getTechEmails(lb))
144 cl2 = getContactsAndContactGroupsFor(lb, "pis", plccache.plc.getPIEmails(lb))
145 # NOTE: slice users will change often.
146 cl3 = getContactsAndContactGroupsFor(lb, "sliceusers", plccache.plc.getSliceUserEmails(lb))
148 for c in [cl1,cl2,cl3]:
153 hn = node['hostname']
154 if len(node['interface_ids']) == 0:
157 ip = netid2ip[str(node['interface_ids'][0])]['ip']
159 if lon_x is not -1 and lat_y is not -1:
160 coords="%s,%s" % (lon_x, lat_y)
164 h = Host(use="planetlab-host",
169 statusmap_image="icon-system.png",
174 s1 = Service(use="generic-service",
176 service_description="aSSH",
178 servicegroups="NET,SSH",
179 check_command="check_ssh!-t 120")
180 s2 = Service(use="generic-service",
182 service_description="bSSH806",
183 display_name="bSSH806",
184 servicegroups="NET,SSH806",
185 check_command="check_ssh!-p 806 -t 120")
186 s3 = Service(use="generic-service",
188 service_description="cHTTP",
189 display_name="cHTTP",
190 servicegroups="NET,HTTP",
191 check_command="check_http!-t 120")
192 s4 = Service(use="generic-service",
194 service_description="dCOTOP",
195 display_name="dCOTOP",
196 servicegroups="NET,COTOP",
197 check_command="check_http!-p 3120 -t 120")
199 se1 = ServiceEscalation( host_name=hn,
200 service_description='aSSH',
201 first_notification=0,
203 notification_interval=24*60*3.5,
204 escalation_options="r,c",
205 contact_groups="%s-techs" % lb)
207 se2 = ServiceEscalation( host_name=hn,
208 service_description='aSSH',
209 first_notification=2,
211 notification_interval=24*60*3.5,
212 escalation_options="r,c",
213 contact_groups="%s-techs,%s-pis" % (lb,lb))
215 se3 = ServiceEscalation( host_name=hn,
216 service_description='aSSH',
217 first_notification=4,
219 notification_interval=24*60*3.5,
220 escalation_options="r,c",
221 contact_groups="%s-techs,%s-pis,%s-sliceusers" % (lb,lb,lb))
223 sd1 = ServiceDependency(host_name=hn,
224 service_description="aSSH",
225 dependent_host_name=hn,
226 dependent_service_description="bSSH806",
227 execution_failure_criteria="w,u,c,p",)
229 sd2 = ServiceDependency(host_name=hn,
230 service_description="aSSH",
231 dependent_host_name=hn,
232 dependent_service_description="cHTTP",
233 execution_failure_criteria="w,u,c,p",)
235 sd3 = ServiceDependency(host_name=hn,
236 service_description="aSSH",
237 dependent_host_name=hn,
238 dependent_service_description="dCOTOP",
239 execution_failure_criteria="w,u,c,p",)
241 for service in [s1,s2,s3,s4,se1,se2,se3,sd1,sd2,sd3]:
242 print service.toString()