/* send failed result */ void send_failed_result(gm_job_t * exec_job, int sig) { struct timeval end_time; char buffer[GM_BUFFERSIZE]; char * signame; buffer[0] = '\x0'; gm_log( GM_LOG_TRACE, "send_failed_result()\n"); gettimeofday(&end_time, NULL); exec_job->finish_time = end_time; exec_job->return_code = STATE_CRITICAL; signame = nr2signal(sig); snprintf( buffer, sizeof( buffer )-1, "(Return code of %d is out of bounds. Worker exited by signal %s on worker: %s)", sig, signame, mod_gm_opt->identifier); free(exec_job->output); exec_job->output = strdup( buffer ); free(signame); send_result_back(exec_job); return; }
void send_timeout_result(gm_job_t * exec_job) { struct timeval end_time; char buffer[GM_BUFFERSIZE]; buffer[0] = '\x0'; gm_log( GM_LOG_TRACE, "send_timeout_result()\n"); gettimeofday(&end_time, NULL); exec_job->finish_time = end_time; exec_job->return_code = mod_gm_opt->timeout_return; exec_job->early_timeout = 1; if ( !strcmp( exec_job->type, "service" ) ) snprintf( buffer, sizeof( buffer ) -1, "(Service Check Timed Out On Worker: %s)\n", mod_gm_opt->identifier); if ( !strcmp( exec_job->type, "host" ) ) snprintf( buffer, sizeof( buffer ) -1, "(Host Check Timed Out On Worker: %s)\n", mod_gm_opt->identifier); free(exec_job->output); exec_job->output = strdup( buffer ); send_result_back(exec_job); return; }
/* do some job */ void do_exec_job( ) { struct timeval start_time, end_time; int latency, age; gm_log( GM_LOG_TRACE, "do_exec_job()\n" ); if(exec_job->type == NULL) { gm_log( GM_LOG_ERROR, "discarded invalid job, no type given\n" ); return; } if(exec_job->command_line == NULL) { gm_log( GM_LOG_ERROR, "discarded invalid job, no command line given\n" ); return; } if ( !strcmp( exec_job->type, "service" ) ) { gm_log( GM_LOG_DEBUG, "got service job: %s - %s\n", exec_job->host_name, exec_job->service_description); } else if ( !strcmp( exec_job->type, "host" ) ) { gm_log( GM_LOG_DEBUG, "got host job: %s\n", exec_job->host_name); } else if ( !strcmp( exec_job->type, "eventhandler" ) ) { gm_log( GM_LOG_DEBUG, "got eventhandler job\n"); } /* check proper timeout value */ if( exec_job->timeout <= 0 ) { exec_job->timeout = mod_gm_opt->job_timeout; } /* get the check start time */ gettimeofday(&start_time,NULL); exec_job->start_time = start_time; latency = start_time.tv_sec - exec_job->next_check.tv_sec; age = start_time.tv_sec - exec_job->core_time.tv_sec; gm_log( GM_LOG_TRACE, "timeout: %i, core latency: %i\n", exec_job->timeout, latency); /* job is too old */ if(mod_gm_opt->max_age > 0 && age > mod_gm_opt->max_age) { exec_job->return_code = 3; if ( !strcmp( exec_job->type, "service" ) ) { gm_log( GM_LOG_INFO, "discarded too old %s job: %i > %i (%s - %s)\n", exec_job->type, (int)age, mod_gm_opt->max_age, exec_job->host_name, exec_job->service_description); } else if ( !strcmp( exec_job->type, "host" ) ) { gm_log( GM_LOG_INFO, "discarded too old %s job: %i > %i (%s - %s)\n", exec_job->type, (int)age, mod_gm_opt->max_age, exec_job->host_name); } else { gm_log( GM_LOG_INFO, "discarded too old %s job: %i > %i\n", exec_job->type, (int)age, mod_gm_opt->max_age); } gettimeofday(&end_time, NULL); exec_job->finish_time = end_time; if ( !strcmp( exec_job->type, "service" ) || !strcmp( exec_job->type, "host" ) ) { exec_job->output = strdup("(Could Not Start Check In Time)"); send_result_back(exec_job); } return; } exec_job->early_timeout = 0; /* run the command */ gm_log( GM_LOG_TRACE, "command: %s\n", exec_job->command_line); current_job = exec_job; execute_safe_command(exec_job, mod_gm_opt->fork_on_exec, mod_gm_opt->identifier ); current_job = NULL; if ( !strcmp( exec_job->type, "service" ) || !strcmp( exec_job->type, "host" ) ) { send_result_back(exec_job); } return; }