*Enh : make the hook_point in the daemon class
[shinken.git] / test / test_obsess.py
blobb1820c3bbace6553e6699ec1e87ff3944817c3fd
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 setUp(self):
32 self.setup_with_file('etc/nagios_obsess.cfg')
35 def test_ocsp(self):
36 self.print_header()
37 # retry_interval 2
38 # critical notification
39 # run loop -> another notification
40 now = time.time()
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)
57 now = time.time()
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()
61 self.worker_loop()
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)
70 now = time.time()
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()
74 self.worker_loop()
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)
83 now = time.time()
84 cmd = "[%lu] START_OBSESSING_OVER_SVC_CHECKS" % now
85 self.sched.run_external_command(cmd)
86 self.sched.get_new_actions()
87 self.worker_loop()
88 self.assert_(svc.obsess_over_service)
89 self.assert_(svc.__class__.obsess_over)
91 now = time.time()
92 cmd = "[%lu] STOP_OBSESSING_OVER_SVC_CHECKS" % now
93 self.sched.run_external_command(cmd)
94 self.sched.get_new_actions()
95 self.worker_loop()
96 self.assert_(svc.obsess_over_service)
97 self.assert_(not svc.__class__.obsess_over)
100 def test_ochp(self):
101 self.print_header()
102 # retry_interval 2
103 # critical notification
104 # run loop -> another notification
105 now = time.time()
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']])
116 self.show_actions()
117 self.assert_(self.count_actions() == 1)
118 self.scheduler_loop(1, [[router, 0, 'OK']])
119 self.show_actions()
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__':
133 unittest.main()