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 reading and processing of config files
26 from shinken_test
import *
29 class TestConfig(ShinkenTest
):
31 self
.setup_with_file('etc/nagios_resultmodulation.cfg')
34 return self
.sched
.services
.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
37 return self
.sched
.hosts
.find_by_name("test_host_0")
41 return self
.sched
.hosts
.find_by_name("test_router_0")
44 def test_service_resultmodulation(self
):
46 host
= self
.get_host()
47 router
= self
.get_router()
49 self
.scheduler_loop(2, [[host
, 0, 'UP | value1=1 value2=2'], [svc
, 2, 'BAD | value1=0 value2=0'], ])
50 self
.assert_(host
.state
== 'UP')
51 self
.assert_(host
.state_type
== 'HARD')
53 #This service got a result modulation. So Criticals are in fact
54 #Warnings. So even with some CRITICAL (2), it must be warning
55 self
.assert_(svc
.state
== 'WARNING')
57 #If we remove the resultmodulations, we should have theclassic behavior
58 svc
.resultmodulations
= []
59 self
.scheduler_loop(2, [[host
, 0, 'UP | value1=1 value2=2'], [svc
, 2, 'BAD | value1=0 value2=0']])
60 self
.assert_(svc
.state
== 'CRITICAL')
62 #Now look for the inheritaed thing
63 #resultmodulation is a inplicit inherited parameter
64 #and router define it, but not test_router_0/test_ok_0. So this service should also be impacted
65 svc2
= self
.sched
.services
.find_srv_by_name_and_hostname("test_router_0", "test_ok_0")
66 self
.assert_(svc2
.resultmodulations
== router
.resultmodulations
)
68 self
.scheduler_loop(2, [[svc2
, 2, 'BAD | value1=0 value2=0']])
69 self
.assert_(svc2
.state
== 'WARNING')
72 if __name__
== '__main__':