[icinga-checkins] icinga.org: icinga-core/mfriedrich/cgis: core: unify check scheduling replacement logic for new events (Andreas Ericsson) #2676

git at icinga.org git at icinga.org
Wed Aug 1 03:00:44 CEST 2012


Module: icinga-core
Branch: mfriedrich/cgis
Commit: be88bd527be56d5b9e81e1b248ad8727b29c12d3
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=be88bd527be56d5b9e81e1b248ad8727b29c12d3

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

core: unify check scheduling replacement logic for new events (Andreas Ericsson) #2676

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 may be a bug in previous versions).

refs #2676

---

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

diff --git a/Changelog b/Changelog
index a494a6d..16d3057 100644
--- a/Changelog
+++ b/Changelog
@@ -11,6 +11,7 @@ ENHANCEMENTS
 * core: try the most common macros ($ARGn$, $USERn$) first (Andreas Ericsson) #2674
 
 FIXES
+* core: unify check scheduling replacement logic for new events (Andreas Ericsson) #2676
 
 CHANGES
 
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