![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /***************************************************************************** 00002 * 00003 * NOTIFICATIONS.C - Icinga Notifications CGI 00004 * 00005 * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org) 00006 * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) 00007 * 00008 * This CGI program will display the notification events for 00009 * a given host or contact or for all contacts/hosts. 00010 * 00011 * License: 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU General Public License version 2 as 00015 * published by the Free Software Foundation. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU General Public License 00023 * along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 *****************************************************************************/ 00026 00027 #include "../include/config.h" 00028 #include "../include/common.h" 00029 00030 #include "../include/getcgi.h" 00031 #include "../include/cgiutils.h" 00032 #include "../include/cgiauth.h" 00033 #include "../include/readlogs.h" 00034 00035 extern char main_config_file[MAX_FILENAME_LENGTH]; 00036 extern char url_html_path[MAX_FILENAME_LENGTH]; 00037 extern char url_images_path[MAX_FILENAME_LENGTH]; 00038 extern char url_docs_path[MAX_FILENAME_LENGTH]; 00039 extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; 00040 extern char url_js_path[MAX_FILENAME_LENGTH]; 00041 00042 extern int log_rotation_method; 00043 00044 extern int embedded; 00045 extern int display_header; 00046 extern int daemon_check; 00047 extern int content_type; 00048 00049 extern logentry *entry_list; 00050 00051 extern char *csv_delimiter; 00052 extern char *csv_data_enclosure; 00053 00054 #define FIND_HOST 1 00055 #define FIND_CONTACT 2 00056 #define FIND_SERVICE 3 00057 00058 authdata current_authdata; 00059 00060 int log_archive=0; 00061 int query_type=FIND_HOST; 00062 int find_all=TRUE; 00063 int notification_options=NOTIFICATION_ALL; 00064 int reverse=FALSE; 00065 int display_type=DISPLAY_HOSTS; 00066 int show_all_hosts=TRUE; 00067 int show_all_hostgroups=TRUE; 00068 int show_all_servicegroups=TRUE; 00069 00070 char log_file_to_use[MAX_FILENAME_LENGTH]; 00071 char *query_contact_name=""; 00072 char *query_host_name=""; 00073 char *query_svc_description=""; 00074 char *host_name=NULL; 00075 char *host_filter=NULL; 00076 char *hostgroup_name=NULL; 00077 char *servicegroup_name=NULL; 00078 char *service_desc=NULL; 00079 char *service_filter=NULL; 00080 00081 int CGI_ID=NOTIFICATIONS_CGI_ID; 00082 00083 void display_notifications(void); 00084 int process_cgivars(void); 00085 00086 int main(void){ 00087 int result=OK; 00088 char temp_buffer[MAX_INPUT_BUFFER]; 00089 char temp_buffer2[MAX_INPUT_BUFFER]; 00090 00091 /* get the arguments passed in the URL */ 00092 process_cgivars(); 00093 00094 /* reset internal variables */ 00095 reset_cgi_vars(); 00096 00097 /* read the CGI configuration file */ 00098 result=read_cgi_config_file(get_cgi_config_location()); 00099 if(result==ERROR){ 00100 document_header(CGI_ID,FALSE); 00101 print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE); 00102 document_footer(CGI_ID); 00103 return ERROR; 00104 } 00105 00106 /* read the main configuration file */ 00107 result=read_main_config_file(main_config_file); 00108 if(result==ERROR){ 00109 document_header(CGI_ID,FALSE); 00110 print_error(main_config_file, ERROR_CGI_MAIN_CFG); 00111 document_footer(CGI_ID); 00112 return ERROR; 00113 } 00114 00115 /* read all object configuration data */ 00116 result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA); 00117 if(result==ERROR){ 00118 document_header(CGI_ID,FALSE); 00119 print_error(NULL, ERROR_CGI_OBJECT_DATA); 00120 document_footer(CGI_ID); 00121 return ERROR; 00122 } 00123 00124 document_header(CGI_ID,TRUE); 00125 00126 /* get authentication information */ 00127 get_authentication_information(¤t_authdata); 00128 00129 /* determine what log file we should use */ 00130 get_log_archive_to_use(log_archive,log_file_to_use,(int)sizeof(log_file_to_use)); 00131 00132 if(display_header==TRUE){ 00133 00134 /* begin top table */ 00135 printf("<table border=0 width=100%%>\n"); 00136 printf("<tr>\n"); 00137 00138 /* left column of top row */ 00139 printf("<td align=left valign=top width=33%%>\n"); 00140 00141 if(query_type==FIND_SERVICE) 00142 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Service Notifications"); 00143 else if(query_type==FIND_HOST){ 00144 if(find_all==TRUE) 00145 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Notifications"); 00146 else 00147 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Host Notifications"); 00148 } 00149 else 00150 snprintf(temp_buffer,sizeof(temp_buffer)-1,"Contact Notifications"); 00151 00152 display_info_table(temp_buffer,FALSE,¤t_authdata, daemon_check); 00153 00154 if(query_type==FIND_HOST || query_type==FIND_SERVICE){ 00155 printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n"); 00156 printf("<TR><TD CLASS='linkBox'>\n"); 00157 if(query_type==FIND_HOST){ 00158 printf("<A HREF='%s?host=%s'>View Status Detail For %s</A><BR>\n",STATUS_CGI,(find_all==TRUE)?"all":url_encode(query_host_name),(find_all==TRUE)?"All Hosts":"This Host"); 00159 printf("<A HREF='%s?host=%s'>View History For %s</A><BR>\n",HISTORY_CGI,(find_all==TRUE)?"all":url_encode(query_host_name),(find_all==TRUE)?"All Hosts":"This Host"); 00160 #ifdef USE_TRENDS 00161 if(find_all==FALSE) 00162 printf("<A HREF='%s?host=%s'>View Trends For This Host</A><BR>\n",TRENDS_CGI,url_encode(query_host_name)); 00163 #endif 00164 } 00165 else if(query_type==FIND_SERVICE){ 00166 printf("<A HREF='%s?host=%s&",HISTORY_CGI,(find_all==TRUE)?"all":url_encode(query_host_name)); 00167 printf("service=%s'>View History For This Service</A><BR>\n",url_encode(query_svc_description)); 00168 #ifdef USE_TRENDS 00169 printf("<A HREF='%s?host=%s&",TRENDS_CGI,(find_all==TRUE)?"all":url_encode(query_host_name)); 00170 printf("service=%s'>View Trends For This Service</A><BR>\n",url_encode(query_svc_description)); 00171 #endif 00172 } 00173 printf("</TD></TR>\n"); 00174 printf("</TABLE>\n"); 00175 } 00176 00177 printf("</td>\n"); 00178 00179 /* middle column of top row */ 00180 printf("<td align=center valign=top width=33%%>\n"); 00181 00182 printf("<DIV ALIGN=CENTER CLASS='dataTitle'>\n"); 00183 if(query_type==FIND_SERVICE) 00184 printf("Service '%s' on Host '%s'",query_svc_description,query_host_name); 00185 else if(query_type==FIND_HOST){ 00186 if(find_all==TRUE) 00187 printf("All Hosts and Services"); 00188 else 00189 printf("Host '%s'",query_host_name); 00190 }else{ 00191 if(find_all==TRUE) 00192 printf("All Contacts"); 00193 else 00194 printf("Contact '%s'",query_contact_name); 00195 } 00196 printf("</DIV>\n"); 00197 printf("<BR>\n"); 00198 00199 if(query_type==FIND_SERVICE){ 00200 snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s?%shost=%s&",NOTIFICATIONS_CGI,(reverse==TRUE)?"oldestfirst&":"",url_encode(query_host_name)); 00201 snprintf(temp_buffer2,sizeof(temp_buffer2)-1,"service=%s&type=%d&",url_encode(query_svc_description),notification_options); 00202 strncat(temp_buffer,temp_buffer2,sizeof(temp_buffer)-strlen(temp_buffer)-1); 00203 } 00204 else 00205 snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s?%s%s=%s&type=%d&",NOTIFICATIONS_CGI,(reverse==TRUE)?"oldestfirst&":"",(query_type==FIND_HOST)?"host":"contact",(query_type==FIND_HOST)?url_encode(query_host_name):url_encode(query_contact_name),notification_options); 00206 00207 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00208 display_nav_table(temp_buffer,log_archive); 00209 00210 printf("</td>\n"); 00211 00212 /* right hand column of top row */ 00213 printf("<td align=right valign=top width=33%%>\n"); 00214 00215 printf("<table border=0 CLASS='optBox'>\n"); 00216 printf("<form method='GET' action='%s'>\n",NOTIFICATIONS_CGI); 00217 if(query_type==FIND_SERVICE){ 00218 printf("<input type='hidden' name='host' value='%s'>\n",escape_string(query_host_name)); 00219 printf("<input type='hidden' name='service' value='%s'>\n",escape_string(query_svc_description)); 00220 }else 00221 printf("<input type='hidden' name='%s' value='%s'>\n",(query_type==FIND_HOST)?"host":"contact",(query_type==FIND_HOST)?escape_string(query_host_name):escape_string(query_contact_name)); 00222 printf("<input type='hidden' name='archive' value='%d'>\n",log_archive); 00223 printf("<tr>\n"); 00224 if(query_type==FIND_SERVICE) 00225 printf("<td align=left colspan=2 CLASS='optBoxItem'>Notification detail level for this service:</td>"); 00226 else 00227 printf("<td align=left colspan=2 CLASS='optBoxItem'>Notification detail level for %s %s%s:</td>",(find_all==TRUE)?"all":"this",(query_type==FIND_HOST)?"host":"contact",(find_all==TRUE)?"s":""); 00228 printf("</tr>\n"); 00229 printf("<tr>\n"); 00230 printf("<td align=left colspan=2 CLASS='optBoxItem'><select name='type'>\n"); 00231 printf("<option value=%d %s>All notifications\n",NOTIFICATION_ALL,(notification_options==NOTIFICATION_ALL)?"selected":""); 00232 if(query_type!=FIND_SERVICE){ 00233 printf("<option value=%d %s>All service notifications\n",NOTIFICATION_SERVICE_ALL,(notification_options==NOTIFICATION_SERVICE_ALL)?"selected":""); 00234 printf("<option value=%d %s>All host notifications\n",NOTIFICATION_HOST_ALL,(notification_options==NOTIFICATION_HOST_ALL)?"selected":""); 00235 } 00236 printf("<option value=%d %s>Service custom\n",NOTIFICATION_SERVICE_CUSTOM,(notification_options==NOTIFICATION_SERVICE_CUSTOM)?"selected":""); 00237 printf("<option value=%d %s>Service acknowledgements\n",NOTIFICATION_SERVICE_ACK,(notification_options==NOTIFICATION_SERVICE_ACK)?"selected":""); 00238 printf("<option value=%d %s>Service warning\n",NOTIFICATION_SERVICE_WARNING,(notification_options==NOTIFICATION_SERVICE_WARNING)?"selected":""); 00239 printf("<option value=%d %s>Service unknown\n",NOTIFICATION_SERVICE_UNKNOWN,(notification_options==NOTIFICATION_SERVICE_UNKNOWN)?"selected":""); 00240 printf("<option value=%d %s>Service critical\n",NOTIFICATION_SERVICE_CRITICAL,(notification_options==NOTIFICATION_SERVICE_CRITICAL)?"selected":""); 00241 printf("<option value=%d %s>Service recovery\n",NOTIFICATION_SERVICE_RECOVERY,(notification_options==NOTIFICATION_SERVICE_RECOVERY)?"selected":""); 00242 printf("<option value=%d %s>Service flapping\n",NOTIFICATION_SERVICE_FLAP,(notification_options==NOTIFICATION_SERVICE_FLAP)?"selected":""); 00243 if(query_type!=FIND_SERVICE){ 00244 printf("<option value=%d %s>Host custom\n",NOTIFICATION_HOST_CUSTOM,(notification_options==NOTIFICATION_HOST_CUSTOM)?"selected":""); 00245 printf("<option value=%d %s>Host acknowledgements\n",NOTIFICATION_HOST_ACK,(notification_options==NOTIFICATION_HOST_ACK)?"selected":""); 00246 printf("<option value=%d %s>Host down\n",NOTIFICATION_HOST_DOWN,(notification_options==NOTIFICATION_HOST_DOWN)?"selected":""); 00247 printf("<option value=%d %s>Host unreachable\n",NOTIFICATION_HOST_UNREACHABLE,(notification_options==NOTIFICATION_HOST_UNREACHABLE)?"selected":""); 00248 printf("<option value=%d %s>Host recovery\n",NOTIFICATION_HOST_RECOVERY,(notification_options==NOTIFICATION_HOST_RECOVERY)?"selected":""); 00249 printf("<option value=%d %s>Host flapping\n",NOTIFICATION_HOST_FLAP,(notification_options==NOTIFICATION_HOST_FLAP)?"selected":""); 00250 } 00251 printf("</select></td>\n"); 00252 printf("</tr>\n"); 00253 printf("<tr>\n"); 00254 printf("<td align=left CLASS='optBoxItem'>Older Entries First:</td>\n"); 00255 printf("<td></td>\n"); 00256 printf("</tr>\n"); 00257 printf("<tr>\n"); 00258 printf("<td align=left valign=bottom CLASS='optBoxItem'><input type='checkbox' name='oldestfirst' %s></td>",(reverse==TRUE)?"checked":""); 00259 printf("<td align=right CLASS='optBoxItem'><input type='submit' value='Update'></td>\n"); 00260 printf("</tr>\n"); 00261 00262 /* display context-sensitive help */ 00263 printf("<tr><td></td><td align=right valign=bottom>\n"); 00264 display_context_help(CONTEXTHELP_NOTIFICATIONS); 00265 printf("</td></tr>\n"); 00266 00267 printf("</form>\n"); 00268 printf("</table>\n"); 00269 00270 printf("</td>\n"); 00271 00272 /* end of top table */ 00273 printf("</tr>\n"); 00274 printf("</table>\n"); 00275 } 00276 00277 /* display notifications */ 00278 display_notifications(); 00279 00280 /* display footer */ 00281 document_footer(CGI_ID); 00282 00283 /* free allocated memory */ 00284 free_memory(); 00285 00286 return OK; 00287 } 00288 00289 int process_cgivars(void){ 00290 char **variables; 00291 int error=FALSE; 00292 int x; 00293 00294 variables=getcgivars(); 00295 00296 for(x=0;variables[x]!=NULL;x++){ 00297 00298 /* do some basic length checking on the variable identifier to prevent buffer overflows */ 00299 if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){ 00300 x++; 00301 continue; 00302 } 00303 00304 /* we found the host argument */ 00305 else if(!strcmp(variables[x],"host")){ 00306 query_type=FIND_HOST; 00307 x++; 00308 if(variables[x]==NULL){ 00309 error=TRUE; 00310 break; 00311 } 00312 00313 if((query_host_name=strdup(variables[x]))==NULL) 00314 query_host_name=""; 00315 strip_html_brackets(query_host_name); 00316 00317 if(!strcmp(query_host_name,"all")) 00318 find_all=TRUE; 00319 else 00320 find_all=FALSE; 00321 } 00322 00323 /* we found the contact argument */ 00324 else if(!strcmp(variables[x],"contact")){ 00325 query_type=FIND_CONTACT; 00326 x++; 00327 if(variables[x]==NULL){ 00328 error=TRUE; 00329 break; 00330 } 00331 00332 if((query_contact_name=strdup(variables[x]))==NULL) 00333 query_contact_name=""; 00334 strip_html_brackets(query_contact_name); 00335 00336 if(!strcmp(query_contact_name,"all")) 00337 find_all=TRUE; 00338 else 00339 find_all=FALSE; 00340 } 00341 00342 /* we found the service argument */ 00343 else if(!strcmp(variables[x],"service")){ 00344 query_type=FIND_SERVICE; 00345 x++; 00346 if(variables[x]==NULL){ 00347 error=TRUE; 00348 break; 00349 } 00350 if((query_svc_description=strdup(variables[x]))==NULL) 00351 query_svc_description=""; 00352 strip_html_brackets(query_svc_description); 00353 } 00354 00355 /* we found the notification type argument */ 00356 else if(!strcmp(variables[x],"type")){ 00357 x++; 00358 if(variables[x]==NULL){ 00359 error=TRUE; 00360 break; 00361 } 00362 00363 notification_options=atoi(variables[x]); 00364 } 00365 00366 /* we found the log archive argument */ 00367 else if(!strcmp(variables[x],"archive")){ 00368 x++; 00369 if(variables[x]==NULL){ 00370 error=TRUE; 00371 break; 00372 } 00373 00374 log_archive=atoi(variables[x]); 00375 if(log_archive<0) 00376 log_archive=0; 00377 } 00378 00379 /* we found the CSV output option */ 00380 else if(!strcmp(variables[x],"csvoutput")){ 00381 display_header=FALSE; 00382 content_type=CSV_CONTENT; 00383 } 00384 00385 /* we found the JSON output option */ 00386 else if(!strcmp(variables[x],"jsonoutput")){ 00387 display_header=FALSE; 00388 content_type=JSON_CONTENT; 00389 } 00390 00391 /* we found the order argument */ 00392 else if(!strcmp(variables[x],"oldestfirst")) 00393 reverse=TRUE; 00394 00395 /* we found the embed option */ 00396 else if(!strcmp(variables[x],"embedded")) 00397 embedded=TRUE; 00398 00399 /* we found the noheader option */ 00400 else if(!strcmp(variables[x],"noheader")) 00401 display_header=FALSE; 00402 00403 /* we found the nodaemoncheck option */ 00404 else if(!strcmp(variables[x],"nodaemoncheck")) 00405 daemon_check=FALSE; 00406 } 00407 00408 /* 00409 * Set some default values if not already set. 00410 * Done here as they won't be set if variable 00411 * not provided via cgi parameters 00412 * Only required for hosts & contacts, not services 00413 * as there is no service_name=all option 00414 */ 00415 if(query_type == FIND_HOST && strlen(query_host_name) == 0) { 00416 query_host_name="all"; 00417 find_all=TRUE; 00418 } 00419 if(query_type == FIND_CONTACT && strlen(query_contact_name) == 0) { 00420 query_contact_name="all"; 00421 find_all=TRUE; 00422 } 00423 00424 /* free memory allocated to the CGI variables */ 00425 free_cgivars(variables); 00426 00427 return error; 00428 } 00429 00430 void display_notifications(void){ 00431 char *temp_buffer; 00432 char date_time[MAX_DATETIME_LENGTH]; 00433 char alert_level[MAX_INPUT_BUFFER]; 00434 char alert_level_class[MAX_INPUT_BUFFER]; 00435 char contact_name[MAX_INPUT_BUFFER]; 00436 char service_name[MAX_INPUT_BUFFER]; 00437 char host_name[MAX_INPUT_BUFFER]; 00438 char method_name[MAX_INPUT_BUFFER]; 00439 char error_text[MAX_INPUT_BUFFER]; 00440 int show_entry, status; 00441 int total_notifications=0; 00442 int notification_detail_type=NOTIFICATION_SERVICE_CRITICAL; 00443 int odd=0; 00444 int json_start=TRUE; 00445 host *temp_host=NULL; 00446 service *temp_service=NULL; 00447 logentry *temp_entry=NULL; 00448 00449 00450 add_log_filter(LOGENTRY_HOST_NOTIFICATION,LOGFILTER_INCLUDE); 00451 add_log_filter(LOGENTRY_SERVICE_NOTIFICATION,LOGFILTER_INCLUDE); 00452 00453 status = get_log_entries(log_file_to_use,NULL,reverse,-1,-1); 00454 00455 free_log_filters(); 00456 00457 if (status==READLOG_ERROR_MEMORY) { 00458 printf("<P><DIV CLASS='warningMessage'>Run out of memory..., showing all I could gather!</DIV></P>"); 00459 } 00460 00461 if (status==READLOG_ERROR_NOFILE) { 00462 snprintf(error_text,sizeof(error_text),"Error: Could not open log file '%s' for reading!",log_file_to_use); 00463 error_text[sizeof(error_text)-1]='\x0'; 00464 print_generic_error_message(error_text,NULL,0); 00465 free_log_entries(); 00466 return; 00467 } 00468 00469 if (status==READLOG_OK) { 00470 if(content_type==JSON_CONTENT) 00471 printf("\"notifications\": [\n"); 00472 else if(content_type==CSV_CONTENT) { 00473 printf("%sHOST%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00474 printf("%sSERVICE%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00475 printf("%sTYPE%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00476 printf("%sTIME%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00477 printf("%sCONTACT%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00478 printf("%sNOTIFICATION_COMMAND%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00479 printf("%sINFORMATION%s\n",csv_data_enclosure,csv_data_enclosure); 00480 } else { 00481 printf("<p>\n"); 00482 printf("<div align='center'>\n"); 00483 00484 printf("<table border=0 CLASS='notifications'>\n"); 00485 00486 /* add export to csv link */ 00487 printf("<TR><TD colspan='7'><DIV class='csv_export_link'><A HREF='%s' target='_blank'>Export to CSV</A></DIV></TD></TR>\n",get_export_csv_link(NOTIFICATIONS_CGI)); 00488 00489 printf("<tr>\n"); 00490 printf("<th CLASS='notifications'>Host</th>\n"); 00491 printf("<th CLASS='notifications'>Service</th>\n"); 00492 printf("<th CLASS='notifications'>Type</th>\n"); 00493 printf("<th CLASS='notifications'>Time</th>\n"); 00494 printf("<th CLASS='notifications'>Contact</th>\n"); 00495 printf("<th CLASS='notifications'>Notification Command</th>\n"); 00496 printf("<th CLASS='notifications'>Information</th>\n"); 00497 printf("</tr>\n"); 00498 } 00499 } 00500 00501 if (status==READLOG_OK) { 00502 00503 /* check all entries */ 00504 for(temp_entry=entry_list;temp_entry!=NULL;temp_entry=temp_entry->next) { 00505 00506 /* get the date/time */ 00507 get_time_string(&temp_entry->timestamp,date_time,(int)sizeof(date_time),SHORT_DATE_TIME); 00508 strip(date_time); 00509 00510 /* get the contact name */ 00511 temp_buffer=(char *)strtok(temp_entry->entry_text,":"); 00512 temp_buffer=(char *)strtok(NULL,";"); 00513 snprintf(contact_name,sizeof(contact_name),"%s",(temp_buffer==NULL)?"":temp_buffer+1); 00514 contact_name[sizeof(contact_name)-1]='\x0'; 00515 00516 /* get the host name */ 00517 temp_buffer=(char *)strtok(NULL,";"); 00518 snprintf(host_name,sizeof(host_name),"%s",(temp_buffer==NULL)?"":temp_buffer); 00519 host_name[sizeof(host_name)-1]='\x0'; 00520 00521 /* get the service name */ 00522 service_name[0]='\x0'; 00523 if(temp_entry->type==LOGENTRY_SERVICE_NOTIFICATION){ 00524 temp_buffer=(char *)strtok(NULL,";"); 00525 snprintf(service_name,sizeof(service_name),"%s",(temp_buffer==NULL)?"":temp_buffer); 00526 service_name[sizeof(service_name)-1]='\x0'; 00527 } 00528 00529 /* get the alert level */ 00530 temp_buffer=(char *)strtok(NULL,";"); 00531 snprintf(alert_level,sizeof(alert_level),"%s",(temp_buffer==NULL)?"":temp_buffer); 00532 alert_level[sizeof(alert_level)-1]='\x0'; 00533 00534 if(temp_entry->type==LOGENTRY_SERVICE_NOTIFICATION){ 00535 00536 if(!strcmp(alert_level,"CRITICAL")){ 00537 notification_detail_type=NOTIFICATION_SERVICE_CRITICAL; 00538 strcpy(alert_level_class,"CRITICAL"); 00539 } 00540 else if(!strcmp(alert_level,"WARNING")){ 00541 notification_detail_type=NOTIFICATION_SERVICE_WARNING; 00542 strcpy(alert_level_class,"WARNING"); 00543 } 00544 else if(!strcmp(alert_level,"RECOVERY") || !strcmp(alert_level,"OK")){ 00545 strcpy(alert_level,"OK"); 00546 notification_detail_type=NOTIFICATION_SERVICE_RECOVERY; 00547 strcpy(alert_level_class,"OK"); 00548 } 00549 else if(strstr(alert_level,"CUSTOM (")){ 00550 notification_detail_type=NOTIFICATION_SERVICE_CUSTOM; 00551 strcpy(alert_level_class,"CUSTOM"); 00552 } 00553 else if(strstr(alert_level,"ACKNOWLEDGEMENT (")){ 00554 notification_detail_type=NOTIFICATION_SERVICE_ACK; 00555 strcpy(alert_level_class,"ACKNOWLEDGEMENT"); 00556 } 00557 else if(strstr(alert_level,"FLAPPINGSTART (")){ 00558 strcpy(alert_level,"FLAPPING START"); 00559 notification_detail_type=NOTIFICATION_SERVICE_FLAP; 00560 strcpy(alert_level_class,"UNKNOWN"); 00561 } 00562 else if(strstr(alert_level,"FLAPPINGSTOP (")){ 00563 strcpy(alert_level,"FLAPPING STOP"); 00564 notification_detail_type=NOTIFICATION_SERVICE_FLAP; 00565 strcpy(alert_level_class,"UNKNOWN"); 00566 } else { 00567 strcpy(alert_level,"UNKNOWN"); 00568 notification_detail_type=NOTIFICATION_SERVICE_UNKNOWN; 00569 strcpy(alert_level_class,"UNKNOWN"); 00570 } 00571 }else{ 00572 00573 if(!strcmp(alert_level,"DOWN")){ 00574 strncpy(alert_level,"HOST DOWN",sizeof(alert_level)); 00575 strcpy(alert_level_class,"HOSTDOWN"); 00576 notification_detail_type=NOTIFICATION_HOST_DOWN; 00577 } 00578 else if(!strcmp(alert_level,"UNREACHABLE")){ 00579 strncpy(alert_level,"HOST UNREACHABLE",sizeof(alert_level)); 00580 strcpy(alert_level_class,"HOSTUNREACHABLE"); 00581 notification_detail_type=NOTIFICATION_HOST_UNREACHABLE; 00582 } 00583 else if(!strcmp(alert_level,"RECOVERY") || !strcmp(alert_level,"UP")){ 00584 strncpy(alert_level,"HOST UP",sizeof(alert_level)); 00585 strcpy(alert_level_class,"HOSTUP"); 00586 notification_detail_type=NOTIFICATION_HOST_RECOVERY; 00587 } 00588 else if(strstr(alert_level,"CUSTOM (")){ 00589 strcpy(alert_level_class,"HOSTCUSTOM"); 00590 notification_detail_type=NOTIFICATION_HOST_CUSTOM; 00591 } 00592 else if(strstr(alert_level,"ACKNOWLEDGEMENT (")){ 00593 strcpy(alert_level_class,"HOSTACKNOWLEDGEMENT"); 00594 notification_detail_type=NOTIFICATION_HOST_ACK; 00595 } 00596 else if(strstr(alert_level,"FLAPPINGSTART (")){ 00597 strcpy(alert_level,"FLAPPING START"); 00598 strcpy(alert_level_class,"UNKNOWN"); 00599 notification_detail_type=NOTIFICATION_HOST_FLAP; 00600 } 00601 else if(strstr(alert_level,"FLAPPINGSTOP (")){ 00602 strcpy(alert_level,"FLAPPING STOP"); 00603 strcpy(alert_level_class,"UNKNOWN"); 00604 notification_detail_type=NOTIFICATION_HOST_FLAP; 00605 } 00606 } 00607 00608 /* get the method name */ 00609 temp_buffer=(char *)strtok(NULL,";"); 00610 snprintf(method_name,sizeof(method_name),"%s",(temp_buffer==NULL)?"":temp_buffer); 00611 method_name[sizeof(method_name)-1]='\x0'; 00612 00613 /* move to the informational message */ 00614 temp_buffer=strtok(NULL,";"); 00615 00616 show_entry=FALSE; 00617 00618 /* if we're searching by contact, filter out unwanted contact */ 00619 if(query_type==FIND_CONTACT){ 00620 if(find_all==TRUE) 00621 show_entry=TRUE; 00622 else if(!strcmp(query_contact_name,contact_name)) 00623 show_entry=TRUE; 00624 } 00625 00626 /* search host */ 00627 else if(query_type==FIND_HOST){ 00628 if(find_all==TRUE) 00629 show_entry=TRUE; 00630 else if(!strcmp(query_host_name,host_name)) 00631 show_entry=TRUE; 00632 } 00633 00634 /* searching service */ 00635 else if(query_type==FIND_SERVICE){ 00636 if(!strcmp(query_host_name,host_name) && !strcmp(query_svc_description,service_name)) 00637 show_entry=TRUE; 00638 } 00639 00640 if(show_entry==TRUE){ 00641 if(notification_options==NOTIFICATION_ALL) 00642 show_entry=TRUE; 00643 else if(notification_options==NOTIFICATION_HOST_ALL && temp_entry->type==LOGENTRY_HOST_NOTIFICATION) 00644 show_entry=TRUE; 00645 else if(notification_options==NOTIFICATION_SERVICE_ALL && temp_entry->type==LOGENTRY_SERVICE_NOTIFICATION) 00646 show_entry=TRUE; 00647 else if(notification_detail_type & notification_options) 00648 show_entry=TRUE; 00649 else 00650 show_entry=FALSE; 00651 } 00652 00653 /* make sure user has authorization to view this notification */ 00654 if(temp_entry->type==LOGENTRY_HOST_NOTIFICATION){ 00655 temp_host=find_host(host_name); 00656 if(is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 00657 show_entry=FALSE; 00658 } else{ 00659 temp_host=find_host(host_name); 00660 temp_service=find_service(host_name,service_name); 00661 if(is_authorized_for_service(temp_service,¤t_authdata)==FALSE) 00662 show_entry=FALSE; 00663 } 00664 00665 if(show_entry==TRUE){ 00666 00667 total_notifications++; 00668 00669 if(odd) 00670 odd=0; 00671 else 00672 odd=1; 00673 00674 if(content_type==JSON_CONTENT) { 00675 if (json_start==FALSE) 00676 printf(",\n"); 00677 printf("{\"host\": \"%s\", ",(temp_host->display_name!=NULL)?json_encode(temp_host->display_name):json_encode(temp_host->name)); 00678 if(temp_entry->type==LOGENTRY_SERVICE_NOTIFICATION) 00679 printf("\"service\": \"%s\", ",(temp_service->display_name!=NULL)?json_encode(temp_service->display_name):json_encode(temp_service->description)); 00680 else 00681 printf("\"service\": null, "); 00682 printf("\"type\": \"%s\", ",alert_level); 00683 printf("\"time\": \"%s\", ",date_time); 00684 printf("\"contact\": \"%s\", ",json_encode(contact_name)); 00685 printf("\"notification_command\": \"%s\", ",json_encode(method_name)); 00686 printf("\"information\": \"%s\"}",json_encode(escape_newlines(temp_buffer))); 00687 } else if(content_type==CSV_CONTENT) { 00688 printf("%s%s%s%s",csv_data_enclosure,(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name,csv_data_enclosure,csv_delimiter); 00689 if(temp_entry->type==LOGENTRY_SERVICE_NOTIFICATION) 00690 printf("%s%s%s%s",csv_data_enclosure,(temp_service->display_name!=NULL)?temp_service->display_name:temp_service->description,csv_data_enclosure,csv_delimiter); 00691 else 00692 printf("%sN/A%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00693 printf("%s%s%s%s",csv_data_enclosure,alert_level,csv_data_enclosure,csv_delimiter); 00694 printf("%s%s%s%s",csv_data_enclosure,date_time,csv_data_enclosure,csv_delimiter); 00695 printf("%s%s%s%s",csv_data_enclosure,contact_name,csv_data_enclosure,csv_delimiter); 00696 printf("%s%s%s%s",csv_data_enclosure,method_name,csv_data_enclosure,csv_delimiter); 00697 printf("%s%s%s\n",csv_data_enclosure,escape_newlines(temp_buffer),csv_data_enclosure); 00698 } else { 00699 printf("<tr CLASS='notifications%s'>\n",(odd)?"Even":"Odd"); 00700 printf("<td CLASS='notifications%s'><a href='%s?type=%d&host=%s'>%s</a></td>\n",(odd)?"Even":"Odd",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(host_name),(temp_host->display_name!=NULL)?temp_host->display_name:temp_host->name); 00701 if(temp_entry->type==LOGENTRY_SERVICE_NOTIFICATION){ 00702 printf("<td CLASS='notifications%s'><a href='%s?type=%d&host=%s",(odd)?"Even":"Odd",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(host_name)); 00703 printf("&service=%s'>%s</a></td>\n",url_encode(service_name),(temp_service->display_name!=NULL)?temp_service->display_name:temp_service->description); 00704 } else 00705 printf("<td CLASS='notifications%s'>N/A</td>\n",(odd)?"Even":"Odd"); 00706 printf("<td CLASS='notifications%s'>%s</td>\n",alert_level_class,alert_level); 00707 printf("<td CLASS='notifications%s'>%s</td>\n",(odd)?"Even":"Odd",date_time); 00708 printf("<td CLASS='notifications%s'><a href='%s?type=contacts#%s'>%s</a></td>\n",(odd)?"Even":"Odd",CONFIG_CGI,url_encode(contact_name),contact_name); 00709 printf("<td CLASS='notifications%s'><a href='%s?type=commands#%s'>%s</a></td>\n",(odd)?"Even":"Odd",CONFIG_CGI,url_encode(method_name),method_name); 00710 printf("<td CLASS='notifications%s'>%s</td>\n",(odd)?"Even":"Odd",html_encode(temp_buffer,FALSE)); 00711 printf("</tr>\n"); 00712 } 00713 if (json_start==TRUE) 00714 json_start=FALSE; 00715 } 00716 } 00717 } 00718 00719 free_log_entries(); 00720 00721 if(content_type!=CSV_CONTENT && content_type!=JSON_CONTENT){ 00722 printf("</table>\n"); 00723 00724 printf("</div>\n"); 00725 printf("</p>\n"); 00726 00727 if(total_notifications==0){ 00728 printf("<P><DIV CLASS='errorMessage' style='text-align:center;'>No notifications have been recorded"); 00729 if(find_all==FALSE){ 00730 if(query_type==FIND_SERVICE) 00731 printf(" for this service"); 00732 else if(query_type==FIND_CONTACT) 00733 printf(" for this contact"); 00734 else 00735 printf(" for this host"); 00736 } 00737 printf(" in %s log file</DIV></P>",(log_archive==0)?"the current":"this archived"); 00738 } else 00739 printf("<DIV align=center>%d Notification%s</DIV>",total_notifications,(total_notifications==1)?"":"s"); 00740 }else if (content_type==JSON_CONTENT){ 00741 printf("\n]\n"); 00742 } 00743 00744 return; 00745 }