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/>.
23 # This file is used to test reading and processing of config files
28 from shinken_test
import *
29 sys
.path
.append("../shinken/modules")
30 from host_perfdata_broker
import *
31 from shinken
.brok
import Brok
33 class TestConfig(ShinkenTest
):
34 #setUp is in shinken_test
37 def test_host_perfdata(self
):
38 print self
.conf
.modules
41 for m
in self
.conf
.modules
:
42 if m
.module_type
== 'host_perfdata':
44 self
.assert_(mod
!= None)
45 self
.assert_(mod
.path
== '/dev/shm/host-perfdata')
46 self
.assert_(mod
.module_name
== 'Host-Perfdata')
47 self
.assert_(mod
.mode
== 'a')
48 #Warning, the r (raw) is important here
49 print "Tempalte%stoto" % mod
.template
50 # self.assert_(mod.template == r'$LASTHOSTCHECK\t$HOSTNAME$\t$HOSTOUTPUT$\t$HOSTSTATE$\t$HOSTPERFDATA$\n')
57 sl
= get_instance(mod
)
61 sl
.properties
['to_queue'] = None
63 svc
= self
.sched
.hosts
.find_by_name("test_host_0")
66 self
.scheduler_loop(1, [[svc
, 2, 'BAD | value1=0 value2=0']])
67 #manage all host check result broks
68 for b
in self
.sched
.broks
.values():
69 if b
.type == 'host_check_result':
76 comparison
= '%d\t%s\t%s\t%s\t%s\n' % (t
, "test_host_0", 'BAD ', 'DOWN', ' value1=0 value2=0')
77 print "Comparison:", comparison
78 self
.assert_(buf
== comparison
)
82 #Now change with a new template
83 #and direct in the instance (do not do this in prod :) )
84 mod
.template
= '$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\t$HOSTSTATE$\n'
85 sl2
= get_instance(mod
)
90 self
.scheduler_loop(1, [[svc
, 2, 'BAD | value1=0 value2=0']])
91 #manage all host check result broks
92 for b
in self
.sched
.broks
.values():
93 if b
.type == 'host_check_result':
99 comparison
= '%d\t%s\t%s\t%s\t%s\n' % (t
, "test_host_0", 'BAD ', ' value1=0 value2=0', 'DOWN')
100 print "Comparison:", comparison
101 self
.assert_(buf
== comparison
)
106 if __name__
== '__main__':