[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Naparuba
naparuba at gmail.com
Tue Feb 28 22:08:27 UTC 2012
The following commit has been merged in the debian/master branch:
commit 92097aa6eb497a8c95b1cc34e2749e21e62f16b3
Author: Naparuba <naparuba at gmail.com>
Date: Mon Dec 12 12:50:00 2011 +0100
Add : ackn with expire date.
diff --git a/shinken/acknowledge.py b/shinken/acknowledge.py
index 0866e65..db028d1 100644
--- a/shinken/acknowledge.py
+++ b/shinken/acknowledge.py
@@ -34,6 +34,7 @@ class Acknowledge:
'id' : None,
'sticky' : None,
'notify' : None,
+ 'end_time' : None,
'author' : None,
'comment' : None,
}
@@ -55,12 +56,13 @@ class Acknowledge:
# next time Nagios restarts. "persistent" not only means "survive
# restarts", but also
#
- def __init__(self, ref, sticky, notify, persistent, author, comment):
+ def __init__(self, ref, sticky, notify, persistent, author, comment, end_time=0):
self.id = self.__class__.id
self.__class__.id += 1
self.ref = ref # pointer to srv or host we are apply
self.sticky = sticky
self.notify = notify
+ self.end_time = end_time
self.author = author
self.comment = comment
@@ -84,3 +86,6 @@ class Acknowledge:
for prop in cls.properties:
if prop in state:
setattr(self, prop, state[prop])
+ # If load a old ack, set the end_time to 0 so it's infinite
+ if not hasattr(self, 'end_time'):
+ self.end_time = 0
diff --git a/shinken/external_command.py b/shinken/external_command.py
index ca8dd0f..e2ae925 100644
--- a/shinken/external_command.py
+++ b/shinken/external_command.py
@@ -50,6 +50,8 @@ class ExternalCommandManager:
'ADD_HOST_COMMENT' : {'global' : False, 'args' : ['host', 'to_bool', 'author', None]},
'ACKNOWLEDGE_SVC_PROBLEM' : {'global' : False, 'args' : ['service' , 'to_int', 'to_bool', 'to_bool', 'author', None]},
'ACKNOWLEDGE_HOST_PROBLEM' : {'global' : False, 'args' : ['host', 'to_int', 'to_bool', 'to_bool', 'author', None]},
+ 'ACKNOWLEDGE_SVC_PROBLEM_EXPIRE' : {'global' : False, 'args' : ['service' , 'to_int', 'to_bool', 'to_bool', 'to_int', 'author', None]},
+ 'ACKNOWLEDGE_HOST_PROBLEM_EXPIRE' : {'global' : False, 'args' : ['host', 'to_int', 'to_bool', 'to_bool', 'to_int', 'author', None]},
'CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD' : {'global' : True, 'args' : ['contact', 'time_period']},
'CHANGE_CUSTOM_CONTACT_VAR' : {'global' : True, 'args' : ['contact', None,None]},
'CHANGE_CUSTOM_HOST_VAR' : {'global' : False, 'args' : ['host', None,None]},
@@ -527,6 +529,15 @@ class ExternalCommandManager:
def ACKNOWLEDGE_HOST_PROBLEM(self, host, sticky, notify, persistent, author, comment):
host.acknowledge_problem(sticky, notify, persistent, author, comment)
+ #ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<end_time>;<author>;<comment>
+ def ACKNOWLEDGE_SVC_PROBLEM_EXPIRE(self, service, sticky, notify, persistent, end_time, author, comment):
+ service.acknowledge_problem(sticky, notify, persistent, author, comment, end_time=end_time)
+
+ #ACKNOWLEDGE_HOST_PROBLEM_EXPIRE;<host_name>;<sticky>;<notify>;<persistent>;<end_time>;<author>;<comment>
+ #TODO : add a better ACK management
+ def ACKNOWLEDGE_HOST_PROBLEM_EXPIRE(self, host, sticky, notify, persistent, end_time, author, comment):
+ host.acknowledge_problem(sticky, notify, persistent, author, comment, end_time=end_time)
+
#CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD;<contact_name>;<notification_timeperiod>
def CHANGE_CONTACT_SVC_NOTIFICATION_TIMEPERIOD(self, contact, notification_timeperiod):
contact.service_notification_period = notification_timeperiod
diff --git a/shinken/objects/item.py b/shinken/objects/item.py
index de021e4..a9fb8bb 100644
--- a/shinken/objects/item.py
+++ b/shinken/objects/item.py
@@ -24,7 +24,7 @@
""" This class is a base class for nearly all configuration
elements like service, hosts or contacts.
"""
-
+import time
from copy import copy
from shinken.commandcall import CommandCall
@@ -389,7 +389,7 @@ Like temporary attributes such as "imported_from", etc.. """
self.comments.remove(c_to_del)
- def acknowledge_problem(self, sticky, notify, persistent, author, comment):
+ def acknowledge_problem(self, sticky, notify, persistent, author, comment, end_time=0):
if self.state != self.ok_up:
if notify:
self.create_notifications('ACKNOWLEDGEMENT')
@@ -398,7 +398,7 @@ Like temporary attributes such as "imported_from", etc.. """
sticky = True
else:
sticky = False
- a = Acknowledge(self, sticky, notify, persistent, author, comment)
+ a = Acknowledge(self, sticky, notify, persistent, author, comment, end_time=end_time)
self.acknowledgement = a
if self.my_type == 'host':
comment_type = 1
@@ -410,6 +410,13 @@ Like temporary attributes such as "imported_from", etc.. """
self.broks.append(self.get_update_status_brok())
+ # Look if we got an ack that is too old with an expire date and should
+ # be delete
+ def check_for_expire_acknowledge(self):
+ if self.acknowledgement and self.acknowledgement.end_time < time.time():
+ self.unacknowledge_problem()
+
+
# Delete the acknowledgement object and reset the flag
# but do not remove the associated comment.
def unacknowledge_problem(self):
diff --git a/shinken/scheduler.py b/shinken/scheduler.py
index 4bc19f8..1d20a9e 100644
--- a/shinken/scheduler.py
+++ b/shinken/scheduler.py
@@ -95,6 +95,7 @@ class Scheduler:
15 : ('update_business_values', self.update_business_values, 60),
# Reset the topology change flag if need
16 : ('reset_topology_change_flag', self.reset_topology_change_flag, 1),
+ 17 : ('check_for_expire_acknowledge', self.check_for_expire_acknowledge, 1),
}
# stats part
@@ -391,6 +392,14 @@ class Scheduler:
self.comments[c_id].ref.del_comment(c_id)
del self.comments[c_id]
+
+ # We are looking for outdated ack, and if so, remove them
+ def check_for_expire_acknowledge(self):
+ for t in [self.hosts, self.services]:
+ for i in t:
+ i.check_for_expire_acknowledge()
+
+
# We update all business_impact for looking at new modulation
# start for impacts, and so update broks status and
# problems value too
diff --git a/test/test_acknowledge.py b/test/test_acknowledge.py
index f32e329..c54fad1 100755
--- a/test/test_acknowledge.py
+++ b/test/test_acknowledge.py
@@ -26,7 +26,7 @@
#It's ugly I know....
from shinken_test import *
-class TestConfig(ShinkenTest):
+class TestAcks(ShinkenTest):
def test_ack_soft_service(self):
self.print_header()
@@ -721,5 +721,8 @@ class TestConfig(ShinkenTest):
# acknowledgement and comments have disappeared
+
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/test/test_acknowledge_with_expire.py b/test/test_acknowledge_with_expire.py
new file mode 100755
index 0000000..fe0802d
--- /dev/null
+++ b/test/test_acknowledge_with_expire.py
@@ -0,0 +1,116 @@
+#!/usr/bin/env python2.6
+#Copyright (C) 2009-2010 :
+# Gabes Jean, naparuba at gmail.com
+# Gerhard Lausser, Gerhard.Lausser at consol.de
+#
+#This file is part of Shinken.
+#
+#Shinken is free software: you can redistribute it and/or modify
+#it under the terms of the GNU Affero General Public License as published by
+#the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+#Shinken is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#GNU Affero General Public License for more details.
+#
+#You should have received a copy of the GNU Affero General Public License
+#along with Shinken. If not, see <http://www.gnu.org/licenses/>.
+
+#
+# This file is used to test acknowledge of problems
+#
+
+
+#It's ugly I know....
+from shinken_test import *
+
+# Restore sleep functions
+time.time = original_time_time
+time.sleep = original_time_sleep
+
+class TestAcksWithExpire(ShinkenTest):
+
+ def test_ack_hard_service_with_expire(self):
+ self.print_header()
+ 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)
+
+ #--------------------------------------------------------------
+ # first check the normal behavior
+ # service reaches hard;2
+ # at the end there must be 3 actions: eventhandler hard,
+ # master notification and contact notification
+ #--------------------------------------------------------------
+ print "- 2 x BAD get hard -------------------------------------"
+ self.scheduler_loop(2, [[svc, 2, 'BAD']])
+ self.assert_(svc.current_notification_number == 1)
+ self.assert_(self.count_actions() == 3)
+ self.assert_(self.log_match(5, 'SERVICE NOTIFICATION'))
+ self.show_and_clear_logs()
+ self.show_actions()
+
+ #--------------------------------------------------------------
+ # stay hard and wait for the second notification (notification_interval)
+ #--------------------------------------------------------------
+ print "- 2 x BAD stay hard -------------------------------------"
+ self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=False)
+ self.show_and_clear_logs()
+ self.show_actions()
+
+ #--------------------------------------------------------------
+ # admin wakes up and acknowledges the problem
+ # the ACK is the only log message
+ # a master notification is still around, but can't be sent
+ #--------------------------------------------------------------
+ self.assert_(not svc.problem_has_been_acknowledged)
+ now = time.time()
+ cmd = "[%lu] ACKNOWLEDGE_SVC_PROBLEM_EXPIRE;test_host_0;test_ok_0;1;1;0;%d;lausser;blablub" % (now, int(now) + 5)
+ self.sched.run_external_command(cmd)
+ self.sched.get_new_actions()
+ self.worker_loop()
+ self.assert_(svc.problem_has_been_acknowledged)
+ self.assert_(self.log_match(1, 'ACKNOWLEDGEMENT \(CRITICAL\)'))
+ self.scheduler_loop(2, [[svc, 2, 'BAD']], do_sleep=False)
+ self.assert_(self.count_logs() == 1)
+ self.assert_(self.count_actions() == 1)
+ self.show_and_clear_logs()
+ self.show_actions()
+
+ #--------------------------------------------------------------
+ # Wait 4 remove acknowledgement
+ # now notifications are sent again
+ #--------------------------------------------------------------
+ time.sleep(5)
+ # Wait a bit
+ self.sched.check_for_expire_acknowledge()
+ self.assert_(not svc.problem_has_been_acknowledged)
+
+ #now = time.time()
+ #cmd = "[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;test_host_0;test_ok_0" % now
+ #self.sched.run_external_command(cmd)
+ self.sched.get_new_actions()
+ self.worker_loop()
+ self.show_logs()
+ self.show_actions()
+ # the contact notification was sent immediately (t_to_go)
+ self.assert_(not svc.problem_has_been_acknowledged)
+ self.show_logs()
+ self.show_actions()
+
+
+if __name__ == '__main__':
+ unittest.main()
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list