[icinga-checkins] icinga.org: icinga-core/master: add tests for host following service check execution (Ton Voon)

git at icinga.org git at icinga.org
Fri Nov 5 08:30:55 CET 2010


Module: icinga-core
Branch: master
Commit: 5870334db28ecd4d305507937154797923aad075
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=5870334db28ecd4d305507937154797923aad075

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Mon Oct 25 15:12:08 2010 +0200

add tests for host following service check execution (Ton Voon)

---

 t-tap/test_events.c |  110 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 96 insertions(+), 14 deletions(-)

diff --git a/t-tap/test_events.c b/t-tap/test_events.c
index 0e98915..e35f239 100644
--- a/t-tap/test_events.c
+++ b/t-tap/test_events.c
@@ -1,19 +1,19 @@
 /*****************************************************************************
-* 
+*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
-* 
+*
 * This program 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 General Public License for more details.
-* 
+*
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
-* 
-* 
+*
+*
 *****************************************************************************/
 
 #define NSCORE 1
@@ -27,7 +27,7 @@
 #include "sretention.h"
 #include "tap.h"
 
-char *config_file="etc/nagios.cfg";
+char *config_file="etc/icinga.cfg";
 int      test_scheduling;
 
 time_t   program_start;
@@ -92,11 +92,14 @@ service  *service_list;
 
 int check_for_expired_comment(unsigned long temp_long) {}
 void broker_timed_event(int int1, int int2, int int3, timed_event *timed_event1, struct timeval *timeval1) {}
-int perform_scheduled_host_check(host *temp_host,int int1,double double1) {}
+int perform_scheduled_host_check(host *temp_host,int int1,double double1) {
+	time_t now=0L;
+	time(&now);
+	temp_host->last_check = now;
+}
 int check_for_expired_downtime(void) {}
 int reap_check_results(void) {}
 void check_host_result_freshness() {}
-int check_for_nagios_updates(int int1, int int2) {}
 time_t get_next_service_notification_time(service *temp_service, time_t time_t1) {}
 int save_state_information(int int1) {}
 void get_time_breakdown(unsigned long long1, int *int1, int *int2, int *int3, int *int4) {}
@@ -108,6 +111,9 @@ time_t get_next_log_rotation_time(void) {}
 void check_for_orphaned_services() {}
 int run_scheduled_service_check(service *service1, int int1, double double1) {
 	currently_running_service_checks++;
+	time_t now=0L;
+	time(&now);
+	service1->last_check = now;
 	/* printf("Currently running service checks: %d\n", currently_running_service_checks); */
 }
 int handle_scheduled_downtime_by_id(unsigned long long1) {}
@@ -117,16 +123,16 @@ void get_next_valid_time(time_t time_t1, time_t *time_t2,timeperiod *temp_timepe
 void logit(int int1,int int2,const char *fmt, ...) {}
 
 int c=0;
-int update_program_status(int aggregated_dump){ 
+int update_program_status(int aggregated_dump){
 	c++;
 	/* printf ("# In the update_program_status hook: %d\n", c); */
-	
+
 	/* Set this to break out of event_execution_loop */
 	if (c>10) {
 		sigshutdown=TRUE;
 		c=0;
 	}
-} 
+}
 int update_service_status(service *svc,int aggregated_dump){}
 int update_all_status_data(void){}
 int log_debug_info(int level, int verbosity, const char *fmt, ...){
@@ -138,7 +144,8 @@ int log_debug_info(int level, int verbosity, const char *fmt, ...){
 int update_host_status(host *hst,int aggregated_dump){}
 
 /* Test variables */
-service *svc1=NULL, *svc2=NULL;
+service *svc1=NULL, *svc2=NULL, *svc3=NULL;
+host *host1=NULL;
 
 void
 setup_events(time_t time) {
@@ -166,7 +173,7 @@ setup_events(time_t time) {
 	new_event->timing_func=NULL;
 	new_event->compensate_for_time_change=TRUE;
 	reschedule_event(new_event,&event_list_low,&event_list_low_tail);
-	
+
 	/* Second service is one that will get nudged forward */
 	svc2=(service *)malloc(sizeof(service));
 	svc2->host_name=strdup("Host1");
@@ -191,12 +198,67 @@ setup_events(time_t time) {
 	reschedule_event(new_event,&event_list_low,&event_list_low_tail);
 }
 
+void
+setup_events_with_host(time_t time) {
+	timed_event *new_event=NULL;
+
+	/* First service is a normal one */
+	if(svc3==NULL)
+		svc3=(service *)malloc(sizeof(service));
+	svc3->host_name=strdup("Host0");
+	svc3->description=strdup("Normal service");
+	svc3->check_options=0;
+	svc3->next_check=time;
+	svc3->state_type=SOFT_STATE;
+	svc3->current_state=STATE_OK;
+	svc3->retry_interval=1;
+	svc3->check_interval=5;
+
+	new_event=(timed_event *)malloc(sizeof(timed_event));
+	new_event->event_type=EVENT_SERVICE_CHECK;
+	new_event->event_data=(void *)svc3;
+	new_event->event_args=(void *)NULL;
+	new_event->event_options=0;
+	new_event->run_time=0L;				/* Straight away */
+	new_event->recurring=FALSE;
+	new_event->event_interval=0L;
+	new_event->timing_func=NULL;
+	new_event->compensate_for_time_change=TRUE;
+	reschedule_event(new_event,&event_list_low,&event_list_low_tail);
+
+	if (host1==NULL)
+		host1=(host *)malloc(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->next_check=time;
+	new_event->recurring=TRUE;
+	host1->state_type=SOFT_STATE;
+	host1->current_state=STATE_OK;
+
+	new_event=(timed_event *)malloc(sizeof(timed_event));
+	new_event->event_type=EVENT_HOST_CHECK;
+	new_event->event_data=(void *)host1;
+	new_event->event_args=(void *)NULL;
+	new_event->event_options=0;
+	new_event->run_time=0L;				/* Straight away */
+	new_event->recurring=TRUE;
+	new_event->event_interval=0L;
+	new_event->timing_func=NULL;
+	new_event->compensate_for_time_change=TRUE;
+	reschedule_event(new_event,&event_list_low,&event_list_low_tail);
+}
+
+
+
 int
 main (int argc, char **argv)
 {
 	time_t now=0L;
 
-	plan_tests(6);
+	plan_tests(10);
 
 	time(&now);
 
@@ -232,6 +294,26 @@ main (int argc, char **argv)
 	ok(svc1->next_check == now+300, "svc1 rescheduled ahead - normal interval" );
 	ok(svc2->next_check == now+60,  "svc2 rescheduled ahead - retry interval" );
 
+	/* Checking that a host check immediately following a service check
+	 * correctly checks the host
+	 */
+	timed_event *temp_event=NULL;
+	while ((temp_event = event_list_low) != NULL) {
+		remove_event(temp_event,&event_list_low,&event_list_low_tail);
+	}
+
+	sigshutdown=FALSE;
+	currently_running_service_checks=0;
+	max_parallel_service_checks=2;
+	execute_service_checks=0;
+	execute_host_checks=1;
+	setup_events_with_host(now);
+	event_execution_loop();
+
+	ok(host1->last_check == now,  "host1 was checked" );
+	ok(svc3->last_check == 0, "svc3 was skipped" );
+	ok(host1->next_check == now,  "host1 rescheduled ahead - normal interval" );
+	ok(svc3->next_check == now+300, "svc3 rescheduled ahead - normal interval" );
 
 	return exit_status ();
 }





More information about the icinga-checkins mailing list