/* handles host check results in an obsessive compulsive manner... */ int obsessive_compulsive_host_check_processor(host *hst) { char *raw_command = NULL; char *processed_command = NULL; int early_timeout = FALSE; double exectime = 0.0; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; icinga_macros mac; log_debug_info(DEBUGL_FUNCTIONS, 0, "obsessive_compulsive_host_check_processor()\n"); if (hst == NULL) return ERROR; /* bail out if we shouldn't be obsessing */ if (obsess_over_hosts == FALSE) return OK; if (hst->obsess_over_host == FALSE) return OK; /* if there is no valid command, exit */ if (ochp_command == NULL) return ERROR; /* update macros */ memset(&mac, 0, sizeof(mac)); grab_host_macros_r(&mac, hst); /* get the raw command line */ get_raw_command_line_r(&mac, ochp_command_ptr, ochp_command, &raw_command, macro_options); if (raw_command == NULL) { clear_volatile_macros_r(&mac); return ERROR; } log_debug_info(DEBUGL_CHECKS, 2, "Raw obsessive compulsive host processor command line: %s\n", raw_command); /* process any macros in the raw command line */ process_macros_r(&mac, raw_command, &processed_command, macro_options); if (processed_command == NULL) { clear_volatile_macros_r(&mac); return ERROR; } log_debug_info(DEBUGL_CHECKS, 2, "Processed obsessive compulsive host processor command line: %s\n", processed_command); /* run the command */ my_system_r(&mac, processed_command, ochp_timeout, &early_timeout, &exectime, NULL, 0); clear_volatile_macros_r(&mac); /* check to see if the command timed out */ if (early_timeout == TRUE) logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: OCHP command '%s' for host '%s' timed out after %d seconds\n", processed_command, hst->name, ochp_timeout); /* free memory */ my_free(raw_command); my_free(processed_command); return OK; }
/* runs the host performance data command */ int xpddefault_run_host_performance_data_command(nagios_macros *mac, host *hst) { char *raw_command_line = NULL; char *processed_command_line = NULL; int early_timeout = FALSE; double exectime; int result = OK; int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; log_debug_info(DEBUGL_FUNCTIONS, 0, "run_host_performance_data_command()\n"); if(hst == NULL) return ERROR; /* we don't have a command */ if(xpddefault_host_perfdata_command == NULL) return OK; /* get the raw command line */ get_raw_command_line_r(mac, xpddefault_host_perfdata_command_ptr, xpddefault_host_perfdata_command, &raw_command_line, macro_options); if(raw_command_line == NULL) return ERROR; log_debug_info(DEBUGL_PERFDATA, 2, "Raw host performance data command line: %s\n", raw_command_line); /* process any macros in the raw command line */ process_macros_r(mac, raw_command_line, &processed_command_line, macro_options); my_free(raw_command_line); if (!processed_command_line) return ERROR; log_debug_info(DEBUGL_PERFDATA, 2, "Processed host performance data command line: %s\n", processed_command_line); /* run the command */ my_system_r(mac, processed_command_line, xpddefault_perfdata_timeout, &early_timeout, &exectime, NULL, 0); if(processed_command_line == NULL) return ERROR; /* check to see if the command timed out */ if(early_timeout == TRUE) logit(NSLOG_RUNTIME_WARNING, TRUE, "Warning: Host performance data command '%s' for host '%s' timed out after %d seconds\n", processed_command_line, hst->name, xpddefault_perfdata_timeout); /* free memory */ my_free(processed_command_line); return result; }
/* runs a host event handler command */ int run_host_event_handler(icinga_macros *mac, host *hst) { char *raw_command = NULL; char *processed_command = NULL; char *raw_logentry = NULL; char *processed_logentry = NULL; char *command_output = NULL; int early_timeout = FALSE; double exectime = 0.0; int result = 0; #ifdef USE_EVENT_BROKER struct timeval start_time; struct timeval end_time; int neb_result = OK; #endif int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; log_debug_info(DEBUGL_FUNCTIONS, 0, "run_host_event_handler()\n"); if (hst == NULL) return ERROR; /* bail if there's no command */ if (hst->event_handler == NULL) return ERROR; log_debug_info(DEBUGL_EVENTHANDLERS, 1, "Running event handler for host '%s'..\n", hst->name); #ifdef USE_EVENT_BROKER /* get start time */ gettimeofday(&start_time, NULL); #endif /* get the raw command line */ get_raw_command_line_r(mac, hst->event_handler_ptr, hst->event_handler, &raw_command, macro_options); if (raw_command == NULL) return ERROR; log_debug_info(DEBUGL_EVENTHANDLERS, 2, "Raw host event handler command line: %s\n", raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, &processed_command, macro_options); my_free(raw_command); if (processed_command == NULL) return ERROR; log_debug_info(DEBUGL_EVENTHANDLERS, 2, "Processed host event handler command line: %s\n", processed_command); if (log_event_handlers == TRUE) { asprintf(&raw_logentry, "HOST EVENT HANDLER: %s;$HOSTSTATE$;$HOSTSTATETYPE$;$HOSTATTEMPT$;%s\n", hst->name, hst->event_handler); process_macros_r(mac, raw_logentry, &processed_logentry, macro_options); logit(NSLOG_EVENT_HANDLER, FALSE, "%s", processed_logentry); } #ifdef USE_EVENT_BROKER /* send event data to broker */ end_time.tv_sec = 0L; end_time.tv_usec = 0L; neb_result = broker_event_handler(NEBTYPE_EVENTHANDLER_START, NEBFLAG_NONE, NEBATTR_NONE, HOST_EVENTHANDLER, (void *)hst, hst->current_state, hst->state_type, start_time, end_time, exectime, event_handler_timeout, early_timeout, result, hst->event_handler, processed_command, NULL, NULL); /* neb module wants to override (or cancel) the event handler - perhaps it will run the eventhandler itself */ if (neb_result == NEBERROR_CALLBACKOVERRIDE) { my_free(processed_command); my_free(raw_logentry); my_free(processed_logentry); return OK; } #endif /* run the command */ result = my_system_r(mac, processed_command, event_handler_timeout, &early_timeout, &exectime, &command_output, 0); /* check to see if the event handler timed out */ if (early_timeout == TRUE) logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE, "Warning: Host event handler command '%s' timed out after %d seconds\n", processed_command, event_handler_timeout); #ifdef USE_EVENT_BROKER /* get end time */ gettimeofday(&end_time, NULL); #endif #ifdef USE_EVENT_BROKER /* send event data to broker */ broker_event_handler(NEBTYPE_EVENTHANDLER_END, NEBFLAG_NONE, NEBATTR_NONE, HOST_EVENTHANDLER, (void *)hst, hst->current_state, hst->state_type, start_time, end_time, exectime, event_handler_timeout, early_timeout, result, hst->event_handler, processed_command, command_output, NULL); #endif /* free memory */ my_free(command_output); my_free(processed_command); my_free(raw_logentry); my_free(processed_logentry); return OK; }
void Syncdb::syncStart_r ( bool amThread ) { // turn this off g_process.m_suspendAutoSave = true; char cmd[1024]; // get synchost best ip char *ips = iptoa ( g_hostdb.getAliveIp ( g_hostdb.m_syncHost ) ); // his dir char *dir = g_hostdb.m_syncHost->m_dir; // use Host *me = g_hostdb.m_myHost; // ours char *mydir = me->m_dir; // generic long err; // loop over every rdb and every data and map file in each rdb for ( long i = 0 ; i < RDB_END ; i++ ) { // skip SYNCDB if ( i == RDB_SYNCDB ) continue; // get that rdb Rdb *rdb = getRdbFromId ( i ); // skip if none if ( ! rdb ) continue; // get coll for ( long j = 0 ; j < rdb->getNumBases() ; j++ ) { // get that base RdbBase *base = rdb->getBase(j);//m_bases[j]; if ( ! base ) continue; // get coll char *coll = base->m_coll; // and num long collnum = base->m_collnum; // make the dir sprintf ( cmd , "ssh %s 'mkdir %scoll.%s.%li'", ips,dir,coll,collnum); // excecute log ( LOG_INFO, "sync: %s", cmd ); //int err = my_system_r ( cmd, 3600*24 ); //if ( err != 0 ) goto hadError; // copy the files for ( long k = 0 ; k < base->m_numFiles ; k++ ) { // sleep while dumping. we are in a thread. if ( base->isDumping() ) sleep ( 1 ); // get map RdbMap *map = base->m_maps[k]; // copy the map file sprintf ( cmd , "rcp %s %s:%scoll.%s.%li/'", map->getFilename(),ips,dir,coll,collnum); log ( LOG_INFO, "sync: %s", cmd ); if ( ( err = my_system_r ( cmd, 3600*24 ) ) ) goto hadError; // get the file BigFile *f = base->m_files[k]; // loop over each little part file for ( long m = 0 ; m < f->m_numParts ; m++ ) { // get part file File *p = f->m_files[m]; // copy that sprintf ( cmd , "rcp %s %s:%scoll.%s.%li/'", p->m_filename,ips,dir,coll,collnum); // excecute log ( LOG_INFO, "sync: %s", cmd ); if ( ( err = my_system_r ( cmd, 3600*24 ) ) ) goto hadError; } } } } // make the dirs sprintf ( cmd , "ssh %s '" "mkdir %s/dict/ ;" "mkdir %s/dict/en/ ;" "mkdir %s/ucdata/ ;" "mkdir %s/.antiword/ ;" "'" , ips, dir, dir, dir, dir ); // excecute log ( LOG_INFO, "sync: %s", cmd ); if ( ( err = my_system_r ( cmd, 3600*24 ) ) ) goto hadError; // loop over the files in Process.cpp for ( long i = 0 ; i < 99999 ; i++ ) { // null means end if ( ! g_files[i] ) break; sprintf ( cmd , "rcp %s%s %s:%s", mydir,g_files[i],ips,dir); // excecute log ( LOG_INFO, "sync: %s", cmd ); if ( ( err = my_system_r ( cmd, 3600*24 ) ) ) goto hadError; } // new guy is NOT in sync sprintf ( cmd , "ssh %s 'echo 0 > %sinsync.dat", ips,dir); // excecute log ( LOG_INFO, "sync: %s", cmd ); if ( ( err = my_system_r ( cmd, 3600*24 ) ) ) goto hadError; // saved files sprintf ( cmd , "rcp %s*-saved.dat %s:%sinsync.dat", mydir,ips,dir); // excecute log ( LOG_INFO, "sync: %s", cmd ); if ( ( err = my_system_r ( cmd, 3600*24 ) ) ) goto hadError; // completed! return; hadError: log ( "sync: Call to system(\"%s\") had error %s.",cmd,strerror(err)); g_hostdb.m_syncHost->m_doingSync = 0; g_hostdb.m_syncHost = NULL; return; }
/* runs the global service event handler */ int run_global_service_event_handler(icinga_macros *mac, service *svc) { char *raw_command = NULL; char *processed_command = NULL; char *raw_logentry = NULL; char *processed_logentry = NULL; char *command_output = NULL; int early_timeout = FALSE; double exectime = 0.0; int result = 0; #ifdef USE_EVENT_BROKER struct timeval start_time; struct timeval end_time; int neb_result = OK; #endif int macro_options = STRIP_ILLEGAL_MACRO_CHARS | ESCAPE_MACRO_CHARS; log_debug_info(DEBUGL_FUNCTIONS, 0, "run_global_service_event_handler()\n"); if (svc == NULL) return ERROR; /* bail out if we shouldn't be running event handlers */ if (enable_event_handlers == FALSE) return OK; /* a global service event handler command has not been defined */ if (global_service_event_handler == NULL) return ERROR; log_debug_info(DEBUGL_EVENTHANDLERS, 1, "Running global event handler for service '%s' on host '%s'...\n", svc->description, svc->host_name); #ifdef USE_EVENT_BROKER /* get start time */ gettimeofday(&start_time, NULL); #endif /* get the raw command line */ get_raw_command_line_r(mac, global_service_event_handler_ptr, global_service_event_handler, &raw_command, macro_options); if (raw_command == NULL) { return ERROR; } log_debug_info(DEBUGL_EVENTHANDLERS, 2, "Raw global service event handler command line: %s\n", raw_command); /* process any macros in the raw command line */ process_macros_r(mac, raw_command, &processed_command, macro_options); my_free(raw_command); if (processed_command == NULL) return ERROR; log_debug_info(DEBUGL_EVENTHANDLERS, 2, "Processed global service event handler command line: %s\n", processed_command); if (log_event_handlers == TRUE) { dummy = asprintf(&raw_logentry, "GLOBAL SERVICE EVENT HANDLER: %s;%s;$SERVICESTATE$;$SERVICESTATETYPE$;$SERVICEATTEMPT$;%s\n", svc->host_name, svc->description, global_service_event_handler); process_macros_r(mac, raw_logentry, &processed_logentry, macro_options); logit(NSLOG_EVENT_HANDLER, FALSE, "%s", processed_logentry); } #ifdef USE_EVENT_BROKER /* send event data to broker */ end_time.tv_sec = 0L; end_time.tv_usec = 0L; neb_result = broker_event_handler(NEBTYPE_EVENTHANDLER_START, NEBFLAG_NONE, NEBATTR_NONE, GLOBAL_SERVICE_EVENTHANDLER, (void *)svc, svc->current_state, svc->state_type, start_time, end_time, exectime, event_handler_timeout, early_timeout, result, global_service_event_handler, processed_command, NULL, NULL); /* neb module wants to override (or cancel) the event handler - perhaps it will run the eventhandler itself */ if (neb_result == NEBERROR_CALLBACKOVERRIDE) { my_free(processed_command); my_free(raw_logentry); my_free(processed_logentry); return OK; } #endif /* run the command */ result = my_system_r(mac, processed_command, event_handler_timeout, &early_timeout, &exectime, &command_output, 0); /* check to see if the event handler timed out */ if (early_timeout == TRUE) logit(NSLOG_EVENT_HANDLER | NSLOG_RUNTIME_WARNING, TRUE, "警报: 全局服务事件处理命令 '%s' 在%d 秒后逾期\n", processed_command, event_handler_timeout); #ifdef USE_EVENT_BROKER /* get end time */ gettimeofday(&end_time, NULL); #endif #ifdef USE_EVENT_BROKER /* send event data to broker */ broker_event_handler(NEBTYPE_EVENTHANDLER_END, NEBFLAG_NONE, NEBATTR_NONE, GLOBAL_SERVICE_EVENTHANDLER, (void *)svc, svc->current_state, svc->state_type, start_time, end_time, exectime, event_handler_timeout, early_timeout, result, global_service_event_handler, processed_command, command_output, NULL); #endif /* free memory */ my_free(command_output); my_free(processed_command); my_free(raw_logentry); my_free(processed_logentry); return OK; }