[icinga-checkins] icinga.org: icinga-core/dev/cgis: core: fix scheduled_downtime_depth falsely incremented if in flexible downtime with duration < end-starttime window #2536

git at icinga.org git at icinga.org
Tue Apr 24 17:30:41 CEST 2012


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

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Sun Apr 22 22:52:41 2012 +0200

core: fix scheduled_downtime_depth falsely incremented if in flexible downtime with duration < end-starttime window #2536

since we now got support for the trigger_time
of a scheduled downtime, we can now decide if
a flexible downtime is to be ended after trigger
time + duration, or not.

adding further tap tests is currently not possible
as we would have to workaround the not-to-be-found
host in skiplist in handle_scheduled_downtime which
is a pita and requires more rework on clearly
abstracted functionality, beyond the checks on hosts
and services existing, to create the relation to
the downtime being handled.

the issue #2536 holds further analysis and debug logs
on the tests, which has been enhanced in #2537 as well.

refs #2536
refs #2537

---

 Changelog                  |    3 +-
 common/downtime.c          |    5 ++-
 t-tap/stub_downtime.c      |    1 -
 t-tap/test_downtime.c      |   80 ++++++++++++++++++++++++++++++++++++++++++++
 t-tap/test_icinga_config.c |    2 +-
 5 files changed, 87 insertions(+), 4 deletions(-)

diff --git a/Changelog b/Changelog
index a523467..c82e229 100644
--- a/Changelog
+++ b/Changelog
@@ -18,7 +18,7 @@ ENHANCEMENTS
 * core: avoid insane looping through event list when rescheduling checks (Mathias Kettner, Andreas Ericsson) #2182 - MF
 * core: allow empty host groups in service and host dependencies if allow_empty_hostgroup_assignment flag is set (Daniel Wittenberg) #2255 - MF
 * core: fix compatibility problems on solaris 10 (affects core, cgis, ido) (Carl R. Friend) #2292 - MF/RB/TD
-* core: add trigger_time to downtimes to allow calculating of flexible downtimes endtime #2537
+* core: add trigger_time to downtimes to allow calculating of flexible downtimes endtime #2537 - MF
 
 * classic ui: Added option for max log entries displayed in showlog.cgi #2145 - RB
 * classic ui: Added config option for status totals in status.cgi #2018 - RB
@@ -78,6 +78,7 @@ FIXES
 * core: fix handling of allow_empty_hostgroup_assignment when hitting NULL'edhost_name attribute, now properly finishing #949 - MF
 * core: drop abbreviations in debug log and make them more telling #2138 - MF
 * core: remove deprecated code for log_external_commands_user #1619 - MF
+* core: fix scheduled_downtime_depth falsely incremented if in flexible downtime with duration < end-starttime window #2536 - MF
 
 * classic ui: Fixed status totals are wrong when searching #1524 - RB
 * classic ui: Fixed wrong URLs for status.cgi overview #2173 - RB
