[icinga-checkins] icinga.org: icinga-core/r1.7: * core: fix duplicated events on check scheduling logic for new events ( Andreas Ericsson) #2676 #2993

git at icinga.org git at icinga.org
Sat Aug 18 16:47:51 CEST 2012


Module: icinga-core
Branch: r1.7
Commit: 379b71295b4846195590350ccb309b3ec79212da
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=379b71295b4846195590350ccb309b3ec79212da

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Fri Jul  6 13:21:41 2012 +0200

* core: fix duplicated events on check scheduling logic for new events (Andreas Ericsson) #2676 #2993

previously, the logic on scheduling a new event was changed using the
new_event attribute. the decision for actually scheduling a new event
now happens generalized after having decided to actually do so.
furthermore next_check_event is correctly assigned to that new event for
the host|service check (which is a bug in previous versions, causing
duplicate events under different circumstances).

refs #2676
refs #2993

Conflicts:

	Changelog

---

 Changelog     |   10 ++++++
 base/checks.c |   89 +++++++++++++++++++++++++-------------------------------
 2 files changed, 50 insertions(+), 49 deletions(-)

diff --git a/Changelog b/Changelog
index 3f1bc89..4da81b4 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,16 @@ Icinga 1.7.x Change Log
 
 Thanks to all contributers, testers and developers. Please read AUTHORS and THANKS for a detailed list :-)
 
+1.7.2 - XX/XX/2012
+
+ENHANCEMENTS
+
+FIXES
+* core: fix duplicated events on check scheduling logic for new events (Andreas Ericsson) #2676 #2993 - MF
+
+CHANGES
+
+
 1.7.1 - 18/06/2012
 
 FIXES
diff --git a/base/checks.c b/base/checks.c
index eedecb7..5d02110 100644
--- a/base/checks.c
+++ b/base/checks.c
@@ -1881,15 +1881,6 @@ void schedule_service_check(service *svc, time_t check_time, int options) {
 		return;
 	}
 
-	/* allocate memory for a new event item */
-	new_event = (timed_event *)malloc(sizeof(timed_event));
-	if (new_event == NULL) {
-
-		logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Could not reschedule check of service '%s' on host '%s'!\n", svc->description, svc->host_name);
-
-		return;
-	}
-
 	/* default is to use the new event */
 	use_original_event = FALSE;
 
@@ -1938,32 +1929,38 @@ void schedule_service_check(service *svc, time_t check_time, int options) {
 				log_debug_info(DEBUGL_CHECKS, 2, "New service check event occurs after the existing event, so we'll ignore it.\n");
 			}
 		}
+	}
+
 
-		/* the originally queued event won the battle, so keep it */
-		if (use_original_event == TRUE) {
-			my_free(new_event);
+	/*
+	 * we can't use the original event,
+	 * so schedule a new event
+	 */
+	if (use_original_event == FALSE) {
+
+		/* allocate memory for a new event item */
+		new_event = (timed_event *)malloc(sizeof(timed_event));
+
+		if (new_event == NULL) {
+			logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Could not reschedule check of service '%s' on host '%s'!\n", svc->description, svc->host_name);
+			return;
 		}
 
-		/* else we're using the new event, so remove the old one */
-		else {
+		/* make sure we kill off the old event */
+		if (temp_event) {
 			remove_event(temp_event, &event_list_low, &event_list_low_tail);
-			/* save new event for later */
-			svc->next_check_event = new_event;
 			my_free(temp_event);
 		}
-	}
-
-	/* save check options for retention purposes */
-	svc->check_options = options;
-
-	/* schedule a new event */
-	if (use_original_event == FALSE) {
 
 		log_debug_info(DEBUGL_CHECKS, 2, "Scheduling new service check event.\n");
 
-		/* set the next service check time */
+		/* set the next service check event and time */
+		svc->next_check_event = new_event;
 		svc->next_check = check_time;
 
+		/* save check options for retention purposes */
+		svc->check_options = options;
+
 		/* place the new event in the event queue */
 		new_event->event_type = EVENT_SERVICE_CHECK;
 		new_event->event_data = (void *)svc;
@@ -2360,14 +2357,6 @@ void schedule_host_check(host *hst, time_t check_time, int options) {
 		return;
 	}
 
-	/* allocate memory for a new event item */
-	if ((new_event = (timed_event *)malloc(sizeof(timed_event))) == NULL) {
-
-		logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Could not reschedule check of host '%s'!\n", hst->name);
-
-		return;
-	}
-
 	/* default is to use the new event */
 	use_original_event = FALSE;
 
@@ -2416,32 +2405,34 @@ void schedule_host_check(host *hst, time_t check_time, int options) {
 				log_debug_info(DEBUGL_CHECKS, 2, "New host check event occurs after the existing event, so we'll ignore it.\n");
 			}
 		}
+	}
 
-		/* the originally queued event won the battle, so keep it */
-		if (use_original_event == TRUE) {
-			my_free(new_event);
+	/*
+	 * we can't use the original event,
+	 * so schedule a new event
+	 */
+	if (use_original_event == FALSE) {
+
+		log_debug_info(DEBUGL_CHECKS, 2, "Scheduling new host check event.\n");
+
+		/* allocate memory for a new event item */
+		if((new_event = (timed_event *)malloc(sizeof(timed_event))) == NULL) {
+			logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Could not reschedule check of host '%s'!\n", hst->name);
+			return;
 		}
 
-		/* else use the new event, so remove the old */
-		else {
+		if (temp_event) {
 			remove_event(temp_event, &event_list_low, &event_list_low_tail);
-			/* save new event for later */
-			hst->next_check_event = new_event;
 			my_free(temp_event);
 		}
-	}
 
-	/* save check options for retention purposes */
-	hst->check_options = options;
-
-	/* use the new event */
-	if (use_original_event == FALSE) {
-
-		log_debug_info(DEBUGL_CHECKS, 2, "Scheduling new host check event.\n");
-
-		/* set the next host check time */
+		/* set the next host check event and time */
+		hst->next_check_event = new_event;
 		hst->next_check = check_time;
 
+		/* save check options for retention purposes */
+		hst->check_options = options;
+
 		/* place the new event in the event queue */
 		new_event->event_type = EVENT_HOST_CHECK;
 		new_event->event_data = (void *)hst;





More information about the icinga-checkins mailing list