![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * HISTORY.C - Icinga History CGI 00004 * 00005 * Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00007 * 00008 * License: 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License version 2 as 00012 * published by the Free Software Foundation. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00022 * 00023 *****************************************************************************/ 00024 00029 #include "../include/config.h" 00030 #include "../include/common.h" 00031 #include "../include/objects.h" 00032 00033 #include "../include/getcgi.h" 00034 #include "../include/cgiutils.h" 00035 #include "../include/cgiauth.h" 00036 #include "../include/readlogs.h" 00037 00038 00041 extern char main_config_file[MAX_FILENAME_LENGTH]; 00042 extern char url_html_path[MAX_FILENAME_LENGTH]; 00043 extern char url_images_path[MAX_FILENAME_LENGTH]; 00044 extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; 00045 extern char url_js_path[MAX_FILENAME_LENGTH]; 00046 00047 extern int log_rotation_method; 00048 extern int enable_splunk_integration; 00049 extern int embedded; 00050 extern int display_header; 00051 extern int daemon_check; 00052 00053 extern logentry *entry_list; 00061 int show_all_hostgroups=TRUE; 00062 int show_all_servicegroups=TRUE; 00063 char *host_filter=NULL; 00064 char *hostgroup_name=NULL; 00065 char *servicegroup_name=NULL; 00066 char *service_filter=NULL; 00071 int log_archive=0; 00072 int display_type=DISPLAY_HOSTS; 00073 int show_all_hosts=TRUE; 00074 int reverse=FALSE; 00075 int history_options=HISTORY_ALL; 00076 int state_options=STATE_ALL; 00078 int display_frills=TRUE; 00079 int display_timebreaks=TRUE; 00080 int display_system_messages=TRUE; 00081 int display_flapping_alerts=TRUE; 00082 int display_downtime_alerts=TRUE; 00084 char *host_name="all"; 00085 char *service_desc=""; 00086 char log_file_to_use[MAX_FILENAME_LENGTH]; 00088 authdata current_authdata; 00090 int CGI_ID=HISTORY_CGI_ID; 00098 void show_history(void); 00099 00107 int process_cgivars(void); 00108 00110 int main(void){ 00111 int result=OK; 00112 char temp_buffer[MAX_INPUT_BUFFER]; 00113 char temp_buffer2[MAX_INPUT_BUFFER]; 00114 00115 /* get the variables passed to us */ 00116 process_cgivars(); 00117 00118 /* reset internal CGI variables */ 00119 reset_cgi_vars(); 00120 00121 /* read the CGI configuration file */ 00122 result=read_cgi_config_file(get_cgi_config_location()); 00123 if(result==ERROR){ 00124 document_header(CGI_ID,FALSE); 00125 print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE); 00126 document_footer(CGI_ID); 00127 return ERROR; 00128 } 00129 00130 /* read the main configuration file */ 00131 result=read_main_config_file(main_config_file); 00132 if(result==ERROR){ 00133 document_header(CGI_ID,FALSE); 00134 print_error(main_config_file, ERROR_CGI_MAIN_CFG); 00135 document_footer(CGI_ID); 00136 return ERROR; 00137 } 00138 00139 /* read all object configuration data */ 00140 result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA); 00141 if(result==ERROR){ 00142 document_header(CGI_ID,FALSE); 00143 print_error(NULL, ERROR_CGI_OBJECT_DATA); 00144 document_footer(CGI_ID); 00145 return ERROR; 00146 } 00147 00148 document_header(CGI_ID,TRUE); 00149 00150 /* get authentication information */ 00151 get_authentication_information(¤t_authdata); 00152 00153 /* determine what log file we should be using */ 00154 get_log_archive_to_use(log_archive,log_file_to_use,(int)sizeof(log_file_to_use)); 00155 00156 if(display_header==TRUE){ 00157 00158 /* begin top table */ 00159 printf("<table border=0 width=100%%>\n"); 00160 printf("<tr>\n"); 00161 00162 /* left column of the first row */ 00163 printf("<td align=left valign=top width=33%%>\n"); 00164 00165 if(display_type==DISPLAY_SERVICES) 00166 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Service Alert History"); 00167 else if(show_all_hosts==TRUE) 00168 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Alert History"); 00169 else 00170 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Host Alert History"); 00171 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00172 display_info_table(temp_buffer,FALSE,¤t_authdata, daemon_check); 00173 00174 printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n"); 00175 printf("<TR><TD CLASS='linkBox'>\n"); 00176 if(display_type==DISPLAY_HOSTS){ 00177 printf("<A HREF='%s?host=%s'>View Status Detail For %s</A><BR />\n",STATUS_CGI,(show_all_hosts==TRUE)?"all":url_encode(host_name),(show_all_hosts==TRUE)?"All Hosts":"This Host"); 00178 printf("<A HREF='%s?host=%s'>View Notifications For %s</A><BR />\n",NOTIFICATIONS_CGI,(show_all_hosts==TRUE)?"all":url_encode(host_name),(show_all_hosts==TRUE)?"All Hosts":"This Host"); 00179 #ifdef USE_TRENDS 00180 if(show_all_hosts==FALSE) 00181 printf("<A HREF='%s?host=%s'>View Trends For This Host</A>\n",TRENDS_CGI,url_encode(host_name)); 00182 #endif 00183 }else{ 00184 printf("<A HREF='%s?host=%s&",NOTIFICATIONS_CGI,url_encode(host_name)); 00185 printf("service=%s'>View Notifications For This Service</A><BR />\n",url_encode(service_desc)); 00186 #ifdef USE_TRENDS 00187 printf("<A HREF='%s?host=%s&",TRENDS_CGI,url_encode(host_name)); 00188 printf("service=%s'>View Trends For This Service</A><BR />\n",url_encode(service_desc)); 00189 #endif 00190 printf("<A HREF='%s?host=%s'>View History For This Host</A>\n",HISTORY_CGI,url_encode(host_name)); 00191 } 00192 printf("</TD></TR>\n"); 00193 printf("</TABLE>\n"); 00194 00195 printf("</td>\n"); 00196 00197 /* middle column of top row */ 00198 printf("<td align=center valign=top width=33%%>\n"); 00199 00200 printf("<DIV ALIGN=CENTER CLASS='dataTitle'>\n"); 00201 if(display_type==DISPLAY_SERVICES) 00202 printf("Service '%s' On Host '%s'",service_desc,host_name); 00203 else if(show_all_hosts==TRUE) 00204 printf("All Hosts and Services"); 00205 else 00206 printf("Host '%s'",host_name); 00207 printf("</DIV>\n"); 00208 printf("<BR />\n"); 00209 00210 snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s?%shost=%s&type=%d&statetype=%d&",HISTORY_CGI,(reverse==TRUE)?"oldestfirst&":"",url_encode(host_name),history_options,state_options); 00211 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00212 if(display_type==DISPLAY_SERVICES){ 00213 snprintf(temp_buffer2,sizeof(temp_buffer2)-1,"service=%s&",url_encode(service_desc)); 00214 temp_buffer2[sizeof(temp_buffer2)-1]='\x0'; 00215 strncat(temp_buffer,temp_buffer2,sizeof(temp_buffer)-strlen(temp_buffer)-1); 00216 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00217 } 00218 display_nav_table(temp_buffer,log_archive); 00219 00220 printf("</td>\n"); 00221 00222 /* right hand column of top row */ 00223 printf("<td align=right valign=top width=33%%>\n"); 00224 00225 printf("<form method=\"GET\" action=\"%s\">\n",HISTORY_CGI); 00226 printf("<table border=0 CLASS='optBox'>\n"); 00227 printf("<input type='hidden' name='host' value='%s'>\n",(show_all_hosts==TRUE)?"all":escape_string(host_name)); 00228 if(display_type==DISPLAY_SERVICES) 00229 printf("<input type='hidden' name='service' value='%s'>\n",escape_string(service_desc)); 00230 printf("<input type='hidden' name='archive' value='%d'>\n",log_archive); 00231 00232 printf("<tr>\n"); 00233 printf("<td align=left CLASS='optBoxItem'>State type options:</td>\n"); 00234 printf("</tr>\n"); 00235 00236 printf("<tr>\n"); 00237 printf("<td align=left CLASS='optBoxItem'><select name='statetype'>\n"); 00238 printf("<option value=%d %s>All state types</option>\n",STATE_ALL,(state_options==STATE_ALL)?"selected":""); 00239 printf("<option value=%d %s>Soft states</option>\n",STATE_SOFT,(state_options==STATE_SOFT)?"selected":""); 00240 printf("<option value=%d %s>Hard states</option>\n",STATE_HARD,(state_options==STATE_HARD)?"selected":""); 00241 printf("</select></td>\n"); 00242 printf("</tr>\n"); 00243 00244 printf("<tr>\n"); 00245 printf("<td align=left CLASS='optBoxItem'>History detail level for "); 00246 if(display_type==DISPLAY_HOSTS) 00247 printf("%s host%s",(show_all_hosts==TRUE)?"all":"this",(show_all_hosts==TRUE)?"s":""); 00248 else 00249 printf("service"); 00250 printf(":</td>\n"); 00251 printf("</tr>\n"); 00252 printf("<tr>\n"); 00253 printf("<td align=left CLASS='optBoxItem'><select name='type'>\n"); 00254 if(display_type==DISPLAY_HOSTS) 00255 printf("<option value=%d %s>All alerts</option>\n",HISTORY_ALL,(history_options==HISTORY_ALL)?"selected":""); 00256 printf("<option value=%d %s>All service alerts</option>\n",HISTORY_SERVICE_ALL,(history_options==HISTORY_SERVICE_ALL)?"selected":""); 00257 if(display_type==DISPLAY_HOSTS) 00258 printf("<option value=%d %s>All host alerts</option>\n",HISTORY_HOST_ALL,(history_options==HISTORY_HOST_ALL)?"selected":""); 00259 printf("<option value=%d %s>Service warning</option>\n",HISTORY_SERVICE_WARNING,(history_options==HISTORY_SERVICE_WARNING)?"selected":""); 00260 printf("<option value=%d %s>Service unknown</option>\n",HISTORY_SERVICE_UNKNOWN,(history_options==HISTORY_SERVICE_UNKNOWN)?"selected":""); 00261 printf("<option value=%d %s>Service critical</option>\n",HISTORY_SERVICE_CRITICAL,(history_options==HISTORY_SERVICE_CRITICAL)?"selected":""); 00262 printf("<option value=%d %s>Service recovery</option>\n",HISTORY_SERVICE_RECOVERY,(history_options==HISTORY_SERVICE_RECOVERY)?"selected":""); 00263 if(display_type==DISPLAY_HOSTS){ 00264 printf("<option value=%d %s>Host down</option>\n",HISTORY_HOST_DOWN,(history_options==HISTORY_HOST_DOWN)?"selected":""); 00265 printf("<option value=%d %s>Host unreachable</option>\n",HISTORY_HOST_UNREACHABLE,(history_options==HISTORY_HOST_UNREACHABLE)?"selected":""); 00266 printf("<option value=%d %s>Host recovery</option>\n",HISTORY_HOST_RECOVERY,(history_options==HISTORY_HOST_RECOVERY)?"selected":""); 00267 } 00268 printf("</select></td>\n"); 00269 printf("</tr>\n"); 00270 00271 printf("<tr>\n"); 00272 printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='noflapping' %s> Hide Flapping Alerts</td>",(display_flapping_alerts==FALSE)?"checked":""); 00273 printf("</tr>\n"); 00274 printf("<tr>\n"); 00275 printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='nodowntime' %s> Hide Downtime Alerts</td>",(display_downtime_alerts==FALSE)?"checked":""); 00276 printf("</tr>\n"); 00277 00278 printf("<tr>\n"); 00279 printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='nosystem' %s> Hide Process Messages</td>",(display_system_messages==FALSE)?"checked":""); 00280 printf("</tr>\n"); 00281 printf("<tr>\n"); 00282 printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='oldestfirst' %s> Older Entries First</td>",(reverse==TRUE)?"checked":""); 00283 printf("</tr>\n"); 00284 00285 printf("<tr>\n"); 00286 printf("<td align=left CLASS='optBoxItem'><input type='submit' value='Update'></td>\n"); 00287 printf("</tr>\n"); 00288 00289 /* display context-sensitive help */ 00290 printf("<tr>\n"); 00291 printf("<td align=right>\n"); 00292 display_context_help(CONTEXTHELP_HISTORY); 00293 printf("</td>\n"); 00294 printf("</tr>\n"); 00295 00296 printf("</table>\n"); 00297 printf("</form>\n"); 00298 00299 printf("</td>\n"); 00300 00301 /* end of top table */ 00302 printf("</tr>\n"); 00303 printf("</table>\n"); 00304 00305 } 00306 00307 /* display history */ 00308 show_history(); 00309 00310 document_footer(CGI_ID); 00311 00312 /* free allocated memory */ 00313 free_memory(); 00314 00315 return OK; 00316 } 00317 00318 int process_cgivars(void){ 00319 char **variables; 00320 int error=FALSE; 00321 int x; 00322 00323 variables=getcgivars(); 00324 00325 for(x=0;variables[x]!=NULL;x++){ 00326 00327 /* do some basic length checking on the variable identifier to prevent buffer overflows */ 00328 if(strlen(variables[x])>=MAX_INPUT_BUFFER-1) 00329 continue; 00330 00331 /* we found the host argument */ 00332 else if(!strcmp(variables[x],"host")){ 00333 x++; 00334 if(variables[x]==NULL){ 00335 error=TRUE; 00336 break; 00337 } 00338 00339 if((host_name=(char *)strdup(variables[x]))==NULL) 00340 host_name=""; 00341 strip_html_brackets(host_name); 00342 00343 display_type=DISPLAY_HOSTS; 00344 00345 if(!strcmp(host_name,"all")) 00346 show_all_hosts=TRUE; 00347 else 00348 show_all_hosts=FALSE; 00349 } 00350 00351 /* we found the service argument */ 00352 else if(!strcmp(variables[x],"service")){ 00353 x++; 00354 if(variables[x]==NULL){ 00355 error=TRUE; 00356 break; 00357 } 00358 00359 if((service_desc=(char *)strdup(variables[x]))==NULL) 00360 service_desc=""; 00361 strip_html_brackets(service_desc); 00362 00363 display_type=DISPLAY_SERVICES; 00364 } 00365 00366 00367 /* we found the history type argument */ 00368 else if(!strcmp(variables[x],"type")){ 00369 x++; 00370 if(variables[x]==NULL){ 00371 error=TRUE; 00372 break; 00373 } 00374 00375 history_options=atoi(variables[x]); 00376 } 00377 00378 /* we found the history state type argument */ 00379 else if(!strcmp(variables[x],"statetype")){ 00380 x++; 00381 if(variables[x]==NULL){ 00382 error=TRUE; 00383 break; 00384 } 00385 00386 state_options=atoi(variables[x]); 00387 } 00388 00389 00390 /* we found the log archive argument */ 00391 else if(!strcmp(variables[x],"archive")){ 00392 x++; 00393 if(variables[x]==NULL){ 00394 error=TRUE; 00395 break; 00396 } 00397 00398 log_archive=atoi(variables[x]); 00399 if(log_archive<0) 00400 log_archive=0; 00401 } 00402 00403 /* we found the order argument */ 00404 else if(!strcmp(variables[x],"oldestfirst")){ 00405 reverse=TRUE; 00406 } 00407 00408 /* we found the embed option */ 00409 else if(!strcmp(variables[x],"embedded")) 00410 embedded=TRUE; 00411 00412 /* we found the noheader option */ 00413 else if(!strcmp(variables[x],"noheader")) 00414 display_header=FALSE; 00415 00416 /* we found the nodaemoncheck option */ 00417 else if(!strcmp(variables[x],"nodaemoncheck")) 00418 daemon_check=FALSE; 00419 00420 /* we found the nofrills option */ 00421 else if(!strcmp(variables[x],"nofrills")) 00422 display_frills=FALSE; 00423 00424 /* we found the notimebreaks option */ 00425 else if(!strcmp(variables[x],"notimebreaks")) 00426 display_timebreaks=FALSE; 00427 00428 /* we found the no system messages option */ 00429 else if(!strcmp(variables[x],"nosystem")) 00430 display_system_messages=FALSE; 00431 00432 /* we found the no flapping alerts option */ 00433 else if(!strcmp(variables[x],"noflapping")) 00434 display_flapping_alerts=FALSE; 00435 00436 /* we found the no downtime alerts option */ 00437 else if(!strcmp(variables[x],"nodowntime")) 00438 display_downtime_alerts=FALSE; 00439 } 00440 00441 /* free memory allocated to the CGI variables */ 00442 free_cgivars(variables); 00443 00444 return error; 00445 } 00446 00447 void show_history(void){ 00448 char image[MAX_INPUT_BUFFER]; 00449 char image_alt[MAX_INPUT_BUFFER]; 00450 char match1[MAX_INPUT_BUFFER]; 00451 char match2[MAX_INPUT_BUFFER]; 00452 char date_time[MAX_DATETIME_LENGTH]; 00453 char *temp_buffer=NULL; 00454 char *entry_host_name=NULL; 00455 char *entry_service_desc=NULL; 00456 char error_text[MAX_INPUT_BUFFER]=""; 00457 char last_message_date[MAX_INPUT_BUFFER]=""; 00458 char current_message_date[MAX_INPUT_BUFFER]=""; 00459 int found_line=FALSE; 00460 int system_message=FALSE; 00461 int display_line=FALSE; 00462 int history_type=SERVICE_HISTORY; 00463 int history_detail_type=HISTORY_SERVICE_CRITICAL; 00464 int status=0; 00465 host *temp_host=NULL; 00466 service *temp_service=NULL; 00467 logentry *temp_entry=NULL; 00468 struct tm *time_ptr=NULL; 00469 00470 /* read log entries */ 00471 status=get_log_entries(log_file_to_use,NULL,reverse,-1,-1); 00472 00473 if (status==READLOG_ERROR_MEMORY) { 00474 printf("<P><DIV CLASS='warningMessage'>Run out of memory..., showing all I could gather!</DIV></P>"); 00475 } 00476 00477 if (status==READLOG_ERROR_NOFILE) { 00478 snprintf(error_text,sizeof(error_text),"Error: Could not open log file '%s' for reading!",log_file_to_use); 00479 error_text[sizeof(error_text)-1]='\x0'; 00480 print_generic_error_message(error_text,NULL,0); 00481 /* free memory */ 00482 free_log_entries(); 00483 return; 00484 00485 } else if (status==READLOG_OK) { 00486 00487 printf("<P><DIV CLASS='logEntries'>\n"); 00488 00489 for(temp_entry=entry_list;temp_entry!=NULL;temp_entry=temp_entry->next) { 00490 00491 strcpy(image,""); 00492 strcpy(image_alt,""); 00493 system_message=FALSE; 00494 00495 switch(temp_entry->type){ 00496 00497 /* service state alerts */ 00498 case LOGENTRY_SERVICE_CRITICAL: 00499 case LOGENTRY_SERVICE_WARNING: 00500 case LOGENTRY_SERVICE_UNKNOWN: 00501 case LOGENTRY_SERVICE_RECOVERY: 00502 case LOGENTRY_SERVICE_OK: 00503 00504 history_type=SERVICE_HISTORY; 00505 00506 /* get host and service names */ 00507 temp_buffer=my_strtok(temp_entry->entry_text,":"); 00508 temp_buffer=my_strtok(NULL,";"); 00509 if(temp_buffer) 00510 entry_host_name=strdup(temp_buffer+1); 00511 else 00512 entry_host_name=NULL; 00513 00514 temp_buffer=my_strtok(NULL,";"); 00515 if(temp_buffer) 00516 entry_service_desc=strdup(temp_buffer); 00517 else 00518 entry_service_desc=NULL; 00519 00520 if(temp_entry->type==LOGENTRY_SERVICE_CRITICAL){ 00521 strcpy(image,CRITICAL_ICON); 00522 strcpy(image_alt,CRITICAL_ICON_ALT); 00523 history_detail_type=HISTORY_SERVICE_CRITICAL; 00524 } 00525 else if(temp_entry->type==LOGENTRY_SERVICE_WARNING){ 00526 strcpy(image,WARNING_ICON); 00527 strcpy(image_alt,WARNING_ICON_ALT); 00528 history_detail_type=HISTORY_SERVICE_WARNING; 00529 } 00530 else if(temp_entry->type==LOGENTRY_SERVICE_UNKNOWN){ 00531 strcpy(image,UNKNOWN_ICON); 00532 strcpy(image_alt,UNKNOWN_ICON_ALT); 00533 history_detail_type=HISTORY_SERVICE_UNKNOWN; 00534 } 00535 else if(temp_entry->type==LOGENTRY_SERVICE_RECOVERY || temp_entry->type==LOGENTRY_SERVICE_OK){ 00536 strcpy(image,OK_ICON); 00537 strcpy(image_alt,OK_ICON_ALT); 00538 history_detail_type=HISTORY_SERVICE_RECOVERY; 00539 } 00540 break; 00541 00542 /* service flapping alerts */ 00543 case LOGENTRY_SERVICE_FLAPPING_STARTED: 00544 case LOGENTRY_SERVICE_FLAPPING_STOPPED: 00545 case LOGENTRY_SERVICE_FLAPPING_DISABLED: 00546 00547 if(display_flapping_alerts==FALSE) 00548 continue; 00549 00550 history_type=SERVICE_FLAPPING_HISTORY; 00551 00552 /* get host and service names */ 00553 temp_buffer=my_strtok(temp_entry->entry_text,":"); 00554 temp_buffer=my_strtok(NULL,";"); 00555 if(temp_buffer) 00556 entry_host_name=strdup(temp_buffer+1); 00557 else 00558 entry_host_name=NULL; 00559 temp_buffer=my_strtok(NULL,";"); 00560 if(temp_buffer) 00561 entry_service_desc=strdup(temp_buffer); 00562 else 00563 entry_service_desc=NULL; 00564 00565 strcpy(image,FLAPPING_ICON); 00566 00567 if(temp_entry->type==LOGENTRY_SERVICE_FLAPPING_STARTED) 00568 strcpy(image_alt,"Service started flapping"); 00569 else if(temp_entry->type==LOGENTRY_SERVICE_FLAPPING_STOPPED) 00570 strcpy(image_alt,"Service stopped flapping"); 00571 else if(temp_entry->type==LOGENTRY_SERVICE_FLAPPING_DISABLED) 00572 strcpy(image_alt,"Service flap detection disabled"); 00573 00574 break; 00575 00576 /* service downtime alerts */ 00577 case LOGENTRY_SERVICE_DOWNTIME_STARTED: 00578 case LOGENTRY_SERVICE_DOWNTIME_STOPPED: 00579 case LOGENTRY_SERVICE_DOWNTIME_CANCELLED: 00580 00581 if(display_downtime_alerts==FALSE) 00582 continue; 00583 00584 history_type=SERVICE_DOWNTIME_HISTORY; 00585 00586 /* get host and service names */ 00587 temp_buffer=my_strtok(temp_entry->entry_text,":"); 00588 temp_buffer=my_strtok(NULL,";"); 00589 if(temp_buffer) 00590 entry_host_name=strdup(temp_buffer+1); 00591 else 00592 entry_host_name=NULL; 00593 temp_buffer=my_strtok(NULL,";"); 00594 if(temp_buffer) 00595 entry_service_desc=strdup(temp_buffer); 00596 else 00597 entry_service_desc=NULL; 00598 00599 strcpy(image,SCHEDULED_DOWNTIME_ICON); 00600 00601 if(temp_entry->type==LOGENTRY_SERVICE_DOWNTIME_STARTED) 00602 strcpy(image_alt,"Service entered a period of scheduled downtime"); 00603 else if(temp_entry->type==LOGENTRY_SERVICE_DOWNTIME_STOPPED) 00604 strcpy(image_alt,"Service exited from a period of scheduled downtime"); 00605 else if(temp_entry->type==LOGENTRY_SERVICE_DOWNTIME_CANCELLED) 00606 strcpy(image_alt,"Service scheduled downtime has been cancelled"); 00607 00608 break; 00609 00610 /* host state alerts */ 00611 case LOGENTRY_HOST_DOWN: 00612 case LOGENTRY_HOST_UNREACHABLE: 00613 case LOGENTRY_HOST_RECOVERY: 00614 case LOGENTRY_HOST_UP: 00615 00616 history_type=HOST_HISTORY; 00617 00618 /* get host name */ 00619 temp_buffer=my_strtok(temp_entry->entry_text,":"); 00620 temp_buffer=my_strtok(NULL,";"); 00621 if(temp_buffer) 00622 entry_host_name=strdup(temp_buffer+1); 00623 else 00624 entry_host_name=NULL; 00625 00626 if(temp_entry->type==LOGENTRY_HOST_DOWN){ 00627 strcpy(image,HOST_DOWN_ICON); 00628 strcpy(image_alt,HOST_DOWN_ICON_ALT); 00629 history_detail_type=HISTORY_HOST_DOWN; 00630 } 00631 else if(temp_entry->type==LOGENTRY_HOST_UNREACHABLE){ 00632 strcpy(image,HOST_UNREACHABLE_ICON); 00633 strcpy(image_alt,HOST_UNREACHABLE_ICON_ALT); 00634 history_detail_type=HISTORY_HOST_UNREACHABLE; 00635 } 00636 else if(temp_entry->type==LOGENTRY_HOST_RECOVERY || temp_entry->type==LOGENTRY_HOST_UP){ 00637 strcpy(image,HOST_UP_ICON); 00638 strcpy(image_alt,HOST_UP_ICON_ALT); 00639 history_detail_type=HISTORY_HOST_RECOVERY; 00640 } 00641 00642 break; 00643 00644 /* host flapping alerts */ 00645 case LOGENTRY_HOST_FLAPPING_STARTED: 00646 case LOGENTRY_HOST_FLAPPING_STOPPED: 00647 case LOGENTRY_HOST_FLAPPING_DISABLED: 00648 00649 if(display_flapping_alerts==FALSE) 00650 continue; 00651 00652 history_type=HOST_FLAPPING_HISTORY; 00653 00654 /* get host name */ 00655 temp_buffer=my_strtok(temp_entry->entry_text,":"); 00656 temp_buffer=my_strtok(NULL,";"); 00657 if(temp_buffer) 00658 entry_host_name=strdup(temp_buffer+1); 00659 else 00660 entry_host_name=NULL; 00661 00662 strcpy(image,FLAPPING_ICON); 00663 00664 if(temp_entry->type==LOGENTRY_HOST_FLAPPING_STARTED) 00665 strcpy(image_alt,"Host started flapping"); 00666 else if(temp_entry->type==LOGENTRY_HOST_FLAPPING_STOPPED) 00667 strcpy(image_alt,"Host stopped flapping"); 00668 else if(temp_entry->type==LOGENTRY_HOST_FLAPPING_DISABLED) 00669 strcpy(image_alt,"Host flap detection disabled"); 00670 00671 break; 00672 00673 /* host downtime alerts */ 00674 case LOGENTRY_HOST_DOWNTIME_STARTED: 00675 case LOGENTRY_HOST_DOWNTIME_STOPPED: 00676 case LOGENTRY_HOST_DOWNTIME_CANCELLED: 00677 00678 if(display_downtime_alerts==FALSE) 00679 continue; 00680 00681 history_type=HOST_DOWNTIME_HISTORY; 00682 00683 /* get host name */ 00684 temp_buffer=my_strtok(temp_entry->entry_text,":"); 00685 temp_buffer=my_strtok(NULL,";"); 00686 if(temp_buffer) 00687 entry_host_name=strdup(temp_buffer+1); 00688 else 00689 entry_host_name=NULL; 00690 00691 strcpy(image,SCHEDULED_DOWNTIME_ICON); 00692 00693 if(temp_entry->type==LOGENTRY_HOST_DOWNTIME_STARTED) 00694 strcpy(image_alt,"Host entered a period of scheduled downtime"); 00695 else if(temp_entry->type==LOGENTRY_HOST_DOWNTIME_STOPPED) 00696 strcpy(image_alt,"Host exited from a period of scheduled downtime"); 00697 else if(temp_entry->type==LOGENTRY_HOST_DOWNTIME_CANCELLED) 00698 strcpy(image_alt,"Host scheduled downtime has been cancelled"); 00699 00700 break; 00701 00702 00703 /* program start */ 00704 case LOGENTRY_STARTUP: 00705 if(display_system_messages==FALSE) 00706 continue; 00707 strcpy(image,START_ICON); 00708 strcpy(image_alt,START_ICON_ALT); 00709 system_message=TRUE; 00710 break; 00711 00712 /* program termination */ 00713 case LOGENTRY_SHUTDOWN: 00714 case LOGENTRY_BAILOUT: 00715 if(display_system_messages==FALSE) 00716 continue; 00717 strcpy(image,STOP_ICON); 00718 strcpy(image_alt,STOP_ICON_ALT); 00719 system_message=TRUE; 00720 break; 00721 00722 /* program restart */ 00723 case LOGENTRY_RESTART: 00724 if(display_system_messages==FALSE) 00725 continue; 00726 strcpy(image,RESTART_ICON); 00727 strcpy(image_alt,RESTART_ICON_ALT); 00728 system_message=TRUE; 00729 break; 00730 } 00731 00732 image[sizeof(image)-1]='\x0'; 00733 image_alt[sizeof(image_alt)-1]='\x0'; 00734 00735 /* get the timestamp */ 00736 time_ptr=localtime(&temp_entry->timestamp); 00737 strftime(current_message_date,sizeof(current_message_date),"%B %d, %Y %H:00\n",time_ptr); 00738 current_message_date[sizeof(current_message_date)-1]='\x0'; 00739 00740 get_time_string(&temp_entry->timestamp,date_time,sizeof(date_time),SHORT_DATE_TIME); 00741 strip(date_time); 00742 00743 if(strcmp(image,"")){ 00744 00745 display_line=FALSE; 00746 00747 if(system_message==TRUE) 00748 display_line=TRUE; 00749 00750 else if(display_type==DISPLAY_HOSTS){ 00751 00752 if(history_type==HOST_HISTORY || history_type==SERVICE_HISTORY){ 00753 sprintf(match1," HOST ALERT: %s;",host_name); 00754 sprintf(match2," SERVICE ALERT: %s;",host_name); 00755 } 00756 else if(history_type==HOST_FLAPPING_HISTORY || history_type==SERVICE_FLAPPING_HISTORY){ 00757 sprintf(match1," HOST FLAPPING ALERT: %s;",host_name); 00758 sprintf(match2," SERVICE FLAPPING ALERT: %s;",host_name); 00759 } 00760 else if(history_type==HOST_DOWNTIME_HISTORY || history_type==SERVICE_DOWNTIME_HISTORY){ 00761 sprintf(match1," HOST DOWNTIME ALERT: %s;",host_name); 00762 sprintf(match2," SERVICE DOWNTIME ALERT: %s;",host_name); 00763 } 00764 00765 if(show_all_hosts==TRUE) 00766 display_line=TRUE; 00767 else if(strstr(temp_entry->entry_text,match1)) 00768 display_line=TRUE; 00769 else if(strstr(temp_entry->entry_text,match2)) 00770 display_line=TRUE; 00771 00772 if(display_line==TRUE){ 00773 if(history_options==HISTORY_ALL) 00774 display_line=TRUE; 00775 else if(history_options==HISTORY_HOST_ALL && (history_type==HOST_HISTORY || history_type==HOST_FLAPPING_HISTORY || history_type==HOST_DOWNTIME_HISTORY)) 00776 display_line=TRUE; 00777 else if(history_options==HISTORY_SERVICE_ALL && (history_type==SERVICE_HISTORY || history_type==SERVICE_FLAPPING_HISTORY || history_type==SERVICE_DOWNTIME_HISTORY)) 00778 display_line=TRUE; 00779 else if((history_type==HOST_HISTORY || history_type==SERVICE_HISTORY) && (history_detail_type & history_options)) 00780 display_line=TRUE; 00781 else 00782 display_line=FALSE; 00783 } 00784 00785 /* check alert state types */ 00786 if(display_line==TRUE && (history_type==HOST_HISTORY || history_type==SERVICE_HISTORY)){ 00787 if(state_options==STATE_ALL) 00788 display_line=TRUE; 00789 else if((state_options & STATE_SOFT) && strstr(temp_buffer,";SOFT;")) 00790 display_line=TRUE; 00791 else if((state_options & STATE_HARD) && strstr(temp_buffer,";HARD;")) 00792 display_line=TRUE; 00793 else 00794 display_line=FALSE; 00795 } 00796 } 00797 00798 else if(display_type==DISPLAY_SERVICES){ 00799 00800 if(history_type==SERVICE_HISTORY) 00801 sprintf(match1," SERVICE ALERT: %s;%s;",host_name,service_desc); 00802 else if(history_type==SERVICE_FLAPPING_HISTORY) 00803 sprintf(match1," SERVICE FLAPPING ALERT: %s;%s;",host_name,service_desc); 00804 else if(history_type==SERVICE_DOWNTIME_HISTORY) 00805 sprintf(match1," SERVICE DOWNTIME ALERT: %s;%s;",host_name,service_desc); 00806 00807 if(strstr(temp_entry->entry_text,match1) && (history_type==SERVICE_HISTORY || history_type==SERVICE_FLAPPING_HISTORY || history_type==SERVICE_DOWNTIME_HISTORY)) 00808 display_line=TRUE; 00809 00810 if(display_line==TRUE){ 00811 if(history_options==HISTORY_ALL || history_options==HISTORY_SERVICE_ALL) 00812 display_line=TRUE; 00813 else if(history_options & history_detail_type) 00814 display_line=TRUE; 00815 else 00816 display_line=FALSE; 00817 } 00818 00819 /* check alert state type */ 00820 if(display_line==TRUE && history_type==SERVICE_HISTORY){ 00821 00822 if(state_options==STATE_ALL) 00823 display_line=TRUE; 00824 else if((state_options & STATE_SOFT) && strstr(temp_buffer,";SOFT;")) 00825 display_line=TRUE; 00826 else if((state_options & STATE_HARD) && strstr(temp_buffer,";HARD;")) 00827 display_line=TRUE; 00828 else 00829 display_line=FALSE; 00830 } 00831 } 00832 00833 /* make sure user is authorized to view this host or service information */ 00834 if(system_message==FALSE){ 00835 00836 if(history_type==HOST_HISTORY || history_type==HOST_FLAPPING_HISTORY || history_type==HOST_DOWNTIME_HISTORY){ 00837 temp_host=find_host(entry_host_name); 00838 if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 00839 display_line=FALSE; 00840 }else{ 00841 temp_service=find_service(entry_host_name,entry_service_desc); 00842 if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) 00843 display_line=FALSE; 00844 } 00845 } 00846 00847 /* display the entry if we should... */ 00848 if(display_line==TRUE){ 00849 00850 if(strcmp(last_message_date,current_message_date)!=0 && display_timebreaks==TRUE){ 00851 printf("</DIV><BR CLEAR='all' />\n"); 00852 printf("<DIV CLASS='dateTimeBreak'>\n"); 00853 printf("<table border=0 width=95%%><tr>"); 00854 printf("<td width=40%%><hr width=100%%></td>"); 00855 printf("<td align=center CLASS='dateTimeBreak'>%s</td>",current_message_date); 00856 printf("<td width=40%%><hr width=100%%></td>"); 00857 printf("</tr></table>\n"); 00858 printf("</DIV>\n"); 00859 printf("<BR CLEAR='all' /><DIV CLASS='logEntries'>\n"); 00860 strncpy(last_message_date,current_message_date,sizeof(last_message_date)); 00861 last_message_date[sizeof(last_message_date)-1]='\x0'; 00862 } 00863 00864 if(display_frills==TRUE) 00865 printf("<img align='left' src='%s%s' alt='%s' title='%s' />",url_images_path,image,image_alt,image_alt); 00866 printf("[%s] %s",date_time,html_encode(temp_entry->entry_text,FALSE)); 00867 if(enable_splunk_integration==TRUE){ 00868 printf(" "); 00869 display_splunk_generic_url(temp_entry->entry_text,2); 00870 } 00871 printf("<br clear='all' />\n"); 00872 00873 found_line=TRUE; 00874 } 00875 } 00876 00877 /* free memory */ 00878 free(entry_host_name); 00879 entry_host_name=NULL; 00880 free(entry_service_desc); 00881 entry_service_desc=NULL; 00882 } 00883 } 00884 00885 free_log_entries(); 00886 00887 printf("</DIV></P>\n"); 00888 00889 if(found_line==FALSE){ 00890 printf("<HR>\n"); 00891 printf("<P><DIV CLASS='errorMessage' style='text-align:center'>No history information was found "); 00892 if(display_type==DISPLAY_HOSTS) 00893 printf("%s",(show_all_hosts==TRUE)?"":"for this host "); 00894 else 00895 printf("for this service "); 00896 printf("in %s log file</DIV></P>",(log_archive==0)?"the current":"this archived"); 00897 } 00898 00899 printf("<HR>\n"); 00900 00901 return; 00902 }