diff --git a/common/downtime.c b/common/downtime.c
index 81e0619..bd5990a 100644
--- a/common/downtime.c
+++ b/common/downtime.c
@@ -402,7 +402,10 @@ int handle_scheduled_downtime(scheduled_downtime *temp_downtime) {
 	time(&current_time);
 
 	/* have we come to the end of the scheduled downtime? */
-	if (temp_downtime->is_in_effect == TRUE && current_time >= temp_downtime->end_time) {
+	if (temp_downtime->is_in_effect == TRUE && ( /* downtime needs to be in effect and ... */
+		(temp_downtime->fixed == TRUE && current_time >= temp_downtime->end_time) || /* fixed downtime, endtime means end of downtime */
+		(temp_downtime->fixed == FALSE && current_time >= (temp_downtime->trigger_time+temp_downtime->duration)) /* flexible downtime, endtime of downtime is trigger_time+duration */
+	)){
 
 		if (temp_downtime->type == HOST_DOWNTIME)
 			log_debug_info(DEBUGL_DOWNTIME, 0, "Host '%s' ending %s scheduled downtime (id=%lu) with depth=%lu, starttime=%lu, entrytime=%lu, triggertime=%lu, endtime=%lu, duration=%lu.\n", hst->name, (temp_downtime->fixed == TRUE) ? "fixed" : "flexible", temp_downtime->downtime_id, hst->scheduled_downtime_depth, temp_downtime->start_time, temp_downtime->entry_time, temp_downtime->trigger_time, temp_downtime->end_time, temp_downtime->duration);
diff --git a/t-tap/stub_downtime.c b/t-tap/stub_downtime.c
index 2299932..741a642 100644
--- a/t-tap/stub_downtime.c
+++ b/t-tap/stub_downtime.c
@@ -2,4 +2,3 @@
 int schedule_downtime(int type, char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *new_downtime_id) {} /* icinga changed, internal */
 int unschedule_downtime(int type, unsigned long downtime_id) {}
 int check_pending_flex_host_downtime(host *hst) {}
-
diff --git a/t-tap/test_downtime.c b/t-tap/test_downtime.c
index 5e78a1a..c554e11 100644
--- a/t-tap/test_downtime.c
+++ b/t-tap/test_downtime.c
@@ -45,6 +45,61 @@ unsigned long next_downtime_id = 1L;
 
 extern scheduled_downtime *scheduled_downtime_list;
 
+/*
+service *svc1 = NULL, *svc2 = NULL;
+host *host1 = NULL;
+
+void
+setup_objects(time_t time) {
+        timed_event *new_event = NULL;
+
+        host1 = (host *)calloc(1, sizeof(host));
+        host1->name = strdup("Host1");
+        host1->address = strdup("127.0.0.1");
+        host1->retry_interval = 1;
+        host1->check_interval = 5;
+        host1->check_options = 0;
+        host1->state_type = SOFT_STATE;
+        host1->current_state = HOST_DOWN;
+        host1->has_been_checked = TRUE;
+        host1->last_check = time;
+        host1->next_check = time;
+        host1->plugin_output = strdup("Initial state");
+        host1->long_plugin_output = strdup("Initial state");
+        host1->perf_data = NULL;
+
+        svc1 = (service *)calloc(1, sizeof(service));
+        svc1->host_name = strdup("Host1");
+        svc1->host_ptr = host1;
+        svc1->description = strdup("Normal service");
+        svc1->check_options = 0;
+        svc1->next_check = time;
+        svc1->state_type = SOFT_STATE;
+        svc1->current_state = STATE_CRITICAL;
+        svc1->retry_interval = 1;
+        svc1->check_interval = 5;
+        svc1->current_attempt = 1;
+        svc1->max_attempts = 4;
+        svc1->last_state_change = 0;
+        svc1->last_state_change = 0;
+        svc1->last_check = (time_t)1234560000;
+        svc1->host_problem_at_last_check = FALSE;
+        svc1->plugin_output = strdup("Initial state");
+        svc1->last_hard_state_change = (time_t)1111111111;
+
+        svc2 = (service *)calloc(1, sizeof(service));
+        svc2->host_name = strdup("Host1");
+        svc2->description = strdup("To be nudged");
+        svc2->check_options = 0;
+        svc2->next_check = time;
+        svc2->state_type = SOFT_STATE;
+        svc2->current_state = STATE_OK;
+        svc2->retry_interval = 1;
+        svc2->check_interval = 5;
+
+}
+*/
+
 int
 main(int argc, char **argv) {
 	time_t now = 0L;
@@ -172,7 +227,32 @@ main(int argc, char **argv) {
 	for (temp_downtime = scheduled_downtime_list, i = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next, i++) {}
 	ok(i == 0, "No downtimes left") || diag("Left: %d", i);
 
+	/* add tests for #2536 */
+	/*
+	setup_objects(now);
+	*/
+
+	/* int schedule_downtime(int type, char *host_name, char *service_description, time_t entry_time, char *author, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long *new_downtime_id) { */
+	/*
+        schedule_downtime(HOST_DOWNTIME, "host1", NULL, now, "user", "test comment", now, now+20, 0, 0, 10, &downtime_id);
+	ok(downtime_id == 21L, "Got host1 downtime: %lu", downtime_id);
+	*/
+
+	/* now set the host to down */
+	/*
+	host1->current_state = HOST_DOWN;
+	*/
+	/* FIXME how to pass the host object to the test function? it will bail early if the downtime->hst|svc entry cannot be found */
+
+	/* handle the downtime, as this would be in events.c */
+	/*
+	handle_scheduled_downtime_by_id(downtime_id);
+	temp_downtime = scheduled_downtime_list;
+
+	printf("id: %lu, in_effect: %lu", temp_downtime->downtime_id, temp_downtime->is_in_effect);
 
+	ok(temp_downtime->is_in_effect == 1, "host1 downtime in effect with trigger_time: %lu", temp_downtime->trigger_time);
+	*/
 
 	return exit_status();
 }
diff --git a/t-tap/test_icinga_config.c b/t-tap/test_icinga_config.c
index 2fb6eea..850fa4b 100644
--- a/t-tap/test_icinga_config.c
+++ b/t-tap/test_icinga_config.c
@@ -309,7 +309,7 @@ int update_contact_status(contact *cntct, int aggregated_dump) {}
 time_t get_next_service_notification_time(service *temp_service, time_t time_t1) {}
 void broker_retention_data(int type, int flags, int attr, struct timeval *timestamp) {}
 int host_notification(host *hst, int type, char *not_author, char *not_data, int options) {}
-void broker_downtime_data(int type, int flags, int attr, int downtime_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, struct timeval *timestamp) {}
+void broker_downtime_data(int type, int flags, int attr, int downtime_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, time_t start_time, time_t end_time, int fixed, unsigned long triggered_by, unsigned long duration, unsigned long downtime_id, struct timeval *timestamp, int is_in_effect, time_t trigger_time) {}
 int update_service_status(service *svc, int aggregated_dump) {}
 time_t get_next_host_notification_time(host *temp_host, time_t time_t1) {}
 void check_for_host_flapping(host *hst, int update, int actual_check, int allow_flapstart_notification) {}





More information about the icinga-checkins mailing list