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
27 from shinken_test
import *
29 class TestConfig(ShinkenTest
):
32 self
.setup_with_file('etc/nagios_obsess.cfg')
38 # critical notification
39 # run loop -> another notification
41 host
= self
.sched
.hosts
.find_by_name("test_host_0")
42 host
.checks_in_progress
= []
43 host
.act_depend_of
= [] # ignore the router
44 svc
= self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
45 svc
.checks_in_progress
= []
46 svc
.act_depend_of
= [] # no hostchecks on critical checkresults
47 #--------------------------------------------------------------
48 # initialize host/service state
49 #--------------------------------------------------------------
50 self
.assert_(svc
.obsess_over_service
)
51 self
.assert_(svc
.__class
__.obsess_over
)
52 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
53 self
.assert_(self
.count_actions() == 1)
54 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
55 self
.assert_(self
.count_actions() == 1)
58 cmd
= "[%lu] STOP_OBSESSING_OVER_SVC;test_host_0;test_ok_0" % now
59 self
.sched
.run_external_command(cmd
)
60 self
.sched
.get_new_actions()
62 self
.assert_(not svc
.obsess_over_service
)
63 self
.assert_(svc
.__class
__.obsess_over
)
64 self
.sched
.run_external_command(cmd
)
65 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
66 self
.assert_(self
.count_actions() == 0)
67 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
68 self
.assert_(self
.count_actions() == 0)
71 cmd
= "[%lu] START_OBSESSING_OVER_SVC;test_host_0;test_ok_0" % now
72 self
.sched
.run_external_command(cmd
)
73 self
.sched
.get_new_actions()
75 self
.assert_(svc
.obsess_over_service
)
76 self
.assert_(svc
.__class
__.obsess_over
)
77 self
.sched
.run_external_command(cmd
)
78 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
79 self
.assert_(self
.count_actions() == 1)
80 self
.scheduler_loop(1, [[svc
, 0, 'OK']])
81 self
.assert_(self
.count_actions() == 1)
84 cmd
= "[%lu] START_OBSESSING_OVER_SVC_CHECKS" % now
85 self
.sched
.run_external_command(cmd
)
86 self
.sched
.get_new_actions()
88 self
.assert_(svc
.obsess_over_service
)
89 self
.assert_(svc
.__class
__.obsess_over
)
92 cmd
= "[%lu] STOP_OBSESSING_OVER_SVC_CHECKS" % now
93 self
.sched
.run_external_command(cmd
)
94 self
.sched
.get_new_actions()
96 self
.assert_(svc
.obsess_over_service
)
97 self
.assert_(not svc
.__class
__.obsess_over
)
103 # critical notification
104 # run loop -> another notification
106 host
= self
.sched
.hosts
.find_by_name("test_host_0")
107 host
.checks_in_progress
= []
108 host
.act_depend_of
= [] # ignore the router
109 router
= self
.sched
.hosts
.find_by_name("test_router_0")
110 router
.checks_in_progress
= []
111 router
.act_depend_of
= [] # ignore the router
112 #--------------------------------------------------------------
113 # initialize host/service state
114 #--------------------------------------------------------------
115 self
.scheduler_loop(1, [[host
, 0, 'OK']])
117 self
.assert_(self
.count_actions() == 1)
118 self
.scheduler_loop(1, [[router
, 0, 'OK']])
120 print "host", host
.obsess_over
121 print "rout", router
.obsess_over
122 print "host", host
.obsess_over_host
123 print "rout", router
.obsess_over_host
124 self
.assert_(self
.count_actions() == 0)
125 self
.assert_(host
.obsess_over_host
)
126 self
.assert_(not router
.obsess_over_host
)
127 # the router does not obsess (host definition)
128 # but it's class does (nagios.cfg)
129 self
.assert_(router
.__class
__.obsess_over
)
132 if __name__
== '__main__':