Merge branch 'master' of ssh://naparuba@shinken.git.sourceforge.net/gitroot/shinken...
[shinken.git] / test / test_notifway.py
blob5ad1c14a772c2b8172be7c1529b5e46f80f09e2c
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 #setUp is in shinken_test
31 def setUp(self):
32 self.setup_with_file('etc/nagios_notif_way.cfg')
35 #Change ME :)
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"
42 now = time.time()
43 contact = self.sched.contacts.find_by_name("test_contact")
44 print "The contact", 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 # And check the criticity values
57 self.assert_(email_in_day.min_criticity == 0)
58 self.assert_(sms_the_night.min_criticity == 5)
61 print "Contact notification way(s) :"
62 for nw in contact.notificationways:
63 print "\t", nw.notificationway_name
65 contact_simple = self.sched.contacts.find_by_name("test_contact_simple")
66 #It's the created notifway for this simple contact
67 test_contact_simple_inner_notificationway = self.sched.notificationways.find_by_name("test_contact_simple_inner_notificationway")
68 print "Simple contact"
69 for nw in contact_simple.notificationways:
70 print "\t", nw.notificationway_name
71 self.assert_(test_contact_simple_inner_notificationway in contact_simple.notificationways)
73 # we take as criticity a huge value from now
74 huge_criticity = 5
76 #Now all want* functions
77 #First is ok with warning alerts
78 self.assert_(email_in_day.want_service_notification(now, 'WARNING', 'PROBLEM', huge_criticity) == True)
80 #But a SMS is now WAY for warning. When we sleep, we wake up for critical only guy!
81 self.assert_(sms_the_night.want_service_notification(now, 'WARNING', 'PROBLEM', huge_criticity) == False)
83 #Same with contacts now
84 #First is ok for warning in the email_in_day nw
85 self.assert_(contact.want_service_notification(now, 'WARNING', 'PROBLEM', huge_criticity) == True)
86 #Simple is not ok for it
87 self.assert_(contact_simple.want_service_notification(now, 'WARNING', 'PROBLEM', huge_criticity) == False)
89 #Then for host notification
90 #First is ok for warning in the email_in_day nw
91 self.assert_(contact.want_host_notification(now, 'FLAPPING', 'PROBLEM', huge_criticity) == True)
92 #Simple is not ok for it
93 self.assert_(contact_simple.want_host_notification(now, 'FLAPPING', 'PROBLEM', huge_criticity) == False)
95 # And now we check that we refuse SMS for a low level criticity
96 # I do not want to be awaken by a dev server! When I sleep, I sleep!
97 # (and my wife will kill me if I do...)
99 # We take the EMAIL test because SMS got the night ony, so we take a very low value for criticity here
100 self.assert_(email_in_day.want_service_notification(now, 'WARNING', 'PROBLEM', -1) == False)
104 if __name__ == '__main__':
105 unittest.main()