<NME> test_acknowledge.py
<BEF> ADDFILE
<MSG> *Began implementing ACKNOWLEDGEMENT (test case, blocking of notifications)

<DFF> @@ -0,0 +1,123 @@
+#!/usr/bin/env python2.6
+
+#
+# This file is used to test acknowledge of problems
+#
+
+
+#It's ugly I know....
+from shinken_test import *
+
+class TestConfig(ShinkenTest):
+    def setUp(self):
+        # i am arbiter-like
+        self.broks = {}
+        self.me = None
+        self.log = Log()
+        self.log.load_obj(self)
+        self.config_files = ['etc/nagios_1r_1h_1s.cfg']
+        self.conf = Config()
+        self.conf.read_config(self.config_files)
+        self.conf.instance_id = 0
+        self.conf.instance_name = 'test'
+        self.conf.linkify_templates()
+        self.conf.apply_inheritance()
+        self.conf.explode()
+        self.conf.create_reversed_list()
+        self.conf.remove_twins()
+        self.conf.apply_implicit_inheritance()
+        self.conf.fill_default()
+        self.conf.clean_useless()
+        self.conf.pythonize()
+        self.conf.linkify()
+        self.conf.apply_dependancies()
+        self.conf.explode_global_conf()
+        self.conf.is_correct()
+        self.confs = self.conf.cut_into_parts()
+        self.dispatcher = Dispatcher(self.conf, self.me)
+        self.sched = Scheduler(None)
+        m = MacroResolver()
+        m.init(self.conf)
+        self.sched.load_conf(self.conf)
+        e = ExternalCommand(self.conf, 'applyer')
+        self.sched.external_command = e
+        e.load_scheduler(self.sched)
+        self.sched.schedule()
+
+
+
+    def test_ack_soft_service(self):
+        self.print_header()
+        # retry_interval 2
+        # critical notification
+        # run loop -> another notification
+        now = time.time()
+        host = self.sched.hosts.find_by_name("test_host_0")
+        host.checks_in_progress = []
+        host.act_depend_of = [] # ignore the router
+        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
+        #--------------------------------------------------------------
+        # initialize host/service state
+        #--------------------------------------------------------------
+        self.scheduler_loop(1, [[host, 0, 'UP']])
+        print "- 1 x OK -------------------------------------"
+        self.scheduler_loop(1, [[svc, 0, 'OK']])
+        self.assert_(svc.current_notification_number == 0)
+
+        #--------------------------------------------------------------
+        # service reaches soft;1
+        # there must not be any notification
+        #--------------------------------------------------------------
+        print "- 1 x BAD get soft -------------------------------------"
+        self.scheduler_loop(1, [[svc, 2, 'BAD']])
+        self.assert_(svc.current_notification_number == 0)
+        self.show_and_clear_logs()
+        self.show_actions()
+
+        #--------------------------------------------------------------
+        # someone acknowldeges the problem before a notification goes out
+        #--------------------------------------------------------------
+        self.assert_(not svc.problem_has_been_acknowledged)
+        now = time.time()
+        cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;1;lausser;blablub" % now
+        self.sched.run_external_command(cmd)
+        self.sched.get_new_actions()
+        self.worker_loop()
+        self.assert_(svc.problem_has_been_acknowledged)
+        self.log_match(0, 'ACKNOWLEDGEMENT \(CRITICAL\)')
+        self.show_and_clear_logs()
+        self.show_actions()
+
+        #--------------------------------------------------------------
+        # service reaches hard;2
+        # a notification must have been created but blocked
+        # log for alert hard and log for eventhandler
+        #--------------------------------------------------------------
+        print "- 1 x BAD get hard -------------------------------------"
+        self.scheduler_loop(1, [[svc, 2, 'BAD']])
+        self.assert_(self.count_logs() == 2)
+        self.assert_(svc.current_notification_number == 0)
+
+        #--------------------------------------------------------------
+        # service reaches hard;2
+        # a notification must have been created but blocked
+        # notification number must be 0
+        #--------------------------------------------------------------
+        self.scheduler_loop(1, [[svc, 0, 'GOOD']])
+        self.show_and_clear_logs()
+        self.show_and_clear_actions()
+        self.assert_(svc.current_notification_number == 0)
+
+
+# service gets hard, notification is sent
+# acknowledge
+# no repetition of notifications
+# ack deleted, notifications again
+#    REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>
+
+
+
+if __name__ == '__main__':
+    unittest.main()

