Merge branch 'master' of ssh://lausser,shinken@shinken.git.sourceforge.net/gitroot...
[shinken.git] / test / test_acknowledge.py
blobf32e329c27fc506a16e15799f6c9a98d68a6ec89
1 #!/usr/bin/env python2.6
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
8 #Shinken is free software: you can redistribute it and/or modify
9 #it under the terms of the GNU Affero General Public License as published by
10 #the Free Software Foundation, either version 3 of the License, or
11 #(at your option) any later version.
13 #Shinken is distributed in the hope that it will be useful,
14 #but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 #GNU Affero General Public License for more details.
18 #You should have received a copy of the GNU Affero General Public License
19 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
22 # This file is used to test acknowledge of problems
26 #It's ugly I know....
27 from shinken_test import *
29 class TestConfig(ShinkenTest):
31 def test_ack_soft_service(self):
32 self.print_header()
33 # retry_interval 2
34 # critical notification
35 # run loop -> another notification
36 now = time.time()
37 host = self.sched.hosts.find_by_name("test_host_0")
38 host.checks_in_progress = []
39 host.act_depend_of = [] # ignore the router
40 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
41 svc.checks_in_progress = []
42 svc.act_depend_of = [] # no hostchecks on critical checkresults
43 #--------------------------------------------------------------
44 # initialize host/service state
45 #--------------------------------------------------------------
46 self.scheduler_loop(1, [[host, 0, 'UP']])
47 print "- 1 x OK -------------------------------------"
48 self.scheduler_loop(1, [[svc, 0, 'OK']])
49 self.assert_(svc.current_notification_number == 0)
51 #--------------------------------------------------------------
52 # first check the normal behavior
53 # service reaches hard;2
54 # at the end there must be 3 actions: eventhandler hard,
55 # master notification and contact notification
56 #--------------------------------------------------------------
57 print "- 2 x BAD get hard -------------------------------------"
58 self.scheduler_loop(2, [[svc, 2, 'BAD']])
59 self.assert_(svc.current_notification_number == 1)
60 self.assert_(self.count_actions() == 3)
61 self.assert_(self.log_match(5, 'SERVICE NOTIFICATION'))
62 self.show_and_clear_logs()
63 self.show_and_clear_actions()
64 # clean up
65 self.scheduler_loop(1, [[svc, 0, 'OK']])
66 self.clear_logs()
67 self.clear_actions()
69 #--------------------------------------------------------------
70 # service reaches soft;1
71 # there must not be any notification
72 #--------------------------------------------------------------
73 print "- 1 x BAD get soft -------------------------------------"
74 self.scheduler_loop(1, [[svc, 2, 'BAD']])
75 self.assert_(svc.current_notification_number == 0)
77 #--------------------------------------------------------------
78 # someone acknowledges the problem before a notification goes out
79 #--------------------------------------------------------------
80 self.assert_(not svc.problem_has_been_acknowledged)
81 now = time.time()
82 cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;0;lausser;blablub" % now
83 self.sched.run_external_command(cmd)
84 self.sched.get_new_actions()
85 self.worker_loop()
86 self.assert_(svc.problem_has_been_acknowledged)
87 self.assert_(self.log_match(3, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
88 self.show_and_clear_logs()
89 self.show_actions()
90 self.sched.update_downtimes_and_comments()
91 self.assert_(len(svc.comments) == 1)
94 #--------------------------------------------------------------
95 # service reaches hard;2
96 # a notification must have been created but blocked
97 # log for alert hard and log for eventhandler
98 #--------------------------------------------------------------
99 print "- 1 x BAD get hard -------------------------------------"
100 self.scheduler_loop(1, [[svc, 2, 'BAD']])
101 self.assert_(self.count_logs() == 2)
102 self.assert_(self.count_actions() == 2)
103 self.assert_(svc.current_notification_number == 0)
104 self.show_and_clear_logs()
105 self.show_actions()
107 #--------------------------------------------------------------
108 # recover
109 # the acknowledgement must have been removed automatically
110 #--------------------------------------------------------------
111 self.scheduler_loop(1, [[svc, 0, 'GOOD']])
112 print "- 1 x OK recover"
113 self.show_logs()
114 self.show_actions()
115 self.assert_(self.count_logs() == 2) # alert, eventhndlr
116 self.assert_(self.count_actions() == 2) # evt, master notif
117 self.assert_(not svc.problem_has_been_acknowledged)
118 self.assert_(svc.current_notification_number == 0)
119 self.show_and_clear_logs()
120 self.show_and_clear_actions()
123 def test_ack_hard_service(self):
124 self.print_header()
125 now = time.time()
126 host = self.sched.hosts.find_by_name("test_host_0")
127 host.checks_in_progress = []
128 host.act_depend_of = [] # ignore the router
129 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
130 svc.checks_in_progress = []
131 svc.act_depend_of = [] # no hostchecks on critical checkresults
132 #--------------------------------------------------------------
133 # initialize host/service state
134 #--------------------------------------------------------------
135 self.scheduler_loop(1, [[host, 0, 'UP']])
136 print "- 1 x OK -------------------------------------"
137 self.scheduler_loop(1, [[svc, 0, 'OK']])
138 self.assert_(svc.current_notification_number == 0)
140 #--------------------------------------------------------------
141 # first check the normal behavior
142 # service reaches hard;2
143 # at the end there must be 3 actions: eventhandler hard,
144 # master notification and contact notification
145 #--------------------------------------------------------------
146 print "- 2 x BAD get hard -------------------------------------"
147 self.scheduler_loop(2, [[svc, 2, 'BAD']])
148 self.assert_(svc.current_notification_number == 1)
149 self.assert_(self.count_actions() == 3)
150 self.assert_(self.log_match(5, 'SERVICE NOTIFICATION'))
151 self.show_and_clear_logs()
152 self.show_actions()
154 #--------------------------------------------------------------
155 # stay hard and wait for the second notification (notification_interval)
156 #--------------------------------------------------------------
157 print "- 2 x BAD stay hard -------------------------------------"
158 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
159 self.show_and_clear_logs()
160 self.show_actions()
161 self.assert_(svc.current_notification_number == 2)
163 #--------------------------------------------------------------
164 # admin wakes up and acknowledges the problem
165 # the ACK is the only log message
166 # a master notification is still around, but can't be sent
167 #--------------------------------------------------------------
168 self.assert_(not svc.problem_has_been_acknowledged)
169 now = time.time()
170 cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;0;lausser;blablub" % now
171 self.sched.run_external_command(cmd)
172 self.sched.get_new_actions()
173 self.worker_loop()
174 self.assert_(svc.problem_has_been_acknowledged)
175 self.assert_(self.log_match(1, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
176 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
177 self.assert_(self.count_logs() == 1)
178 self.assert_(self.count_actions() == 1)
179 self.show_and_clear_logs()
180 self.show_actions()
182 #--------------------------------------------------------------
183 # remove acknowledgement
184 # now notifications are sent again
185 #--------------------------------------------------------------
186 now = time.time()
187 cmd = "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;test_host_0;test_ok_0" % now
188 self.sched.run_external_command(cmd)
189 self.sched.get_new_actions()
190 self.worker_loop()
191 self.show_logs()
192 self.show_actions()
193 # the contact notification was sent immediately (t_to_go)
194 self.assert_(not svc.problem_has_been_acknowledged)
195 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
196 self.show_logs()
197 self.show_actions()
198 self.assert_(self.log_match(1, 'SERVICE NOTIFICATION'))
199 self.assert_(self.log_match(2, 'SERVICE NOTIFICATION'))
200 self.assert_(self.count_logs() == 2)
201 self.assert_(self.count_actions() == 2) # master sched, contact zombie
202 self.assert_(svc.current_notification_number == 4)
203 self.show_and_clear_logs()
204 self.show_actions()
206 #--------------------------------------------------------------
207 # recover
208 # the acknowledgement must have been removed automatically
209 # recover notifications are only sent to contacts which
210 # received a critical/warning notification
211 #--------------------------------------------------------------
212 self.scheduler_loop(1, [[svc, 0, 'GOOD']])
213 print "- 1 x OK recover"
214 self.show_logs()
215 self.show_actions()
216 self.assert_(self.count_logs() == 3) # alert, eventhndlr, notif
217 self.assert_(self.count_actions() == 3) # evt, master notif, notif
218 self.assert_(not svc.problem_has_been_acknowledged)
219 self.assert_(svc.current_notification_number == 0)
220 self.show_and_clear_logs()
221 self.show_and_clear_actions()
224 def test_ack_nonsticky_changing_service(self):
225 # acknowledge is not sticky
226 # service goes from critical to warning
227 # this means, the acknowledge deletes itself
228 self.print_header()
229 now = time.time()
230 host = self.sched.hosts.find_by_name("test_host_0")
231 host.checks_in_progress = []
232 host.act_depend_of = [] # ignore the router
233 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
234 svc.checks_in_progress = []
235 svc.act_depend_of = [] # no hostchecks on critical checkresults
236 #--------------------------------------------------------------
237 # initialize host/service state
238 #--------------------------------------------------------------
239 self.scheduler_loop(1, [[host, 0, 'UP']])
240 print "- 1 x OK -------------------------------------"
241 self.scheduler_loop(1, [[svc, 0, 'OK']])
242 self.assert_(svc.current_notification_number == 0)
244 #--------------------------------------------------------------
245 # first check the normal behavior
246 # service reaches hard;2
247 # at the end there must be 3 actions: eventhandler hard,
248 # master notification and contact notification
249 #--------------------------------------------------------------
250 print "- 2 x BAD get hard -------------------------------------"
251 self.scheduler_loop(2, [[svc, 2, 'BAD']])
252 self.assert_(svc.current_notification_number == 1)
253 self.assert_(self.count_actions() == 3)
254 self.assert_(self.log_match(5, 'SERVICE NOTIFICATION'))
255 self.show_and_clear_logs()
256 self.show_actions()
258 #--------------------------------------------------------------
259 # stay hard and wait for the second notification (notification_interval)
260 #--------------------------------------------------------------
261 print "- 2 x BAD stay hard -------------------------------------"
262 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
263 self.show_and_clear_logs()
264 self.show_actions()
265 self.assert_(svc.current_notification_number == 2)
267 #--------------------------------------------------------------
268 # admin wakes up and acknowledges the problem
269 # the ACK is the only log message
270 # a master notification is still around, but can't be sent
271 #--------------------------------------------------------------
272 self.assert_(not svc.problem_has_been_acknowledged)
273 now = time.time()
274 cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;1;lausser;blablub" % now
275 self.sched.run_external_command(cmd)
276 self.sched.get_new_actions()
277 self.worker_loop()
278 self.assert_(svc.problem_has_been_acknowledged)
279 self.assert_(self.log_match(1, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
280 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
281 self.assert_(self.count_logs() == 1)
282 self.assert_(self.count_actions() == 1)
283 self.show_and_clear_logs()
284 self.show_actions()
286 #--------------------------------------------------------------
287 # now become warning
288 # ack is deleted automatically and notifications are sent again
289 #--------------------------------------------------------------
290 self.scheduler_loop(2, [[svc, 1, 'NOT REALLY BAD']], do_sleep=True)
291 self.assert_(not svc.problem_has_been_acknowledged)
292 self.show_logs()
293 self.show_actions()
294 self.assert_(self.log_match(1, 'SERVICE ALERT.*WARNING'))
295 self.assert_(self.log_match(2, 'SERVICE NOTIFICATION'))
296 self.assert_(self.log_match(3, 'SERVICE NOTIFICATION'))
297 self.assert_(self.count_logs() == 3)
298 self.assert_(self.count_actions() == 2) # master sched, contact zombie
299 self.assert_(svc.current_notification_number == 4)
300 self.show_and_clear_logs()
301 self.show_actions()
303 #--------------------------------------------------------------
304 # recover
305 # the acknowledgement must have been removed automatically
306 #--------------------------------------------------------------
307 self.scheduler_loop(1, [[svc, 0, 'GOOD']])
308 print "- 1 x OK recover"
309 self.show_logs()
310 self.show_actions()
311 self.assert_(self.count_logs() == 3) # alert, eventhndlr, notification
312 self.assert_(self.count_actions() == 3) # evt, master notif, contact notif
313 self.assert_(not svc.problem_has_been_acknowledged)
314 self.assert_(svc.current_notification_number == 0)
315 self.show_and_clear_logs()
316 self.show_and_clear_actions()
319 def test_ack_sticky_changing_service(self):
320 # acknowledge is sticky
321 # service goes from critical to warning
322 # still acknowledged
323 self.print_header()
324 now = time.time()
325 host = self.sched.hosts.find_by_name("test_host_0")
326 host.checks_in_progress = []
327 host.act_depend_of = [] # ignore the router
328 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
329 svc.checks_in_progress = []
330 svc.act_depend_of = [] # no hostchecks on critical checkresults
331 #--------------------------------------------------------------
332 # initialize host/service state
333 #--------------------------------------------------------------
334 self.scheduler_loop(1, [[host, 0, 'UP']])
335 print "- 1 x OK -------------------------------------"
336 self.scheduler_loop(1, [[svc, 0, 'OK']])
337 self.assert_(svc.current_notification_number == 0)
339 #--------------------------------------------------------------
340 # first check the normal behavior
341 # service reaches hard;2
342 # at the end there must be 3 actions: eventhandler hard,
343 # master notification and contact notification
344 #--------------------------------------------------------------
345 print "- 2 x BAD get hard -------------------------------------"
346 self.scheduler_loop(2, [[svc, 2, 'BAD']])
347 self.assert_(svc.current_notification_number == 1)
348 self.assert_(self.count_actions() == 3)
349 self.assert_(self.log_match(5, 'SERVICE NOTIFICATION'))
350 self.show_and_clear_logs()
351 self.show_actions()
353 #--------------------------------------------------------------
354 # stay hard and wait for the second notification (notification_interval)
355 #--------------------------------------------------------------
356 print "- 2 x BAD stay hard -------------------------------------"
357 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
358 self.show_and_clear_logs()
359 self.show_actions()
360 self.assert_(svc.current_notification_number == 2)
362 #--------------------------------------------------------------
363 # admin wakes up and acknowledges the problem
364 # the ACK is the only log message
365 # a master notification is still around, but can't be sent
366 #--------------------------------------------------------------
367 self.assert_(not svc.problem_has_been_acknowledged)
368 now = time.time()
369 cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;2;1;0;lausser;blablub" % now
370 self.sched.run_external_command(cmd)
371 self.sched.get_new_actions()
372 self.worker_loop()
373 self.assert_(svc.problem_has_been_acknowledged)
374 self.assert_(self.log_match(1, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
375 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
376 self.assert_(self.count_logs() == 1)
377 self.assert_(self.count_actions() == 1)
378 self.show_and_clear_logs()
379 self.show_actions()
381 #--------------------------------------------------------------
382 # now become warning
383 # ack remains set
384 #--------------------------------------------------------------
385 self.scheduler_loop(2, [[svc, 1, 'NOT REALLY BAD']], do_sleep=True)
386 self.assert_(svc.problem_has_been_acknowledged)
387 self.show_logs()
388 self.show_actions()
389 self.assert_(self.log_match(1, 'SERVICE ALERT.*WARNING'))
390 self.assert_(self.count_logs() == 1) # alert
391 self.assert_(svc.current_notification_number == 2)
392 self.show_and_clear_logs()
393 self.show_actions()
394 self.assert_(len(svc.comments) == 1)
395 self.assert_(svc.comments[0].comment == 'blablub')
397 #--------------------------------------------------------------
398 # recover
399 # the acknowledgement must have been removed automatically
400 #--------------------------------------------------------------
401 self.scheduler_loop(1, [[svc, 0, 'GOOD']])
402 print "- 1 x OK recover"
403 self.show_logs()
404 self.show_actions()
405 self.assert_(self.count_logs() == 3) # alert, eventhndlr, notification
406 self.assert_(self.count_actions() == 3) # evt, master notif, contact notif
407 self.assert_(not svc.problem_has_been_acknowledged)
408 self.assert_(svc.current_notification_number == 0)
409 self.assert_(len(svc.comments) == 0)
410 self.show_and_clear_logs()
411 self.show_and_clear_actions()
414 def test_ack_soft_host(self):
415 self.print_header()
416 # retry_interval 2
417 # critical notification
418 # run loop -> another notification
419 now = time.time()
420 host = self.sched.hosts.find_by_name("test_host_0")
421 host.checks_in_progress = []
422 host.act_depend_of = [] # ignore the router
423 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
424 svc.checks_in_progress = []
425 svc.act_depend_of = [] # no hostchecks on critical checkresults
426 #--------------------------------------------------------------
427 # initialize host/service state
428 #--------------------------------------------------------------
429 self.scheduler_loop(1, [[host, 0, 'UP']])
430 print "- 1 x OK -------------------------------------"
431 self.scheduler_loop(1, [[svc, 0, 'OK']])
432 self.assert_(host.current_notification_number == 0)
434 #--------------------------------------------------------------
435 # first check the normal behavior
436 # service reaches hard;2
437 # at the end there must be 3 actions: eventhandler hard,
438 # master notification and contact notification
439 #--------------------------------------------------------------
440 print "- 3 x DOWN get hard -------------------------------------"
441 self.scheduler_loop(3, [[host, 2, 'DOWN']])
442 self.assert_(host.current_notification_number == 1)
443 self.assert_(self.count_actions() == 3)
444 self.assert_(self.log_match(7, 'HOST NOTIFICATION'))
445 self.show_and_clear_logs()
446 self.show_and_clear_actions()
447 # clean up
448 self.scheduler_loop(1, [[host, 0, 'UP']])
449 self.clear_logs()
450 self.clear_actions()
452 #--------------------------------------------------------------
453 # service reaches soft;1
454 # there must not be any notification
455 #--------------------------------------------------------------
456 print "- 1 x BAD get soft -------------------------------------"
457 self.scheduler_loop(1, [[host, 2, 'DOWN']])
458 self.assert_(host.current_notification_number == 0)
460 #--------------------------------------------------------------
461 # someone acknowledges the problem before a notification goes out
462 #--------------------------------------------------------------
463 self.assert_(not host.problem_has_been_acknowledged)
464 now = time.time()
465 cmd = "[%lu] ACKNOWLEDGE_HOST_PROBLEM;test_host_0;1;1;0;lausser;blablub" % now
466 self.sched.run_external_command(cmd)
467 self.sched.get_new_actions()
468 self.worker_loop()
469 self.assert_(host.problem_has_been_acknowledged)
470 self.assert_(self.log_match(3, 'ACKNOWLEDGEMENT \(DOWN\)'))
471 self.show_and_clear_logs()
472 self.show_actions()
474 #--------------------------------------------------------------
475 # service reaches hard;2
476 # a notification must have been created but blocked
477 # log for alert soft2, hard3 and log for eventhandler soft2, hard3
478 # eventhandler hard3 (eventhandler soft2 is already zombied when
479 # the workerloop is finished
480 #--------------------------------------------------------------
481 print "- 2 x BAD get hard -------------------------------------"
482 self.scheduler_loop(2, [[host, 2, 'DOWN']])
483 self.show_logs()
484 self.show_actions()
485 self.assert_(self.count_logs() == 4)
486 self.assert_(self.count_actions() == 2)
487 self.assert_(host.current_notification_number == 0)
488 self.show_and_clear_logs()
489 self.show_actions()
491 #--------------------------------------------------------------
492 # recover
493 # the acknowledgement must have been removed automatically
494 # recover notifications are only sent to contacts which
495 # received a critical/warning notification
496 #--------------------------------------------------------------
497 self.scheduler_loop(1, [[host, 0, 'UP']])
498 print "- 1 x OK recover"
499 self.show_logs()
500 self.show_actions()
501 self.assert_(self.count_logs() == 2) # alert, eventhndlr, notification
502 self.assert_(self.count_actions() == 2) # evt, master notif, contact notif
503 self.assert_(not host.problem_has_been_acknowledged)
504 self.assert_(host.current_notification_number == 0)
505 self.show_and_clear_logs()
506 self.show_and_clear_actions()
509 def test_ack_hard_host(self):
510 self.print_header()
511 now = time.time()
512 host = self.sched.hosts.find_by_name("test_host_0")
513 host.checks_in_progress = []
514 host.act_depend_of = [] # ignore the router
515 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
516 svc.checks_in_progress = []
517 svc.act_depend_of = [] # no hostchecks on critical checkresults
518 #--------------------------------------------------------------
519 # initialize host/service state
520 #--------------------------------------------------------------
521 self.scheduler_loop(1, [[host, 0, 'UP']])
522 print "- 1 x OK -------------------------------------"
523 self.scheduler_loop(1, [[svc, 0, 'OK']])
524 self.assert_(host.current_notification_number == 0)
526 #--------------------------------------------------------------
527 # first check the normal behavior
528 # service reaches hard;2
529 # at the end there must be 3 actions: eventhandler hard,
530 # master notification and contact notification
531 #--------------------------------------------------------------
532 print "- 2 x BAD get hard -------------------------------------"
533 self.scheduler_loop(3, [[host, 2, 'DOWN']])
534 self.assert_(host.current_notification_number == 1)
535 self.assert_(self.count_actions() == 3)
536 self.assert_(self.log_match(7, 'HOST NOTIFICATION'))
537 self.show_and_clear_logs()
538 self.show_actions()
540 #--------------------------------------------------------------
541 # stay hard and wait for the second notification (notification_interval)
542 #--------------------------------------------------------------
543 print "- 2 x BAD stay hard -------------------------------------"
544 self.scheduler_loop(2, [[host, 2, 'DOWN']], do_sleep=True)
545 self.show_and_clear_logs()
546 self.show_actions()
547 self.assert_(host.current_notification_number == 2)
549 #--------------------------------------------------------------
550 # admin wakes up and acknowledges the problem
551 # the ACK is the only log message
552 # a master notification is still around, but can't be sent
553 #--------------------------------------------------------------
554 self.assert_(not host.problem_has_been_acknowledged)
555 now = time.time()
556 cmd = "[%lu] ACKNOWLEDGE_HOST_PROBLEM;test_host_0;1;1;0;lausser;blablub" % now
557 self.sched.run_external_command(cmd)
558 self.sched.get_new_actions()
559 self.worker_loop()
560 self.assert_(host.problem_has_been_acknowledged)
561 self.assert_(self.log_match(1, 'ACKNOWLEDGEMENT \(DOWN\)'))
562 self.scheduler_loop(2, [[host, 2, 'DOWN']], do_sleep=True)
563 self.assert_(self.count_logs() == 1)
564 self.assert_(self.count_actions() == 1)
565 self.show_and_clear_logs()
566 self.show_actions()
568 #--------------------------------------------------------------
569 # remove acknowledgement
570 # now notifications are sent again
571 #--------------------------------------------------------------
572 now = time.time()
573 cmd = "[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;test_host_0" % now
574 self.sched.run_external_command(cmd)
575 self.sched.get_new_actions()
576 self.worker_loop()
577 # the contact notification was sent immediately (t_to_go)
578 self.assert_(not host.problem_has_been_acknowledged)
579 self.scheduler_loop(2, [[host, 2, 'DOWN']], do_sleep=True)
580 self.show_logs()
581 self.show_actions()
582 self.assert_(self.log_match(1, 'HOST NOTIFICATION'))
583 self.assert_(self.log_match(2, 'HOST NOTIFICATION'))
584 self.assert_(self.count_logs() == 2)
585 self.assert_(self.count_actions() == 2) # master sched, contact zombie
586 self.assert_(host.current_notification_number == 4)
587 self.show_and_clear_logs()
588 self.show_actions()
590 #--------------------------------------------------------------
591 # recover
592 # the acknowledgement must have been removed automatically
593 #--------------------------------------------------------------
594 self.scheduler_loop(1, [[host, 0, 'GOOD']])
595 print "- 1 x OK recover"
596 self.show_logs()
597 self.show_actions()
598 self.assert_(self.count_logs() == 3) # alert, eventhndlr, notification
599 self.assert_(self.count_actions() == 3) # evt, master notif, contact notif
600 self.assert_(not host.problem_has_been_acknowledged)
601 self.assert_(host.current_notification_number == 0)
602 self.show_and_clear_logs()
603 self.show_and_clear_actions()
606 def test_unack_removes_comments(self):
607 # critical
608 # ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;2;1;1;test_contact_alias;ackweb6
609 # ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;2;1;1;test_contact_alias;ackweb6
610 # ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;2;1;0;test_contact_alias;acknull
611 # now remove the ack
612 # the first two comments remain. So persistent not only means "survice a reboot"
613 # but also "stay after the ack has been deleted"
614 self.print_header()
615 now = time.time()
616 host = self.sched.hosts.find_by_name("test_host_0")
617 host.checks_in_progress = []
618 host.act_depend_of = [] # ignore the router
619 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
620 svc.checks_in_progress = []
621 svc.act_depend_of = [] # no hostchecks on critical checkresults
622 #--------------------------------------------------------------
623 # initialize host/service state
624 #--------------------------------------------------------------
625 self.scheduler_loop(1, [[host, 0, 'UP']])
626 print "- 1 x OK -------------------------------------"
627 self.scheduler_loop(1, [[svc, 0, 'OK']])
628 self.assert_(svc.current_notification_number == 0)
630 #--------------------------------------------------------------
631 # first check the normal behavior
632 # service reaches hard;2
633 # at the end there must be 3 actions: eventhandler hard,
634 # master notification and contact notification
635 #--------------------------------------------------------------
636 print "- 2 x BAD get hard -------------------------------------"
637 self.scheduler_loop(2, [[svc, 2, 'BAD']])
638 self.assert_(svc.current_notification_number == 1)
639 self.assert_(self.count_actions() == 3)
640 self.assert_(self.log_match(5, 'SERVICE NOTIFICATION'))
641 self.show_and_clear_logs()
642 self.show_actions()
644 #--------------------------------------------------------------
645 # stay hard and wait for the second notification (notification_interval)
646 #--------------------------------------------------------------
647 print "- 2 x BAD stay hard -------------------------------------"
648 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
649 self.show_and_clear_logs()
650 self.show_actions()
651 self.assert_(svc.current_notification_number == 2)
653 #--------------------------------------------------------------
654 # admin wakes up and acknowledges the problem
655 # the ACK is the only log message
656 # a master notification is still around, but can't be sent
657 #--------------------------------------------------------------
658 self.assert_(not svc.problem_has_been_acknowledged)
659 now = time.time()
660 cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;2;1;1;lausser;blablub1" % now
661 self.sched.run_external_command(cmd)
662 self.sched.get_new_actions()
663 self.worker_loop()
664 now = time.time()
665 cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;2;1;1;lausser;blablub2" % now
666 self.sched.run_external_command(cmd)
667 self.sched.get_new_actions()
668 self.worker_loop()
669 now = time.time()
670 cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;2;1;0;lausser;blablub3" % now
671 self.sched.run_external_command(cmd)
672 self.sched.get_new_actions()
673 self.worker_loop()
674 self.assert_(svc.problem_has_been_acknowledged)
675 self.assert_(self.log_match(1, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
676 self.assert_(self.log_match(2, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
677 self.assert_(self.log_match(3, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
678 self.scheduler_loop(1, [[svc, 2, 'BAD']], do_sleep=True)
679 self.assert_(self.count_actions() == 1)
680 self.show_and_clear_logs()
681 self.show_actions()
682 self.assert_(len(svc.comments) == 3)
683 print "- 2 x BAD stay hard -------------------------------------"
684 self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=True)
685 self.show_and_clear_logs()
686 self.show_actions()
687 self.assert_(svc.current_notification_number == 2)
689 #--------------------------------------------------------------
690 # remove the ack. the 2 persistent comments must remain
691 #--------------------------------------------------------------
692 now = time.time()
693 cmd = "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;test_host_0;test_ok_0" % now
694 self.sched.run_external_command(cmd)
695 self.sched.get_new_actions()
696 self.worker_loop()
697 self.assert_(not svc.problem_has_been_acknowledged)
698 self.assert_(len(svc.comments) == 2)
699 self.assert_(svc.comments[0].comment == 'blablub1')
700 self.assert_(svc.comments[1].comment == 'blablub2')
703 # service is critical, notification is out
704 # click on ack without setting the sticky checkbox in the webinterface
705 # EXTERNAL COMMAND: ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;0;test_contact_alias;weback
706 # now service is acknowledged and has a comment
707 # silence...
708 # service is warning
709 # notification is sent
710 # acknowledgement and comment have disappeared
712 # service is critical, notification is out
713 # send external command through the pipe 3 times
714 # ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;0;test_contact_alias;weback
715 # ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;0;test_contact_alias;weback
716 # ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;0;test_contact_alias;weback
717 # now service is acknowledged and has 3 comments
718 # silence...
719 # service is warning
720 # notification is sent
721 # acknowledgement and comments have disappeared
724 if __name__ == '__main__':
725 unittest.main()