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 TestConfig(ShinkenTest
):
30 #setUp is in shinken_test
32 self
.setup_with_file('etc/nagios_notif_way.cfg')
36 def test_contact_def(self
):
38 # Config is not correct because of a wrong relative path
39 # in the main config file
41 print "Get the contact"
43 contact
= self
.sched
.contacts
.find_by_name("test_contact")
44 print "The service", contact
.__dict
__
46 print "All notification Way :"
47 for nw
in self
.sched
.notificationways
:
48 print "\t", nw
.notificationway_name
50 email_in_day
= self
.sched
.notificationways
.find_by_name('email_in_day')
51 self
.assert_(email_in_day
in contact
.notificationways
)
53 sms_the_night
= self
.sched
.notificationways
.find_by_name('sms_the_night')
54 self
.assert_(sms_the_night
in contact
.notificationways
)
56 print "Contact notification way(s) :"
57 for nw
in contact
.notificationways
:
58 print "\t", nw
.notificationway_name
60 contact_simple
= self
.sched
.contacts
.find_by_name("test_contact_simple")
61 #It's the created notifway for this simple contact
62 test_contact_simple_inner_notificationway
= self
.sched
.notificationways
.find_by_name("test_contact_simple_inner_notificationway")
63 print "Simple contact"
64 for nw
in contact_simple
.notificationways
:
65 print "\t", nw
.notificationway_name
66 self
.assert_(test_contact_simple_inner_notificationway
in contact_simple
.notificationways
)
68 #Now all want* functions
69 #First is ok with warning alerts
70 self
.assert_(email_in_day
.want_service_notification(now
, 'WARNING', 'PROBLEM') == True)
71 #But a SMS is now WAY for warning. When we sleep, we wake up for critical only guy!
72 self
.assert_(sms_the_night
.want_service_notification(now
, 'WARNING', 'PROBLEM') == False)
74 #Same with contacts now
75 #First is ok for warning in the email_in_day nw
76 self
.assert_(contact
.want_service_notification(now
, 'WARNING', 'PROBLEM') == True)
77 #Simple is not ok for it
78 self
.assert_(contact_simple
.want_service_notification(now
, 'WARNING', 'PROBLEM') == False)
80 #Then for host notification
81 #First is ok for warning in the email_in_day nw
82 self
.assert_(contact
.want_host_notification(now
, 'FLAPPING', 'PROBLEM') == True)
83 #Simple is not ok for it
84 self
.assert_(contact_simple
.want_host_notification(now
, 'FLAPPING', 'PROBLEM') == False)
88 if __name__
== '__main__':