![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * ICINGASTATS.C - Displays Icinga Statistics 00004 * 00005 * Program: Icingastats 00006 * Version: 1.4.0 00007 * License: GPL 00008 * Copyright (c) 2003-2008 Ethan Galstad (egalstad@nagios.org) 00009 * Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors 00010 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00011 * 00012 * License: 00013 * 00014 * This program is free software; you can redistribute it and/or modify 00015 * it under the terms of the GNU General Public License version 2 as 00016 * published by the Free Software Foundation. 00017 * 00018 * This program is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License 00024 * along with this program; if not, write to the Free Software 00025 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00026 * 00027 *****************************************************************************/ 00028 00029 #include "../include/config.h" 00030 #include "../include/common.h" 00031 #include "../include/icinga.h" 00032 #include "../include/locations.h" 00033 00034 /* make sure gcc3 won't hit here */ 00035 #ifndef GCCTOOOLD 00036 #include "../include/statsprofiler.h" 00037 #endif 00038 00039 #define STATUS_NO_DATA 0 00040 #define STATUS_INFO_DATA 1 00041 #define STATUS_PROGRAM_DATA 2 00042 #define STATUS_HOST_DATA 3 00043 #define STATUS_SERVICE_DATA 4 00044 00045 /* make sure gcc3 won't hit here */ 00046 #ifndef GCCTOOOLD 00047 profile_object* profiled_data = NULL; 00048 #endif 00049 00050 char *main_config_file=NULL; 00051 char *status_file=NULL; 00052 char *icingastats_file=NULL; 00053 char *mrtg_variables=NULL; 00054 char *mrtg_delimiter="\n"; 00055 00056 int mrtg_mode=FALSE; 00057 00058 time_t status_creation_date=0L; 00059 char *status_version=NULL; 00060 time_t program_start=0L; 00061 int status_service_entries=0; 00062 int status_host_entries=0; 00063 unsigned long nagios_pid=0L; 00064 00065 double min_service_state_change=0.0; 00066 int have_min_service_state_change=FALSE; 00067 double max_service_state_change=0.0; 00068 int have_max_service_state_change=FALSE; 00069 double average_service_state_change=0.0; 00070 double min_active_service_state_change=0.0; 00071 int have_min_active_service_state_change=FALSE; 00072 double max_active_service_state_change=0.0; 00073 int have_max_active_service_state_change=FALSE; 00074 double average_active_service_state_change=0.0; 00075 double min_active_service_latency=0.0; 00076 int have_min_active_service_latency=FALSE; 00077 double max_active_service_latency=0.0; 00078 int have_max_active_service_latency=FALSE; 00079 double average_active_service_latency=0.0; 00080 double min_active_service_execution_time=0.0; 00081 int have_min_active_service_execution_time=FALSE; 00082 double max_active_service_execution_time=0.0; 00083 int have_max_active_service_execution_time=FALSE; 00084 double average_active_service_execution_time=0.0; 00085 double min_passive_service_state_change=0.0; 00086 int have_min_passive_service_state_change=FALSE; 00087 double max_passive_service_state_change=0.0; 00088 int have_max_passive_service_state_change=FALSE; 00089 double average_passive_service_state_change=0.0; 00090 double min_passive_service_latency=0.0; 00091 int have_min_passive_service_latency=FALSE; 00092 double max_passive_service_latency=0.0; 00093 int have_max_passive_service_latency=FALSE; 00094 double average_passive_service_latency=0.0; 00095 00096 int have_min_host_state_change=FALSE; 00097 double min_host_state_change=0.0; 00098 int have_max_host_state_change=FALSE; 00099 double max_host_state_change=0.0; 00100 double average_host_state_change=0.0; 00101 int have_min_active_host_state_change=FALSE; 00102 double min_active_host_state_change=0.0; 00103 int have_max_active_host_state_change=FALSE; 00104 double max_active_host_state_change=0.0; 00105 double average_active_host_state_change=0.0; 00106 int have_min_active_host_latency=FALSE; 00107 double min_active_host_latency=0.0; 00108 int have_max_active_host_latency=FALSE; 00109 double max_active_host_latency=0.0; 00110 double average_active_host_latency=0.0; 00111 int have_min_active_host_execution_time=FALSE; 00112 double min_active_host_execution_time=0.0; 00113 int have_max_active_host_execution_time=FALSE; 00114 double max_active_host_execution_time=0.0; 00115 double average_active_host_execution_time=0.0; 00116 int have_min_passive_host_latency=FALSE; 00117 double min_passive_host_latency=0.0; 00118 int have_max_passive_host_latency=FALSE; 00119 double max_passive_host_latency=0.0; 00120 double average_passive_host_latency=0.0; 00121 double min_passive_host_state_change=0.0; 00122 int have_min_passive_host_state_change=FALSE; 00123 double max_passive_host_state_change=0.0; 00124 int have_max_passive_host_state_change=FALSE; 00125 double average_passive_host_state_change=0.0; 00126 00127 int passive_service_checks=0; 00128 int active_service_checks=0; 00129 int services_ok=0; 00130 int services_warning=0; 00131 int services_unknown=0; 00132 int services_critical=0; 00133 int services_flapping=0; 00134 int services_in_downtime=0; 00135 int services_checked=0; 00136 int services_scheduled=0; 00137 int passive_host_checks=0; 00138 int active_host_checks=0; 00139 int hosts_up=0; 00140 int hosts_down=0; 00141 int hosts_unreachable=0; 00142 int hosts_flapping=0; 00143 int hosts_in_downtime=0; 00144 int hosts_checked=0; 00145 int hosts_scheduled=0; 00146 00147 int passive_services_checked_last_1min=0; 00148 int passive_services_checked_last_5min=0; 00149 int passive_services_checked_last_15min=0; 00150 int passive_services_checked_last_1hour=0; 00151 int active_services_checked_last_1min=0; 00152 int active_services_checked_last_5min=0; 00153 int active_services_checked_last_15min=0; 00154 int active_services_checked_last_1hour=0; 00155 int passive_hosts_checked_last_1min=0; 00156 int passive_hosts_checked_last_5min=0; 00157 int passive_hosts_checked_last_15min=0; 00158 int passive_hosts_checked_last_1hour=0; 00159 int active_hosts_checked_last_1min=0; 00160 int active_hosts_checked_last_5min=0; 00161 int active_hosts_checked_last_15min=0; 00162 int active_hosts_checked_last_1hour=0; 00163 00164 int active_host_checks_last_1min=0; 00165 int active_host_checks_last_5min=0; 00166 int active_host_checks_last_15min=0; 00167 int active_ondemand_host_checks_last_1min=0; 00168 int active_ondemand_host_checks_last_5min=0; 00169 int active_ondemand_host_checks_last_15min=0; 00170 int active_scheduled_host_checks_last_1min=0; 00171 int active_scheduled_host_checks_last_5min=0; 00172 int active_scheduled_host_checks_last_15min=0; 00173 int passive_host_checks_last_1min=0; 00174 int passive_host_checks_last_5min=0; 00175 int passive_host_checks_last_15min=0; 00176 int active_cached_host_checks_last_1min=0; 00177 int active_cached_host_checks_last_5min=0; 00178 int active_cached_host_checks_last_15min=0; 00179 int parallel_host_checks_last_1min=0; 00180 int parallel_host_checks_last_5min=0; 00181 int parallel_host_checks_last_15min=0; 00182 int serial_host_checks_last_1min=0; 00183 int serial_host_checks_last_5min=0; 00184 int serial_host_checks_last_15min=0; 00185 00186 int active_service_checks_last_1min=0; 00187 int active_service_checks_last_5min=0; 00188 int active_service_checks_last_15min=0; 00189 int active_ondemand_service_checks_last_1min=0; 00190 int active_ondemand_service_checks_last_5min=0; 00191 int active_ondemand_service_checks_last_15min=0; 00192 int active_scheduled_service_checks_last_1min=0; 00193 int active_scheduled_service_checks_last_5min=0; 00194 int active_scheduled_service_checks_last_15min=0; 00195 int passive_service_checks_last_1min=0; 00196 int passive_service_checks_last_5min=0; 00197 int passive_service_checks_last_15min=0; 00198 int active_cached_service_checks_last_1min=0; 00199 int active_cached_service_checks_last_5min=0; 00200 int active_cached_service_checks_last_15min=0; 00201 00202 int external_commands_last_1min=0; 00203 int external_commands_last_5min=0; 00204 int external_commands_last_15min=0; 00205 00206 int total_external_command_buffer_slots=0; 00207 int used_external_command_buffer_slots=0; 00208 int high_external_command_buffer_slots=0; 00209 00210 /* make sure gcc3 won't hit here */ 00211 #ifndef GCCTOOOLD 00212 int event_profiling_enabled=0; 00213 #endif 00214 00215 00216 int display_mrtg_values(void); 00217 int display_stats(void); 00218 int read_config_file(void); 00219 int read_status_file(void); 00220 void strip(char *); 00221 void get_time_breakdown(unsigned long,int *,int *,int *,int *); 00222 int read_icingastats_file(void); 00223 00224 int main(int argc, char **argv){ 00225 int result; 00226 int error=FALSE; 00227 int display_license=FALSE; 00228 int display_help=FALSE; 00229 int c; 00230 /* make sure gcc3 won't hit here */ 00231 #ifndef GCCTOOOLD 00232 profile_object *p=NULL; 00233 #endif 00234 00235 #ifdef HAVE_GETOPT_H 00236 int option_index=0; 00237 static struct option long_options[]= 00238 { 00239 {"help",no_argument,0,'h'}, 00240 {"version",no_argument,0,'V'}, 00241 {"license",no_argument,0,'L'}, 00242 {"config",required_argument,0,'c'}, 00243 {"statsfile",required_argument,0,'s'}, 00244 {"mrtg",no_argument,0,'m'}, 00245 {"data",required_argument,0,'d'}, 00246 {"delimiter",required_argument,0,'D'}, 00247 {0,0,0,0} 00248 }; 00249 #endif 00250 00251 /* defaults */ 00252 main_config_file=strdup(DEFAULT_CONFIG_FILE); 00253 status_file=strdup(DEFAULT_STATUS_FILE); 00254 00255 /* get all command line arguments */ 00256 while(1){ 00257 00258 #ifdef HAVE_GETOPT_H 00259 c=getopt_long(argc,argv,"+hVLc:ms:d:D:",long_options,&option_index); 00260 #else 00261 c=getopt(argc,argv,"+hVLc:ms:d:D:"); 00262 #endif 00263 00264 if(c==-1 || c==EOF) 00265 break; 00266 00267 switch(c){ 00268 00269 case '?': 00270 case 'h': 00271 display_help=TRUE; 00272 break; 00273 case 'V': 00274 display_license=TRUE; 00275 break; 00276 case 'L': 00277 display_license=TRUE; 00278 break; 00279 case 'c': 00280 if(main_config_file) 00281 free(main_config_file); 00282 main_config_file=strdup(optarg); 00283 break; 00284 case 's': 00285 icingastats_file=strdup(optarg); 00286 break; 00287 case 'm': 00288 mrtg_mode=TRUE; 00289 break; 00290 case 'd': 00291 mrtg_variables=strdup(optarg); 00292 break; 00293 case 'D': 00294 mrtg_delimiter=strdup(optarg); 00295 break; 00296 00297 default: 00298 break; 00299 } 00300 00301 } 00302 00303 if(mrtg_mode==FALSE){ 00304 printf("\n%s Stats %s\n", PROGRAM_NAME, PROGRAM_VERSION); 00305 printf("Copyright (c) 2009 Nagios Core Development Team and Community Contributors\n"); 00306 printf("Copyright (c) 1999-2009 Ethan Galstad\n"); 00307 printf("Last Modified: %s\n",PROGRAM_MODIFICATION_DATE); 00308 printf("License: GPL\n\n"); 00309 } 00310 00311 /* just display the license */ 00312 if(display_license==TRUE){ 00313 00314 printf("This program is free software; you can redistribute it and/or modify\n"); 00315 printf("it under the terms of the GNU General Public License version 2 as\n"); 00316 printf("published by the Free Software Foundation.\n\n"); 00317 printf("This program is distributed in the hope that it will be useful,\n"); 00318 printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); 00319 printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); 00320 printf("GNU General Public License for more details.\n\n"); 00321 printf("You should have received a copy of the GNU General Public License\n"); 00322 printf("along with this program; if not, write to the Free Software\n"); 00323 printf("Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n\n"); 00324 00325 exit(OK); 00326 } 00327 00328 /* if there are no command line options (or if we encountered an error), print usage */ 00329 if(error==TRUE || display_help==TRUE){ 00330 00331 printf("Usage: %s [options]\n",argv[0]); 00332 printf("\n"); 00333 printf("Startup:\n"); 00334 printf(" -V, --version display program version information and exit.\n"); 00335 printf(" -L, --license display license information and exit.\n"); 00336 printf(" -h, --help display usage information and exit.\n"); 00337 printf("\n"); 00338 printf("Input file:\n"); 00339 printf(" -c, --config=FILE specifies location of main %s config file.\n", PROGRAM_NAME); 00340 printf(" -s, --statsfile=FILE specifies alternate location of file to read %s\n", PROGRAM_NAME); 00341 printf(" performance data from.\n"); 00342 printf("\n"); 00343 printf("Output:\n"); 00344 printf(" -m, --mrtg display output in MRTG compatible format.\n"); 00345 printf(" -d, --data=VARS comma-seperated list of variables to output in MRTG\n"); 00346 printf(" (or compatible) format. See possible values below.\n"); 00347 printf(" Percentages are rounded, times are in milliseconds.\n"); 00348 printf(" -D, --delimiter=C character to use as delimiter in MRTG output mode.\n"); 00349 printf(" Defaults to a newline.\n"); 00350 printf("\n"); 00351 printf("MRTG DATA VARIABLES (-d option):\n"); 00352 printf(" PROGRUNTIME string with time %s process has been running.\n", PROGRAM_NAME); 00353 printf(" PROGRUNTIMETT time %s process has been running (time_t format).\n", PROGRAM_NAME); 00354 printf(" STATUSFILEAGE string with age of status data file.\n"); 00355 printf(" STATUSFILEAGETT string with age of status data file (time_t format).\n"); 00356 printf(" %sVERSION string with %s version.\n", PROGRAM_NAME_UC, PROGRAM_NAME); 00357 printf(" %sPID pid number of %s deamon.\n", PROGRAM_NAME_UC, PROGRAM_NAME); 00358 printf(" %sVERPID string with %s version and PID.\n", PROGRAM_NAME_UC, PROGRAM_NAME); 00359 printf(" TOTCMDBUF total number of external command buffer slots available.\n"); 00360 printf(" USEDCMDBUF number of external command buffer slots currently in use.\n"); 00361 printf(" HIGHCMDBUF highest number of external command buffer slots ever in use.\n"); 00362 printf(" NUMSERVICES total number of services.\n"); 00363 printf(" NUMHOSTS total number of hosts.\n"); 00364 printf(" NUMSVCOK number of services OK.\n"); 00365 printf(" NUMSVCWARN number of services WARNING.\n"); 00366 printf(" NUMSVCUNKN number of services UNKNOWN.\n"); 00367 printf(" NUMSVCCRIT number of services CRITICAL.\n"); 00368 printf(" NUMSVCPROB number of service problems (WARNING, UNKNOWN or CRITIAL).\n"); 00369 printf(" NUMSVCCHECKED number of services that have been checked since start.\n"); 00370 printf(" NUMSVCSCHEDULED number of services that are currently scheduled to be checked.\n"); 00371 printf(" NUMSVCFLAPPING number of services that are currently flapping.\n"); 00372 printf(" NUMSVCDOWNTIME number of services that are currently in downtime.\n"); 00373 printf(" NUMHSTUP number of hosts UP.\n"); 00374 printf(" NUMHSTDOWN number of hosts DOWN.\n"); 00375 printf(" NUMHSTUNR number of hosts UNREACHABLE.\n"); 00376 printf(" NUMHSTPROB number of host problems (DOWN or UNREACHABLE).\n"); 00377 printf(" NUMHSTCHECKED number of hosts that have been checked since start.\n"); 00378 printf(" NUMHSTSCHEDULED number of hosts that are currently scheduled to be checked.\n"); 00379 printf(" NUMHSTFLAPPING number of hosts that are currently flapping.\n"); 00380 printf(" NUMHSTDOWNTIME number of hosts that are currently in downtime.\n"); 00381 printf(" NUMHSTACTCHKxM number of hosts actively checked in last 1/5/15/60 minutes.\n"); 00382 printf(" NUMHSTPSVCHKxM number of hosts passively checked in last 1/5/15/60 minutes.\n"); 00383 printf(" NUMSVCACTCHKxM number of services actively checked in last 1/5/15/60 minutes.\n"); 00384 printf(" NUMSVCPSVCHKxM number of services passively checked in last 1/5/15/60 minutes.\n"); 00385 printf(" xxxACTSVCLAT MIN/MAX/AVG active service check latency (ms).\n"); 00386 printf(" xxxACTSVCEXT MIN/MAX/AVG active service check execution time (ms).\n"); 00387 printf(" xxxACTSVCPSC MIN/MAX/AVG active service check %% state change.\n"); 00388 printf(" xxxPSVSVCLAT MIN/MAX/AVG passive service check latency (ms).\n"); 00389 printf(" xxxPSVSVCPSC MIN/MAX/AVG passive service check %% state change.\n"); 00390 printf(" xxxSVCPSC MIN/MAX/AVG service check %% state change.\n"); 00391 printf(" xxxACTHSTLAT MIN/MAX/AVG active host check latency (ms).\n"); 00392 printf(" xxxACTHSTEXT MIN/MAX/AVG active host check execution time (ms).\n"); 00393 printf(" xxxACTHSTPSC MIN/MAX/AVG active host check %% state change.\n"); 00394 printf(" xxxPSVHSTLAT MIN/MAX/AVG passive host check latency (ms).\n"); 00395 printf(" xxxPSVHSTPSC MIN/MAX/AVG passive host check %% state change.\n"); 00396 printf(" xxxHSTPSC MIN/MAX/AVG host check %% state change.\n"); 00397 printf(" NUMACTHSTCHECKSxM number of total active host checks occuring in last 1/5/15 minutes.\n"); 00398 printf(" NUMOACTHSTCHECKSxM number of on-demand active host checks occuring in last 1/5/15 minutes.\n"); 00399 printf(" NUMCACHEDHSTCHECKSxM number of cached host checks occuring in last 1/5/15 minutes.\n"); 00400 printf(" NUMSACTHSTCHECKSxM number of scheduled active host checks occuring in last 1/5/15 minutes.\n"); 00401 printf(" NUMPARHSTCHECKSxM number of parallel host checks occuring in last 1/5/15 minutes.\n"); 00402 printf(" NUMSERHSTCHECKSxM number of serial host checks occuring in last 1/5/15 minutes.\n"); 00403 printf(" NUMPSVHSTCHECKSxM number of passive host checks occuring in last 1/5/15 minutes.\n"); 00404 printf(" NUMACTSVCCHECKSxM number of total active service checks occuring in last 1/5/15 minutes.\n"); 00405 printf(" NUMOACTSVCCHECKSxM number of on-demand active service checks occuring in last 1/5/15 minutes.\n"); 00406 printf(" NUMCACHEDSVCCHECKSxM number of cached service checks occuring in last 1/5/15 minutes.\n"); 00407 printf(" NUMSACTSVCCHECKSxM number of scheduled active service checks occuring in last 1/5/15 minutes.\n"); 00408 printf(" NUMPSVSVCCHECKSxM number of passive service checks occuring in last 1/5/15 minutes.\n"); 00409 printf(" NUMEXTCMDSxM number of external commands processed in last 1/5/15 minutes.\n"); 00410 00411 /* make sure gcc3 won't hit here */ 00412 #ifndef GCCTOOOLD 00413 /* event profiler */ 00414 if(event_profiling_enabled==TRUE){ 00415 00416 /* read main config file */ 00417 result=read_config_file(); 00418 if(result==ERROR && mrtg_mode==FALSE){ 00419 printf("Error processing config file '%s'\n",main_config_file); 00420 return ERROR; 00421 } 00422 00423 /* read the status file */ 00424 result=read_status_file(); 00425 if(result==ERROR && mrtg_mode==FALSE){ 00426 printf("Error reading status file '%s'\n",status_file); 00427 return ERROR; 00428 } 00429 00430 p = profiled_data; 00431 while(p){ 00432 printf("PROFILE_(COUNTER/ELAPSED/EVENTPS)_%s\t\tdynamically generated profile data.\n",p->name); 00433 p = p->next; 00434 } 00435 } 00436 #endif 00437 printf("\n"); 00438 printf(" Note: Replace x's in MRTG variable names with 'MIN', 'MAX', 'AVG', or the\n"); 00439 printf(" the appropriate number (i.e. '1', '5', '15', or '60').\n"); 00440 printf("\n"); 00441 00442 exit(ERROR); 00443 } 00444 00445 /* read pre-processed stats file */ 00446 if(icingastats_file){ 00447 result=read_icingastats_file(); 00448 if(result==ERROR && mrtg_mode==FALSE){ 00449 printf("Error reading stats file '%s': %s\n",icingastats_file,strerror(errno)); 00450 return ERROR; 00451 } 00452 } 00453 00454 /* else read the normal status file */ 00455 else{ 00456 /* read main config file */ 00457 result=read_config_file(); 00458 if(result==ERROR && mrtg_mode==FALSE){ 00459 printf("Error processing config file '%s'\n",main_config_file); 00460 return ERROR; 00461 } 00462 00463 /* read status file */ 00464 result=read_status_file(); 00465 if(result==ERROR && mrtg_mode==FALSE){ 00466 printf("Error reading status file '%s': %s\n",status_file,strerror(errno)); 00467 return ERROR; 00468 } 00469 } 00470 00471 /* display stats */ 00472 if(mrtg_mode==FALSE) 00473 display_stats(); 00474 else 00475 display_mrtg_values(); 00476 00477 if(icingastats_file) 00478 free(icingastats_file); 00479 00480 /* Opsera patch - return based on error, because mrtg_mode was always returning OK */ 00481 if(result==ERROR) 00482 return ERROR; 00483 else 00484 return OK; 00485 } 00486 00487 00488 00489 int display_mrtg_values(void){ 00490 char *temp_ptr; 00491 time_t current_time; 00492 unsigned long time_difference; 00493 int days; 00494 int hours; 00495 int minutes; 00496 int seconds; 00497 00498 time(¤t_time); 00499 00500 if(mrtg_variables==NULL) 00501 return OK; 00502 00503 /* process all variables */ 00504 for(temp_ptr=strtok(mrtg_variables,",");temp_ptr!=NULL;temp_ptr=strtok(NULL,",")){ 00505 00506 if(!strcmp(temp_ptr,"PROGRUNTIME")){ 00507 time_difference=(current_time-program_start); 00508 get_time_breakdown(time_difference,&days,&hours,&minutes,&seconds); 00509 printf("%dd %dh %dm %ds%s",days,hours,minutes,seconds,mrtg_delimiter); 00510 } 00511 else if(!strcmp(temp_ptr,"PROGRUNTIMETT")){ 00512 time_difference=(current_time-program_start); 00513 printf("%lu%s",time_difference,mrtg_delimiter); 00514 } 00515 else if(!strcmp(temp_ptr,"STATUSFILEAGE")){ 00516 time_difference=(current_time-status_creation_date); 00517 get_time_breakdown(time_difference,&days,&hours,&minutes,&seconds); 00518 printf("%dd %dh %dm %ds%s",days,hours,minutes,seconds,mrtg_delimiter); 00519 } 00520 else if(!strcmp(temp_ptr,"STATUSFILEAGETT")){ 00521 time_difference=(current_time-status_creation_date); 00522 printf("%lu%s",time_difference,mrtg_delimiter); 00523 } 00524 else if(!strcmp(temp_ptr,"ICINGAVERSION")) 00525 printf("%s%s",status_version,mrtg_delimiter); 00526 else if(!strcmp(temp_ptr,"ICINGAPID")) 00527 printf("%lu%s",nagios_pid,mrtg_delimiter); 00528 else if(!strcmp(temp_ptr,"ICINGAVERPID")) 00529 printf("%s %s (pid=%lu)%s", PROGRAM_NAME, status_version, nagios_pid, mrtg_delimiter); 00530 00531 00532 else if(!strcmp(temp_ptr,"TOTCMDBUF")) 00533 printf("%d%s",total_external_command_buffer_slots,mrtg_delimiter); 00534 else if(!strcmp(temp_ptr,"USEDCMDBUF")) 00535 printf("%d%s",used_external_command_buffer_slots,mrtg_delimiter); 00536 else if(!strcmp(temp_ptr,"HIGHCMDBUF")) 00537 printf("%d%s",high_external_command_buffer_slots,mrtg_delimiter); 00538 00539 else if(!strcmp(temp_ptr,"NUMSERVICES")) 00540 printf("%d%s",status_service_entries,mrtg_delimiter); 00541 else if(!strcmp(temp_ptr,"NUMHOSTS")) 00542 printf("%d%s",status_host_entries,mrtg_delimiter); 00543 00544 /* active service check latency */ 00545 else if(!strcmp(temp_ptr,"MINACTSVCLAT")) 00546 printf("%d%s",(int)(min_active_service_latency*1000),mrtg_delimiter); 00547 else if(!strcmp(temp_ptr,"MAXACTSVCLAT")) 00548 printf("%d%s",(int)(max_active_service_latency*1000),mrtg_delimiter); 00549 else if(!strcmp(temp_ptr,"AVGACTSVCLAT")) 00550 printf("%d%s",(int)(average_active_service_latency*1000),mrtg_delimiter); 00551 00552 /* active service check execution time */ 00553 else if(!strcmp(temp_ptr,"MINACTSVCEXT")) 00554 printf("%d%s",(int)(min_active_service_execution_time*1000),mrtg_delimiter); 00555 else if(!strcmp(temp_ptr,"MAXACTSVCEXT")) 00556 printf("%d%s",(int)(max_active_service_execution_time*1000),mrtg_delimiter); 00557 else if(!strcmp(temp_ptr,"AVGACTSVCEXT")) 00558 printf("%d%s",(int)(average_active_service_execution_time*1000),mrtg_delimiter); 00559 00560 /* active service check percent state change */ 00561 else if(!strcmp(temp_ptr,"MINACTSVCPSC")) 00562 printf("%d%s",(int)min_active_service_state_change,mrtg_delimiter); 00563 else if(!strcmp(temp_ptr,"MAXACTSVCPSC")) 00564 printf("%d%s",(int)max_active_service_state_change,mrtg_delimiter); 00565 else if(!strcmp(temp_ptr,"AVGACTSVCPSC")) 00566 printf("%d%s",(int)average_active_service_state_change,mrtg_delimiter); 00567 00568 /* passive service check latency */ 00569 else if(!strcmp(temp_ptr,"MINPSVSVCLAT")) 00570 printf("%d%s",(int)(min_passive_service_latency*1000),mrtg_delimiter); 00571 else if(!strcmp(temp_ptr,"MAXPSVSVCLAT")) 00572 printf("%d%s",(int)(max_passive_service_latency*1000),mrtg_delimiter); 00573 else if(!strcmp(temp_ptr,"AVGPSVSVCLAT")) 00574 printf("%d%s",(int)(average_passive_service_latency*1000),mrtg_delimiter); 00575 00576 /* passive service check percent state change */ 00577 else if(!strcmp(temp_ptr,"MINPSVSVCPSC")) 00578 printf("%d%s",(int)min_passive_service_state_change,mrtg_delimiter); 00579 else if(!strcmp(temp_ptr,"MAXPSVSVCPSC")) 00580 printf("%d%s",(int)max_passive_service_state_change,mrtg_delimiter); 00581 else if(!strcmp(temp_ptr,"AVGPSVSVCPSC")) 00582 printf("%d%s",(int)average_passive_service_state_change,mrtg_delimiter); 00583 00584 /* service check percent state change */ 00585 else if(!strcmp(temp_ptr,"MINSVCPSC")) 00586 printf("%d%s",(int)min_service_state_change,mrtg_delimiter); 00587 else if(!strcmp(temp_ptr,"MAXSVCPSC")) 00588 printf("%d%s",(int)max_service_state_change,mrtg_delimiter); 00589 else if(!strcmp(temp_ptr,"AVGSVCPSC")) 00590 printf("%d%s",(int)average_service_state_change,mrtg_delimiter); 00591 00592 /* active host check latency */ 00593 else if(!strcmp(temp_ptr,"MINACTHSTLAT")) 00594 printf("%d%s",(int)(min_active_host_latency*1000),mrtg_delimiter); 00595 else if(!strcmp(temp_ptr,"MAXACTHSTLAT")) 00596 printf("%d%s",(int)(max_active_host_latency*1000),mrtg_delimiter); 00597 else if(!strcmp(temp_ptr,"AVGACTHSTLAT")) 00598 printf("%d%s",(int)(average_active_host_latency*1000),mrtg_delimiter); 00599 00600 /* active host check execution time */ 00601 else if(!strcmp(temp_ptr,"MINACTHSTEXT")) 00602 printf("%d%s",(int)(min_active_host_execution_time*1000),mrtg_delimiter); 00603 else if(!strcmp(temp_ptr,"MAXACTHSTEXT")) 00604 printf("%d%s",(int)(max_active_host_execution_time*1000),mrtg_delimiter); 00605 else if(!strcmp(temp_ptr,"AVGACTHSTEXT")) 00606 printf("%d%s",(int)(average_active_host_execution_time*1000),mrtg_delimiter); 00607 00608 /* active host check percent state change */ 00609 else if(!strcmp(temp_ptr,"MINACTHSTPSC")) 00610 printf("%d%s",(int)min_active_host_state_change,mrtg_delimiter); 00611 else if(!strcmp(temp_ptr,"MAXACTHSTPSC")) 00612 printf("%d%s",(int)max_active_host_state_change,mrtg_delimiter); 00613 else if(!strcmp(temp_ptr,"AVGACTHSTPSC")) 00614 printf("%d%s",(int)average_active_host_state_change,mrtg_delimiter); 00615 00616 /* passive host check latency */ 00617 else if(!strcmp(temp_ptr,"MINPSVHSTLAT")) 00618 printf("%d%s",(int)(min_passive_host_latency*1000),mrtg_delimiter); 00619 else if(!strcmp(temp_ptr,"MAXPSVHSTLAT")) 00620 printf("%d%s",(int)(max_passive_host_latency*1000),mrtg_delimiter); 00621 else if(!strcmp(temp_ptr,"AVGPSVHSTLAT")) 00622 printf("%d%s",(int)(average_passive_host_latency*1000),mrtg_delimiter); 00623 00624 /* passive host check percent state change */ 00625 else if(!strcmp(temp_ptr,"MINPSVHSTPSC")) 00626 printf("%d%s",(int)min_passive_host_state_change,mrtg_delimiter); 00627 else if(!strcmp(temp_ptr,"MAXPSVHSTPSC")) 00628 printf("%d%s",(int)max_passive_host_state_change,mrtg_delimiter); 00629 else if(!strcmp(temp_ptr,"AVGPSVHSTPSC")) 00630 printf("%d%s",(int)average_passive_host_state_change,mrtg_delimiter); 00631 00632 /* host check percent state change */ 00633 else if(!strcmp(temp_ptr,"MINHSTPSC")) 00634 printf("%d%s",(int)min_host_state_change,mrtg_delimiter); 00635 else if(!strcmp(temp_ptr,"MAXHSTPSC")) 00636 printf("%d%s",(int)max_host_state_change,mrtg_delimiter); 00637 else if(!strcmp(temp_ptr,"AVGHSTPSC")) 00638 printf("%d%s",(int)average_host_state_change,mrtg_delimiter); 00639 00640 /* active host checks over time */ 00641 else if(!strcmp(temp_ptr,"NUMHSTACTCHK1M")) 00642 printf("%d%s",active_hosts_checked_last_1min,mrtg_delimiter); 00643 else if(!strcmp(temp_ptr,"NUMHSTACTCHK5M")) 00644 printf("%d%s",active_hosts_checked_last_5min,mrtg_delimiter); 00645 else if(!strcmp(temp_ptr,"NUMHSTACTCHK15M")) 00646 printf("%d%s",active_hosts_checked_last_15min,mrtg_delimiter); 00647 else if(!strcmp(temp_ptr,"NUMHSTACTCHK60M")) 00648 printf("%d%s",active_hosts_checked_last_1hour,mrtg_delimiter); 00649 00650 /* passive host checks over time */ 00651 else if(!strcmp(temp_ptr,"NUMHSTPSVCHK1M")) 00652 printf("%d%s",passive_hosts_checked_last_1min,mrtg_delimiter); 00653 else if(!strcmp(temp_ptr,"NUMHSTPSVCHK5M")) 00654 printf("%d%s",passive_hosts_checked_last_5min,mrtg_delimiter); 00655 else if(!strcmp(temp_ptr,"NUMHSTPSVCHK15M")) 00656 printf("%d%s",passive_hosts_checked_last_15min,mrtg_delimiter); 00657 else if(!strcmp(temp_ptr,"NUMHSTPSVCHK60M")) 00658 printf("%d%s",passive_hosts_checked_last_1hour,mrtg_delimiter); 00659 00660 /* active service checks over time */ 00661 else if(!strcmp(temp_ptr,"NUMSVCACTCHK1M")) 00662 printf("%d%s",active_services_checked_last_1min,mrtg_delimiter); 00663 else if(!strcmp(temp_ptr,"NUMSVCACTCHK5M")) 00664 printf("%d%s",active_services_checked_last_5min,mrtg_delimiter); 00665 else if(!strcmp(temp_ptr,"NUMSVCACTCHK15M")) 00666 printf("%d%s",active_services_checked_last_15min,mrtg_delimiter); 00667 else if(!strcmp(temp_ptr,"NUMSVCACTCHK60M")) 00668 printf("%d%s",active_services_checked_last_1hour,mrtg_delimiter); 00669 00670 /* passive service checks over time */ 00671 else if(!strcmp(temp_ptr,"NUMSVCPSVCHK1M")) 00672 printf("%d%s",passive_services_checked_last_1min,mrtg_delimiter); 00673 else if(!strcmp(temp_ptr,"NUMSVCPSVCHK5M")) 00674 printf("%d%s",passive_services_checked_last_5min,mrtg_delimiter); 00675 else if(!strcmp(temp_ptr,"NUMSVCPSVCHK15M")) 00676 printf("%d%s",passive_services_checked_last_15min,mrtg_delimiter); 00677 else if(!strcmp(temp_ptr,"NUMSVCPSVCHK60M")) 00678 printf("%d%s",passive_services_checked_last_1hour,mrtg_delimiter); 00679 00680 /* host check statistics */ 00681 else if(!strcmp(temp_ptr,"NUMACTHSTCHECKS1M")) 00682 printf("%d%s",active_host_checks_last_1min,mrtg_delimiter); 00683 else if(!strcmp(temp_ptr,"NUMACTHSTCHECKS5M")) 00684 printf("%d%s",active_host_checks_last_5min,mrtg_delimiter); 00685 else if(!strcmp(temp_ptr,"NUMACTHSTCHECKS15M")) 00686 printf("%d%s",active_host_checks_last_15min,mrtg_delimiter); 00687 else if(!strcmp(temp_ptr,"NUMOACTHSTCHECKS1M")) 00688 printf("%d%s",active_ondemand_host_checks_last_1min,mrtg_delimiter); 00689 else if(!strcmp(temp_ptr,"NUMOACTHSTCHECKS5M")) 00690 printf("%d%s",active_ondemand_host_checks_last_5min,mrtg_delimiter); 00691 else if(!strcmp(temp_ptr,"NUMOACTHSTCHECKS15M")) 00692 printf("%d%s",active_ondemand_host_checks_last_15min,mrtg_delimiter); 00693 else if(!strcmp(temp_ptr,"NUMSACTHSTCHECKS1M")) 00694 printf("%d%s",active_scheduled_host_checks_last_1min,mrtg_delimiter); 00695 else if(!strcmp(temp_ptr,"NUMSACTHSTCHECKS5M")) 00696 printf("%d%s",active_scheduled_host_checks_last_5min,mrtg_delimiter); 00697 else if(!strcmp(temp_ptr,"NUMSACTHSTCHECKS15M")) 00698 printf("%d%s",active_scheduled_host_checks_last_15min,mrtg_delimiter); 00699 else if(!strcmp(temp_ptr,"NUMPARHSTCHECKS1M")) 00700 printf("%d%s",parallel_host_checks_last_1min,mrtg_delimiter); 00701 else if(!strcmp(temp_ptr,"NUMPARHSTCHECKS5M")) 00702 printf("%d%s",parallel_host_checks_last_5min,mrtg_delimiter); 00703 else if(!strcmp(temp_ptr,"NUMPARHSTCHECKS15M")) 00704 printf("%d%s",parallel_host_checks_last_15min,mrtg_delimiter); 00705 else if(!strcmp(temp_ptr,"NUMSERHSTCHECKS1M")) 00706 printf("%d%s",serial_host_checks_last_1min,mrtg_delimiter); 00707 else if(!strcmp(temp_ptr,"NUMSERHSTCHECKS5M")) 00708 printf("%d%s",serial_host_checks_last_5min,mrtg_delimiter); 00709 else if(!strcmp(temp_ptr,"NUMSERHSTCHECKS15M")) 00710 printf("%d%s",serial_host_checks_last_15min,mrtg_delimiter); 00711 else if(!strcmp(temp_ptr,"NUMPSVHSTCHECKS1M")) 00712 printf("%d%s",passive_host_checks_last_1min,mrtg_delimiter); 00713 else if(!strcmp(temp_ptr,"NUMPSVHSTCHECKS5M")) 00714 printf("%d%s",passive_host_checks_last_5min,mrtg_delimiter); 00715 else if(!strcmp(temp_ptr,"NUMPSVHSTCHECKS15M")) 00716 printf("%d%s",passive_host_checks_last_15min,mrtg_delimiter); 00717 else if(!strcmp(temp_ptr,"NUMCACHEDHSTCHECKS1M")) 00718 printf("%d%s",active_cached_host_checks_last_1min,mrtg_delimiter); 00719 else if(!strcmp(temp_ptr,"NUMCACHEDHSTCHECKS5M")) 00720 printf("%d%s",active_cached_host_checks_last_5min,mrtg_delimiter); 00721 else if(!strcmp(temp_ptr,"NUMCACHEDHSTCHECKS15M")) 00722 printf("%d%s",active_cached_host_checks_last_15min,mrtg_delimiter); 00723 00724 /* service check statistics */ 00725 else if(!strcmp(temp_ptr,"NUMACTSVCCHECKS1M")) 00726 printf("%d%s",active_service_checks_last_1min,mrtg_delimiter); 00727 else if(!strcmp(temp_ptr,"NUMACTSVCCHECKS5M")) 00728 printf("%d%s",active_service_checks_last_5min,mrtg_delimiter); 00729 else if(!strcmp(temp_ptr,"NUMACTSVCCHECKS15M")) 00730 printf("%d%s",active_service_checks_last_15min,mrtg_delimiter); 00731 else if(!strcmp(temp_ptr,"NUMOACTSVCCHECKS1M")) 00732 printf("%d%s",active_ondemand_service_checks_last_1min,mrtg_delimiter); 00733 else if(!strcmp(temp_ptr,"NUMOACTSVCCHECKS5M")) 00734 printf("%d%s",active_ondemand_service_checks_last_5min,mrtg_delimiter); 00735 else if(!strcmp(temp_ptr,"NUMOACTSVCCHECKS15M")) 00736 printf("%d%s",active_ondemand_service_checks_last_15min,mrtg_delimiter); 00737 else if(!strcmp(temp_ptr,"NUMSACTSVCCHECKS1M")) 00738 printf("%d%s",active_scheduled_service_checks_last_1min,mrtg_delimiter); 00739 else if(!strcmp(temp_ptr,"NUMSACTSVCCHECKS5M")) 00740 printf("%d%s",active_scheduled_service_checks_last_5min,mrtg_delimiter); 00741 else if(!strcmp(temp_ptr,"NUMSACTSVCCHECKS15M")) 00742 printf("%d%s",active_scheduled_service_checks_last_15min,mrtg_delimiter); 00743 else if(!strcmp(temp_ptr,"NUMPSVSVCCHECKS1M")) 00744 printf("%d%s",passive_service_checks_last_1min,mrtg_delimiter); 00745 else if(!strcmp(temp_ptr,"NUMPSVSVCCHECKS5M")) 00746 printf("%d%s",passive_service_checks_last_5min,mrtg_delimiter); 00747 else if(!strcmp(temp_ptr,"NUMPSVSVCCHECKS15M")) 00748 printf("%d%s",passive_service_checks_last_15min,mrtg_delimiter); 00749 else if(!strcmp(temp_ptr,"NUMCACHEDSVCCHECKS1M")) 00750 printf("%d%s",active_cached_service_checks_last_1min,mrtg_delimiter); 00751 else if(!strcmp(temp_ptr,"NUMCACHEDSVCCHECKS5M")) 00752 printf("%d%s",active_cached_service_checks_last_5min,mrtg_delimiter); 00753 else if(!strcmp(temp_ptr,"NUMCACHEDSVCCHECKS15M")) 00754 printf("%d%s",active_cached_service_checks_last_15min,mrtg_delimiter); 00755 00756 /* external command stats */ 00757 else if(!strcmp(temp_ptr,"NUMEXTCMDS1M")) 00758 printf("%d%s",external_commands_last_1min,mrtg_delimiter); 00759 else if(!strcmp(temp_ptr,"NUMEXTCMDS5M")) 00760 printf("%d%s",external_commands_last_5min,mrtg_delimiter); 00761 else if(!strcmp(temp_ptr,"NUMEXTCMDS15M")) 00762 printf("%d%s",external_commands_last_15min,mrtg_delimiter); 00763 00764 /* service states */ 00765 else if(!strcmp(temp_ptr,"NUMSVCOK")) 00766 printf("%d%s",services_ok,mrtg_delimiter); 00767 else if(!strcmp(temp_ptr,"NUMSVCWARN")) 00768 printf("%d%s",services_warning,mrtg_delimiter); 00769 else if(!strcmp(temp_ptr,"NUMSVCUNKN")) 00770 printf("%d%s",services_unknown,mrtg_delimiter); 00771 else if(!strcmp(temp_ptr,"NUMSVCCRIT")) 00772 printf("%d%s",services_critical,mrtg_delimiter); 00773 else if(!strcmp(temp_ptr,"NUMSVCPROB")) 00774 printf("%d%s",services_warning+services_unknown+services_critical,mrtg_delimiter); 00775 00776 /* misc service info */ 00777 else if(!strcmp(temp_ptr,"NUMSVCCHECKED")) 00778 printf("%d%s",services_checked,mrtg_delimiter); 00779 else if(!strcmp(temp_ptr,"NUMSVCSCHEDULED")) 00780 printf("%d%s",services_scheduled,mrtg_delimiter); 00781 else if(!strcmp(temp_ptr,"NUMSVCFLAPPING")) 00782 printf("%d%s",services_flapping,mrtg_delimiter); 00783 else if(!strcmp(temp_ptr,"NUMSVCDOWNTIME")) 00784 printf("%d%s",services_in_downtime,mrtg_delimiter); 00785 00786 /* host states */ 00787 else if(!strcmp(temp_ptr,"NUMHSTUP")) 00788 printf("%d%s",hosts_up,mrtg_delimiter); 00789 else if(!strcmp(temp_ptr,"NUMHSTDOWN")) 00790 printf("%d%s",hosts_down,mrtg_delimiter); 00791 else if(!strcmp(temp_ptr,"NUMHSTUNR")) 00792 printf("%d%s",hosts_unreachable,mrtg_delimiter); 00793 else if(!strcmp(temp_ptr,"NUMHSTPROB")) 00794 printf("%d%s",hosts_down+hosts_unreachable,mrtg_delimiter); 00795 00796 /* misc host info */ 00797 else if(!strcmp(temp_ptr,"NUMHSTCHECKED")) 00798 printf("%d%s",hosts_checked,mrtg_delimiter); 00799 else if(!strcmp(temp_ptr,"NUMHSTSCHEDULED")) 00800 printf("%d%s",hosts_scheduled,mrtg_delimiter); 00801 else if(!strcmp(temp_ptr,"NUMHSTFLAPPING")) 00802 printf("%d%s",hosts_flapping,mrtg_delimiter); 00803 else if(!strcmp(temp_ptr,"NUMHSTDOWNTIME")) 00804 printf("%d%s",hosts_in_downtime,mrtg_delimiter); 00805 00806 /* make sure gcc3 won't hit here */ 00807 #ifndef GCCTOOOLD 00808 else if(strstr(temp_ptr,"PROFILE_") && event_profiling_enabled) 00809 profile_data_output_mrtg(temp_ptr+strlen("PROFILE_"),mrtg_delimiter); 00810 #endif 00811 else 00812 printf("%s%s",temp_ptr,mrtg_delimiter); 00813 } 00814 00815 /* add a newline if necessary */ 00816 if(strcmp(mrtg_delimiter,"\n")) 00817 printf("\n"); 00818 00819 return OK; 00820 } 00821 00822 00823 int display_stats(void){ 00824 time_t current_time; 00825 unsigned long time_difference; 00826 int days; 00827 int hours; 00828 int minutes; 00829 int seconds; 00830 00831 time(¤t_time); 00832 00833 printf("CURRENT STATUS DATA\n"); 00834 printf("------------------------------------------------------\n"); 00835 printf("Status File: %s\n",(icingastats_file!=NULL)?icingastats_file:status_file); 00836 time_difference=(current_time-status_creation_date); 00837 get_time_breakdown(time_difference,&days,&hours,&minutes,&seconds); 00838 printf("Status File Age: %dd %dh %dm %ds\n",days,hours,minutes,seconds); 00839 printf("Status File Version: %s\n",status_version); 00840 printf("\n"); 00841 time_difference=(current_time-program_start); 00842 get_time_breakdown(time_difference,&days,&hours,&minutes,&seconds); 00843 printf("Program Running Time: %dd %dh %dm %ds\n",days,hours,minutes,seconds); 00844 printf("%s PID: %lu\n", PROGRAM_NAME, nagios_pid); 00845 printf("Used/High/Total Command Buffers: %d / %d / %d\n",used_external_command_buffer_slots,high_external_command_buffer_slots,total_external_command_buffer_slots); 00846 printf("\n"); 00847 printf("Total Services: %d\n",status_service_entries); 00848 printf("Services Checked: %d\n",services_checked); 00849 printf("Services Scheduled: %d\n",services_scheduled); 00850 printf("Services Actively Checked: %d\n",active_service_checks); 00851 printf("Services Passively Checked: %d\n",passive_service_checks); 00852 printf("Total Service State Change: %.3f / %.3f / %.3f %%\n",min_service_state_change,max_service_state_change,average_service_state_change); 00853 printf("Active Service Latency: %.3f / %.3f / %.3f sec\n",min_active_service_latency,max_active_service_latency,average_active_service_latency); 00854 printf("Active Service Execution Time: %.3f / %.3f / %.3f sec\n",min_active_service_execution_time,max_active_service_execution_time,average_active_service_execution_time); 00855 printf("Active Service State Change: %.3f / %.3f / %.3f %%\n",min_active_service_state_change,max_active_service_state_change,average_active_service_state_change); 00856 printf("Active Services Last 1/5/15/60 min: %d / %d / %d / %d\n",active_services_checked_last_1min,active_services_checked_last_5min,active_services_checked_last_15min,active_services_checked_last_1hour); 00857 printf("Passive Service Latency: %.3f / %.3f / %.3f sec\n",min_passive_service_latency,max_passive_service_latency,average_passive_service_latency); 00858 printf("Passive Service State Change: %.3f / %.3f / %.3f %%\n",min_passive_service_state_change,max_passive_service_state_change,average_passive_service_state_change); 00859 printf("Passive Services Last 1/5/15/60 min: %d / %d / %d / %d\n",passive_services_checked_last_1min,passive_services_checked_last_5min,passive_services_checked_last_15min,passive_services_checked_last_1hour); 00860 printf("Services Ok/Warn/Unk/Crit: %d / %d / %d / %d\n",services_ok,services_warning,services_unknown,services_critical); 00861 printf("Services Flapping: %d\n",services_flapping); 00862 printf("Services In Downtime: %d\n",services_in_downtime); 00863 printf("\n"); 00864 printf("Total Hosts: %d\n",status_host_entries); 00865 printf("Hosts Checked: %d\n",hosts_checked); 00866 printf("Hosts Scheduled: %d\n",hosts_scheduled); 00867 printf("Hosts Actively Checked: %d\n",active_host_checks); 00868 printf("Host Passively Checked: %d\n",passive_host_checks); 00869 printf("Total Host State Change: %.3f / %.3f / %.3f %%\n",min_host_state_change,max_host_state_change,average_host_state_change); 00870 printf("Active Host Latency: %.3f / %.3f / %.3f sec\n",min_active_host_latency,max_active_host_latency,average_active_host_latency); 00871 printf("Active Host Execution Time: %.3f / %.3f / %.3f sec\n",min_active_host_execution_time,max_active_host_execution_time,average_active_host_execution_time); 00872 printf("Active Host State Change: %.3f / %.3f / %.3f %%\n",min_active_host_state_change,max_active_host_state_change,average_active_host_state_change); 00873 printf("Active Hosts Last 1/5/15/60 min: %d / %d / %d / %d\n",active_hosts_checked_last_1min,active_hosts_checked_last_5min,active_hosts_checked_last_15min,active_hosts_checked_last_1hour); 00874 printf("Passive Host Latency: %.3f / %.3f / %.3f sec\n",min_passive_host_latency,max_passive_host_latency,average_passive_host_latency); 00875 printf("Passive Host State Change: %.3f / %.3f / %.3f %%\n",min_passive_host_state_change,max_passive_host_state_change,average_passive_host_state_change); 00876 printf("Passive Hosts Last 1/5/15/60 min: %d / %d / %d / %d\n",passive_hosts_checked_last_1min,passive_hosts_checked_last_5min,passive_hosts_checked_last_15min,passive_hosts_checked_last_1hour); 00877 printf("Hosts Up/Down/Unreach: %d / %d / %d\n",hosts_up,hosts_down,hosts_unreachable); 00878 printf("Hosts Flapping: %d\n",hosts_flapping); 00879 printf("Hosts In Downtime: %d\n",hosts_in_downtime); 00880 printf("\n"); 00881 printf("Active Host Checks Last 1/5/15 min: %d / %d / %d\n",active_host_checks_last_1min,active_host_checks_last_5min,active_host_checks_last_15min); 00882 printf(" Scheduled: %d / %d / %d\n",active_scheduled_host_checks_last_1min,active_scheduled_host_checks_last_5min,active_scheduled_host_checks_last_15min); 00883 printf(" On-demand: %d / %d / %d\n",active_ondemand_host_checks_last_1min,active_ondemand_host_checks_last_5min,active_ondemand_host_checks_last_15min); 00884 printf(" Parallel: %d / %d / %d\n",parallel_host_checks_last_1min,parallel_host_checks_last_5min,parallel_host_checks_last_15min); 00885 printf(" Serial: %d / %d / %d\n",serial_host_checks_last_1min,serial_host_checks_last_5min,serial_host_checks_last_15min); 00886 printf(" Cached: %d / %d / %d\n",active_cached_host_checks_last_1min,active_cached_host_checks_last_5min,active_cached_host_checks_last_15min); 00887 printf("Passive Host Checks Last 1/5/15 min: %d / %d / %d\n",passive_host_checks_last_1min,passive_host_checks_last_5min,passive_host_checks_last_15min); 00888 00889 printf("Active Service Checks Last 1/5/15 min: %d / %d / %d\n",active_service_checks_last_1min,active_service_checks_last_5min,active_service_checks_last_15min); 00890 printf(" Scheduled: %d / %d / %d\n",active_scheduled_service_checks_last_1min,active_scheduled_service_checks_last_5min,active_scheduled_service_checks_last_15min); 00891 printf(" On-demand: %d / %d / %d\n",active_ondemand_service_checks_last_1min,active_ondemand_service_checks_last_5min,active_ondemand_service_checks_last_15min); 00892 printf(" Cached: %d / %d / %d\n",active_cached_service_checks_last_1min,active_cached_service_checks_last_5min,active_cached_service_checks_last_15min); 00893 printf("Passive Service Checks Last 1/5/15 min: %d / %d / %d\n",passive_service_checks_last_1min,passive_service_checks_last_5min,passive_service_checks_last_15min); 00894 printf("\n"); 00895 printf("External Commands Last 1/5/15 min: %d / %d / %d\n",external_commands_last_1min,external_commands_last_5min,external_commands_last_15min); 00896 printf("\n"); 00897 printf("\n"); 00898 00899 /* make sure gcc3 won't hit here */ 00900 #ifndef GCCTOOOLD 00901 if(event_profiling_enabled){ 00902 printf("\n\nEVENT PROFILE DATA:\t\ttotal seconds spent / number of events / avg time per event / events per second \n"); 00903 printf("----------------------------------------------------\n"); 00904 00905 profile_data_print(); 00906 } 00907 #endif 00908 00909 00910 /* 00911 printf("CURRENT COMMENT DATA\n"); 00912 printf("----------------------------------------------------\n"); 00913 printf("\n"); 00914 printf("\n"); 00915 00916 printf("CURRENT DOWNTIME DATA\n"); 00917 printf("----------------------------------------------------\n"); 00918 printf("\n"); 00919 */ 00920 00921 return OK; 00922 } 00923 00924 00925 int read_config_file(void){ 00926 char temp_buffer[MAX_INPUT_BUFFER]; 00927 FILE *fp; 00928 char *var; 00929 char *val; 00930 00931 00932 fp=fopen(main_config_file,"r"); 00933 if(fp==NULL) 00934 return ERROR; 00935 00936 /* read all lines from the main Icinga config file */ 00937 while(fgets(temp_buffer,sizeof(temp_buffer)-1,fp)){ 00938 00939 strip(temp_buffer); 00940 00941 /* skip blank lines and comments */ 00942 if(temp_buffer[0]=='#' || temp_buffer[0]=='\x0') 00943 continue; 00944 00945 var=strtok(temp_buffer,"="); 00946 val=strtok(NULL,"\n"); 00947 if(val==NULL) 00948 continue; 00949 00950 if(!strcmp(var,"status_file") || !strcmp(var,"status_log") || !strcmp(var,"xsddefault_status_log")){ 00951 if(status_file) 00952 free(status_file); 00953 status_file=strdup(val); 00954 } 00955 00956 } 00957 00958 fclose(fp); 00959 00960 return OK; 00961 } 00962 00963 00964 int read_status_file(void){ 00965 char temp_buffer[MAX_INPUT_BUFFER]; 00966 FILE *fp=NULL; 00967 int data_type=STATUS_NO_DATA; 00968 char *var=NULL; 00969 char *val=NULL; 00970 char *temp_ptr=NULL; 00971 time_t current_time; 00972 unsigned long time_difference=0L; 00973 00974 double execution_time=0.0; 00975 double latency=0.0; 00976 int check_type=SERVICE_CHECK_ACTIVE; 00977 int current_state=STATE_OK; 00978 double state_change=0.0; 00979 int is_flapping=FALSE; 00980 int downtime_depth=0; 00981 time_t last_check=0L; 00982 int should_be_scheduled=TRUE; 00983 int has_been_checked=TRUE; 00984 00985 00986 time(¤t_time); 00987 00988 fp=fopen(status_file,"r"); 00989 if(fp==NULL) 00990 return ERROR; 00991 00992 /* read all lines in the status file */ 00993 while(fgets(temp_buffer,sizeof(temp_buffer)-1,fp)){ 00994 00995 /* skip blank lines and comments */ 00996 if(temp_buffer[0]=='#' || temp_buffer[0]=='\x0') 00997 continue; 00998 00999 strip(temp_buffer); 01000 01001 /* start of definition */ 01002 if(!strcmp(temp_buffer,"servicestatus {")){ 01003 data_type=STATUS_SERVICE_DATA; 01004 status_service_entries++; 01005 } 01006 else if(!strcmp(temp_buffer,"hoststatus {")){ 01007 data_type=STATUS_HOST_DATA; 01008 status_host_entries++; 01009 } 01010 else if(!strcmp(temp_buffer,"info {")) 01011 data_type=STATUS_INFO_DATA; 01012 else if(!strcmp(temp_buffer,"programstatus {")) 01013 data_type=STATUS_PROGRAM_DATA; 01014 01015 01016 /* end of definition */ 01017 else if(!strcmp(temp_buffer,"}")){ 01018 01019 switch(data_type){ 01020 01021 case STATUS_INFO_DATA: 01022 break; 01023 01024 case STATUS_PROGRAM_DATA: 01025 /* 02-15-2008 exclude cached host checks from total (they were ondemand checks that never actually executed) */ 01026 active_host_checks_last_1min=active_scheduled_host_checks_last_1min+active_ondemand_host_checks_last_1min; 01027 active_host_checks_last_5min=active_scheduled_host_checks_last_5min+active_ondemand_host_checks_last_5min; 01028 active_host_checks_last_15min=active_scheduled_host_checks_last_15min+active_ondemand_host_checks_last_15min; 01029 01030 /* 02-15-2008 exclude cached service checks from total (they were ondemand checks that never actually executed) */ 01031 active_service_checks_last_1min=active_scheduled_service_checks_last_1min+active_ondemand_service_checks_last_1min; 01032 active_service_checks_last_5min=active_scheduled_service_checks_last_5min+active_ondemand_service_checks_last_5min; 01033 active_service_checks_last_15min=active_scheduled_service_checks_last_15min+active_ondemand_service_checks_last_15min; 01034 break; 01035 01036 case STATUS_HOST_DATA: 01037 average_host_state_change=(((average_host_state_change*((double)status_host_entries-1.0))+state_change)/(double)status_host_entries); 01038 if(have_min_host_state_change==FALSE || min_host_state_change>state_change){ 01039 have_min_host_state_change=TRUE; 01040 min_host_state_change=state_change; 01041 } 01042 if(have_max_host_state_change==FALSE || max_host_state_change<state_change){ 01043 have_max_host_state_change=TRUE; 01044 max_host_state_change=state_change; 01045 } 01046 if(check_type==HOST_CHECK_ACTIVE){ 01047 active_host_checks++; 01048 average_active_host_latency=(((average_active_host_latency*((double)active_host_checks-1.0))+latency)/(double)active_host_checks); 01049 if(have_min_active_host_latency==FALSE || min_active_host_latency>latency){ 01050 have_min_active_host_latency=TRUE; 01051 min_active_host_latency=latency; 01052 } 01053 if(have_max_active_host_latency==FALSE || max_active_host_latency<latency){ 01054 have_max_active_host_latency=TRUE; 01055 max_active_host_latency=latency; 01056 } 01057 average_active_host_execution_time=(((average_active_host_execution_time*((double)active_host_checks-1.0))+execution_time)/(double)active_host_checks); 01058 if(have_min_active_host_execution_time==FALSE || min_active_host_execution_time>execution_time){ 01059 have_min_active_host_execution_time=TRUE; 01060 min_active_host_execution_time=execution_time; 01061 } 01062 if(have_max_active_host_execution_time==FALSE || max_active_host_execution_time<execution_time){ 01063 have_max_active_host_execution_time=TRUE; 01064 max_active_host_execution_time=execution_time; 01065 } 01066 average_active_host_state_change=(((average_active_host_state_change*((double)active_host_checks-1.0))+state_change)/(double)active_host_checks); 01067 if(have_min_active_host_state_change==FALSE || min_active_host_state_change>state_change){ 01068 have_min_active_host_state_change=TRUE; 01069 min_active_host_state_change=state_change; 01070 } 01071 if(have_max_active_host_state_change==FALSE || max_active_host_state_change<state_change){ 01072 have_max_active_host_state_change=TRUE; 01073 max_active_host_state_change=state_change; 01074 } 01075 time_difference=current_time-last_check; 01076 if(time_difference<=3600) 01077 active_hosts_checked_last_1hour++; 01078 if(time_difference<=900) 01079 active_hosts_checked_last_15min++; 01080 if(time_difference<=300) 01081 active_hosts_checked_last_5min++; 01082 if(time_difference<=60) 01083 active_hosts_checked_last_1min++; 01084 } 01085 else{ 01086 passive_host_checks++; 01087 average_passive_host_latency=(((average_passive_host_latency*((double)passive_host_checks-1.0))+latency)/(double)passive_host_checks); 01088 if(have_min_passive_host_latency==FALSE || min_passive_host_latency>latency){ 01089 have_min_passive_host_latency=TRUE; 01090 min_passive_host_latency=latency; 01091 } 01092 if(have_max_passive_host_latency==FALSE || max_passive_host_latency<latency){ 01093 have_max_passive_host_latency=TRUE; 01094 max_passive_host_latency=latency; 01095 } 01096 average_passive_host_state_change=(((average_passive_host_state_change*((double)passive_host_checks-1.0))+state_change)/(double)passive_host_checks); 01097 if(have_min_passive_host_state_change==FALSE || min_passive_host_state_change>state_change){ 01098 have_min_passive_host_state_change=TRUE; 01099 min_passive_host_state_change=state_change; 01100 } 01101 if(have_max_passive_host_state_change==FALSE || max_passive_host_state_change<state_change){ 01102 have_max_passive_host_state_change=TRUE; 01103 max_passive_host_state_change=state_change; 01104 } 01105 time_difference=current_time-last_check; 01106 if(time_difference<=3600) 01107 passive_hosts_checked_last_1hour++; 01108 if(time_difference<=900) 01109 passive_hosts_checked_last_15min++; 01110 if(time_difference<=300) 01111 passive_hosts_checked_last_5min++; 01112 if(time_difference<=60) 01113 passive_hosts_checked_last_1min++; 01114 } 01115 switch(current_state){ 01116 case HOST_UP: 01117 hosts_up++; 01118 break; 01119 case HOST_DOWN: 01120 hosts_down++; 01121 break; 01122 case HOST_UNREACHABLE: 01123 hosts_unreachable++; 01124 break; 01125 default: 01126 break; 01127 } 01128 if(is_flapping==TRUE) 01129 hosts_flapping++; 01130 if(downtime_depth>0) 01131 hosts_in_downtime++; 01132 if(has_been_checked==TRUE) 01133 hosts_checked++; 01134 if(should_be_scheduled==TRUE) 01135 hosts_scheduled++; 01136 break; 01137 01138 case STATUS_SERVICE_DATA: 01139 average_service_state_change=(((average_service_state_change*((double)status_service_entries-1.0))+state_change)/(double)status_service_entries); 01140 if(have_min_service_state_change==FALSE || min_service_state_change>state_change){ 01141 have_min_service_state_change=TRUE; 01142 min_service_state_change=state_change; 01143 } 01144 if(have_max_service_state_change==FALSE || max_service_state_change<state_change){ 01145 have_max_service_state_change=TRUE; 01146 max_service_state_change=state_change; 01147 } 01148 if(check_type==SERVICE_CHECK_ACTIVE){ 01149 active_service_checks++; 01150 average_active_service_latency=(((average_active_service_latency*((double)active_service_checks-1.0))+latency)/(double)active_service_checks); 01151 if(have_min_active_service_latency==FALSE || min_active_service_latency>latency){ 01152 have_min_active_service_latency=TRUE; 01153 min_active_service_latency=latency; 01154 } 01155 if(have_max_active_service_latency==FALSE || max_active_service_latency<latency){ 01156 have_max_active_service_latency=TRUE; 01157 max_active_service_latency=latency; 01158 } 01159 average_active_service_execution_time=(((average_active_service_execution_time*((double)active_service_checks-1.0))+execution_time)/(double)active_service_checks); 01160 if(have_min_active_service_execution_time==FALSE || min_active_service_execution_time>execution_time){ 01161 have_min_active_service_execution_time=TRUE; 01162 min_active_service_execution_time=execution_time; 01163 } 01164 if(have_max_active_service_execution_time==FALSE || max_active_service_execution_time<execution_time){ 01165 have_max_active_service_execution_time=TRUE; 01166 max_active_service_execution_time=execution_time; 01167 } 01168 average_active_service_state_change=(((average_active_service_state_change*((double)active_service_checks-1.0))+state_change)/(double)active_service_checks); 01169 if(have_min_active_service_state_change==FALSE || min_active_service_state_change>state_change){ 01170 have_min_active_service_state_change=TRUE; 01171 min_active_service_state_change=state_change; 01172 } 01173 if(have_max_active_service_state_change==FALSE || max_active_service_state_change<state_change){ 01174 have_max_active_service_state_change=TRUE; 01175 max_active_service_state_change=state_change; 01176 } 01177 time_difference=current_time-last_check; 01178 if(time_difference<=3600) 01179 active_services_checked_last_1hour++; 01180 if(time_difference<=900) 01181 active_services_checked_last_15min++; 01182 if(time_difference<=300) 01183 active_services_checked_last_5min++; 01184 if(time_difference<=60) 01185 active_services_checked_last_1min++; 01186 } 01187 else{ 01188 passive_service_checks++; 01189 average_passive_service_latency=(((average_passive_service_latency*((double)passive_service_checks-1.0))+latency)/(double)passive_service_checks); 01190 if(have_min_passive_service_latency==FALSE || min_passive_service_latency>latency){ 01191 have_min_passive_service_latency=TRUE; 01192 min_passive_service_latency=latency; 01193 } 01194 if(have_max_passive_service_latency==FALSE || max_passive_service_latency<latency){ 01195 have_max_passive_service_latency=TRUE; 01196 max_passive_service_latency=latency; 01197 } 01198 average_passive_service_state_change=(((average_passive_service_state_change*((double)passive_service_checks-1.0))+state_change)/(double)passive_service_checks); 01199 if(have_min_passive_service_state_change==FALSE || min_passive_service_state_change>state_change){ 01200 have_min_passive_service_state_change=TRUE; 01201 min_passive_service_state_change=state_change; 01202 } 01203 if(have_max_passive_service_state_change==FALSE || max_passive_service_state_change<state_change){ 01204 have_max_passive_service_state_change=TRUE; 01205 max_passive_service_state_change=state_change; 01206 } 01207 time_difference=current_time-last_check; 01208 if(time_difference<=3600) 01209 passive_services_checked_last_1hour++; 01210 if(time_difference<=900) 01211 passive_services_checked_last_15min++; 01212 if(time_difference<=300) 01213 passive_services_checked_last_5min++; 01214 if(time_difference<=60) 01215 passive_services_checked_last_1min++; 01216 } 01217 switch(current_state){ 01218 case STATE_OK: 01219 services_ok++; 01220 break; 01221 case STATE_WARNING: 01222 services_warning++; 01223 break; 01224 case STATE_UNKNOWN: 01225 services_unknown++; 01226 break; 01227 case STATE_CRITICAL: 01228 services_critical++; 01229 break; 01230 default: 01231 break; 01232 } 01233 if(is_flapping==TRUE) 01234 services_flapping++; 01235 if(downtime_depth>0) 01236 services_in_downtime++; 01237 if(has_been_checked==TRUE) 01238 services_checked++; 01239 if(should_be_scheduled==TRUE) 01240 services_scheduled++; 01241 break; 01242 01243 default: 01244 break; 01245 } 01246 01247 data_type=STATUS_NO_DATA; 01248 01249 execution_time=0.0; 01250 latency=0.0; 01251 check_type=0; 01252 current_state=0; 01253 state_change=0.0; 01254 is_flapping=FALSE; 01255 downtime_depth=0; 01256 last_check=(time_t)0; 01257 has_been_checked=FALSE; 01258 should_be_scheduled=FALSE; 01259 } 01260 01261 01262 /* inside definition */ 01263 else if(data_type!=STATUS_NO_DATA){ 01264 01265 var=strtok(temp_buffer,"="); 01266 val=strtok(NULL,"\n"); 01267 if(val==NULL) 01268 continue; 01269 01270 switch(data_type){ 01271 01272 case STATUS_INFO_DATA: 01273 if(!strcmp(var,"created")) 01274 status_creation_date=strtoul(val,NULL,10); 01275 else if(!strcmp(var,"version")) 01276 status_version=strdup(val); 01277 break; 01278 01279 case STATUS_PROGRAM_DATA: 01280 if(!strcmp(var,"program_start")) 01281 program_start=strtoul(val,NULL,10); 01282 else if(!strcmp(var,"total_external_command_buffer_slots")) 01283 total_external_command_buffer_slots=atoi(val); 01284 else if(!strcmp(var,"used_external_command_buffer_slots")) 01285 used_external_command_buffer_slots=atoi(val); 01286 else if(!strcmp(var,"high_external_command_buffer_slots")) 01287 high_external_command_buffer_slots=atoi(val); 01288 else if(!strcmp(var,"icinga_pid")) 01289 nagios_pid=strtoul(val,NULL,10); 01290 else if(!strcmp(var,"active_scheduled_host_check_stats")){ 01291 if((temp_ptr=strtok(val,","))) 01292 active_scheduled_host_checks_last_1min=atoi(temp_ptr); 01293 if((temp_ptr=strtok(NULL,","))) 01294 active_scheduled_host_checks_last_5min=atoi(temp_ptr); 01295 if((temp_ptr=strtok(NULL,","))) 01296 active_scheduled_host_checks_last_15min=atoi(temp_ptr); 01297 } 01298 else if(!strcmp(var,"active_ondemand_host_check_stats")){ 01299 if((temp_ptr=strtok(val,","))) 01300 active_ondemand_host_checks_last_1min=atoi(temp_ptr); 01301 if((temp_ptr=strtok(NULL,","))) 01302 active_ondemand_host_checks_last_5min=atoi(temp_ptr); 01303 if((temp_ptr=strtok(NULL,","))) 01304 active_ondemand_host_checks_last_15min=atoi(temp_ptr); 01305 } 01306 else if(!strcmp(var,"cached_host_check_stats")){ 01307 if((temp_ptr=strtok(val,","))) 01308 active_cached_host_checks_last_1min=atoi(temp_ptr); 01309 if((temp_ptr=strtok(NULL,","))) 01310 active_cached_host_checks_last_5min=atoi(temp_ptr); 01311 if((temp_ptr=strtok(NULL,","))) 01312 active_cached_host_checks_last_15min=atoi(temp_ptr); 01313 } 01314 else if(!strcmp(var,"passive_host_check_stats")){ 01315 if((temp_ptr=strtok(val,","))) 01316 passive_host_checks_last_1min=atoi(temp_ptr); 01317 if((temp_ptr=strtok(NULL,","))) 01318 passive_host_checks_last_5min=atoi(temp_ptr); 01319 if((temp_ptr=strtok(NULL,","))) 01320 passive_host_checks_last_15min=atoi(temp_ptr); 01321 } 01322 else if(!strcmp(var,"active_scheduled_service_check_stats")){ 01323 if((temp_ptr=strtok(val,","))) 01324 active_scheduled_service_checks_last_1min=atoi(temp_ptr); 01325 if((temp_ptr=strtok(NULL,","))) 01326 active_scheduled_service_checks_last_5min=atoi(temp_ptr); 01327 if((temp_ptr=strtok(NULL,","))) 01328 active_scheduled_service_checks_last_15min=atoi(temp_ptr); 01329 } 01330 else if(!strcmp(var,"active_ondemand_service_check_stats")){ 01331 if((temp_ptr=strtok(val,","))) 01332 active_ondemand_service_checks_last_1min=atoi(temp_ptr); 01333 if((temp_ptr=strtok(NULL,","))) 01334 active_ondemand_service_checks_last_5min=atoi(temp_ptr); 01335 if((temp_ptr=strtok(NULL,","))) 01336 active_ondemand_service_checks_last_15min=atoi(temp_ptr); 01337 } 01338 else if(!strcmp(var,"cached_service_check_stats")){ 01339 if((temp_ptr=strtok(val,","))) 01340 active_cached_service_checks_last_1min=atoi(temp_ptr); 01341 if((temp_ptr=strtok(NULL,","))) 01342 active_cached_service_checks_last_5min=atoi(temp_ptr); 01343 if((temp_ptr=strtok(NULL,","))) 01344 active_cached_service_checks_last_15min=atoi(temp_ptr); 01345 } 01346 else if(!strcmp(var,"passive_service_check_stats")){ 01347 if((temp_ptr=strtok(val,","))) 01348 passive_service_checks_last_1min=atoi(temp_ptr); 01349 if((temp_ptr=strtok(NULL,","))) 01350 passive_service_checks_last_5min=atoi(temp_ptr); 01351 if((temp_ptr=strtok(NULL,","))) 01352 passive_service_checks_last_15min=atoi(temp_ptr); 01353 } 01354 else if(!strcmp(var,"external_command_stats")){ 01355 if((temp_ptr=strtok(val,","))) 01356 external_commands_last_1min=atoi(temp_ptr); 01357 if((temp_ptr=strtok(NULL,","))) 01358 external_commands_last_5min=atoi(temp_ptr); 01359 if((temp_ptr=strtok(NULL,","))) 01360 external_commands_last_15min=atoi(temp_ptr); 01361 } 01362 else if(!strcmp(var,"parallel_host_check_stats")){ 01363 if((temp_ptr=strtok(val,","))) 01364 parallel_host_checks_last_1min=atoi(temp_ptr); 01365 if((temp_ptr=strtok(NULL,","))) 01366 parallel_host_checks_last_5min=atoi(temp_ptr); 01367 if((temp_ptr=strtok(NULL,","))) 01368 parallel_host_checks_last_15min=atoi(temp_ptr); 01369 } 01370 else if(!strcmp(var,"serial_host_check_stats")){ 01371 if((temp_ptr=strtok(val,","))) 01372 serial_host_checks_last_1min=atoi(temp_ptr); 01373 if((temp_ptr=strtok(NULL,","))) 01374 serial_host_checks_last_5min=atoi(temp_ptr); 01375 if((temp_ptr=strtok(NULL,","))) 01376 serial_host_checks_last_15min=atoi(temp_ptr); 01377 } 01378 else if(!strcmp(var,"event_profiling_enabled")){ 01379 /* make sure gcc3 won't hit here */ 01380 #ifndef GCCTOOOLD 01381 event_profiling_enabled=atoi(val); 01382 #endif 01383 } 01384 else if(strstr(var,"PROFILE_") && !strstr(var,"null")){ 01385 01386 /* make sure gcc3 won't hit here */ 01387 #ifndef GCCTOOOLD 01388 if(strstr(var,"COUNTER")) 01389 profile_object_update_count(var+strlen("PROFILE_COUNTER_"),strtod(val,NULL)); 01390 01391 if(strstr(var,"ELAPSED")) 01392 profile_object_update_elapsed(var+strlen("PROFILE_ELAPSED_"),atoi(val)); 01393 #endif 01394 } 01395 break; 01396 01397 case STATUS_HOST_DATA: 01398 if(!strcmp(var,"check_execution_time")) 01399 execution_time=strtod(val,NULL); 01400 else if(!strcmp(var,"check_latency")) 01401 latency=strtod(val,NULL); 01402 else if(!strcmp(var,"percent_state_change")) 01403 state_change=strtod(val,NULL); 01404 else if(!strcmp(var,"check_type")) 01405 check_type=atoi(val); 01406 else if(!strcmp(var,"current_state")) 01407 current_state=atoi(val); 01408 else if(!strcmp(var,"is_flapping")) 01409 is_flapping=(atoi(val)>0)?TRUE:FALSE; 01410 else if(!strcmp(var,"scheduled_downtime_depth")) 01411 downtime_depth=atoi(val); 01412 else if(!strcmp(var,"last_check")) 01413 last_check=strtoul(val,NULL,10); 01414 else if(!strcmp(var,"has_been_checked")) 01415 has_been_checked=(atoi(val)>0)?TRUE:FALSE; 01416 else if(!strcmp(var,"should_be_scheduled")) 01417 should_be_scheduled=(atoi(val)>0)?TRUE:FALSE; 01418 break; 01419 01420 case STATUS_SERVICE_DATA: 01421 if(!strcmp(var,"check_execution_time")) 01422 execution_time=strtod(val,NULL); 01423 else if(!strcmp(var,"check_latency")) 01424 latency=strtod(val,NULL); 01425 else if(!strcmp(var,"percent_state_change")) 01426 state_change=strtod(val,NULL); 01427 else if(!strcmp(var,"check_type")) 01428 check_type=atoi(val); 01429 else if(!strcmp(var,"current_state")) 01430 current_state=atoi(val); 01431 else if(!strcmp(var,"is_flapping")) 01432 is_flapping=(atoi(val)>0)?TRUE:FALSE; 01433 else if(!strcmp(var,"scheduled_downtime_depth")) 01434 downtime_depth=atoi(val); 01435 else if(!strcmp(var,"last_check")) 01436 last_check=strtoul(val,NULL,10); 01437 else if(!strcmp(var,"has_been_checked")) 01438 has_been_checked=(atoi(val)>0)?TRUE:FALSE; 01439 else if(!strcmp(var,"should_be_scheduled")) 01440 should_be_scheduled=(atoi(val)>0)?TRUE:FALSE; 01441 break; 01442 01443 default: 01444 break; 01445 } 01446 01447 } 01448 } 01449 01450 fclose(fp); 01451 01452 return OK; 01453 } 01454 01455 01456 int read_icingastats_file(void){ 01457 char temp_buffer[MAX_INPUT_BUFFER]; 01458 FILE *fp=NULL; 01459 char *var=NULL; 01460 char *val=NULL; 01461 char *temp_ptr=NULL; 01462 time_t current_time; 01463 01464 time(¤t_time); 01465 01466 fp=fopen(icingastats_file,"r"); 01467 if(fp==NULL) 01468 return ERROR; 01469 01470 /* read all lines in the status file */ 01471 while(fgets(temp_buffer,sizeof(temp_buffer)-1,fp)){ 01472 01473 /* skip comments */ 01474 if(temp_buffer[0]=='#') 01475 continue; 01476 01477 strip(temp_buffer); 01478 01479 var=strtok(temp_buffer,"="); 01480 val=strtok(NULL,"\n"); 01481 if(val==NULL) 01482 continue; 01483 01484 /**** INFO ****/ 01485 if(!strcmp(var,"created")) 01486 status_creation_date=strtoul(val,NULL,10); 01487 else if(!strcmp(var,"nagios_version")) 01488 status_version=strdup(val); 01489 01490 /**** PROGRAM INFO ****/ 01491 else if(!strcmp(var,"program_start")) 01492 program_start=strtoul(val,NULL,10); 01493 else if(!strcmp(var,"total_external_command_buffer_slots")) 01494 total_external_command_buffer_slots=atoi(val); 01495 else if(!strcmp(var,"used_external_command_buffer_slots")) 01496 used_external_command_buffer_slots=atoi(val); 01497 else if(!strcmp(var,"high_external_command_buffer_slots")) 01498 high_external_command_buffer_slots=atoi(val); 01499 else if(!strcmp(var,"icinga_pid")) 01500 nagios_pid=strtoul(val,NULL,10); 01501 else if(!strcmp(var,"active_scheduled_host_check_stats")){ 01502 if((temp_ptr=strtok(val,","))) 01503 active_scheduled_host_checks_last_1min=atoi(temp_ptr); 01504 if((temp_ptr=strtok(NULL,","))) 01505 active_scheduled_host_checks_last_5min=atoi(temp_ptr); 01506 if((temp_ptr=strtok(NULL,","))) 01507 active_scheduled_host_checks_last_15min=atoi(temp_ptr); 01508 } 01509 else if(!strcmp(var,"active_ondemand_host_check_stats")){ 01510 if((temp_ptr=strtok(val,","))) 01511 active_ondemand_host_checks_last_1min=atoi(temp_ptr); 01512 if((temp_ptr=strtok(NULL,","))) 01513 active_ondemand_host_checks_last_5min=atoi(temp_ptr); 01514 if((temp_ptr=strtok(NULL,","))) 01515 active_ondemand_host_checks_last_15min=atoi(temp_ptr); 01516 } 01517 else if(!strcmp(var,"cached_host_check_stats")){ 01518 if((temp_ptr=strtok(val,","))) 01519 active_cached_host_checks_last_1min=atoi(temp_ptr); 01520 if((temp_ptr=strtok(NULL,","))) 01521 active_cached_host_checks_last_5min=atoi(temp_ptr); 01522 if((temp_ptr=strtok(NULL,","))) 01523 active_cached_host_checks_last_15min=atoi(temp_ptr); 01524 } 01525 else if(!strcmp(var,"passive_host_check_stats")){ 01526 if((temp_ptr=strtok(val,","))) 01527 passive_host_checks_last_1min=atoi(temp_ptr); 01528 if((temp_ptr=strtok(NULL,","))) 01529 passive_host_checks_last_5min=atoi(temp_ptr); 01530 if((temp_ptr=strtok(NULL,","))) 01531 passive_host_checks_last_15min=atoi(temp_ptr); 01532 } 01533 else if(!strcmp(var,"active_scheduled_service_check_stats")){ 01534 if((temp_ptr=strtok(val,","))) 01535 active_scheduled_service_checks_last_1min=atoi(temp_ptr); 01536 if((temp_ptr=strtok(NULL,","))) 01537 active_scheduled_service_checks_last_5min=atoi(temp_ptr); 01538 if((temp_ptr=strtok(NULL,","))) 01539 active_scheduled_service_checks_last_15min=atoi(temp_ptr); 01540 } 01541 else if(!strcmp(var,"active_ondemand_service_check_stats")){ 01542 if((temp_ptr=strtok(val,","))) 01543 active_ondemand_service_checks_last_1min=atoi(temp_ptr); 01544 if((temp_ptr=strtok(NULL,","))) 01545 active_ondemand_service_checks_last_5min=atoi(temp_ptr); 01546 if((temp_ptr=strtok(NULL,","))) 01547 active_ondemand_service_checks_last_15min=atoi(temp_ptr); 01548 } 01549 else if(!strcmp(var,"cached_service_check_stats")){ 01550 if((temp_ptr=strtok(val,","))) 01551 active_cached_service_checks_last_1min=atoi(temp_ptr); 01552 if((temp_ptr=strtok(NULL,","))) 01553 active_cached_service_checks_last_5min=atoi(temp_ptr); 01554 if((temp_ptr=strtok(NULL,","))) 01555 active_cached_service_checks_last_15min=atoi(temp_ptr); 01556 } 01557 else if(!strcmp(var,"passive_service_check_stats")){ 01558 if((temp_ptr=strtok(val,","))) 01559 passive_service_checks_last_1min=atoi(temp_ptr); 01560 if((temp_ptr=strtok(NULL,","))) 01561 passive_service_checks_last_5min=atoi(temp_ptr); 01562 if((temp_ptr=strtok(NULL,","))) 01563 passive_service_checks_last_15min=atoi(temp_ptr); 01564 } 01565 else if(!strcmp(var,"external_command_stats")){ 01566 if((temp_ptr=strtok(val,","))) 01567 external_commands_last_1min=atoi(temp_ptr); 01568 if((temp_ptr=strtok(NULL,","))) 01569 external_commands_last_5min=atoi(temp_ptr); 01570 if((temp_ptr=strtok(NULL,","))) 01571 external_commands_last_15min=atoi(temp_ptr); 01572 } 01573 else if(!strcmp(var,"parallel_host_check_stats")){ 01574 if((temp_ptr=strtok(val,","))) 01575 parallel_host_checks_last_1min=atoi(temp_ptr); 01576 if((temp_ptr=strtok(NULL,","))) 01577 parallel_host_checks_last_5min=atoi(temp_ptr); 01578 if((temp_ptr=strtok(NULL,","))) 01579 parallel_host_checks_last_15min=atoi(temp_ptr); 01580 } 01581 else if(!strcmp(var,"serial_host_check_stats")){ 01582 if((temp_ptr=strtok(val,","))) 01583 serial_host_checks_last_1min=atoi(temp_ptr); 01584 if((temp_ptr=strtok(NULL,","))) 01585 serial_host_checks_last_5min=atoi(temp_ptr); 01586 if((temp_ptr=strtok(NULL,","))) 01587 serial_host_checks_last_15min=atoi(temp_ptr); 01588 } 01589 01590 /***** HOST INFO *****/ 01591 01592 else if(!strcmp(var,"total_hosts")) 01593 status_host_entries=atoi(val); 01594 else if(!strcmp(var,"hosts_checked")) 01595 hosts_checked=atoi(val); 01596 else if(!strcmp(var,"hosts_scheduled")) 01597 hosts_scheduled=atoi(val); 01598 else if(!strcmp(var,"hosts_flapping")) 01599 hosts_flapping=atoi(val); 01600 else if(!strcmp(var,"hosts_in_downtime")) 01601 hosts_in_downtime=atoi(val); 01602 else if(!strcmp(var,"hosts_up")) 01603 hosts_up=atoi(val); 01604 else if(!strcmp(var,"hosts_down")) 01605 hosts_down=atoi(val); 01606 else if(!strcmp(var,"hosts_unreachable")) 01607 hosts_unreachable=atoi(val); 01608 else if(!strcmp(var,"hosts_actively_checked")) 01609 active_host_checks=atoi(val); 01610 else if(!strcmp(var,"hosts_passively_checked")) 01611 passive_host_checks=atoi(val); 01612 else if(!strcmp(var,"total_host_state_change")){ 01613 if((temp_ptr=strtok(val,","))) 01614 min_host_state_change=strtod(temp_ptr,NULL); 01615 if((temp_ptr=strtok(NULL,","))) 01616 max_host_state_change=strtod(temp_ptr,NULL); 01617 if((temp_ptr=strtok(NULL,","))) 01618 average_host_state_change=strtod(temp_ptr,NULL); 01619 } 01620 else if(!strcmp(var,"active_host_latency")){ 01621 if((temp_ptr=strtok(val,","))) 01622 min_active_host_latency=strtod(temp_ptr,NULL); 01623 if((temp_ptr=strtok(NULL,","))) 01624 max_active_host_latency=strtod(temp_ptr,NULL); 01625 if((temp_ptr=strtok(NULL,","))) 01626 average_active_host_latency=strtod(temp_ptr,NULL); 01627 } 01628 else if(!strcmp(var,"active_host_execution_time")){ 01629 if((temp_ptr=strtok(val,","))) 01630 min_active_host_execution_time=strtod(temp_ptr,NULL); 01631 if((temp_ptr=strtok(NULL,","))) 01632 max_active_host_execution_time=strtod(temp_ptr,NULL); 01633 if((temp_ptr=strtok(NULL,","))) 01634 average_active_host_execution_time=strtod(temp_ptr,NULL); 01635 } 01636 else if(!strcmp(var,"active_host_state_change")){ 01637 if((temp_ptr=strtok(val,","))) 01638 min_active_host_state_change=strtod(temp_ptr,NULL); 01639 if((temp_ptr=strtok(NULL,","))) 01640 max_active_host_state_change=strtod(temp_ptr,NULL); 01641 if((temp_ptr=strtok(NULL,","))) 01642 average_active_host_state_change=strtod(temp_ptr,NULL); 01643 } 01644 else if(!strcmp(var,"active_hosts_last_x")){ 01645 if((temp_ptr=strtok(val,","))) 01646 active_hosts_checked_last_1min=atoi(temp_ptr); 01647 if((temp_ptr=strtok(NULL,","))) 01648 active_hosts_checked_last_5min=atoi(temp_ptr); 01649 if((temp_ptr=strtok(NULL,","))) 01650 active_hosts_checked_last_15min=atoi(temp_ptr); 01651 if((temp_ptr=strtok(NULL,","))) 01652 active_hosts_checked_last_1hour=atoi(temp_ptr); 01653 } 01654 else if(!strcmp(var,"passive_host_latency")){ 01655 if((temp_ptr=strtok(val,","))) 01656 min_passive_host_latency=strtod(temp_ptr,NULL); 01657 if((temp_ptr=strtok(NULL,","))) 01658 max_passive_host_latency=strtod(temp_ptr,NULL); 01659 if((temp_ptr=strtok(NULL,","))) 01660 average_passive_host_latency=strtod(temp_ptr,NULL); 01661 } 01662 else if(!strcmp(var,"passive_host_state_change")){ 01663 if((temp_ptr=strtok(val,","))) 01664 min_passive_host_state_change=strtod(temp_ptr,NULL); 01665 if((temp_ptr=strtok(NULL,","))) 01666 max_passive_host_state_change=strtod(temp_ptr,NULL); 01667 if((temp_ptr=strtok(NULL,","))) 01668 average_passive_host_state_change=strtod(temp_ptr,NULL); 01669 } 01670 else if(!strcmp(var,"passive_hosts_last_x")){ 01671 if((temp_ptr=strtok(val,","))) 01672 passive_hosts_checked_last_1min=atoi(temp_ptr); 01673 if((temp_ptr=strtok(NULL,","))) 01674 passive_hosts_checked_last_5min=atoi(temp_ptr); 01675 if((temp_ptr=strtok(NULL,","))) 01676 passive_hosts_checked_last_15min=atoi(temp_ptr); 01677 if((temp_ptr=strtok(NULL,","))) 01678 passive_hosts_checked_last_1hour=atoi(temp_ptr); 01679 } 01680 01681 01682 /***** SERVICE INFO *****/ 01683 01684 else if(!strcmp(var,"total_services")) 01685 status_service_entries=atoi(val); 01686 else if(!strcmp(var,"services_checked")) 01687 services_checked=atoi(val); 01688 else if(!strcmp(var,"services_scheduled")) 01689 services_scheduled=atoi(val); 01690 else if(!strcmp(var,"services_flapping")) 01691 services_flapping=atoi(val); 01692 else if(!strcmp(var,"services_in_downtime")) 01693 services_in_downtime=atoi(val); 01694 else if(!strcmp(var,"services_ok")) 01695 services_ok=atoi(val); 01696 else if(!strcmp(var,"services_warning")) 01697 services_warning=atoi(val); 01698 else if(!strcmp(var,"services_critical")) 01699 services_critical=atoi(val); 01700 else if(!strcmp(var,"services_unknown")) 01701 services_unknown=atoi(val); 01702 else if(!strcmp(var,"services_actively_checked")) 01703 active_service_checks=atoi(val); 01704 else if(!strcmp(var,"services_passively_checked")) 01705 passive_service_checks=atoi(val); 01706 else if(!strcmp(var,"total_service_state_change")){ 01707 if((temp_ptr=strtok(val,","))) 01708 min_service_state_change=strtod(temp_ptr,NULL); 01709 if((temp_ptr=strtok(NULL,","))) 01710 max_service_state_change=strtod(temp_ptr,NULL); 01711 if((temp_ptr=strtok(NULL,","))) 01712 average_service_state_change=strtod(temp_ptr,NULL); 01713 } 01714 else if(!strcmp(var,"active_service_latency")){ 01715 if((temp_ptr=strtok(val,","))) 01716 min_active_service_latency=strtod(temp_ptr,NULL); 01717 if((temp_ptr=strtok(NULL,","))) 01718 max_active_service_latency=strtod(temp_ptr,NULL); 01719 if((temp_ptr=strtok(NULL,","))) 01720 average_active_service_latency=strtod(temp_ptr,NULL); 01721 } 01722 else if(!strcmp(var,"active_service_execution_time")){ 01723 if((temp_ptr=strtok(val,","))) 01724 min_active_service_execution_time=strtod(temp_ptr,NULL); 01725 if((temp_ptr=strtok(NULL,","))) 01726 max_active_service_execution_time=strtod(temp_ptr,NULL); 01727 if((temp_ptr=strtok(NULL,","))) 01728 average_active_service_execution_time=strtod(temp_ptr,NULL); 01729 } 01730 else if(!strcmp(var,"active_service_state_change")){ 01731 if((temp_ptr=strtok(val,","))) 01732 min_active_service_state_change=strtod(temp_ptr,NULL); 01733 if((temp_ptr=strtok(NULL,","))) 01734 max_active_service_state_change=strtod(temp_ptr,NULL); 01735 if((temp_ptr=strtok(NULL,","))) 01736 average_active_service_state_change=strtod(temp_ptr,NULL); 01737 } 01738 else if(!strcmp(var,"active_services_last_x")){ 01739 if((temp_ptr=strtok(val,","))) 01740 active_services_checked_last_1min=atoi(temp_ptr); 01741 if((temp_ptr=strtok(NULL,","))) 01742 active_services_checked_last_5min=atoi(temp_ptr); 01743 if((temp_ptr=strtok(NULL,","))) 01744 active_services_checked_last_15min=atoi(temp_ptr); 01745 if((temp_ptr=strtok(NULL,","))) 01746 active_services_checked_last_1hour=atoi(temp_ptr); 01747 } 01748 else if(!strcmp(var,"passive_service_latency")){ 01749 if((temp_ptr=strtok(val,","))) 01750 min_passive_service_latency=strtod(temp_ptr,NULL); 01751 if((temp_ptr=strtok(NULL,","))) 01752 max_passive_service_latency=strtod(temp_ptr,NULL); 01753 if((temp_ptr=strtok(NULL,","))) 01754 average_passive_service_latency=strtod(temp_ptr,NULL); 01755 } 01756 else if(!strcmp(var,"passive_service_state_change")){ 01757 if((temp_ptr=strtok(val,","))) 01758 min_passive_service_state_change=strtod(temp_ptr,NULL); 01759 if((temp_ptr=strtok(NULL,","))) 01760 max_passive_service_state_change=strtod(temp_ptr,NULL); 01761 if((temp_ptr=strtok(NULL,","))) 01762 average_passive_service_state_change=strtod(temp_ptr,NULL); 01763 } 01764 else if(!strcmp(var,"passive_services_last_x")){ 01765 if((temp_ptr=strtok(val,","))) 01766 passive_services_checked_last_1min=atoi(temp_ptr); 01767 if((temp_ptr=strtok(NULL,","))) 01768 passive_services_checked_last_5min=atoi(temp_ptr); 01769 if((temp_ptr=strtok(NULL,","))) 01770 passive_services_checked_last_15min=atoi(temp_ptr); 01771 if((temp_ptr=strtok(NULL,","))) 01772 passive_services_checked_last_1hour=atoi(temp_ptr); 01773 } 01774 } 01775 01776 fclose(fp); 01777 01778 /* 02-15-2008 exclude cached host checks from total (they were ondemand checks that never actually executed) */ 01779 active_host_checks_last_1min=active_scheduled_host_checks_last_1min+active_ondemand_host_checks_last_1min; 01780 active_host_checks_last_5min=active_scheduled_host_checks_last_5min+active_ondemand_host_checks_last_5min; 01781 active_host_checks_last_15min=active_scheduled_host_checks_last_15min+active_ondemand_host_checks_last_15min; 01782 01783 /* 02-15-2008 exclude cached service checks from total (they were ondemand checks that never actually executed) */ 01784 active_service_checks_last_1min=active_scheduled_service_checks_last_1min+active_ondemand_service_checks_last_1min; 01785 active_service_checks_last_5min=active_scheduled_service_checks_last_5min+active_ondemand_service_checks_last_5min; 01786 active_service_checks_last_15min=active_scheduled_service_checks_last_15min+active_ondemand_service_checks_last_15min; 01787 01788 return OK; 01789 } 01790 01791 01792 /* strip newline, carriage return, and tab characters from beginning and end of a string */ 01793 void strip(char *buffer){ 01794 register int x; 01795 register int y; 01796 register int z; 01797 01798 if(buffer==NULL || buffer[0]=='\x0') 01799 return; 01800 01801 /* strip end of string */ 01802 y=(int)strlen(buffer); 01803 for(x=y-1;x>=0;x--){ 01804 if(buffer[x]==' ' || buffer[x]=='\n' || buffer[x]=='\r' || buffer[x]=='\t' || buffer[x]==13) 01805 buffer[x]='\x0'; 01806 else 01807 break; 01808 } 01809 01810 /* strip beginning of string (by shifting) */ 01811 y=(int)strlen(buffer); 01812 for(x=0;x<y;x++){ 01813 if(buffer[x]==' ' || buffer[x]=='\n' || buffer[x]=='\r' || buffer[x]=='\t' || buffer[x]==13) 01814 continue; 01815 else 01816 break; 01817 } 01818 if(x>0){ 01819 for(z=x;z<y;z++) 01820 buffer[z-x]=buffer[z]; 01821 buffer[y-x]='\x0'; 01822 } 01823 01824 return; 01825 } 01826 01827 01828 01829 /* get days, hours, minutes, and seconds from a raw time_t format or total seconds */ 01830 void get_time_breakdown(unsigned long raw_time,int *days,int *hours,int *minutes,int *seconds){ 01831 unsigned long temp_time; 01832 int temp_days; 01833 int temp_hours; 01834 int temp_minutes; 01835 int temp_seconds; 01836 01837 temp_time=raw_time; 01838 01839 temp_days=temp_time/86400; 01840 temp_time-=(temp_days * 86400); 01841 temp_hours=temp_time/3600; 01842 temp_time-=(temp_hours * 3600); 01843 temp_minutes=temp_time/60; 01844 temp_time-=(temp_minutes * 60); 01845 temp_seconds=(int)temp_time; 01846 01847 *days=temp_days; 01848 *hours=temp_hours; 01849 *minutes=temp_minutes; 01850 *seconds=temp_seconds; 01851 01852 return; 01853 } 01854