Merge branch 'master' of ssh://naparuba@shinken.git.sourceforge.net/gitroot/shinken...
[shinken.git] / test / test_service_generators.py
blob630419b07a196e56003d7f50f11e2d323e36f7c9
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
25 #It's ugly I know....
26 from shinken_test import *
29 class TestConfig(ShinkenTest):
30 #Uncomment this is you want to use a specific configuration
31 #for your test
32 def setUp(self):
33 self.setup_with_file('etc/nagios_service_generators.cfg')
36 #Change ME :)
37 def test_service_generators(self):
39 host = self.sched.hosts.find_by_name("test_host_0")
40 host.checks_in_progress = []
41 host.act_depend_of = [] # ignore the router
42 router = self.sched.hosts.find_by_name("test_router_0")
43 router.checks_in_progress = []
44 router.act_depend_of = [] # ignore the router
45 svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
47 print "All service of", "test_host_0"
48 for s in host.services:
49 print s.get_name()
50 #We ask for 4 services with our disks :)
51 svc_c = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "Generated Service C")
52 svc_d = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "Generated Service D")
53 svc_e = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "Generated Service E")
54 svc_f = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "Generated Service F")
55 svc_g = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "Generated Service G")
57 self.assert_(svc_c != None)
58 self.assert_(svc_d != None)
59 self.assert_(svc_e != None)
60 self.assert_(svc_f != None)
61 self.assert_(svc_g != None)
63 #two classics
64 self.assert_(svc_c.check_command.args == ['C', '80%', '90%'])
65 self.assert_(svc_d.check_command.args == ['D', '95%', '70%'])
66 #a default parameters
67 self.assert_(svc_e.check_command.args == ['E', '38%', '24%'])
68 #and another one
69 self.assert_(svc_f.check_command.args == ['F', '95%', '70%'])
70 #and the tricky last one (with no value :) )
71 self.assert_(svc_g.check_command.args == ['G', '38%', '24%'])
74 #Change ME :)
75 def test_service_generators_key_generator(self):
77 host = self.sched.hosts.find_by_name("sw_0")
78 host.checks_in_progress = []
79 host.act_depend_of = [] # ignore the router
81 print "All service of", "sw_0"
82 for s in host.services:
83 print s.get_name()
85 #We ask for our 6*46 + 6 services with our ports :)
86 #_ports Unit [1-6] Port [0-46]$(80%!90%)$,Unit [1-6] Port 47$(80%!90%)$
87 for unit_id in xrange(1, 7):
88 for port_id in xrange(0, 47):
89 n = "Unit %d Port %d" % (unit_id, port_id)
90 print "Look for port", 'Generated Service ' + n
91 svc = self.sched.services.find_srv_by_name_and_hostname("sw_0", 'Generated Service ' + n)
92 self.assert_(svc != None)
93 for unit_id in xrange(1, 7):
94 port_id = 47
95 n = "Unit %d Port %d" % (unit_id, port_id)
96 print "Look for port", 'Generated Service ' + n
97 svc = self.sched.services.find_srv_by_name_and_hostname("sw_0", 'Generated Service ' + n)
98 self.assert_(svc != None)
102 def test_service_generators_array(self):
104 host = self.sched.hosts.find_by_name("sw_1")
105 host.checks_in_progress = []
106 host.act_depend_of = [] # ignore the router
108 print "All service of", "sw_1"
109 for s in host.services:
110 print s.get_name()
112 svc = self.sched.services.find_srv_by_name_and_hostname("sw_1", 'Generated Service Gigabit0/1')
113 self.assert_(svc != None)
114 self.assert_(svc.check_command.call == 'check_service!1!80%!90%')
116 svc = self.sched.services.find_srv_by_name_and_hostname("sw_1", 'Generated Service Gigabit0/2')
117 self.assert_(svc != None)
118 self.assert_(svc.check_command.call == 'check_service!2!80%!90%')
120 svc = self.sched.services.find_srv_by_name_and_hostname("sw_1", 'Generated Service Ethernet0/1')
121 self.assert_(svc != None)
122 self.assert_(svc.check_command.call == 'check_service!3!80%!95%')
124 svc = self.sched.services.find_srv_by_name_and_hostname("sw_1", 'Generated Service ISDN1')
125 self.assert_(svc != None)
126 self.assert_(svc.check_command.call == 'check_service!4!80%!95%')
129 if __name__ == '__main__':
130 unittest.main()