Fix : test for service and host good definition with the new no contact nor host...
[shinken.git] / shinken / external_command.py
blobc49312560b8bfa62ad599770b2967a9ca955bc46
1 #!/usr/bin/env python
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
24 import os
25 import time
27 from shinken.util import to_int, to_bool
28 from shinken.downtime import Downtime
29 from shinken.contactdowntime import ContactDowntime
30 from shinken.comment import Comment
31 from shinken.objects import CommandCall
32 from shinken.log import logger
33 from shinken.pollerlink import PollerLink
36 class ExternalCommand:
37 my_type = 'externalcommand'
38 def __init__(self, cmd_line):
39 self.cmd_line = cmd_line
42 class ExternalCommandManager:
44 commands = {
45 'CHANGE_CONTACT_MODSATTR' : {'global' : True, 'args' : ['contact', None]},
46 'CHANGE_CONTACT_MODHATTR' : {'global' : True, 'args' : ['contact', None]},
47 'CHANGE_CONTACT_MODATTR' : {'global' : True, 'args' : ['contact', None]},
48 'CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD' : {'global' : True, 'args' : ['contact', 'time_period']},
49 'ADD_SVC_COMMENT' : {'global' : False, 'args' : ['service', 'to_bool', 'author', None]},
50 'ADD_HOST_COMMENT' : {'global' : False, 'args' : ['host', 'to_bool', 'author', None]},
51 'ACKNOWLEDGE_SVC_PROBLEM' : {'global' : False, 'args' : ['service' , 'to_int', 'to_bool', 'to_bool', 'author', None]},
52 'ACKNOWLEDGE_HOST_PROBLEM' : {'global' : False, 'args' : ['host', 'to_int', 'to_bool', 'to_bool', 'author', None]},
53 'CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD' : {'global' : True, 'args' : ['contact', 'time_period']},
54 'CHANGE_CUSTOM_CONTACT_VAR' : {'global' : True, 'args' : ['contact', None,None]},
55 'CHANGE_CUSTOM_HOST_VAR' : {'global' : False, 'args' : ['host', None,None]},
56 'CHANGE_CUSTOM_SVC_VAR' : {'global' : False, 'args' : ['service', None,None]},
57 'CHANGE_GLOBAL_HOST_EVENT_HANDLER' : {'global' : True, 'args' : ['command']},
58 'CHANGE_GLOBAL_SVC_EVENT_HANDLER' : {'global' : True, 'args' : ['command']},
59 'CHANGE_HOST_CHECK_COMMAND' : {'global' : False, 'args' : ['host', 'command']},
60 'CHANGE_HOST_CHECK_TIMEPERIOD' : {'global' : False, 'args' : ['host', 'time_period']},
61 'CHANGE_HOST_EVENT_HANDLER' : {'global' : False, 'args' : ['host', 'command']},
62 'CHANGE_HOST_MODATTR' : {'global' : False, 'args' : ['host', 'to_int']},
63 'CHANGE_MAX_HOST_CHECK_ATTEMPTS': {'global' : False, 'args' : ['host', 'to_int']},
64 'CHANGE_MAX_SVC_CHECK_ATTEMPTS' : {'global' : False, 'args' : ['service', 'to_int']},
65 'CHANGE_NORMAL_HOST_CHECK_INTERVAL' : {'global' : False, 'args' : ['host', 'to_int']},
66 'CHANGE_NORMAL_SVC_CHECK_INTERVAL' : {'global' : False, 'args' : ['service', 'to_int']},
67 'CHANGE_RETRY_HOST_CHECK_INTERVAL' : {'global' : False, 'args' : ['service', 'to_int']},
68 'CHANGE_RETRY_SVC_CHECK_INTERVAL' : {'global' : False, 'args' : ['service', 'to_int']},
69 'CHANGE_SVC_CHECK_COMMAND' : {'global' : False, 'args' : ['service', 'command']},
70 'CHANGE_SVC_CHECK_TIMEPERIOD' : {'global' : False, 'args' : ['service', 'time_period']},
71 'CHANGE_SVC_EVENT_HANDLER' : {'global' : False, 'args' : ['service', 'command']},
72 'CHANGE_SVC_MODATTR' : {'global' : False, 'args' : ['service', 'to_int']},
73 'CHANGE_SVC_NOTIFICATION_TIMEPERIOD' : {'global' : False, 'args' : ['service', 'time_period']},
74 'DELAY_HOST_NOTIFICATION' : {'global' : False, 'args' : ['host', 'to_int']},
75 'DELAY_SVC_NOTIFICATION' : {'global' : False, 'args' : ['service', 'to_int']},
76 'DEL_ALL_HOST_COMMENTS' : {'global' : False, 'args' : ['host']},
77 'DEL_ALL_SVC_COMMENTS' : {'global' : False, 'args' : ['service']},
78 'DEL_CONTACT_DOWNTIME' : {'global' : True, 'args' : ['to_int']},
79 'DEL_HOST_COMMENT' : {'global' : True, 'args' : ['to_int']},
80 'DEL_HOST_DOWNTIME' : {'global' : True, 'args' : ['to_int']},
81 'DEL_SVC_COMMENT' : {'global' : True, 'args' : ['to_int']},
82 'DEL_SVC_DOWNTIME' : {'global' : True, 'args' : ['to_int']},
83 'DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST' : {'global' : False, 'args' : ['host']},
84 'DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['contact_group']},
85 'DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['contact_group']},
86 'DISABLE_CONTACT_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['contact']},
87 'DISABLE_CONTACT_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['contact']},
88 'DISABLE_EVENT_HANDLERS' : {'global' : True, 'args' : []},
89 'DISABLE_FAILURE_PREDICTION' : {'global' : True, 'args' : []},
90 'DISABLE_FLAP_DETECTION' : {'global' : True, 'args' : []},
91 'DISABLE_HOSTGROUP_HOST_CHECKS' : {'global' : True, 'args' : ['host_group']},
92 'DISABLE_HOSTGROUP_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['host_group']},
93 'DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS' : {'global' : True, 'args' : ['host_group']},
94 'DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS' : {'global' : True, 'args' : ['host_group']},
95 'DISABLE_HOSTGROUP_SVC_CHECKS' : {'global' : True, 'args' : ['host_group']},
96 'DISABLE_HOSTGROUP_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['host_group']},
97 'DISABLE_HOST_AND_CHILD_NOTIFICATIONS' : {'global' : False, 'args' : ['host']},
98 'DISABLE_HOST_CHECK' : {'global' : False, 'args' : ['host']},
99 'DISABLE_HOST_EVENT_HANDLER' : {'global' : False, 'args' : ['host']},
100 'DISABLE_HOST_FLAP_DETECTION' : {'global' : False, 'args' : ['host']},
101 'DISABLE_HOST_FRESHNESS_CHECKS' : {'global' : True, 'args' : []},
102 'DISABLE_HOST_NOTIFICATIONS' : {'global' : False, 'args' : ['host']},
103 'DISABLE_HOST_SVC_CHECKS' : {'global' : False, 'args' : ['host']},
104 'DISABLE_HOST_SVC_NOTIFICATIONS' : {'global' : False, 'args' : ['host']},
105 'DISABLE_NOTIFICATIONS' : {'global' : True, 'args' : []},
106 'DISABLE_PASSIVE_HOST_CHECKS' : {'global' : False, 'args' : ['host']},
107 'DISABLE_PASSIVE_SVC_CHECKS' : {'global' : False, 'args' : ['service']},
108 'DISABLE_PERFORMANCE_DATA' : {'global' : True, 'args' : []},
109 'DISABLE_SERVICEGROUP_HOST_CHECKS' : {'global' : True, 'args' : ['service_group']},
110 'DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['service_group']},
111 'DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS' : {'global' : True, 'args' : ['service_group']},
112 'DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS' : {'global' : True, 'args' : ['service_group']},
113 'DISABLE_SERVICEGROUP_SVC_CHECKS' : {'global' : True, 'args' : ['service_group']},
114 'DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['service_group']},
115 'DISABLE_SERVICE_FLAP_DETECTION' : {'global' : False, 'args' : ['service']},
116 'DISABLE_SERVICE_FRESHNESS_CHECKS' : {'global' : True, 'args' : []},
117 'DISABLE_SVC_CHECK' : {'global' : False, 'args' : ['service']},
118 'DISABLE_SVC_EVENT_HANDLER' : {'global' : False, 'args' : ['service']},
119 'DISABLE_SVC_FLAP_DETECTION' : {'global' : False, 'args' : ['service']},
120 'DISABLE_SVC_NOTIFICATIONS' : {'global' : False, 'args' : ['service']},
121 'ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST' : {'global' : False, 'args' : ['host']},
122 'ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['contact_group']},
123 'ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['contact_group']},
124 'ENABLE_CONTACT_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['contact']},
125 'ENABLE_CONTACT_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['contact']},
126 'ENABLE_EVENT_HANDLERS' : {'global' : True, 'args' : []},
127 'ENABLE_FAILURE_PREDICTION' : {'global' : True, 'args' : []},
128 'ENABLE_FLAP_DETECTION' : {'global' : True, 'args' : []},
129 'ENABLE_HOSTGROUP_HOST_CHECKS' : {'global' : True, 'args' : ['host_group']},
130 'ENABLE_HOSTGROUP_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['host_group']},
131 'ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS' : {'global' : True, 'args' : ['host_group']},
132 'ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS' : {'global' : True, 'args' : ['host_group']},
133 'ENABLE_HOSTGROUP_SVC_CHECKS' : {'global' : True, 'args' : ['host_group']},
134 'ENABLE_HOSTGROUP_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['host_group']},
135 'ENABLE_HOST_AND_CHILD_NOTIFICATIONS' : {'global' : False, 'args' : ['host']},
136 'ENABLE_HOST_CHECK' : {'global' : False, 'args' : ['host']},
137 'ENABLE_HOST_EVENT_HANDLER' : {'global' : False, 'args' : ['host']},
138 'ENABLE_HOST_FLAP_DETECTION' : {'global' : False, 'args' : ['host']},
139 'ENABLE_HOST_FRESHNESS_CHECKS' : {'global' : True, 'args' : []},
140 'ENABLE_HOST_NOTIFICATIONS' : {'global' : False, 'args' : ['host']},
141 'ENABLE_HOST_SVC_CHECKS' : {'global' : False, 'args' : ['host']},
142 'ENABLE_HOST_SVC_NOTIFICATIONS' : {'global' : False, 'args' : ['host']},
143 'ENABLE_NOTIFICATIONS' : {'global' : True, 'args' : []},
144 'ENABLE_PASSIVE_HOST_CHECKS' : {'global' : False, 'args' : ['host']},
145 'ENABLE_PASSIVE_SVC_CHECKS' : {'global' : False, 'args' : ['service']},
146 'ENABLE_PERFORMANCE_DATA' : {'global' : True, 'args' : []},
147 'ENABLE_SERVICEGROUP_HOST_CHECKS' : {'global' : True, 'args' : ['service_group']},
148 'ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS' : {'global' : True, 'args' : ['service_group']},
149 'ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS' : {'global' : True, 'args' : ['service_group']},
150 'ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS' : {'global' : True, 'args' : ['service_group']},
151 'ENABLE_SERVICEGROUP_SVC_CHECKS' : {'global' : True, 'args' : ['service_group']},
152 'ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS' : {'global' : True, 'args' : ['service_group']},
153 'ENABLE_SERVICE_FRESHNESS_CHECKS' : {'global' : True, 'args' : []},
154 'ENABLE_SVC_CHECK': {'global' : False, 'args' : ['service']},
155 'ENABLE_SVC_EVENT_HANDLER' : {'global' : False, 'args' : ['service']},
156 'ENABLE_SVC_FLAP_DETECTION' : {'global' : False, 'args' : ['service']},
157 'ENABLE_SVC_NOTIFICATIONS' : {'global' : False, 'args' : ['service']},
158 'PROCESS_FILE' : {'global' : True, 'args' : [None, 'to_bool']},
159 'PROCESS_HOST_CHECK_RESULT' : {'global' : False, 'args' : ['host', 'to_int', None]},
160 'PROCESS_SERVICE_CHECK_RESULT' : {'global' : False, 'args' : ['service', 'to_int', None]},
161 'READ_STATE_INFORMATION' : {'global' : True, 'args' : []},
162 'REMOVE_HOST_ACKNOWLEDGEMENT' : {'global' : False, 'args' : ['host']},
163 'REMOVE_SVC_ACKNOWLEDGEMENT' : {'global' : False, 'args' : ['service']},
164 'RESTART_PROGRAM' : {'global' : True, 'args' : []},
165 'SAVE_STATE_INFORMATION' : {'global' : True, 'args' : []},
166 'SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME' : {'global' : False, 'args' : ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author',None]},
167 'SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME' : {'global' : False, 'args' : ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
168 'SCHEDULE_CONTACT_DOWNTIME' : {'global' : True, 'args' : ['contact', 'to_int', 'to_int', 'author', None]},
169 'SCHEDULE_FORCED_HOST_CHECK' : {'global' : False, 'args' : ['host', 'to_int']},
170 'SCHEDULE_FORCED_HOST_SVC_CHECKS' : {'global' : False, 'args' : ['host', 'to_int']},
171 'SCHEDULE_FORCED_SVC_CHECK' : {'global' : False, 'args' : ['service', 'to_int']},
172 'SCHEDULE_HOSTGROUP_HOST_DOWNTIME' : {'global' : True, 'args' : ['host_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author',None]},
173 'SCHEDULE_HOSTGROUP_SVC_DOWNTIME' : {'global' : True, 'args' : ['host_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author',None]},
174 'SCHEDULE_HOST_CHECK' : {'global' : False, 'args' : ['host', 'to_int']},
175 'SCHEDULE_HOST_DOWNTIME' : {'global' : False, 'args' : ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
176 'SCHEDULE_HOST_SVC_CHECKS' : {'global' : False, 'args' : ['host', 'to_int']},
177 'SCHEDULE_HOST_SVC_DOWNTIME' : {'global' : False, 'args' : ['host', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
178 'SCHEDULE_SERVICEGROUP_HOST_DOWNTIME' : {'global' : True, 'args' : ['service_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
179 'SCHEDULE_SERVICEGROUP_SVC_DOWNTIME' : {'global' : True, 'args' : ['service_group', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
180 'SCHEDULE_SVC_CHECK' : {'global' : False, 'args' : ['service', 'to_int']},
181 'SCHEDULE_SVC_DOWNTIME' : {'global' : False, 'args' : ['service', 'to_int', 'to_int', 'to_bool', 'to_int', 'to_int', 'author', None]},
182 'SEND_CUSTOM_HOST_NOTIFICATION' : {'global' : False, 'args' : ['host', 'to_int', 'author', None]},
183 'SEND_CUSTOM_SVC_NOTIFICATION' : {'global' : False, 'args' : ['service', 'to_int', 'author', None]},
184 'SET_HOST_NOTIFICATION_NUMBER' : {'global' : False, 'args' : ['host', 'to_int']},
185 'SET_SVC_NOTIFICATION_NUMBER' : {'global' : False, 'args' : ['service', 'to_int']},
186 'SHUTDOWN_PROGRAM' : {'global' : True, 'args' : []},
187 'START_ACCEPTING_PASSIVE_HOST_CHECKS' : {'global' : True, 'args' : []},
188 'START_ACCEPTING_PASSIVE_SVC_CHECKS' : {'global' : True, 'args' : []},
189 'START_EXECUTING_HOST_CHECKS' : {'global' : True, 'args' : []},
190 'START_EXECUTING_SVC_CHECKS' : {'global' : True, 'args' : []},
191 'START_OBSESSING_OVER_HOST' : {'global' : False, 'args' : ['host']},
192 'START_OBSESSING_OVER_HOST_CHECKS' : {'global' : True, 'args' : []},
193 'START_OBSESSING_OVER_SVC' : {'global' : False, 'args' : ['service']},
194 'START_OBSESSING_OVER_SVC_CHECKS' : {'global' : True, 'args' : []},
195 'STOP_ACCEPTING_PASSIVE_HOST_CHECKS' : {'global' : True, 'args' : []},
196 'STOP_ACCEPTING_PASSIVE_SVC_CHECKS' : {'global' : True, 'args' : []},
197 'STOP_EXECUTING_HOST_CHECKS' : {'global' : True, 'args' : []},
198 'STOP_EXECUTING_SVC_CHECKS' : {'global' : True, 'args' : []},
199 'STOP_OBSESSING_OVER_HOST' : {'global' : False, 'args' : ['host']},
200 'STOP_OBSESSING_OVER_HOST_CHECKS' : {'global' : True, 'args' : []},
201 'STOP_OBSESSING_OVER_SVC' : {'global' : False, 'args' : ['service']},
202 'STOP_OBSESSING_OVER_SVC_CHECKS' : {'global' : True, 'args' : []},
203 'LAUNCH_SVC_EVENT_HANDLER' : {'global' : False, 'args' : ['service']},
204 'LAUNCH_HOST_EVENT_HANDLER' : {'global' : False, 'args' : ['host']},
205 # Now internal calls
206 'ADD_SIMPLE_HOST_DEPENDENCY' : {'global' : False, 'args' : ['host', 'host']},
207 'DEL_HOST_DEPENDENCY' : {'global' : False, 'args' : ['host', 'host']},
208 'ADD_SIMPLE_POLLER' : {'global' : True, 'internal' : True, 'args' : [None, None, None, None]},
212 def __init__(self, conf, mode):
213 self.mode = mode
214 self.conf = conf
215 self.hosts = conf.hosts
216 self.services = conf.services
217 self.contacts = conf.contacts
218 self.hostgroups = conf.hostgroups
219 self.commands = conf.commands
220 self.servicegroups = conf.servicegroups
221 self.contactgroups = conf.contactgroups
222 self.timeperiods = conf.timeperiods
223 self.pipe_path = conf.command_file
224 self.fifo = None
225 self.cmd_fragments = ''
226 if self.mode == 'dispatcher':
227 self.confs = conf.confs
230 def load_scheduler(self, scheduler):
231 self.sched = scheduler
233 def load_arbiter(self, arbiter):
234 self.arbiter = arbiter
237 def open(self):
238 #At the first open del and create the fifo
239 if self.fifo is None:
240 if os.path.exists(self.pipe_path):
241 os.unlink(self.pipe_path)
243 if not os.path.exists(self.pipe_path):
244 os.umask(0)
245 try :
246 os.mkfifo(self.pipe_path, 0660)
247 open(self.pipe_path, 'w+', os.O_NONBLOCK)
248 except OSError , exp:
249 print "Error : pipe creation failed (",self.pipe_path,')', exp
250 return None
251 self.fifo = os.open(self.pipe_path, os.O_NONBLOCK)
252 return self.fifo
255 def get(self):
256 buf = os.read(self.fifo, 8096)
257 r = []
258 fullbuf = len(buf) == 8096 and True or False
259 # If the buffer ended with a fragment last time, prepend it here
260 buf = self.cmd_fragments + buf
261 buflen = len(buf)
262 self.cmd_fragments = ''
263 if fullbuf and buf[-1] != '\n':
264 # The buffer was full but ends with a command fragment
265 r.extend([ExternalCommand(s) for s in (buf.split('\n'))[:-1] if s])
266 self.cmd_fragments = (buf.split('\n'))[-1]
267 elif buflen:
268 # The buffer is either half-filled or full with a '\n' at the end.
269 r.extend([ExternalCommand(s) for s in buf.split('\n') if s])
270 else:
271 # The buffer is empty. We "reset" the fifo here. It will be
272 # re-opened in the main loop.
273 os.close(self.fifo)
274 return r
277 def resolve_command(self, excmd):
278 command = excmd.cmd_line
279 command = command.strip()
280 #Only log if we are in the Arbiter
281 if self.mode == 'dispatcher':
282 logger.log('EXTERNAL COMMAND: '+command.rstrip())
283 self.get_command_and_args(command)
286 #Ok the command is not for every one, so we search
287 #by the hostname which scheduler have the host. Then send
288 #it the command
289 def search_host_and_dispatch(self, host_name, command):
290 print "Calling search_host_and_dispatch", 'for', host_name
291 for cfg in self.confs.values():
292 if cfg.hosts.find_by_name(host_name) is not None:
293 print "Host", host_name, "found in a configuration"
294 if cfg.is_assigned :
295 sched = cfg.assigned_to
296 print "Sending command to the scheduler", sched.get_name()
297 sched.run_external_command(command)
298 else:
299 print "Problem: a configuration is found, but is not assigned!"
300 else:
301 logger.log("Warning: Passive check result was received for host '%s', but the host could not be found!" % host_name)
302 #print "Sorry but the host", host_name, "was not found"
305 #The command is global, so sent it to every schedulers
306 def dispatch_global_command(self, command):
307 for sched in self.conf.schedulerlinks:
308 print "Sending a command", command, 'to scheduler', sched
309 if sched.alive:
310 sched.run_external_command(command)
313 #We need to get the first part, the command name
314 def get_command_and_args(self, command):
315 print "Trying to resolve", command
316 command = command.rstrip()
317 elts = command.split(';') # danger!!! passive checkresults with perfdata
318 part1 = elts[0]
320 elts2 = part1.split(' ')
321 print "Elts2:", elts2
322 if len(elts2) != 2:
323 print "Malformed command", command
324 return None
325 c_name = elts2[1]
327 print "Get command name", c_name
328 if c_name not in ExternalCommandManager.commands:
329 print "This command is not recognized, sorry"
330 return None
332 # Split again based on the number of args we expect. We cannot split
333 # on every ; because this character may appear in the perfdata of
334 # passive check results.
335 entry = ExternalCommandManager.commands[c_name]
337 #Look if the command is purely internal or not
338 internal = False
339 if 'internal' in entry and entry['internal']:
340 internal = True
342 numargs = len(entry['args'])
343 if numargs and 'service' in entry['args']:
344 numargs += 1
345 elts = command.split(';', numargs)
347 print self.mode, entry['global']
348 if self.mode == 'dispatcher' and entry['global']:
349 if not internal:
350 print "This command is a global one, we resent it to all schedulers"
351 self.dispatch_global_command(command)
352 return None
354 print "Is global?", c_name, entry['global']
355 print "Mode:", self.mode
356 print "This command have arguments:", entry['args'], len(entry['args'])
358 args = []
359 i = 1
360 in_service = False
361 tmp_host = ''
362 try:
363 for elt in elts[1:]:
364 print "Searching for a new arg:", elt, i
365 val = elt.strip()
366 if val[-1] == '\n':
367 val = val[:-1]
369 print "For command arg", val
371 if not in_service:
372 type_searched = entry['args'][i-1]
373 print "Search for a arg", type_searched
375 if type_searched == 'host':
376 if self.mode == 'dispatcher':
377 self.search_host_and_dispatch(val, command)
378 return None
379 h = self.hosts.find_by_name(val)
380 if h is not None:
381 args.append(h)
383 elif type_searched == 'contact':
384 c = self.contacts.find_by_name(val)
385 if c is not None:
386 args.append(c)
388 elif type_searched == 'time_period':
389 t = self.timeperiods.find_by_name(val)
390 if t is not None:
391 args.append(t)
393 elif type_searched == 'to_bool':
394 args.append(to_bool(val))
396 elif type_searched == 'to_int':
397 args.append(to_int(val))
399 elif type_searched in ('author', None):
400 args.append(val)
402 elif type_searched == 'command':
403 c = self.commands.find_cmd_by_name(val)
404 if c is not None:
405 args.append(val)#the find will be redone by
406 #the commandCall creation, but != None
407 #is usefull so a bad command will be catch
409 elif type_searched == 'host_group':
410 hg = self.hostgroups.find_by_name(val)
411 if hg is not None:
412 args.append(hg)
414 elif type_searched == 'service_group':
415 sg = self.servicegroups.find_by_name(val)
416 if sg is not None:
417 args.append(sg)
419 elif type_searched == 'contact_group':
420 cg = self.contact_groups.find_by_name(val)
421 if cg is not None:
422 args.append(cg)
424 #special case: service are TWO args host;service, so one more loop
425 #to get the two parts
426 elif type_searched == 'service':
427 in_service = True
428 tmp_host = elt.strip()
429 print "TMP HOST", tmp_host
430 if tmp_host[-1] == '\n':
431 tmp_host = tmp_host[:-1]
433 if self.mode == 'dispatcher':
434 self.search_host_and_dispatch(tmp_host, command)
435 return None
437 i += 1
438 else:
439 in_service = False
440 srv_name = elt
441 if srv_name[-1] == '\n':
442 srv_name = srv_name[:-1]
443 print "Got service full", tmp_host, srv_name
444 s = self.services.find_srv_by_name_and_hostname(tmp_host, srv_name)
445 if s is not None:
446 args.append(s)
447 else: #error, must be logged
448 logger.log("Warning: a command was received for service '%s' on host '%s', but the service could not be found!" % (srv_name, tmp_host))
450 except IndexError:
451 print "Sorry, the arguments are not corrects"
452 return None
453 print 'Finally got ARGS:', args
454 if len(args) == len(entry['args']):
455 print "OK, we can call the command", c_name, "with", args
456 f = getattr(self, c_name)
457 apply(f, args)
458 else:
459 print "Sorry, the arguments are not corrects", args
463 #CHANGE_CONTACT_MODSATTR;<contact_name>;<value>
464 def CHANGE_CONTACT_MODSATTR(self, contact, value):
465 pass
467 #CHANGE_CONTACT_MODHATTR;<contact_name>;<value>
468 def CHANGE_CONTACT_MODHATTR(self, contact, value):
469 pass
471 #CHANGE_CONTACT_MODATTR;<contact_name>;<value>
472 def CHANGE_CONTACT_MODATTR(self, contact, value):
473 pass
475 #CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD;<contact_name>;<notification_timeperiod>
476 def CHANGE_CONTACT_HOST_NOTIFICATION_TIMEPERIOD(self, contact, notification_timeperiod):
477 contact.host_notification_period = notification_timeperiod
478 self.sched.get_and_register_status_brok(contact)
480 #ADD_SVC_COMMENT;<host_name>;<service_description>;<persistent>;<author>;<comment>
481 def ADD_SVC_COMMENT(self, service, persistent, author, comment):
482 c = Comment(service, persistent, author, comment, 2, 1, 1, False, 0)
483 service.add_comment(c)
484 self.sched.add(c)
486 #ADD_HOST_COMMENT;<host_name>;<persistent>;<author>;<comment>
487 def ADD_HOST_COMMENT(self, host, persistent, author, comment):
488 c = Comment(host, persistent, author, comment, 1, 1, 1, False, 0)
489 host.add_comment(c)
490 self.sched.add(c)
492 #ACKNOWLEDGE_SVC_PROBLEM;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<author>;<comment>
493 def ACKNOWLEDGE_SVC_PROBLEM(self, service, sticky, notify, persistent, author, comment):
494 service.acknowledge_problem(sticky, notify, persistent, author, comment)
496 #ACKNOWLEDGE_HOST_PROBLEM;<host_name>;<sticky>;<notify>;<persistent>;<author>;<comment>
497 #TODO : add a better ACK management
498 def ACKNOWLEDGE_HOST_PROBLEM(self, host, sticky, notify, persistent, author, comment):
499 host.acknowledge_problem(sticky, notify, persistent, author, comment)
501 #CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;<contact_name>;<notification_timeperiod>
502 def CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD(self, contact, notification_timeperiod):
503 contact.service_notification_period = notification_timeperiod
504 self.sched.get_and_register_status_brok(contact)
506 #CHANGE_CUSTOM_CONTACT_VAR;<contact_name>;<varname>;<varvalue>
507 def CHANGE_CUSTOM_CONTACT_VAR(self, contact, varname, varvalue):
508 contact.customs[varname.upper()] = varvalue
510 #CHANGE_CUSTOM_HOST_VAR;<host_name>;<varname>;<varvalue>
511 def CHANGE_CUSTOM_HOST_VAR(self, host, varname, varvalue):
512 host.customs[varname.upper()] = varvalue
514 #CHANGE_CUSTOM_SVC_VAR;<host_name>;<service_description>;<varname>;<varvalue>
515 def CHANGE_CUSTOM_SVC_VAR(self, service, varname, varvalue):
516 service.customs[varname.upper()] = varvalue
518 #CHANGE_GLOBAL_HOST_EVENT_HANDLER;<event_handler_command>
519 def CHANGE_GLOBAL_HOST_EVENT_HANDLER(self, event_handler_command):
520 pass
522 #CHANGE_GLOBAL_SVC_EVENT_HANDLER;<event_handler_command>
523 def CHANGE_GLOBAL_SVC_EVENT_HANDLER(self, event_handler_command):
524 pass
526 #CHANGE_HOST_CHECK_COMMAND;<host_name>;<check_command>
527 def CHANGE_HOST_CHECK_COMMAND(self, host, check_command):
528 host.check_command = CommandCall(self.commands, check_command, poller_tag=host.poller_tag)
529 self.sched.get_and_register_status_brok(host)
531 #CHANGE_HOST_CHECK_TIMEPERIOD;<host_name>;<timeperiod>
532 def CHANGE_HOST_CHECK_TIMEPERIOD(self, host, timeperiod):
533 host.check_period = timeperiod
534 self.sched.get_and_register_status_brok(service)
536 #CHANGE_HOST_EVENT_HANDLER;<host_name>;<event_handler_command>
537 def CHANGE_HOST_EVENT_HANDLER(self, host, event_handler_command):
538 host.event_handler = CommandCall(self.commands, event_handler_command)
539 self.sched.get_and_register_status_brok(host)
541 #CHANGE_HOST_MODATTR;<host_name>;<value>
542 def CHANGE_HOST_MODATTR(self, host, value):
543 pass
545 #CHANGE_MAX_HOST_CHECK_ATTEMPTS;<host_name>;<check_attempts>
546 def CHANGE_MAX_HOST_CHECK_ATTEMPTS(self, host, check_attempts):
547 host.max_check_attempts = check_attempts
548 self.sched.get_and_register_status_brok(host)
550 #CHANGE_MAX_SVC_CHECK_ATTEMPTS;<host_name>;<service_description>;<check_attempts>
551 def CHANGE_MAX_SVC_CHECK_ATTEMPTS(self, service, check_attempts):
552 service.max_check_attempts = check_attempts
553 self.sched.get_and_register_status_brok(service)
555 #CHANGE_NORMAL_HOST_CHECK_INTERVAL;<host_name>;<check_interval>
556 def CHANGE_NORMAL_HOST_CHECK_INTERVAL(self, host, check_interval):
557 host.check_interval = check_interval
558 self.sched.get_and_register_status_brok(host)
560 #CHANGE_NORMAL_SVC_CHECK_INTERVAL;<host_name>;<service_description>;<check_interval>
561 def CHANGE_NORMAL_SVC_CHECK_INTERVAL(self, service, check_interval):
562 service.check_interval = check_interval
563 self.sched.get_and_register_status_brok(service)
565 #CHANGE_RETRY_HOST_CHECK_INTERVAL;<host_name>;<service_description>;<check_interval>
566 def CHANGE_RETRY_HOST_CHECK_INTERVAL(self, host, check_interval):
567 host.retry_interval = check_interval
568 self.sched.get_and_register_status_brok(host)
570 #CHANGE_RETRY_SVC_CHECK_INTERVAL;<host_name>;<service_description>;<check_interval>
571 def CHANGE_RETRY_SVC_CHECK_INTERVAL(self, service, check_interval):
572 service.retry_interval = check_interval
573 self.sched.get_and_register_status_brok(service)
575 #CHANGE_SVC_CHECK_COMMAND;<host_name>;<service_description>;<check_command>
576 def CHANGE_SVC_CHECK_COMMAND(self, service, check_command):
577 service.check_command = CommandCall(self.commands, check_command, poller_tag=service.poller_tag)
578 self.sched.get_and_register_status_brok(service)
580 #CHANGE_SVC_CHECK_TIMEPERIOD;<host_name>;<service_description>;<check_timeperiod>
581 def CHANGE_SVC_CHECK_TIMEPERIOD(self, service, check_timeperiod):
582 service.check_period = check_timeperiod
583 self.sched.get_and_register_status_brok(service)
585 #CHANGE_SVC_EVENT_HANDLER;<host_name>;<service_description>;<event_handler_command>
586 def CHANGE_SVC_EVENT_HANDLER(self, service, event_handler_command):
587 service.event_handler = CommandCall(self.commands, event_handler_command)
588 self.sched.get_and_register_status_brok(service)
590 #CHANGE_SVC_MODATTR;<host_name>;<service_description>;<value>
591 def CHANGE_SVC_MODATTR(self, service, value):
592 pass
594 #CHANGE_SVC_NOTIFICATION_TIMEPERIOD;<host_name>;<service_description>;<notification_timeperiod>
595 def CHANGE_SVC_NOTIFICATION_TIMEPERIOD(self, service, notification_timeperiod):
596 service.notification_period = notification_timeperiod
597 self.sched.get_and_register_status_brok(service)
599 #DELAY_HOST_NOTIFICATION;<host_name>;<notification_time>
600 def DELAY_HOST_NOTIFICATION(self, host, notification_time):
601 host.first_notification_delay = notification_time
602 self.sched.get_and_register_status_brok(host)
604 #DELAY_SVC_NOTIFICATION;<host_name>;<service_description>;<notification_time>
605 def DELAY_SVC_NOTIFICATION(self, service, notification_time):
606 service.first_notification_delay = notification_time
607 self.sched.get_and_register_status_brok(service)
609 #DEL_ALL_HOST_COMMENTS;<host_name>
610 def DEL_ALL_HOST_COMMENTS(self, host):
611 for c in host.comments:
612 self.DEL_HOST_COMMENT(c.id)
614 #DEL_ALL_SVC_COMMENTS;<host_name>;<service_description>
615 def DEL_ALL_SVC_COMMENTS(self, service):
616 for c in service.comments:
617 self.DEL_SVC_COMMENT(c.id)
619 #DEL_CONTACT_DOWNTIME;<downtime_id>
620 def DEL_CONTACT_DOWNTIME(self, downtime_id):
621 if downtime_id in self.sched.contact_downtimes:
622 self.sched.contact_downtimes[downtime_id].cancel()
625 #DEL_HOST_COMMENT;<comment_id>
626 def DEL_HOST_COMMENT(self, comment_id):
627 if comment_id in self.sched.comments:
628 self.sched.comments[comment_id].can_be_deleted = True
630 #DEL_HOST_DOWNTIME;<downtime_id>
631 def DEL_HOST_DOWNTIME(self, downtime_id):
632 if downtime_id in self.sched.downtimes:
633 self.sched.downtimes[downtime_id].cancel()
635 #DEL_SVC_COMMENT;<comment_id>
636 def DEL_SVC_COMMENT(self, comment_id):
637 if comment_id in self.sched.comments:
638 self.sched.comments[comment_id].can_be_deleted = True
640 #DEL_SVC_DOWNTIME;<downtime_id>
641 def DEL_SVC_DOWNTIME(self, downtime_id):
642 if downtime_id in self.sched.downtimes:
643 self.sched.downtimes[downtime_id].cancel()
645 #DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST;<host_name>
646 def DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST(self, host):
647 pass
649 #DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS;<contactgroup_name>
650 def DISABLE_CONTACTGROUP_HOST_NOTIFICATIONS(self, contactgroup):
651 for contact in contactgroup:
652 self.DISABLE_CONTACT_HOST_NOTIFICATIONS(contact)
654 #DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS;<contactgroup_name>
655 def DISABLE_CONTACTGROUP_SVC_NOTIFICATIONS(self, contactgroup):
656 for contact in contactgroup:
657 self.DISABLE_CONTACT_SVC_NOTIFICATIONS(contact)
659 #DISABLE_CONTACT_HOST_NOTIFICATIONS;<contact_name>
660 def DISABLE_CONTACT_HOST_NOTIFICATIONS(self, contact):
661 contact.host_notifications_enabled = False
662 self.sched.get_and_register_status_brok(contact)
664 #DISABLE_CONTACT_SVC_NOTIFICATIONS;<contact_name>
665 def DISABLE_CONTACT_SVC_NOTIFICATIONS(self, contact):
666 contact.service_notifications_enabled = False
667 self.sched.get_and_register_status_brok(contact)
669 #DISABLE_EVENT_HANDLERS
670 def DISABLE_EVENT_HANDLERS(self):
671 self.conf.enable_event_handlers = False
672 self.conf.explode_global_conf()
673 self.sched.get_and_register_update_program_status_brok()
675 #DISABLE_FAILURE_PREDICTION
676 def DISABLE_FAILURE_PREDICTION(self):
677 self.conf.enable_failure_prediction = False
678 self.conf.explode_global_conf()
679 self.sched.get_and_register_update_program_status_brok()
681 #DISABLE_FLAP_DETECTION
682 def DISABLE_FLAP_DETECTION(self):
683 self.conf.enable_flap_detection = False
684 self.conf.explode_global_conf()
685 self.sched.get_and_register_update_program_status_brok()
687 #DISABLE_HOSTGROUP_HOST_CHECKS;<hostgroup_name>
688 def DISABLE_HOSTGROUP_HOST_CHECKS(self, hostgroup):
689 for host in hostgroup:
690 self.DISABLE_HOST_CHECK(host)
692 #DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;<hostgroup_name>
693 def DISABLE_HOSTGROUP_HOST_NOTIFICATIONS(self, hostgroup):
694 for host in hostgroup:
695 self.DISABLE_HOST_NOTIFICATIONS(host)
697 #DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;<hostgroup_name>
698 def DISABLE_HOSTGROUP_PASSIVE_HOST_CHECKS(self, hostgroup):
699 for host in hostgroup:
700 self.DISABLE_PASSIVE_HOST_CHECKS(host)
702 #DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;<hostgroup_name>
703 def DISABLE_HOSTGROUP_PASSIVE_SVC_CHECKS(self, hostgroup):
704 for host in hostgroup:
705 for service in host.services:
706 self.DISABLE_PASSIVE_SVC_CHECKS(service)
708 #DISABLE_HOSTGROUP_SVC_CHECKS;<hostgroup_name>
709 def DISABLE_HOSTGROUP_SVC_CHECKS(self, hostgroup):
710 for host in hostgroup:
711 for service in host.services:
712 self.DISABLE_SVC_CHECK(service)
714 #DISABLE_HOSTGROUP_SVC_NOTIFICATIONS;<hostgroup_name>
715 def DISABLE_HOSTGROUP_SVC_NOTIFICATIONS(self, hostgroup):
716 for host in hostgroup:
717 for service in host.services:
718 self.DISABLE_SVC_NOTIFICATIONS(service)
720 #DISABLE_HOST_AND_CHILD_NOTIFICATIONS;<host_name>
721 def DISABLE_HOST_AND_CHILD_NOTIFICATIONS(self, host):
722 pass
724 #DISABLE_HOST_CHECK;<host_name>
725 def DISABLE_HOST_CHECK(self, host):
726 host.active_checks_enabled = False
727 self.sched.get_and_register_status_brok(host)
729 #DISABLE_HOST_EVENT_HANDLER;<host_name>
730 def DISABLE_HOST_EVENT_HANDLER(self, host):
731 host.event_handler_enabled = False
732 self.sched.get_and_register_status_brok(host)
734 #DISABLE_HOST_FLAP_DETECTION;<host_name>
735 def DISABLE_HOST_FLAP_DETECTION(self, host):
736 host.flap_detection_enabled = False
737 self.sched.get_and_register_status_brok(host)
739 #DISABLE_HOST_FRESHNESS_CHECKS
740 def DISABLE_HOST_FRESHNESS_CHECKS(self, host):
741 host.check_freshness = False
742 self.sched.get_and_register_status_brok(host)
744 #DISABLE_HOST_NOTIFICATIONS;<host_name>
745 def DISABLE_HOST_NOTIFICATIONS(self, host):
746 host.notifications_enabled = False
747 self.sched.get_and_register_status_brok(host)
749 #DISABLE_HOST_SVC_CHECKS;<host_name>
750 def DISABLE_HOST_SVC_CHECKS(self, host):
751 for s in host.services:
752 self.DISABLE_SVC_CHECK(s)
753 self.sched.get_and_register_status_brok(s)
755 #DISABLE_HOST_SVC_NOTIFICATIONS;<host_name>
756 def DISABLE_HOST_SVC_NOTIFICATIONS(self, host):
757 for s in host.services:
758 self.DISABLE_SVC_NOTIFICATIONS(s)
759 self.sched.get_and_register_status_brok(s)
761 #DISABLE_NOTIFICATIONS
762 def DISABLE_NOTIFICATIONS(self):
763 self.conf.enable_notifications = False
764 self.conf.explode_global_conf()
765 self.sched.get_and_register_update_program_status_brok()
767 #DISABLE_PASSIVE_HOST_CHECKS;<host_name>
768 def DISABLE_PASSIVE_HOST_CHECKS(self, host):
769 host.passive_checks_enabled = False
770 self.sched.get_and_register_status_brok(host)
772 #DISABLE_PASSIVE_SVC_CHECKS;<host_name>;<service_description>
773 def DISABLE_PASSIVE_SVC_CHECKS(self, service):
774 service.passive_checks_enabled = False
775 self.sched.get_and_register_status_brok(service)
777 #DISABLE_PERFORMANCE_DATA
778 def DISABLE_PERFORMANCE_DATA(self):
779 self.conf.process_performance_data = False
780 self.conf.explode_global_conf()
781 self.sched.get_and_register_update_program_status_brok()
783 #DISABLE_SERVICEGROUP_HOST_CHECKS;<servicegroup_name>
784 def DISABLE_SERVICEGROUP_HOST_CHECKS(self, servicegroup):
785 for service in servicegroup:
786 self.DISABLE_HOST_CHECK(service.host)
788 #DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;<servicegroup_name>
789 def DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS(self, servicegroup):
790 for service in servicegroup:
791 self.DISABLE_HOST_NOTIFICATIONS(service.host)
793 #DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;<servicegroup_name>
794 def DISABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS(self, servicegroup):
795 for service in servicegroup:
796 self.DISABLE_PASSIVE_HOST_CHECKS(service.host)
798 #DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;<servicegroup_name>
799 def DISABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS(self, servicegroup):
800 for service in servicegroup:
801 self.DISABLE_PASSIVE_SVC_CHECKS(service)
803 #DISABLE_SERVICEGROUP_SVC_CHECKS;<servicegroup_name>
804 def DISABLE_SERVICEGROUP_SVC_CHECKS(self, servicegroup):
805 for service in servicegroup:
806 self.DISABLE_SVC_CHECK(service)
808 #DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;<servicegroup_name>
809 def DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS(self, servicegroup):
810 for service in servicegroup:
811 self.DISABLE_SVC_NOTIFICATIONS(service)
813 #DISABLE_SERVICE_FLAP_DETECTION;<host_name>;<service_description>
814 def DISABLE_SERVICE_FLAP_DETECTION(self, service):
815 service.flap_detection_enabled = False
816 self.sched.get_and_register_status_brok(service)
818 #DISABLE_SERVICE_FRESHNESS_CHECKS
819 def DISABLE_SERVICE_FRESHNESS_CHECKS(self):
820 self.conf.check_service_freshness = False
821 self.conf.explode_global_conf()
822 self.sched.get_and_register_update_program_status_brok()
824 #DISABLE_SVC_CHECK;<host_name>;<service_description>
825 def DISABLE_SVC_CHECK(self, service):
826 service.active_checks_enabled = False
827 self.sched.get_and_register_status_brok(service)
829 #DISABLE_SVC_EVENT_HANDLER;<host_name>;<service_description>
830 def DISABLE_SVC_EVENT_HANDLER(self, service):
831 service.event_handler_enabled = False
832 self.sched.get_and_register_status_brok(service)
834 #DISABLE_SVC_FLAP_DETECTION;<host_name>;<service_description>
835 def DISABLE_SVC_FLAP_DETECTION(self, service):
836 service.flap_detection_enabled = False
837 self.sched.get_and_register_status_brok(service)
839 #DISABLE_SVC_NOTIFICATIONS;<host_name>;<service_description>
840 def DISABLE_SVC_NOTIFICATIONS(self, service):
841 service.notifications_enabled = False
842 self.sched.get_and_register_status_brok(service)
844 #ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST;<host_name>
845 def ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST(self, host):
846 pass
848 #ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS;<contactgroup_name>
849 def ENABLE_CONTACTGROUP_HOST_NOTIFICATIONS(self, contactgroup):
850 for contact in contactgroup:
851 self.ENABLE_CONTACT_HOST_NOTIFICATIONS(contact)
853 #ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS;<contactgroup_name>
854 def ENABLE_CONTACTGROUP_SVC_NOTIFICATIONS(self, contactgroup):
855 for contact in contactgroup:
856 self.ENABLE_CONTACT_SVC_NOTIFICATIONS(contact)
858 #ENABLE_CONTACT_HOST_NOTIFICATIONS;<contact_name>
859 def ENABLE_CONTACT_HOST_NOTIFICATIONS(self, contact):
860 contact.host_notifications_enabled = True
861 self.sched.get_and_register_status_brok(contact)
863 #ENABLE_CONTACT_SVC_NOTIFICATIONS;<contact_name>
864 def ENABLE_CONTACT_SVC_NOTIFICATIONS(self, contact):
865 contact.service_notifications_enabled = True
866 self.sched.get_and_register_status_brok(contact)
868 #ENABLE_EVENT_HANDLERS
869 def ENABLE_EVENT_HANDLERS(self):
870 self.conf.enable_event_handlers = True
871 self.conf.explode_global_conf()
872 self.sched.get_and_register_update_program_status_brok()
874 #ENABLE_FAILURE_PREDICTION
875 def ENABLE_FAILURE_PREDICTION(self):
876 self.conf.enable_failure_prediction = True
877 self.conf.explode_global_conf()
878 self.sched.get_and_register_update_program_status_brok()
880 #ENABLE_FLAP_DETECTION
881 def ENABLE_FLAP_DETECTION(self):
882 self.conf.enable_flap_detection = True
883 self.conf.explode_global_conf()
884 self.sched.get_and_register_update_program_status_brok()
886 #ENABLE_HOSTGROUP_HOST_CHECKS;<hostgroup_name>
887 def ENABLE_HOSTGROUP_HOST_CHECKS(self, hostgroup):
888 for host in hostgroup:
889 self.ENABLE_HOST_CHECK(host)
891 #ENABLE_HOSTGROUP_HOST_NOTIFICATIONS;<hostgroup_name>
892 def ENABLE_HOSTGROUP_HOST_NOTIFICATIONS(self, hostgroup):
893 for host in hostgroup:
894 self.ENABLE_HOST_NOTIFICATIONS(host)
896 #ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS;<hostgroup_name>
897 def ENABLE_HOSTGROUP_PASSIVE_HOST_CHECKS(self, hostgroup):
898 for host in hostgroup:
899 self.ENABLE_PASSIVE_HOST_CHECKS(host)
901 #ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS;<hostgroup_name>
902 def ENABLE_HOSTGROUP_PASSIVE_SVC_CHECKS(self, hostgroup):
903 for host in hostgroup:
904 for service in host.services:
905 self.ENABLE_PASSIVE_SVC_CHECKS(service)
907 #ENABLE_HOSTGROUP_SVC_CHECKS;<hostgroup_name>
908 def ENABLE_HOSTGROUP_SVC_CHECKS(self, hostgroup):
909 for host in hostgroup:
910 for service in host.services:
911 self.ENABLE_SVC_CHECK(service)
913 #ENABLE_HOSTGROUP_SVC_NOTIFICATIONS;<hostgroup_name>
914 def ENABLE_HOSTGROUP_SVC_NOTIFICATIONS(self, hostgroup):
915 for host in hostgroup:
916 for service in host.services:
917 self.ENABLE_SVC_NOTIFICATIONS(service)
919 #ENABLE_HOST_AND_CHILD_NOTIFICATIONS;<host_name>
920 def ENABLE_HOST_AND_CHILD_NOTIFICATIONS(self, host):
921 pass
923 #ENABLE_HOST_CHECK;<host_name>
924 def ENABLE_HOST_CHECK(self, host):
925 host.active_checks_enabled = True
926 self.sched.get_and_register_status_brok(host)
928 #ENABLE_HOST_EVENT_HANDLER;<host_name>
929 def ENABLE_HOST_EVENT_HANDLER(self, host):
930 host.enable_event_handlers = True
931 self.sched.get_and_register_status_brok(host)
933 #ENABLE_HOST_FLAP_DETECTION;<host_name>
934 def ENABLE_HOST_FLAP_DETECTION(self, host):
935 host.flap_detection_enabled = True
936 self.sched.get_and_register_status_brok(host)
938 #ENABLE_HOST_FRESHNESS_CHECKS
939 def ENABLE_HOST_FRESHNESS_CHECKS(self):
940 self.conf.check_host_freshness = True
941 self.conf.explode_global_conf()
942 self.sched.get_and_register_update_program_status_brok()
944 #ENABLE_HOST_NOTIFICATIONS;<host_name>
945 def ENABLE_HOST_NOTIFICATIONS(self, host):
946 host.notifications_enabled = True
947 self.sched.get_and_register_status_brok(host)
949 #ENABLE_HOST_SVC_CHECKS;<host_name>
950 def ENABLE_HOST_SVC_CHECKS(self, host):
951 for s in host.services:
952 self.ENABLE_SVC_CHECK(s)
953 self.sched.get_and_register_status_brok(s)
955 #ENABLE_HOST_SVC_NOTIFICATIONS;<host_name>
956 def ENABLE_HOST_SVC_NOTIFICATIONS(self, host):
957 for s in host.services:
958 self.ENABLE_SVC_NOTIFICATIONS(s)
959 self.sched.get_and_register_status_brok(s)
961 #ENABLE_NOTIFICATIONS
962 def ENABLE_NOTIFICATIONS(self):
963 self.conf.enable_notifications = True
964 self.conf.explode_global_conf()
965 self.sched.get_and_register_update_program_status_brok()
967 #ENABLE_PASSIVE_HOST_CHECKS;<host_name>
968 def ENABLE_PASSIVE_HOST_CHECKS(self, host):
969 host.passive_checks_enabled = True
970 self.sched.get_and_register_status_brok(host)
972 #ENABLE_PASSIVE_SVC_CHECKS;<host_name>;<service_description>
973 def ENABLE_PASSIVE_SVC_CHECKS(self, service):
974 service.passive_checks_enabled = True
975 self.sched.get_and_register_status_brok(service)
977 #ENABLE_PERFORMANCE_DATA
978 def ENABLE_PERFORMANCE_DATA(self):
979 self.conf.process_performance_data = True
980 self.conf.explode_global_conf()
981 self.sched.get_and_register_update_program_status_brok()
983 #ENABLE_SERVICEGROUP_HOST_CHECKS;<servicegroup_name>
984 def ENABLE_SERVICEGROUP_HOST_CHECKS(self, servicegroup):
985 for service in servicegroup:
986 self.ENABLE_HOST_CHECK(service.host)
988 #ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS;<servicegroup_name>
989 def ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS(self, servicegroup):
990 for service in servicegroup:
991 self.ENABLE_HOST_NOTIFICATIONS(service.host)
993 #ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS;<servicegroup_name>
994 def ENABLE_SERVICEGROUP_PASSIVE_HOST_CHECKS(self, servicegroup):
995 for service in servicegroup:
996 self.ENABLE_PASSIVE_HOST_CHECKS(service.host)
998 #ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS;<servicegroup_name>
999 def ENABLE_SERVICEGROUP_PASSIVE_SVC_CHECKS(self, servicegroup):
1000 for service in servicegroup:
1001 self.ENABLE_PASSIVE_SVC_CHECKS(service)
1003 #ENABLE_SERVICEGROUP_SVC_CHECKS;<servicegroup_name>
1004 def ENABLE_SERVICEGROUP_SVC_CHECKS(self, servicegroup):
1005 for service in servicegroup:
1006 self.ENABLE_SVC_CHECK(service)
1008 #ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;<servicegroup_name>
1009 def ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS(self, servicegroup):
1010 for service in servicegroup:
1011 self.ENABLE_SVC_NOTIFICATIONS(service)
1013 #ENABLE_SERVICE_FRESHNESS_CHECKS
1014 def ENABLE_SERVICE_FRESHNESS_CHECKS(self):
1015 self.conf.check_service_freshness = True
1016 self.conf.explode_global_conf()
1017 self.sched.get_and_register_update_program_status_brok()
1019 #ENABLE_SVC_CHECK;<host_name>;<service_description>
1020 def ENABLE_SVC_CHECK(self, service):
1021 service.active_checks_enabled = True
1022 self.sched.get_and_register_status_brok(service)
1024 #ENABLE_SVC_EVENT_HANDLER;<host_name>;<service_description>
1025 def ENABLE_SVC_EVENT_HANDLER(self, service):
1026 service.event_handler_enabled = True
1027 self.sched.get_and_register_status_brok(service)
1029 #ENABLE_SVC_FLAP_DETECTION;<host_name>;<service_description>
1030 def ENABLE_SVC_FLAP_DETECTION(self, service):
1031 service.flap_detection_enabled = True
1032 self.sched.get_and_register_status_brok(service)
1034 #ENABLE_SVC_NOTIFICATIONS;<host_name>;<service_description>
1035 def ENABLE_SVC_NOTIFICATIONS(self, service):
1036 service.notifications_enabled = True
1037 self.sched.get_and_register_status_brok(service)
1039 #PROCESS_FILE;<file_name>;<delete>
1040 def PROCESS_FILE(self, file_name, delete):
1041 pass
1043 #TODO : say that check is PASSIVE
1044 #PROCESS_HOST_CHECK_RESULT;<host_name>;<status_code>;<plugin_output>
1045 def PROCESS_HOST_CHECK_RESULT(self, host, status_code, plugin_output):
1046 #raise a PASSIVE check only if needed
1047 if self.conf.log_passive_checks:
1048 logger.log('PASSIVE HOST CHECK: %s;%d;%s' % (host.get_name(), status_code, plugin_output))
1049 now = time.time()
1050 cls = host.__class__
1051 #If globally disable OR locally, do not launch
1052 if cls.accept_passive_checks and host.passive_checks_enabled:
1053 i = host.launch_check(now, force=True)
1054 for chk in host.actions:
1055 if chk.id == i:
1056 c = chk
1057 #Now we 'transform the check into a result'
1058 #So exit_status, output and status is eaten by the host
1059 c.exit_status = status_code
1060 c.get_outputs(plugin_output, host.max_plugins_output_length)
1061 c.status = 'waitconsume'
1062 c.check_time = now
1063 self.sched.nb_check_received += 1
1064 #Ok now this result will be reap by scheduler the next loop
1067 #PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output>
1068 def PROCESS_SERVICE_CHECK_RESULT(self, service, return_code, plugin_output):
1069 #raise a PASSIVE check only if needed
1070 if self.conf.log_passive_checks:
1071 logger.log('PASSIVE SERVICE CHECK: %s;%s;%d;%s' % (service.host.get_name(), service.get_name(), return_code, plugin_output))
1072 now = time.time()
1073 cls = service.__class__
1074 #If globally disable OR locally, do not launch
1075 if cls.accept_passive_checks and service.passive_checks_enabled:
1076 i = service.launch_check(now, force=True)
1077 for chk in service.actions:
1078 if chk.id == i:
1079 c = chk
1080 #Now we 'transform the check into a result'
1081 #So exit_status, output and status is eaten by the service
1082 c.exit_status = return_code
1083 c.get_outputs(plugin_output, service.max_plugins_output_length)
1084 c.status = 'waitconsume'
1085 c.check_time = now
1086 self.sched.nb_check_received += 1
1087 #Ok now this result will be reap by scheduler the next loop
1090 #READ_STATE_INFORMATION
1091 def READ_STATE_INFORMATION(self):
1092 pass
1094 #REMOVE_HOST_ACKNOWLEDGEMENT;<host_name>
1095 def REMOVE_HOST_ACKNOWLEDGEMENT(self, host):
1096 host.unacknowledge_problem()
1098 #REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>
1099 def REMOVE_SVC_ACKNOWLEDGEMENT(self, service):
1100 service.unacknowledge_problem()
1102 #RESTART_PROGRAM
1103 def RESTART_PROGRAM(self):
1104 pass
1106 #SAVE_STATE_INFORMATION
1107 def SAVE_STATE_INFORMATION(self):
1108 pass
1110 #SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1111 def SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
1112 pass
1114 #SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1115 def SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
1116 pass
1118 #SCHEDULE_CONTACT_DOWNTIME;<contact_name>;<start_time>;<end_time>;<author>;<comment>
1119 def SCHEDULE_CONTACT_DOWNTIME(self, contact, start_time, end_time, author, comment):
1120 dt = ContactDowntime(contact, start_time, end_time, author, comment)
1121 contact.add_downtime(dt)
1122 self.sched.add(dt)
1123 self.sched.get_and_register_status_brok(contact)
1125 #SCHEDULE_FORCED_HOST_CHECK;<host_name>;<check_time>
1126 def SCHEDULE_FORCED_HOST_CHECK(self, host, check_time):
1127 host.schedule(force=True, force_time=check_time)
1128 self.sched.get_and_register_status_brok(host)
1130 #SCHEDULE_FORCED_HOST_SVC_CHECKS;<host_name>;<check_time>
1131 def SCHEDULE_FORCED_HOST_SVC_CHECKS(self, host, check_time):
1132 for s in host.services:
1133 self.SCHEDULE_FORCED_SVC_CHECK(s, check_time)
1134 self.sched.get_and_register_status_brok(s)
1136 #SCHEDULE_FORCED_SVC_CHECK;<host_name>;<service_description>;<check_time>
1137 def SCHEDULE_FORCED_SVC_CHECK(self, service, check_time):
1138 service.schedule(force=True, force_time=check_time)
1139 self.sched.get_and_register_status_brok(service)
1141 #SCHEDULE_HOSTGROUP_HOST_DOWNTIME;<hostgroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1142 def SCHEDULE_HOSTGROUP_HOST_DOWNTIME(self, hostgroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
1143 pass
1145 #SCHEDULE_HOSTGROUP_SVC_DOWNTIME;<hostgroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1146 def SCHEDULE_HOSTGROUP_SVC_DOWNTIME(self, hostgroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
1147 pass
1149 #SCHEDULE_HOST_CHECK;<host_name>;<check_time>
1150 def SCHEDULE_HOST_CHECK(self, host, check_time):
1151 host.schedule(force=False, force_time=check_time)
1152 self.sched.get_and_register_status_brok(host)
1154 #SCHEDULE_HOST_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1155 def SCHEDULE_HOST_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
1156 dt = Downtime(host, start_time, end_time, fixed, trigger_id, duration, author, comment)
1157 host.add_downtime(dt)
1158 self.sched.add(dt)
1159 self.sched.get_and_register_status_brok(host)
1160 if trigger_id != 0 and trigger_id in self.sched.downtimes:
1161 self.sched.downtimes[trigger_id].trigger_me(dt)
1163 #SCHEDULE_HOST_SVC_CHECKS;<host_name>;<check_time>
1164 def SCHEDULE_HOST_SVC_CHECKS(self, host, check_time):
1165 for s in host.services:
1166 self.SCHEDULE_SVC_CHECK(s, check_time)
1167 self.sched.get_and_register_status_brok(s)
1169 #SCHEDULE_HOST_SVC_DOWNTIME;<host_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1170 def SCHEDULE_HOST_SVC_DOWNTIME(self, host, start_time, end_time, fixed, trigger_id, duration, author, comment):
1171 for s in host.services:
1172 self.SCHEDULE_SVC_DOWNTIME(s, start_time, end_time, fixed, trigger_id, duration, author, comment)
1174 #SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;<servicegroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1175 def SCHEDULE_SERVICEGROUP_HOST_DOWNTIME(self, servicegroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
1176 for h in [s.host for s in servicegroup.get_services()]:
1177 self.SCHEDULE_HOST_DOWNTIME(h, start_time, end_time, fixed, trigger_id, duration, author, comment)
1179 #SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;<servicegroup_name>;<start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1180 def SCHEDULE_SERVICEGROUP_SVC_DOWNTIME(self, servicegroup, start_time, end_time, fixed, trigger_id, duration, author, comment):
1181 for s in servicegroup.get_services():
1182 self.SCHEDULE_SVC_DOWNTIME(s, start_time, end_time, fixed, trigger_id, duration, author, comment)
1184 #SCHEDULE_SVC_CHECK;<host_name>;<service_description>;<check_time>
1185 def SCHEDULE_SVC_CHECK(self, service, check_time):
1186 service.schedule(force=False, force_time=check_time)
1187 self.sched.get_and_register_status_brok(service)
1189 #SCHEDULE_SVC_DOWNTIME;<host_name>;<service_desription><start_time>;<end_time>;<fixed>;<trigger_id>;<duration>;<author>;<comment>
1190 def SCHEDULE_SVC_DOWNTIME(self, service, start_time, end_time, fixed, trigger_id, duration, author, comment):
1191 dt = Downtime(service, start_time, end_time, fixed, trigger_id, duration, author, comment)
1192 service.add_downtime(dt)
1193 self.sched.add(dt)
1194 self.sched.get_and_register_status_brok(service)
1195 if trigger_id != 0 and trigger_id in self.sched.downtimes:
1196 self.sched.downtimes[trigger_id].trigger_me(dt)
1198 #SEND_CUSTOM_HOST_NOTIFICATION;<host_name>;<options>;<author>;<comment>
1199 def SEND_CUSTOM_HOST_NOTIFICATION(self, host, options, author, comment):
1200 pass
1202 #SEND_CUSTOM_SVC_NOTIFICATION;<host_name>;<service_description>;<options>;<author>;<comment>
1203 def SEND_CUSTOM_SVC_NOTIFICATION(self, service, options, author, comment):
1204 pass
1206 #SET_HOST_NOTIFICATION_NUMBER;<host_name>;<notification_number>
1207 def SET_HOST_NOTIFICATION_NUMBER(self, host, notification_number):
1208 pass
1210 #SET_SVC_NOTIFICATION_NUMBER;<host_name>;<service_description>;<notification_number>
1211 def SET_SVC_NOTIFICATION_NUMBER(self, service, notification_number):
1212 pass
1214 #SHUTDOWN_PROGRAM
1215 def SHUTDOWN_PROGRAM(self):
1216 pass
1218 #START_ACCEPTING_PASSIVE_HOST_CHECKS
1219 def START_ACCEPTING_PASSIVE_HOST_CHECKS(self):
1220 self.conf.accept_passive_host_checks = True
1221 self.conf.explode_global_conf()
1222 self.sched.get_and_register_update_program_status_brok()
1224 #START_ACCEPTING_PASSIVE_SVC_CHECKS
1225 def START_ACCEPTING_PASSIVE_SVC_CHECKS(self):
1226 self.conf.accept_passive_service_checks = True
1227 self.conf.explode_global_conf()
1228 self.sched.get_and_register_update_program_status_brok()
1230 #START_EXECUTING_HOST_CHECKS
1231 def START_EXECUTING_HOST_CHECKS(self):
1232 self.conf.execute_host_checks = True
1233 self.conf.explode_global_conf()
1234 self.sched.get_and_register_update_program_status_brok()
1236 #START_EXECUTING_SVC_CHECKS
1237 def START_EXECUTING_SVC_CHECKS(self):
1238 self.conf.execute_service_checks = True
1239 self.conf.explode_global_conf()
1240 self.sched.get_and_register_update_program_status_brok()
1242 #START_OBSESSING_OVER_HOST;<host_name>
1243 def START_OBSESSING_OVER_HOST(self, host):
1244 host.obsess_over_host = True
1245 self.sched.get_and_register_status_brok(host)
1247 #START_OBSESSING_OVER_HOST_CHECKS
1248 def START_OBSESSING_OVER_HOST_CHECKS(self):
1249 self.conf.obsess_over_hosts = True
1250 self.conf.explode_global_conf()
1252 #START_OBSESSING_OVER_SVC;<host_name>;<service_description>
1253 def START_OBSESSING_OVER_SVC(self, service):
1254 service.obsess_over_service = True
1255 self.sched.get_and_register_status_brok(service)
1257 #START_OBSESSING_OVER_SVC_CHECKS
1258 def START_OBSESSING_OVER_SVC_CHECKS(self):
1259 self.conf.obsess_over_services = True
1260 self.conf.explode_global_conf()
1261 self.sched.get_and_register_update_program_status_brok()
1263 #STOP_ACCEPTING_PASSIVE_HOST_CHECKS
1264 def STOP_ACCEPTING_PASSIVE_HOST_CHECKS(self):
1265 self.accept_passive_host_checks = False
1266 self.conf.explode_global_conf()
1267 self.sched.get_and_register_update_program_status_brok()
1269 #STOP_ACCEPTING_PASSIVE_SVC_CHECKS
1270 def STOP_ACCEPTING_PASSIVE_SVC_CHECKS(self):
1271 self.accept_passive_service_checks = False
1272 self.conf.explode_global_conf()
1273 self.sched.get_and_register_update_program_status_brok()
1275 #STOP_EXECUTING_HOST_CHECKS
1276 def STOP_EXECUTING_HOST_CHECKS(self):
1277 self.conf.execute_host_checks = False
1278 self.conf.explode_global_conf()
1279 self.sched.get_and_register_update_program_status_brok()
1281 #STOP_EXECUTING_SVC_CHECKS
1282 def STOP_EXECUTING_SVC_CHECKS(self):
1283 self.conf.execute_service_checks = False
1284 self.conf.explode_global_conf()
1285 self.sched.get_and_register_update_program_status_brok()
1287 #STOP_OBSESSING_OVER_HOST;<host_name>
1288 def STOP_OBSESSING_OVER_HOST(self, host):
1289 host.obsess_over_host = False
1290 self.sched.get_and_register_status_brok(host)
1292 #STOP_OBSESSING_OVER_HOST_CHECKS
1293 def STOP_OBSESSING_OVER_HOST_CHECKS(self):
1294 self.conf.obsess_over_hosts = False
1295 self.conf.explode_global_conf()
1296 self.sched.get_and_register_update_program_status_brok()
1298 #STOP_OBSESSING_OVER_SVC;<host_name>;<service_description>
1299 def STOP_OBSESSING_OVER_SVC(self, service):
1300 service.obsess_over_service = False
1301 self.sched.get_and_register_status_brok(service)
1303 #STOP_OBSESSING_OVER_SVC_CHECKS
1304 def STOP_OBSESSING_OVER_SVC_CHECKS(self):
1305 self.conf.obsess_over_services = False
1306 self.conf.explode_global_conf()
1307 self.sched.get_and_register_update_program_status_brok()
1310 ### Now the shinken specific ones
1311 #LAUNCH_SVC_EVENT_HANDLER;<host_name>;<service_description>
1312 def LAUNCH_SVC_EVENT_HANDLER(self, service):
1313 service.get_event_handlers(externalcmd=True)
1316 #LAUNCH_SVC_EVENT_HANDLER;<host_name>;<service_description>
1317 def LAUNCH_HOST_EVENT_HANDLER(self, host):
1318 host.get_event_handlers(externalcmd=True)
1321 #ADD_SIMPLE_HOST_DEPENDENCY;<host_name>;<host_name>
1322 def ADD_SIMPLE_HOST_DEPENDENCY(self, son, father):
1323 if not son.is_linked_with_host(father):
1324 print "Doing simple link between", son.get_name(), 'and', father.get_name()
1325 # Add a dep link between the son and the father
1326 son.add_host_act_dependancy(father, ['w', 'u', 'd'], None, True)
1327 self.sched.get_and_register_status_brok(son)
1328 self.sched.get_and_register_status_brok(father)
1331 #ADD_SIMPLE_HOST_DEPENDENCY;<host_name>;<host_name>
1332 def DEL_HOST_DEPENDENCY(self, son, father):
1333 if son.is_linked_with_host(father):
1334 print "removing simple link between", son.get_name(), 'and', father.get_name()
1335 son.del_host_act_dependancy(father)
1336 self.sched.get_and_register_status_brok(son)
1337 self.sched.get_and_register_status_brok(father)
1340 #ADD_SIMPLE_POLLER;realm_name;poller_name;address;port
1341 def ADD_SIMPLE_POLLER(self, realm_name, poller_name, address, port):
1342 print "I need to add the poller", realm_name, poller_name, address, port
1344 # First we look for the realm
1345 r = self.conf.realms.find_by_name(realm_name)
1346 if r is None:
1347 print "Sorry, the realm %s is unknown" % realm_name
1348 return
1349 print "We found the realm", r
1350 # TODO : backport this in the config class?
1351 # We create the PollerLink object
1352 t = {'poller_name' : poller_name, 'address' : address, 'port' : port}
1353 p = PollerLink(t)
1354 p.fill_default()
1355 p.pythonize()
1356 p.prepare_for_conf()
1357 parameters = {'max_plugins_output_length' : self.conf.max_plugins_output_length}
1358 p.add_global_conf_parameters(parameters)
1359 self.arbiter.conf.pollers[p.id] = p
1360 self.arbiter.dispatcher.elements.append(p)
1361 self.arbiter.dispatcher.satellites.append(p)
1362 r.pollers.append(p)
1363 r.count_pollers()
1364 r.fill_potential_pollers()
1365 print "Poller %s added" % poller_name
1366 print "Potential", r.get_potential_satellites_by_type('poller')
1369 if __name__ == '__main__':
1371 FIFO_PATH = '/tmp/my_fifo'
1373 if os.path.exists(FIFO_PATH):
1374 os.unlink(FIFO_PATH)
1376 if not os.path.exists(FIFO_PATH):
1377 os.umask(0)
1378 os.mkfifo(FIFO_PATH, 0660)
1379 my_fifo = open(FIFO_PATH, 'w+')
1380 print "my_fifo:", my_fifo
1382 print open(FIFO_PATH, 'r').readline()