diff -ur nagios-2.8.orig/base/config.c nagios-2.8/base/config.c --- nagios-2.8.orig/base/config.c 2007-04-16 11:34:23.000000000 +0100 +++ nagios-2.8/base/config.c 2007-04-18 15:25:54.000000000 +0100 @@ -1714,6 +1714,38 @@ } } + /* check the check timeperiod command */ + if(temp_service->service_check_timeperiod_command!=NULL){ + if(temp_service->service_check_timeperiod_command->command_period!=NULL){ + temp_timeperiod=find_timeperiod(temp_service->service_check_timeperiod_command->command_period); + if(temp_timeperiod==NULL){ + snprintf(temp_buffer,sizeof(temp_buffer),"Error: Time period '%s' specified for check time period command in service '%s' on host '%s' is not defined anywhere!",temp_service->service_check_timeperiod_command->command_period,temp_service->description,temp_service->host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_VERIFICATION_ERROR,TRUE); + errors++; + } + } else { + snprintf(temp_buffer,sizeof(temp_buffer),"Error: Time period specified for check timeperiod command in service '%s' on host '%s' is defined incorrectly!",temp_service->description,temp_service->host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_VERIFICATION_ERROR,TRUE); + errors++; + } + /* check the time period command */ + strncpy(temp_buffer,temp_service->service_check_timeperiod_command->service_check_command,sizeof(temp_buffer)); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + + /* get the command name, leave any arguments behind */ + temp_command_name=my_strtok(temp_buffer,"!"); + + temp_command=find_command(temp_command_name); + if(temp_command==NULL){ + snprintf(temp_buffer,sizeof(temp_buffer),"Error: Service check command '%s' specified for check timeperiod command in service '%s' for host '%s' not defined anywhere!",temp_command_name,temp_service->description,temp_service->host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_VERIFICATION_ERROR,TRUE); + errors++; + } + } + /* check the service check_command */ strncpy(temp_buffer,temp_service->service_check_command,sizeof(temp_buffer)); temp_buffer[sizeof(temp_buffer)-1]='\x0'; Only in nagios-2.8/base: .config.c.swp diff -ur nagios-2.8.orig/common/objects.c nagios-2.8/common/objects.c --- nagios-2.8.orig/common/objects.c 2007-04-16 11:34:23.000000000 +0100 +++ nagios-2.8/common/objects.c 2007-04-18 15:03:06.000000000 +0100 @@ -2753,9 +2753,10 @@ /* add a new service to the list in memory */ -service *add_service(char *host_name, char *description, char *check_period, int max_attempts, int parallelize, int accept_passive_checks, int check_interval, int retry_interval, int notification_interval, char *notification_period, int notify_recovery, int notify_unknown, int notify_warning, int notify_critical, int notify_flapping, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int stalk_ok, int stalk_warning, int stalk_unknown, int stalk_critical, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, int retain_status_information, int retain_nonstatus_information, int obsess_over_service){ +service *add_service(char *host_name, char *description, char *check_period, int max_attempts, int parallelize, int accept_passive_checks, int check_interval, int retry_interval, int notification_interval, char *notification_period, int notify_recovery, int notify_unknown, int notify_warning, int notify_critical, int notify_flapping, int notifications_enabled, int is_volatile, char *event_handler, int event_handler_enabled, char *check_command, char *check_timeperiod_command, int checks_enabled, int flap_detection_enabled, double low_flap_threshold, double high_flap_threshold, int stalk_ok, int stalk_warning, int stalk_unknown, int stalk_critical, int process_perfdata, int failure_prediction_enabled, char *failure_prediction_options, int check_freshness, int freshness_threshold, int retain_status_information, int retain_nonstatus_information, int obsess_over_service){ service *temp_service; service *new_service; + char *temp_ptr; #ifdef NSCORE char temp_buffer[MAX_INPUT_BUFFER]; int x; @@ -2778,6 +2779,7 @@ strip(host_name); strip(description); strip(check_command); + strip(check_timeperiod_command); strip(event_handler); strip(notification_period); strip(check_period); @@ -3056,6 +3058,71 @@ free(new_service); return NULL; } + if(check_timeperiod_command!=NULL && strcmp(check_timeperiod_command,"")){ + + new_service->service_check_timeperiod_command=(timeperiodcommand *)malloc(sizeof(timeperiodcommand)); + if(new_service->service_check_timeperiod_command==NULL){ +#ifdef NSCORE + snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' check timeperiod command\n",description,host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); +#endif + free(new_service->host_name); + free(new_service); + return NULL; + } + + temp_ptr=strtok(check_timeperiod_command,","); + if(temp_ptr==NULL){ +#ifdef NSCORE + snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Invalid entry for service '%s' on host '%s' check timeperiod command\n",description,host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); +#endif + free(new_service->service_check_timeperiod_command); + free(new_service->host_name); + free(new_service); + return NULL; + } + new_service->service_check_timeperiod_command->command_period=strdup(temp_ptr); + if(new_service->service_check_timeperiod_command->command_period==NULL){ +#ifdef NSCORE + snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' check command\n",description,host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); +#endif + free(new_service->service_check_timeperiod_command); + free(new_service->host_name); + free(new_service); + return NULL; + } + temp_ptr=strtok(NULL,"\n"); + if(temp_ptr==NULL){ +#ifdef NSCORE + snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Invalid entry for service '%s' on host '%s' check timeperiod command\n",description,host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); +#endif + free(new_service->service_check_timeperiod_command->command_period); + free(new_service->service_check_timeperiod_command); + free(new_service->host_name); + free(new_service); + return NULL; + } + new_service->service_check_timeperiod_command->service_check_command=strdup(temp_ptr); + if(new_service->service_check_timeperiod_command->service_check_command==NULL){ +#ifdef NSCORE + snprintf(temp_buffer,sizeof(temp_buffer)-1,"Error: Could not allocate memory for service '%s' on host '%s' check command\n",description,host_name); + temp_buffer[sizeof(temp_buffer)-1]='\x0'; + write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); +#endif + free(new_service->service_check_timeperiod_command->command_period); + free(new_service->service_check_timeperiod_command); + free(new_service->host_name); + free(new_service); + return NULL; + } + } if(event_handler!=NULL && strcmp(event_handler,"")){ new_service->event_handler=strdup(event_handler); if(new_service->event_handler==NULL){ @@ -3064,6 +3131,8 @@ temp_buffer[sizeof(temp_buffer)-1]='\x0'; write_to_logs_and_console(temp_buffer,NSLOG_CONFIG_ERROR,TRUE); #endif + if(new_service->service_check_timeperiod_command!=NULL) + free(new_service->service_check_timeperiod_command); free(new_service->service_check_command); free(new_service->description); free(new_service->host_name); @@ -3083,6 +3152,8 @@ #endif if(new_service->event_handler!=NULL) free(new_service->event_handler); + if(new_service->service_check_timeperiod_command!=NULL) + free(new_service->service_check_timeperiod_command); free(new_service->service_check_command); free(new_service->description); free(new_service->host_name); @@ -3104,6 +3175,8 @@ free(new_service->notification_period); if(new_service->event_handler!=NULL) free(new_service->event_handler); + if(new_service->service_check_timeperiod_command!=NULL) + free(new_service->service_check_timeperiod_command); free(new_service->service_check_command); free(new_service->description); free(new_service->host_name); @@ -3127,6 +3200,8 @@ free(new_service->notification_period); if(new_service->event_handler!=NULL) free(new_service->event_handler); + if(new_service->service_check_timeperiod_command!=NULL) + free(new_service->service_check_timeperiod_command); free(new_service->service_check_command); free(new_service->description); free(new_service->host_name); @@ -3229,6 +3304,8 @@ free(new_service->notification_period); if(new_service->event_handler!=NULL) free(new_service->event_handler); + if(new_service->service_check_timeperiod_command!=NULL) + free(new_service->service_check_timeperiod_command); free(new_service->service_check_command); free(new_service->description); free(new_service->host_name); @@ -3251,6 +3328,8 @@ free(new_service->notification_period); if(new_service->event_handler!=NULL) free(new_service->event_handler); + if(new_service->service_check_timeperiod_command!=NULL) + free(new_service->service_check_timeperiod_command); free(new_service->service_check_command); free(new_service->description); free(new_service->host_name); @@ -3283,6 +3362,8 @@ free(new_service->notification_period); if(new_service->event_handler!=NULL) free(new_service->event_handler); + if(new_service->service_check_timeperiod_command!=NULL) + free(new_service->service_check_timeperiod_command); if(new_service->service_check_command) free(new_service->service_check_command); if(new_service->description) @@ -3313,6 +3394,7 @@ printf("\tHost: %s\n",new_service->host_name); printf("\tDescription: %s\n",new_service->description); printf("\tCommand: %s\n",new_service->service_check_command); + printf("\tCommand Timeperiod: %s\n",new_service->service_check_timeperiod_command); printf("\tCheck Interval: %d\n",new_service->check_interval); printf("\tRetry Interval: %d\n",new_service->retry_interval); printf("\tMax attempts: %d\n",new_service->max_attempts); Only in nagios-2.8.orig: config.log diff -ur nagios-2.8.orig/include/objects.h nagios-2.8/include/objects.h --- nagios-2.8.orig/include/objects.h 2007-04-16 11:34:23.000000000 +0100 +++ nagios-2.8/include/objects.h 2007-04-18 14:11:43.000000000 +0100 @@ -279,12 +279,18 @@ }contact; +/* COMMAND_TIMEPERIOD structure */ +typedef struct timeperiodcommand_struct{ + char *command_period; + char *service_check_command; + } timeperiodcommand; /* SERVICE structure */ typedef struct service_struct{ char *host_name; char *description; char *service_check_command; + timeperiodcommand *service_check_timeperiod_command; char *event_handler; int check_interval; int retry_interval; @@ -546,7 +552,7 @@ contactgroup *add_contactgroup(char *,char *); /* adds a contactgroup definition */ contactgroupmember *add_contact_to_contactgroup(contactgroup *,char *); /* adds a contact to a contact group definition */ command *add_command(char *,char *); /* adds a command definition */ -service *add_service(char *,char *,char *,int,int,int,int,int,int,char *,int,int,int,int,int,int,int,char *,int,char *,int,int,double,double,int,int,int,int,int,int,char *,int,int,int,int,int); /* adds a service definition */ +service *add_service(char *,char *,char *,int,int,int,int,int,int,char *,int,int,int,int,int,int,int,char *,int,char *,char*,int,int,double,double,int,int,int,int,int,int,char *,int,int,int,int,int); /* adds a service definition */ contactgroupsmember *add_contactgroup_to_service(service *,char *); /* adds a contact group to a service definition */ serviceescalation *add_serviceescalation(char *,char *,int,int,int,char *,int,int,int,int); /* adds a service escalation definition */ contactgroupsmember *add_contactgroup_to_serviceescalation(serviceescalation *,char *); /* adds a contact group to a service escalation definition */ diff -ur nagios-2.8.orig/xdata/xodtemplate.c nagios-2.8/xdata/xodtemplate.c --- nagios-2.8.orig/xdata/xodtemplate.c 2007-04-16 11:34:23.000000000 +0100 +++ nagios-2.8/xdata/xodtemplate.c 2007-04-18 14:16:22.000000000 +0100 @@ -1293,6 +1293,7 @@ new_service->service_description=NULL; new_service->servicegroups=NULL; new_service->check_command=NULL; + new_service->check_timeperiod_command=NULL; new_service->check_period=NULL; new_service->event_handler=NULL; new_service->notification_period=NULL; @@ -1369,7 +1370,7 @@ new_hostdependency=(xodtemplate_hostdependency *)malloc(sizeof(xodtemplate_hostdependency)); if(new_hostdependency==NULL){ #ifdef DEBUG1 - printf("Error: Could not allocate memory for hostdependency definition\n"); + printf("Error: Could ntimeperiod_ot allocate memory for hostdependency definition\n"); #endif return ERROR; } @@ -2950,6 +2951,15 @@ return ERROR; } } + else if(!strcmp(variable,"check_timeperiod_command")){ + temp_service->check_timeperiod_command=strdup(value); + if(temp_service->check_command==NULL){ +#ifdef DEBUG1 + printf("Error: Could not allocate memory for service check_command.\n"); +#endif + return ERROR; + } + } else if(!strcmp(variable,"check_period")){ temp_service->check_period=strdup(value); if(temp_service->check_period==NULL){ @@ -8139,7 +8149,7 @@ return OK; /* add the service */ - new_service=add_service(this_service->host_name,this_service->service_description,this_service->check_period,this_service->max_check_attempts,this_service->parallelize_check,this_service->passive_checks_enabled,this_service->normal_check_interval,this_service->retry_check_interval,this_service->notification_interval,this_service->notification_period,this_service->notify_on_recovery,this_service->notify_on_unknown,this_service->notify_on_warning,this_service->notify_on_critical,this_service->notify_on_flapping,this_service->notifications_enabled,this_service->is_volatile,this_service->event_handler,this_service->event_handler_enabled,this_service->check_command,this_service->active_checks_enabled,this_service->flap_detection_enabled,this_service->low_flap_threshold,this_service->high_flap_threshold,this_service->stalk_on_ok,this_service->stalk_on_warning,this_service->stalk_on_unknown,this_service->stalk_on_critical,this_service->process_perf_data,this_service->failure_prediction_enabled,this_service->failure_prediction_options,this_service->check_freshness,this_service->freshness_threshold,this_service->retain_status_information,this_service->retain_nonstatus_information,this_service->obsess_over_service); + new_service=add_service(this_service->host_name,this_service->service_description,this_service->check_period,this_service->max_check_attempts,this_service->parallelize_check,this_service->passive_checks_enabled,this_service->normal_check_interval,this_service->retry_check_interval,this_service->notification_interval,this_service->notification_period,this_service->notify_on_recovery,this_service->notify_on_unknown,this_service->notify_on_warning,this_service->notify_on_critical,this_service->notify_on_flapping,this_service->notifications_enabled,this_service->is_volatile,this_service->event_handler,this_service->event_handler_enabled,this_service->check_command,this_service->check_timeperiod_command,this_service->active_checks_enabled,this_service->flap_detection_enabled,this_service->low_flap_threshold,this_service->high_flap_threshold,this_service->stalk_on_ok,this_service->stalk_on_warning,this_service->stalk_on_unknown,this_service->stalk_on_critical,this_service->process_perf_data,this_service->failure_prediction_enabled,this_service->failure_prediction_options,this_service->check_freshness,this_service->freshness_threshold,this_service->retain_status_information,this_service->retain_nonstatus_information,this_service->obsess_over_service); /* return with an error if we couldn't add the service */ if(new_service==NULL){ diff -ur nagios-2.8.orig/xdata/xodtemplate.h nagios-2.8/xdata/xodtemplate.h --- nagios-2.8.orig/xdata/xodtemplate.h 2007-04-16 11:34:23.000000000 +0100 +++ nagios-2.8/xdata/xodtemplate.h 2007-04-18 11:47:35.000000000 +0100 @@ -243,6 +243,7 @@ char *service_description; char *servicegroups; char *check_command; + char *check_timeperiod_command; int max_check_attempts; int normal_check_interval; int retry_check_interval;