[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Naparuba naparuba at gmail.com
Tue Feb 28 22:13:07 UTC 2012


The following commit has been merged in the debian/master branch:
commit 1cd6f8d10fb11a6501c58e8e5fe677639a3b1c51
Author: Naparuba <naparuba at gmail.com>
Date:   Wed Jan 11 13:44:03 2012 +0100

    Fix :(reported by : lminoza) too much notifications for a contact with multiple notification ways, all where send when just a part of them was able to pass filter.

diff --git a/shinken/objects/contact.py b/shinken/objects/contact.py
index 9899e42..061817f 100644
--- a/shinken/objects/contact.py
+++ b/shinken/objects/contact.py
@@ -105,9 +105,9 @@ class Contact(Item):
         return self.contact_name
 
 
-    #Search for notification_options with state and if t is
-    #in service_notification_period
-    def want_service_notification(self, t, state, type, business_impact):
+    # Search for notification_options with state and if t is
+    # in service_notification_period
+    def want_service_notification(self, t, state, type, business_impact, cmd):
         if not self.service_notifications_enabled:
             return False
 
@@ -116,9 +116,10 @@ class Contact(Item):
             if dt.is_in_effect:
                 return False
 
-        #Now the rest is for sub notificationways. If one is OK, we are ok
+        # Now the rest is for sub notificationways. If one is OK, we are ok
+        # We will filter in another phase
         for nw in self.notificationways:
-            nw_b = nw.want_service_notification(t, state, type, business_impact)
+            nw_b = nw.want_service_notification(t, state, type, business_impact, cmd)
             if nw_b:
                 return True
 
@@ -128,7 +129,7 @@ class Contact(Item):
 
     #Search for notification_options with state and if t is in
     #host_notification_period
-    def want_host_notification(self, t, state, type, business_impact):
+    def want_host_notification(self, t, state, type, business_impact, cmd):
         if not self.host_notifications_enabled:
             return False
 
@@ -137,9 +138,10 @@ class Contact(Item):
             if dt.is_in_effect:
                 return False
 
-        #Now it's all for sub notificationways. If one is OK, we are OK
+        # Now it's all for sub notificationways. If one is OK, we are OK
+        # We will filter in another phase
         for nw in self.notificationways:
-            nw_b = nw.want_host_notification(t, state, type, business_impact)
+            nw_b = nw.want_host_notification(t, state, type, business_impact, cmd)
             if nw_b:
                 return True
 
@@ -150,7 +152,7 @@ class Contact(Item):
     #Call to get our commands to launch a Notification
     def get_notification_commands(self, type):
         r = []
-        #service_notification_commands for service
+        # service_notification_commands for service
         notif_commands_prop = type+'_notification_commands'
         for nw in self.notificationways:
             r.extend(getattr(nw, notif_commands_prop))
diff --git a/shinken/objects/host.py b/shinken/objects/host.py
index 5727c2e..b49aaaa 100644
--- a/shinken/objects/host.py
+++ b/shinken/objects/host.py
@@ -798,7 +798,7 @@ class Host(SchedulingItem):
 
     #See if the notification is launchable (time is OK and contact is OK too)
     def notification_is_blocked_by_contact(self, n, contact):
-        return not contact.want_host_notification(self.last_chk, self.state, n.type, self.business_impact)
+        return not contact.want_host_notification(self.last_chk, self.state, n.type, self.business_impact, n.command_call)
 
 
     #MACRO PART
diff --git a/shinken/objects/notificationway.py b/shinken/objects/notificationway.py
index 9b24e97..301d5c6 100644
--- a/shinken/objects/notificationway.py
+++ b/shinken/objects/notificationway.py
@@ -67,10 +67,15 @@ class NotificationWay(Item):
 
     #Search for notification_options with state and if t is
     #in service_notification_period
-    def want_service_notification(self, t, state, type, business_impact):
+    def want_service_notification(self, t, state, type, business_impact, cmd):
         if not self.service_notifications_enabled:
             return False
 
+        # Maybe the command we ask for are not for us, but for another notification ways
+        # on the same contact. If so, bail out
+        if not cmd in self.service_notification_commands:
+            return False
+
         # If the business_impact is not high enough, we bail out
         if business_impact < self.min_business_impact:
             return False
@@ -100,7 +105,7 @@ class NotificationWay(Item):
 
     #Search for notification_options with state and if t is in
     #host_notification_period
-    def want_host_notification(self, t, state, type, business_impact):
+    def want_host_notification(self, t, state, type, business_impact, cmd):
         if not self.host_notifications_enabled:
             return False
 
@@ -108,6 +113,11 @@ class NotificationWay(Item):
         if business_impact < self.min_business_impact:
             return False
 
+        # Maybe the command we ask for are not for us, but for another notification ways
+        # on the same contact. If so, bail out
+        if not cmd in self.host_notification_commands:
+            return False
+
         b = self.host_notification_period.is_time_valid(t)
         if 'n' in self.host_notification_options:
             return False
diff --git a/shinken/objects/schedulingitem.py b/shinken/objects/schedulingitem.py
index 335fe19..3c0dcaf 100644
--- a/shinken/objects/schedulingitem.py
+++ b/shinken/objects/schedulingitem.py
@@ -1168,7 +1168,7 @@ class SchedulingItem(Item):
                 rt = cmd.reactionner_tag
                 child_n = Notification(n.type, 'scheduled', 'VOID', cmd, self,
                     contact, n.t_to_go, timeout=cls.notification_timeout,
-                    notif_nb=n.notif_nb, reactionner_tag=rt, module_type=cmd.module_type )
+                    notif_nb=n.notif_nb, reactionner_tag=rt, module_type=cmd.module_type)
                 if not self.notification_is_blocked_by_contact(child_n, contact):
                     # Update the notification with fresh status information
                     # of the item. Example: during the notification_delay
