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
27 from shinken_test
import unittest
, ShinkenTest
30 class TestConfig(ShinkenTest
):
31 #setUp is in shinken_test
33 self
.setup_with_file('etc/nagios_notif_way.cfg')
37 def test_contact_def(self
):
39 # Config is not correct because of a wrong relative path
40 # in the main config file
42 print "Get the contact"
44 contact
= self
.sched
.contacts
.find_by_name("test_contact")
45 print "The contact", contact
.__dict
__
47 print "All notification Way :"
48 for nw
in self
.sched
.notificationways
:
49 print "\t", nw
.notificationway_name
51 email_in_day
= self
.sched
.notificationways
.find_by_name('email_in_day')
52 self
.assert_(email_in_day
in contact
.notificationways
)
54 sms_the_night
= self
.sched
.notificationways
.find_by_name('sms_the_night')
55 self
.assert_(sms_the_night
in contact
.notificationways
)
57 # And check the criticity values
58 self
.assert_(email_in_day
.min_criticity
== 0)
59 self
.assert_(sms_the_night
.min_criticity
== 5)
62 print "Contact notification way(s) :"
63 for nw
in contact
.notificationways
:
64 print "\t", nw
.notificationway_name
66 contact_simple
= self
.sched
.contacts
.find_by_name("test_contact_simple")
67 #It's the created notifway for this simple contact
68 test_contact_simple_inner_notificationway
= self
.sched
.notificationways
.find_by_name("test_contact_simple_inner_notificationway")
69 print "Simple contact"
70 for nw
in contact_simple
.notificationways
:
71 print "\t", nw
.notificationway_name
72 self
.assert_(test_contact_simple_inner_notificationway
in contact_simple
.notificationways
)
74 # we take as criticity a huge value from now
77 #Now all want* functions
78 #First is ok with warning alerts
79 self
.assert_(email_in_day
.want_service_notification(now
, 'WARNING', 'PROBLEM', huge_criticity
) == True)
81 #But a SMS is now WAY for warning. When we sleep, we wake up for critical only guy!
82 self
.assert_(sms_the_night
.want_service_notification(now
, 'WARNING', 'PROBLEM', huge_criticity
) == False)
84 #Same with contacts now
85 #First is ok for warning in the email_in_day nw
86 self
.assert_(contact
.want_service_notification(now
, 'WARNING', 'PROBLEM', huge_criticity
) == True)
87 #Simple is not ok for it
88 self
.assert_(contact_simple
.want_service_notification(now
, 'WARNING', 'PROBLEM', huge_criticity
) == False)
90 #Then for host notification
91 #First is ok for warning in the email_in_day nw
92 self
.assert_(contact
.want_host_notification(now
, 'FLAPPING', 'PROBLEM', huge_criticity
) == True)
93 #Simple is not ok for it
94 self
.assert_(contact_simple
.want_host_notification(now
, 'FLAPPING', 'PROBLEM', huge_criticity
) == False)
96 # And now we check that we refuse SMS for a low level criticity
97 # I do not want to be awaken by a dev server! When I sleep, I sleep!
98 # (and my wife will kill me if I do...)
100 # We take the EMAIL test because SMS got the night ony, so we take a very low value for criticity here
101 self
.assert_(email_in_day
.want_service_notification(now
, 'WARNING', 'PROBLEM', -1) == False)
105 if __name__
== '__main__':