Add : first discoveryrun Class.
[shinken.git] / test / test_discovery_def.py
blob9ebd18bc2662a193b8b77c875b3eeafefdcec10b
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.matches['openports'] == '80,443')
41 self.assert_(genhttp.matches['os'] == 'windows')
43 key = 'osversion'
44 value = '2003'
45 # Should not match this
46 self.assert_(genhttp.is_matching(key, value) == False)
47 # But should match this one
48 key = 'openports'
49 value = '80'
50 self.assert_(genhttp.is_matching(key, value) == True)
52 # Low look for a list of matchings
53 l = [('openports', '80'), ('os', 'windows')]
54 # should match this
55 self.assert_(genhttp.is_matching_disco_datas(l) == True)
56 # Match this one too
57 l = [('openports', '80'), ('os', 'windows'), ('super', 'man')]
58 self.assert_(genhttp.is_matching_disco_datas(l) == True)
59 # But not this one
60 l = [('openports', '80')]
61 self.assert_(genhttp.is_matching_disco_datas(l) == False)
64 # Now search the NOT rule
65 genhttpnowin = self.sched.conf.discoveryrules.find_by_name('GenHttpNotWindows')
67 # Should manage this
68 l = [('openports', '80'), ('os', 'linux')]
69 self.assert_(genhttpnowin.is_matching_disco_datas(l) == True)
71 # But NOT this one
72 l = [('openports', '80'), ('os', 'windows')]
73 print "Should NOT match"
74 self.assert_(genhttpnowin.is_matching_disco_datas(l) == False)
77 #Change ME :)
78 def test_look_for_discorun(self):
79 nmap = self.sched.conf.discoveryruns.find_by_name('nmap')
80 self.assert_(nmap != None)
82 if __name__ == '__main__':
83 unittest.main()