diff --git a/shinken/objects/service.py b/shinken/objects/service.py
index 8562c1a..0927ac0 100644
--- a/shinken/objects/service.py
+++ b/shinken/objects/service.py
@@ -794,7 +794,7 @@ class Service(SchedulingItem):
 
     # See if the notification is launchable (time is OK and contact is OK too)
     def notification_is_blocked_by_contact(self, n, contact):
-        return not contact.want_service_notification(self.last_chk, self.state, n.type, self.business_impact)
+        return not contact.want_service_notification(self.last_chk, self.state, n.type, self.business_impact, n.command_call)
 
 
     def get_duration_sec(self):
diff --git a/test/etc/nagios_1r_1h_1s.cfg b/test/etc/nagios_notif_too_much.cfg
similarity index 89%
copy from test/etc/nagios_1r_1h_1s.cfg
copy to test/etc/nagios_notif_too_much.cfg
index 1566c73..0ac86dd 100644
--- a/test/etc/nagios_1r_1h_1s.cfg
+++ b/test/etc/nagios_notif_too_much.cfg
@@ -8,14 +8,14 @@ auto_rescheduling_interval=30
 auto_rescheduling_window=180
 cached_host_check_horizon=15
 cached_service_check_horizon=15
-cfg_file=1r_1h_1s/hosts.cfg
-cfg_file=1r_1h_1s/services.cfg
-cfg_file=1r_1h_1s/contacts.cfg
-cfg_file=1r_1h_1s/commands.cfg
-cfg_file=1r_1h_1s/timeperiods.cfg
-cfg_file=1r_1h_1s/hostgroups.cfg
-cfg_file=1r_1h_1s/servicegroups.cfg
-cfg_file=1r_1h_1s/shinken-specific.cfg
+cfg_file=notif_too_much/hosts.cfg
+cfg_file=notif_too_much/services.cfg
+cfg_file=notif_too_much/contacts.cfg
+cfg_file=notif_too_much/commands.cfg
+cfg_file=notif_too_much/timeperiods.cfg
+cfg_file=notif_too_much/hostgroups.cfg
+cfg_file=notif_too_much/servicegroups.cfg
+cfg_file=notif_too_much/shinken-specific.cfg
 check_external_commands=1
 check_for_orphaned_hosts=1
 check_for_orphaned_services=1
