Fix : fix hot module under windows test. (at leat I hope...)
[shinken.git] / test / test_discovery_def.py
blobac5b61c4cdfbad361cb31fead1094423bf38c4d0
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 TestDiscoveryConf(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_discovery_def.cfg')
36 #Change ME :)
37 def test_look_for_discorule(self):
38 genhttp = self.sched.conf.discoveryrules.find_by_name('GenHttp')
39 self.assert_(genhttp != None)
40 self.assert_(genhttp.creation_type == 'service')
41 self.assert_(genhttp.matches['openports'] == '80,443')
42 self.assert_(genhttp.matches['os'] == 'windows')
44 key = 'osversion'
45 value = '2003'
46 # Should not match this
47 self.assert_(genhttp.is_matching(key, value) == False)
48 # But should match this one
49 key = 'openports'
50 value = '80'
51 self.assert_(genhttp.is_matching(key, value) == True)
54 # Low look for a list of matchings
55 l = [('openports', '80'), ('os', 'windows')]
56 # should match this
57 self.assert_(genhttp.is_matching_disco_datas(l) == True)
58 # Match this one too
59 l = [('openports', '80'), ('os', 'windows'), ('super', 'man')]
60 self.assert_(genhttp.is_matching_disco_datas(l) == True)
61 # But not this one
62 l = [('openports', '80')]
63 self.assert_(genhttp.is_matching_disco_datas(l) == False)
66 # Now search the NOT rule
67 genhttpnowin = self.sched.conf.discoveryrules.find_by_name('GenHttpNotWindows')
69 # Should manage this
70 l = [('openports', '80'), ('os', 'linux')]
71 self.assert_(genhttpnowin.is_matching_disco_datas(l) == True)
73 # But NOT this one
74 l = [('openports', '80'), ('os', 'windows')]
75 print "Should NOT match"
76 self.assert_(genhttpnowin.is_matching_disco_datas(l) == False)
78 # Now look for strict rule application
79 genhttpstrict = self.sched.conf.discoveryrules.find_by_name('GenHttpStrict')
80 self.assert_(genhttpstrict is not None)
81 key = 'openports'
82 value = '80,443'
83 self.assert_(genhttpstrict.is_matching(key, value) == True)
85 #But NOT this one
86 key = 'openports'
87 value = '800'
88 self.assert_(genhttpstrict.is_matching(key, value) == False)
92 #Look for good definition and call of a discoveryrun
93 def test_look_for_discorun(self):
94 nmap = self.sched.conf.discoveryruns.find_by_name('nmap')
95 self.assert_(nmap != None)
96 nmapcmd = self.sched.conf.commands.find_cmd_by_name('nmap_runner')
97 self.assert_(nmapcmd != None)
98 self.assert_(nmap.discoveryrun_command != None)
99 # Launch it
100 nmap.launch()
101 for i in xrange(1, 5):
102 nmap.check_finished()
103 if nmap.is_finished():
104 break
105 time.sleep(1)
106 print "Exit status", nmap.current_launch.exit_status
107 print "Output", nmap.current_launch.output
108 print "LongOutput", nmap.current_launch.long_output
110 if __name__ == '__main__':
111 unittest.main()