Add : service without host will be just droped, like Nagios.
[shinken.git] / test / test_commands_perfdata.py
blob0b7aa30389f7209703f63266965cd331943eb8b4
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_commands_perfdata.cfg')
35 def test_service_perfdata_command(self):
36 self.print_header()
38 #We want an eventhandelr (the perfdata command) to be put in the actions dict
39 #after we got a service check
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 print "Service perfdata command", svc.__class__.perfdata_command, type(svc.__class__.perfdata_command)
51 #We do not want to be just a string but a real command
52 self.assert_(not isinstance(svc.__class__.perfdata_command, str))
53 print svc.__class__.perfdata_command.__class__.my_type
54 self.assert_(svc.__class__.perfdata_command.__class__.my_type == 'CommandCall')
55 self.scheduler_loop(1, [[svc, 0, 'OK | bibi=99%']])
56 print "Actions", self.sched.actions
57 self.assert_(self.count_actions() == 1)
59 #Ok now I disable the perfdata
60 now = time.time()
61 cmd = "[%lu] DISABLE_PERFORMANCE_DATA" % now
62 self.sched.run_external_command(cmd)
63 self.scheduler_loop(1, [[svc, 0, 'OK | bibi=99%']])
64 print "Actions", self.sched.actions
65 self.assert_(self.count_actions() == 0)
68 def test_host_perfdata_command(self):
69 #We want an eventhandelr (the perfdata command) to be put in the actions dict
70 #after we got a service check
71 now = time.time()
72 host = self.sched.hosts.find_by_name("test_host_0")
73 host.checks_in_progress = []
74 host.act_depend_of = [] # ignore the router
75 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
76 svc.checks_in_progress = []
77 svc.act_depend_of = [] # no hostchecks on critical checkresults
78 #--------------------------------------------------------------
79 # initialize host/service state
80 #--------------------------------------------------------------
81 print "Host perfdata command", host.__class__.perfdata_command, type(host.__class__.perfdata_command)
82 #We do not want to be just a string but a real command
83 self.assert_(not isinstance(host.__class__.perfdata_command, str))
84 print host.__class__.perfdata_command.__class__.my_type
85 self.assert_(host.__class__.perfdata_command.__class__.my_type == 'CommandCall')
86 self.scheduler_loop(1, [[host, 0, 'UP | bibi=99%']])
87 print "Actions", self.sched.actions
88 self.assert_(self.count_actions() == 1)
90 #Ok now I disable the perfdata
91 now = time.time()
92 cmd = "[%lu] DISABLE_PERFORMANCE_DATA" % now
93 self.sched.run_external_command(cmd)
94 self.scheduler_loop(1, [[host, 0, 'UP | bibi=99%']])
95 print "Actions", self.sched.actions
96 self.assert_(self.count_actions() == 0)
99 if __name__ == '__main__':
100 unittest.main()