{'commit': 'diff --git a/src/contact.py b/src/contact.py\nindex 026b3b589..542c56628 100644\n--- a/src/contact.py\n+++ b/src/contact.py\n@@ -92,9 +92,9 @@ class Contact(Item):\n             if type in t:\n                 return b and t[type] in self.service_notification_options\n         elif type == \'ACKNOWLEDGEMENT\':\n-            pass\n+            return b\n         elif type == \'FLAPPINGSTART\' or type == \'FLAPPINGSTOP\' or type == \'FLAPPINGDISABLED\':\n-            pass \n+            return b and \'f\' in self.service_notification_options\n         elif type == \'DOWNTIMESTART\' or type == \'DOWNTIMEEND\' or type == \'DOWNTIMECANCELLED\':\n             #No notification when a downtime was cancelled. Is that true??\n             # According to the documentation we need to look at _host_ options\n@@ -120,9 +120,9 @@ class Contact(Item):\n             if type in t:\n                 return b and t[type] in self.host_notification_options\n         elif type == \'ACKNOWLEDGEMENT\':\n-            pass\n+             return b\n         elif type == \'FLAPPINGSTART\' or type == \'FLAPPINGSTOP\' or type == \'FLAPPINGDISABLED\':\n-            pass \n+            return b and \'f\' in self.host_notification_options\n         elif type == \'DOWNTIMESTART\' or type == \'DOWNTIMEEND\' or type == \'DOWNTIMECANCELLED\':\n             return b and \'s\' in self.host_notification_options\n \ndiff --git a/src/external_command.py b/src/external_command.py\nindex 86aabbda9..e992c632f 100644\n--- a/src/external_command.py\n+++ b/src/external_command.py\n@@ -429,14 +429,18 @@ class ExternalCommand:\n \n     #ACKNOWLEDGE_SVC_PROBLEM;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<author>;<comment>\n     def ACKNOWLEDGE_SVC_PROBLEM(self, service, sticky, notify, persistent, author, comment):\n-        service.problem_has_been_acknowledged = True\n-        self.sched.get_and_register_status_brok(service)\n+        if not service.problem_has_been_acknowledged:\n+            service.create_notifications(\'ACKNOWLEDGEMENT\')\n+            service.problem_has_been_acknowledged = True\n+            self.sched.get_and_register_status_brok(service)\n \n     #ACKNOWLEDGE_HOST_PROBLEM;<host_name>;<sticky>;<notify>;<persistent>;<author>;<comment>\n     #TODO : add a better ACK management\n     def ACKNOWLEDGE_HOST_PROBLEM(self, host, sticky, notify, persistent, author, comment):\n-        host.problem_has_been_acknowledged = True\n-        self.sched.get_and_register_status_brok(host)\n+        if not host.problem_has_been_acknowledged:\n+            host.create_notifications(\'ACKNOWLEDGEMENT\')\n+            host.problem_has_been_acknowledged = True\n+            self.sched.get_and_register_status_brok(host)\n         \n     #CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;<contact_name>;<notification_timeperiod>\n     def CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD(self, contact, notification_timeperiod):\ndiff --git a/src/host.py b/src/host.py\nindex e6285f005..df6af043e 100644\n--- a/src/host.py\n+++ b/src/host.py\n@@ -660,7 +660,7 @@ class Host(SchedulingItem):\n             return True\n \n         # Block if the problem has already been acknowledged\n-        if self.problem_has_been_acknowledged:\n+        if self.problem_has_been_acknowledged and type != \'ACKNOWLEDGEMENT\':\n             return True\n \n         # Block if flapping\ndiff --git a/src/service.py b/src/service.py\nindex 923ee9024..497f2dd09 100644\n--- a/src/service.py\n+++ b/src/service.py\n@@ -622,7 +622,7 @@ class Service(SchedulingItem):\n             return True\n \n         # Block if the problem has already been acknowledged\n-        if self.problem_has_been_acknowledged:\n+        if self.problem_has_been_acknowledged and type != \'ACKNOWLEDGEMENT\':\n             return True\n \n         # Block if flapping\ndiff --git a/test/shinken_test.py b/test/shinken_test.py\nindex c00aa5ac8..5445a6182 100644\n--- a/test/shinken_test.py\n+++ b/test/shinken_test.py\n@@ -223,7 +223,7 @@ class ShinkenTest(unittest.TestCase):\n     \n     \n \n-    def test_conf_is_correct(self):\n+    def xtest_conf_is_correct(self):\n         self.print_header()\n         self.assert_(self.conf.conf_is_correct)\n \ndiff --git a/test/test_acknowledge.py b/test/test_acknowledge.py\nnew file mode 100644\nindex 000000000..c959ef334\n--- /dev/null\n+++ b/test/test_acknowledge.py\n@@ -0,0 +1,123 @@\n+#!/usr/bin/env python2.6\n+\n+#\n+# This file is used to test acknowledge of problems\n+#\n+\n+\n+#It\'s ugly I know....\n+from shinken_test import *\n+\n+class TestConfig(ShinkenTest):\n+    def setUp(self):\n+        # i am arbiter-like\n+        self.broks = {}\n+        self.me = None\n+        self.log = Log()\n+        self.log.load_obj(self)\n+        self.config_files = [\'etc/nagios_1r_1h_1s.cfg\']\n+        self.conf = Config()\n+        self.conf.read_config(self.config_files)\n+        self.conf.instance_id = 0\n+        self.conf.instance_name = \'test\'\n+        self.conf.linkify_templates()\n+        self.conf.apply_inheritance()\n+        self.conf.explode()\n+        self.conf.create_reversed_list()\n+        self.conf.remove_twins()\n+        self.conf.apply_implicit_inheritance()\n+        self.conf.fill_default()\n+        self.conf.clean_useless()\n+        self.conf.pythonize()\n+        self.conf.linkify()\n+        self.conf.apply_dependancies()\n+        self.conf.explode_global_conf()\n+        self.conf.is_correct()\n+        self.confs = self.conf.cut_into_parts()\n+        self.dispatcher = Dispatcher(self.conf, self.me)\n+        self.sched = Scheduler(None)\n+        m = MacroResolver()\n+        m.init(self.conf)\n+        self.sched.load_conf(self.conf)\n+        e = ExternalCommand(self.conf, \'applyer\')\n+        self.sched.external_command = e\n+        e.load_scheduler(self.sched)\n+        self.sched.schedule()\n+\n+\n+\n+    def test_ack_soft_service(self):\n+        self.print_header()\n+        # retry_interval 2\n+        # critical notification\n+        # run loop -> another notification\n+        now = time.time()\n+        host = self.sched.hosts.find_by_name("test_host_0")\n+        host.checks_in_progress = []\n+        host.act_depend_of = [] # ignore the router\n+        svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")\n+        svc.checks_in_progress = []\n+        svc.act_depend_of = [] # no hostchecks on critical checkresults\n+        #--------------------------------------------------------------\n+        # initialize host/service state\n+        #--------------------------------------------------------------\n+        self.scheduler_loop(1, [[host, 0, \'UP\']])\n+        print "- 1 x OK -------------------------------------"\n+        self.scheduler_loop(1, [[svc, 0, \'OK\']])\n+        self.assert_(svc.current_notification_number == 0)\n+\n+        #--------------------------------------------------------------\n+        # service reaches soft;1\n+        # there must not be any notification\n+        #--------------------------------------------------------------\n+        print "- 1 x BAD get soft -------------------------------------"\n+        self.scheduler_loop(1, [[svc, 2, \'BAD\']])\n+        self.assert_(svc.current_notification_number == 0)\n+        self.show_and_clear_logs()\n+        self.show_actions()\n+\n+        #--------------------------------------------------------------\n+        # someone acknowldeges the problem before a notification goes out\n+        #--------------------------------------------------------------\n+        self.assert_(not svc.problem_has_been_acknowledged)\n+        now = time.time()\n+        cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;1;lausser;blablub" % now\n+        self.sched.run_external_command(cmd)\n+        self.sched.get_new_actions()\n+        self.worker_loop()\n+        self.assert_(svc.problem_has_been_acknowledged)\n+        self.log_match(0, \'ACKNOWLEDGEMENT \\(CRITICAL\\)\')\n+        self.show_and_clear_logs()\n+        self.show_actions()\n+\n+        #--------------------------------------------------------------\n+        # service reaches hard;2\n+        # a notification must have been created but blocked\n+        # log for alert hard and log for eventhandler\n+        #--------------------------------------------------------------\n+        print "- 1 x BAD get hard -------------------------------------"\n+        self.scheduler_loop(1, [[svc, 2, \'BAD\']])\n+        self.assert_(self.count_logs() == 2)\n+        self.assert_(svc.current_notification_number == 0)\n+\n+        #--------------------------------------------------------------\n+        # service reaches hard;2\n+        # a notification must have been created but blocked\n+        # notification number must be 0\n+        #--------------------------------------------------------------\n+        self.scheduler_loop(1, [[svc, 0, \'GOOD\']])\n+        self.show_and_clear_logs()\n+        self.show_and_clear_actions()\n+        self.assert_(svc.current_notification_number == 0)\n+\n+\n+# service gets hard, notification is sent\n+# acknowledge\n+# no repetition of notifications\n+# ack deleted, notifications again\n+#    REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>\n+\n+\n+\n+if __name__ == \'__main__\':\n+    unittest.main()\n', 'commit_subject': '*Began implementing ACKNOWLEDGEMENT (test case, blocking of notifications)', 'repo_name': 'naparuba/shinken', 'committer': {'name': 'Gerhard Lausser', 'email': '282ea0875e59d4f268a0297e1988097372c7976d@consol.de', 'time_sec': '1279757141', 'tz_offset': '120', 'date': {'seconds': '1279757141'}}, 'commit_tree': '669470fababe4e8ae06a373ba9a34cfa02fe64b2', 'commit_message': '*Began implementing ACKNOWLEDGEMENT (test case, blocking of notifications)\n', 'language_name': 'Java', 'license': 'agpl-3.0', 'hunks': '@@ -0,0 +1,123 @@\n+#!/usr/bin/env python2.6\n+\n+#\n+# This file is used to test acknowledge of problems\n+#\n+\n+\n+#It\'s ugly I know....\n+from shinken_test import *\n+\n+class TestConfig(ShinkenTest):\n+    def setUp(self):\n+        # i am arbiter-like\n+        self.broks = {}\n+        self.me = None\n+        self.log = Log()\n+        self.log.load_obj(self)\n+        self.config_files = [\'etc/nagios_1r_1h_1s.cfg\']\n+        self.conf = Config()\n+        self.conf.read_config(self.config_files)\n+        self.conf.instance_id = 0\n+        self.conf.instance_name = \'test\'\n+        self.conf.linkify_templates()\n+        self.conf.apply_inheritance()\n+        self.conf.explode()\n+        self.conf.create_reversed_list()\n+        self.conf.remove_twins()\n+        self.conf.apply_implicit_inheritance()\n+        self.conf.fill_default()\n+        self.conf.clean_useless()\n+        self.conf.pythonize()\n+        self.conf.linkify()\n+        self.conf.apply_dependancies()\n+        self.conf.explode_global_conf()\n+        self.conf.is_correct()\n+        self.confs = self.conf.cut_into_parts()\n+        self.dispatcher = Dispatcher(self.conf, self.me)\n+        self.sched = Scheduler(None)\n+        m = MacroResolver()\n+        m.init(self.conf)\n+        self.sched.load_conf(self.conf)\n+        e = ExternalCommand(self.conf, \'applyer\')\n+        self.sched.external_command = e\n+        e.load_scheduler(self.sched)\n+        self.sched.schedule()\n+\n+\n+\n+    def test_ack_soft_service(self):\n+        self.print_header()\n+        # retry_interval 2\n+        # critical notification\n+        # run loop -> another notification\n+        now = time.time()\n+        host = self.sched.hosts.find_by_name("test_host_0")\n+        host.checks_in_progress = []\n+        host.act_depend_of = [] # ignore the router\n+        svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")\n+        svc.checks_in_progress = []\n+        svc.act_depend_of = [] # no hostchecks on critical checkresults\n+        #--------------------------------------------------------------\n+        # initialize host/service state\n+        #--------------------------------------------------------------\n+        self.scheduler_loop(1, [[host, 0, \'UP\']])\n+        print "- 1 x OK -------------------------------------"\n+        self.scheduler_loop(1, [[svc, 0, \'OK\']])\n+        self.assert_(svc.current_notification_number == 0)\n+\n+        #--------------------------------------------------------------\n+        # service reaches soft;1\n+        # there must not be any notification\n+        #--------------------------------------------------------------\n+        print "- 1 x BAD get soft -------------------------------------"\n+        self.scheduler_loop(1, [[svc, 2, \'BAD\']])\n+        self.assert_(svc.current_notification_number == 0)\n+        self.show_and_clear_logs()\n+        self.show_actions()\n+\n+        #--------------------------------------------------------------\n+        # someone acknowldeges the problem before a notification goes out\n+        #--------------------------------------------------------------\n+        self.assert_(not svc.problem_has_been_acknowledged)\n+        now = time.time()\n+        cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM;test_host_0;test_ok_0;1;1;1;lausser;blablub" % now\n+        self.sched.run_external_command(cmd)\n+        self.sched.get_new_actions()\n+        self.worker_loop()\n+        self.assert_(svc.problem_has_been_acknowledged)\n+        self.log_match(0, \'ACKNOWLEDGEMENT \\(CRITICAL\\)\')\n+        self.show_and_clear_logs()\n+        self.show_actions()\n+\n+        #--------------------------------------------------------------\n+        # service reaches hard;2\n+        # a notification must have been created but blocked\n+        # log for alert hard and log for eventhandler\n+        #--------------------------------------------------------------\n+        print "- 1 x BAD get hard -------------------------------------"\n+        self.scheduler_loop(1, [[svc, 2, \'BAD\']])\n+        self.assert_(self.count_logs() == 2)\n+        self.assert_(svc.current_notification_number == 0)\n+\n+        #--------------------------------------------------------------\n+        # service reaches hard;2\n+        # a notification must have been created but blocked\n+        # notification number must be 0\n+        #--------------------------------------------------------------\n+        self.scheduler_loop(1, [[svc, 0, \'GOOD\']])\n+        self.show_and_clear_logs()\n+        self.show_and_clear_actions()\n+        self.assert_(svc.current_notification_number == 0)\n+\n+\n+# service gets hard, notification is sent\n+# acknowledge\n+# no repetition of notifications\n+# ack deleted, notifications again\n+#    REMOVE_SVC_ACKNOWLEDGEMENT;<host_name>;<service_description>\n+\n+\n+\n+if __name__ == \'__main__\':\n+    unittest.main()\n', 'addition_count': 123, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/test/test_acknowledge.py', 'file_extension': '.py', 'before_file': 'ADDFILE', 'message': '*Began implementing ACKNOWLEDGEMENT (test case, blocking of notifications)\n', 'author_name': 'Gerhard Lausser', 'lang': 'py'}