diff --git a/test/etc/inheritance_and_plus/commands.cfg b/test/etc/notif_too_much/commands.cfg
similarity index 82%
copy from test/etc/inheritance_and_plus/commands.cfg
copy to test/etc/notif_too_much/commands.cfg
index 7614492..6be54ee 100644
--- a/test/etc/inheritance_and_plus/commands.cfg
+++ b/test/etc/notif_too_much/commands.cfg
@@ -28,3 +28,8 @@ define command{
   command_name    special_macro
   command_line	  $USER1$/nothing $ARG1$
 }
+define command{
+    command_name    notify-service2
+    command_line    $USER1$/notifier.pl2 --hostname $HOSTNAME$ --servicedesc $SERVICEDESC$ --notificationtype $NOTIFICATIONTYPE$ --servicestate $SERVICESTATE$ --serviceoutput $SERVICEOUTPUT$ --longdatetime $LONGDATETIME$ --serviceattempt $SERVICEATTEMPT$ --servicestatetype $SERVICESTATETYPE$
+    #command_line    sleep 1 && /bin/true
+}
diff --git a/test/etc/notif_too_much/contacts.cfg b/test/etc/notif_too_much/contacts.cfg
new file mode 100644
index 0000000..74987a3
--- /dev/null
+++ b/test/etc/notif_too_much/contacts.cfg
@@ -0,0 +1,36 @@
+define contactgroup{
+    contactgroup_name       test_contact
+    alias                   test_contacts_alias
+    members                 test_contact
+}
+
+define contact{
+    contact_name                    test_contact
+    alias                           test_contact_alias
+    email                           nobody at localhost
+    notificationways                email_in_day,never
+}
+
+
+
+define notificationway{
+       notificationway_name            email_in_day
+       service_notification_period     24x7
+       host_notification_period        24x7
+       service_notification_options    w,u,c,r,f
+       host_notification_options       d,u,r,f,s
+       service_notification_commands   notify-service
+       host_notification_commands      notify-host
+}
+
+
+
+define notificationway{
+       notificationway_name	       never
+       service_notification_period     none
+       host_notification_period        none
+       service_notification_options    w,u,c,r,f
+       host_notification_options       d,u,r,f,s
+       service_notification_commands   notify-service2
+       host_notification_commands      notify-host
+}
diff --git a/test/etc/1r_1h_1s/hostgroups.cfg b/test/etc/notif_too_much/hostgroups.cfg
similarity index 100%
copy from test/etc/1r_1h_1s/hostgroups.cfg
copy to test/etc/notif_too_much/hostgroups.cfg
diff --git a/test/etc/1r_1h_1s/hosts.cfg b/test/etc/notif_too_much/hosts.cfg
similarity index 100%
copy from test/etc/1r_1h_1s/hosts.cfg
copy to test/etc/notif_too_much/hosts.cfg
diff --git a/test/etc/1r_1h_1s/servicegroups.cfg b/test/etc/notif_too_much/servicegroups.cfg
similarity index 100%
copy from test/etc/1r_1h_1s/servicegroups.cfg
copy to test/etc/notif_too_much/servicegroups.cfg
diff --git a/test/etc/1r_1h_1s/services.cfg b/test/etc/notif_too_much/services.cfg
similarity index 100%
copy from test/etc/1r_1h_1s/services.cfg
copy to test/etc/notif_too_much/services.cfg
diff --git a/test/etc/1r_1h_1s/shinken-specific.cfg b/test/etc/notif_too_much/shinken-specific.cfg
similarity index 100%
copy from test/etc/1r_1h_1s/shinken-specific.cfg
copy to test/etc/notif_too_much/shinken-specific.cfg
diff --git a/test/etc/problem_impact/timeperiods.cfg b/test/etc/notif_too_much/timeperiods.cfg
similarity index 93%
copy from test/etc/problem_impact/timeperiods.cfg
copy to test/etc/notif_too_much/timeperiods.cfg
index 9f572f4..81a46cc 100644
--- a/test/etc/problem_impact/timeperiods.cfg
+++ b/test/etc/notif_too_much/timeperiods.cfg
@@ -13,5 +13,4 @@ define timeperiod{
 
 define timeperiod{
        timeperiod_name none
-       alias 	       none
 }
\ No newline at end of file
diff --git a/test/jenkins/longtests.txt b/test/jenkins/longtests.txt
index bc85ba8..364eb15 100644
--- a/test/jenkins/longtests.txt
+++ b/test/jenkins/longtests.txt
@@ -88,6 +88,7 @@ test_module_ip_tag.py
 test_dot_virg_in_command.py
 test_bad_escalation_on_groups.py
 test_no_host_template.py
+test_notif_too_much.py
 test_parse_perfdata.py
 
 # takes long
diff --git a/test/jenkins/shorttests.txt b/test/jenkins/shorttests.txt
index 6e95840..7166721 100644
--- a/test/jenkins/shorttests.txt
+++ b/test/jenkins/shorttests.txt
@@ -95,4 +95,5 @@ test_module_ip_tag.py
 test_dot_virg_in_command.py
 test_bad_escalation_on_groups.py
 test_no_host_template.py
+test_notif_too_much.py
 test_parse_perfdata.py
diff --git a/test/quick_tests.sh b/test/quick_tests.sh
index 58c2912..0db5388 100755
--- a/test/quick_tests.sh
+++ b/test/quick_tests.sh
@@ -133,6 +133,7 @@ launch_and_assert test_module_ip_tag.py
 launch_and_assert test_dot_virg_in_command.py
 launch_and_assert test_bad_escalation_on_groups.py
 launch_and_assert test_no_host_template.py
+launch_and_assert test_notif_too_much.py
 
 launch_and_assert test_maintenance_period.py
 #Live status is a bit longer than the previous, so we put it at the end.
diff --git a/test/test_missing_object_value.py b/test/test_notif_too_much.py
similarity index 66%
copy from test/test_missing_object_value.py
copy to test/test_notif_too_much.py
index bb83662..29067be 100755
--- a/test/test_missing_object_value.py
+++ b/test/test_notif_too_much.py
@@ -26,20 +26,21 @@
 from shinken_test import *
 
 
-class TestMissingObjectValue(ShinkenTest):
+class TestNotifTooMuch(ShinkenTest):
     #Uncomment this is you want to use a specific configuration
     #for your test
     def setUp(self):
-        self.setup_with_file('etc/nagios_missing_object_value.cfg')
+        self.setup_with_file('etc/nagios_notif_too_much.cfg')
 
     
-    #Change ME :)
-    def test_missing_object_value(self):
+    # The goal of this test is to check if we manage this case:
+    # 2 notif ways on one contact. One notif ways should activate, not the other
+    # for one timeperiod
+    def test_notif_too_much(self):
         #
         # Config is not correct because of a wrong relative path
         # in the main config file
         #
-
         print "Get the hosts and services"
         now = time.time()
         host = self.sched.hosts.find_by_name("test_host_0")
@@ -51,11 +52,20 @@ class TestMissingObjectValue(ShinkenTest):
         svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
         svc.checks_in_progress = []
         svc.act_depend_of = [] # no hostchecks on critical checkresults
-        self.scheduler_loop(2, [[host, 0, 'UP | value1=1 value2=2'], [router, 0, 'UP | rtt=10'], [svc, 2, 'BAD | value1=0 value2=0']])
+        test_contact = self.sched.contacts.find_by_name('test_contact')
+        self.assert_(test_contact is not None)
+        self.scheduler_loop(1, [[host, 0, 'UP | value1=1 value2=2'], [router, 0, 'UP | rtt=10'], [svc, 2, 'BAD | value1=0 value2=0']])
         self.assert_(host.state == 'UP')
         self.assert_(host.state_type == 'HARD')
-        # The service is mising a value for active_check_enabled, it's an error.
-        self.assert_(svc.is_correct() == False)
+        
+        self.scheduler_loop(1, [[host, 0, 'UP | value1=1 value2=2'], [router, 0, 'UP | rtt=10'], [svc, 2, 'BAD | value1=0 value2=0']])
+
+        # We should NOT see a send for the notify-service2 call because it's the good contact
+        # but NOT the good period for this notifways. So 24x7 ok, not the never :)
+        self.assert_(self.any_log_match('SERVICE NOTIFICATION.*;notify-service'))
+        self.assert_(not self.any_log_match('SERVICE NOTIFICATION.*;notify-service2'))
+            
+
 
 
 if __name__ == '__main__':

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list