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 TestDiscoveryConf(ShinkenTest
):
30 #Uncomment this is you want to use a specific configuration
33 self
.setup_with_file('etc/nagios_discovery_def.cfg')
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')
46 # Should not match this
47 self
.assert_(genhttp
.is_matching(key
, value
) == False)
48 # But should match this one
51 self
.assert_(genhttp
.is_matching(key
, value
) == True)
54 # Low look for a list of matchings
55 l
= [('openports', '80'), ('os', 'windows')]
57 self
.assert_(genhttp
.is_matching_disco_datas(l
) == True)
59 l
= [('openports', '80'), ('os', 'windows'), ('super', 'man')]
60 self
.assert_(genhttp
.is_matching_disco_datas(l
) == True)
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')
70 l
= [('openports', '80'), ('os', 'linux')]
71 self
.assert_(genhttpnowin
.is_matching_disco_datas(l
) == True)
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)
83 self
.assert_(genhttpstrict
.is_matching(key
, value
) == True)
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)
101 for i
in xrange(1, 5):
102 nmap
.check_finished()
103 if nmap
.is_finished():
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__':