![]() |
Icinga-core 1.4.0
next gen monitoring
|
00001 /************************************************************************** 00002 * 00003 * OUTAGES.C - Icinga Network Outages 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 * 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 #include "../include/config.h" 00025 #include "../include/common.h" 00026 #include "../include/objects.h" 00027 #include "../include/comments.h" 00028 #include "../include/statusdata.h" 00029 00030 #include "../include/cgiutils.h" 00031 #include "../include/getcgi.h" 00032 #include "../include/cgiauth.h" 00033 00034 extern time_t program_start; 00035 00036 extern host *host_list; 00037 extern service *service_list; 00038 extern hoststatus *hoststatus_list; 00039 extern servicestatus *servicestatus_list; 00040 00041 extern char main_config_file[MAX_FILENAME_LENGTH]; 00042 extern char url_html_path[MAX_FILENAME_LENGTH]; 00043 extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; 00044 extern char url_js_path[MAX_FILENAME_LENGTH]; 00045 extern char url_images_path[MAX_FILENAME_LENGTH]; 00046 extern char url_logo_images_path[MAX_FILENAME_LENGTH]; 00047 extern char log_file[MAX_FILENAME_LENGTH]; 00048 00049 int display_type=DISPLAY_HOSTS; 00050 int show_all_hosts=TRUE; 00051 int show_all_hostgroups=TRUE; 00052 int show_all_servicegroups=TRUE; 00053 00054 char *host_name=NULL; 00055 char *host_filter=NULL; 00056 char *hostgroup_name=NULL; 00057 char *servicegroup_name=NULL; 00058 char *service_desc=NULL; 00059 char *service_filter=NULL; 00060 00061 /* HOSTOUTAGE structure */ 00062 typedef struct hostoutage_struct{ 00063 host *hst; 00064 int severity; 00065 int affected_child_hosts; 00066 int affected_child_services; 00067 unsigned long monitored_time; 00068 unsigned long time_up; 00069 float percent_time_up; 00070 unsigned long time_down; 00071 float percent_time_down; 00072 unsigned long time_unreachable; 00073 float percent_time_unreachable; 00074 struct hostoutage_struct *next; 00075 }hostoutage; 00076 00077 00078 /* HOSTOUTAGESORT structure */ 00079 typedef struct hostoutagesort_struct{ 00080 hostoutage *outage; 00081 struct hostoutagesort_struct *next; 00082 }hostoutagesort; 00083 00084 int process_cgivars(void); 00085 00086 void display_network_outages(void); 00087 void find_hosts_causing_outages(void); 00088 void calculate_outage_effects(void); 00089 void calculate_outage_effect_of_host(host *,int *,int *); 00090 int is_route_to_host_blocked(host *); 00091 int number_of_host_services(host *); 00092 void add_hostoutage(host *); 00093 void sort_hostoutages(void); 00094 void free_hostoutage_list(void); 00095 void free_hostoutagesort_list(void); 00096 00097 00098 authdata current_authdata; 00099 00100 hostoutage *hostoutage_list=NULL; 00101 hostoutagesort *hostoutagesort_list=NULL; 00102 00103 int service_severity_divisor=4; /* default = services are 1/4 as important as hosts */ 00104 00105 extern int embedded; 00106 extern int refresh; 00107 extern int display_header; 00108 extern int daemon_check; 00109 extern int content_type; 00110 00111 extern char *csv_delimiter; 00112 extern char *csv_data_enclosure; 00113 00114 int CGI_ID=OUTAGES_CGI_ID; 00115 00116 int main(void){ 00117 int result=OK; 00118 00119 00120 /* get the arguments passed in the URL */ 00121 process_cgivars(); 00122 00123 /* reset internal variables */ 00124 reset_cgi_vars(); 00125 00126 /* read the CGI configuration file */ 00127 result=read_cgi_config_file(get_cgi_config_location()); 00128 if(result==ERROR){ 00129 document_header(CGI_ID,FALSE); 00130 print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE); 00131 document_footer(CGI_ID); 00132 return ERROR; 00133 } 00134 00135 /* read the main configuration file */ 00136 result=read_main_config_file(main_config_file); 00137 if(result==ERROR){ 00138 document_header(CGI_ID,FALSE); 00139 print_error(main_config_file, ERROR_CGI_MAIN_CFG); 00140 document_footer(CGI_ID); 00141 return ERROR; 00142 } 00143 00144 /* read all object configuration data */ 00145 result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA); 00146 if(result==ERROR){ 00147 document_header(CGI_ID,FALSE); 00148 print_error(NULL, ERROR_CGI_OBJECT_DATA); 00149 document_footer(CGI_ID); 00150 return ERROR; 00151 } 00152 00153 /* read all status data */ 00154 result=read_all_status_data(get_cgi_config_location(),READ_ALL_STATUS_DATA); 00155 if(result==ERROR && daemon_check==TRUE){ 00156 document_header(CGI_ID,FALSE); 00157 print_error(NULL, ERROR_CGI_STATUS_DATA); 00158 document_footer(CGI_ID); 00159 free_memory(); 00160 return ERROR; 00161 } 00162 00163 document_header(CGI_ID,TRUE); 00164 00165 /* get authentication information */ 00166 get_authentication_information(¤t_authdata); 00167 00168 if(display_header==TRUE){ 00169 00170 /* begin top table */ 00171 printf("<table border=0 width=100%%>\n"); 00172 printf("<tr>\n"); 00173 00174 /* left column of the first row */ 00175 printf("<td align=left valign=top width=33%%>\n"); 00176 display_info_table("Network Outages",TRUE,¤t_authdata, daemon_check); 00177 printf("</td>\n"); 00178 00179 /* middle column of top row */ 00180 printf("<td align=center valign=top width=33%%>\n"); 00181 printf("</td>\n"); 00182 00183 /* right column of top row */ 00184 printf("<td align=right valign=bottom width=33%%>\n"); 00185 00186 /* display context-sensitive help */ 00187 display_context_help(CONTEXTHELP_OUTAGES); 00188 00189 printf("</td>\n"); 00190 00191 /* end of top table */ 00192 printf("</tr>\n"); 00193 printf("</table>\n"); 00194 00195 } 00196 00197 00198 /* display network outage info */ 00199 display_network_outages(); 00200 00201 document_footer(CGI_ID); 00202 00203 /* free memory allocated to comment data */ 00204 free_comment_data(); 00205 00206 /* free all allocated memory */ 00207 free_memory(); 00208 00209 return OK; 00210 } 00211 00212 int process_cgivars(void){ 00213 char **variables; 00214 int error=FALSE; 00215 int x; 00216 00217 variables=getcgivars(); 00218 00219 for(x=0;variables[x]!=NULL;x++){ 00220 00221 /* do some basic length checking on the variable identifier to prevent buffer overflows */ 00222 if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){ 00223 x++; 00224 continue; 00225 } 00226 00227 /* we found the service severity divisor option */ 00228 if(!strcmp(variables[x],"service_divisor")){ 00229 x++; 00230 if(variables[x]==NULL){ 00231 error=TRUE; 00232 break; 00233 } 00234 00235 service_severity_divisor=atoi(variables[x]); 00236 if(service_severity_divisor<1) 00237 service_severity_divisor=1; 00238 } 00239 00240 /* we found the CSV output option */ 00241 else if(!strcmp(variables[x],"csvoutput")){ 00242 display_header=FALSE; 00243 content_type=CSV_CONTENT; 00244 } 00245 00246 else if(!strcmp(variables[x],"jsonoutput")){ 00247 display_header=FALSE; 00248 content_type=JSON_CONTENT; 00249 } 00250 00251 /* we found the embed option */ 00252 else if(!strcmp(variables[x],"embedded")) 00253 embedded=TRUE; 00254 00255 /* we found the noheader option */ 00256 else if(!strcmp(variables[x],"noheader")) 00257 display_header=FALSE; 00258 00259 /* we found the pause option */ 00260 else if(!strcmp(variables[x],"paused")) 00261 refresh=FALSE; 00262 00263 /* we found the nodaemoncheck option */ 00264 else if(!strcmp(variables[x],"nodaemoncheck")) 00265 daemon_check=FALSE; 00266 00267 } 00268 00269 /* free memory allocated to the CGI variables */ 00270 free_cgivars(variables); 00271 00272 return error; 00273 } 00274 00275 /* shows all hosts that are causing network outages */ 00276 void display_network_outages(void){ 00277 char temp_buffer[MAX_INPUT_BUFFER]; 00278 int number_of_problem_hosts=0; 00279 int number_of_blocking_problem_hosts=0; 00280 hostoutagesort *temp_hostoutagesort; 00281 hostoutage *temp_hostoutage; 00282 hoststatus *temp_hoststatus; 00283 int odd=0; 00284 char *bg_class=""; 00285 char *status=""; 00286 int days; 00287 int hours; 00288 int minutes; 00289 int seconds; 00290 int total_comments; 00291 time_t t; 00292 time_t current_time; 00293 char state_duration[48]; 00294 int total_entries=0; 00295 int json_start=TRUE; 00296 00297 /* find all hosts that are causing network outages */ 00298 find_hosts_causing_outages(); 00299 00300 /* calculate outage effects */ 00301 calculate_outage_effects(); 00302 00303 /* sort the outage list by severity */ 00304 sort_hostoutages(); 00305 00306 /* count the number of top-level hosts that are down and the ones that are actually blocking children hosts */ 00307 for(temp_hostoutage=hostoutage_list;temp_hostoutage!=NULL;temp_hostoutage=temp_hostoutage->next){ 00308 number_of_problem_hosts++; 00309 if(temp_hostoutage->affected_child_hosts>1) 00310 number_of_blocking_problem_hosts++; 00311 } 00312 00313 if(content_type==JSON_CONTENT) { 00314 printf("\"outages\": [\n"); 00315 } else if(content_type==CSV_CONTENT) { 00316 printf("%sSEVERITY%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00317 printf("%sHOST%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00318 printf("%sSTATE%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00319 printf("%sNOTES%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00320 printf("%sSTATE_DURATION%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00321 printf("%sHOSTS_AFFECTED%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); 00322 printf("%sSERVICES_AFFECTED%s\n",csv_data_enclosure,csv_data_enclosure); 00323 } else { 00324 /* display the problem hosts... */ 00325 printf("<P><DIV ALIGN=CENTER>\n"); 00326 printf("<DIV CLASS='dataTitle'>Blocking Outages</DIV>\n"); 00327 00328 printf("<TABLE BORDER=0 CLASS='data'>\n"); 00329 00330 /* add export to csv link */ 00331 printf("<TR><TD colspan='8'><DIV class='csv_export_link'><A HREF='%s' target='_blank'>Export to CSV</A></DIV></TD></TR>\n",get_export_csv_link(OUTAGES_CGI)); 00332 00333 printf("<TR>\n"); 00334 printf("<TH CLASS='data'>Severity</TH><TH CLASS='data'>Host</TH><TH CLASS='data'>State</TH><TH CLASS='data'>Notes</TH><TH CLASS='data'>State Duration</TH><TH CLASS='data'># Hosts Affected</TH><TH CLASS='data'># Services Affected</TH><TH CLASS='data'>Actions</TH>\n"); 00335 printf("</TR>\n"); 00336 } 00337 00338 for(temp_hostoutagesort=hostoutagesort_list;temp_hostoutagesort!=NULL;temp_hostoutagesort=temp_hostoutagesort->next){ 00339 00340 temp_hostoutage=temp_hostoutagesort->outage; 00341 if(temp_hostoutage==NULL) 00342 continue; 00343 00344 /* skip hosts that are not blocking anyone */ 00345 if(temp_hostoutage->affected_child_hosts<=1) 00346 continue; 00347 00348 temp_hoststatus=find_hoststatus(temp_hostoutage->hst->name); 00349 if(temp_hoststatus==NULL) 00350 continue; 00351 00352 /* make sure we only caught valid state types */ 00353 if(temp_hoststatus->status!=HOST_DOWN && temp_hoststatus->status!=HOST_UNREACHABLE) 00354 continue; 00355 00356 total_entries++; 00357 00358 if(odd==0){ 00359 odd=1; 00360 bg_class="dataOdd"; 00361 } else { 00362 odd=0; 00363 bg_class="dataEven"; 00364 } 00365 00366 if(temp_hoststatus->status==HOST_UNREACHABLE) 00367 status="UNREACHABLE"; 00368 else if(temp_hoststatus->status==HOST_DOWN) 00369 status="DOWN"; 00370 00371 if(content_type==JSON_CONTENT) { 00372 // always add a comma, except for the first line 00373 if (json_start==FALSE) 00374 printf(",\n"); 00375 json_start=FALSE; 00376 printf("{ \"severity\": %d, ",temp_hostoutage->severity); 00377 printf(" \"host\": \"%s\", ",(temp_hostoutage->hst->display_name!=NULL)?json_encode(temp_hostoutage->hst->display_name):json_encode(temp_hostoutage->hst->name)); 00378 printf(" \"state\": \"%s\", ",status); 00379 } else if(content_type==CSV_CONTENT) { 00380 printf("%s%d%s%s",csv_data_enclosure,temp_hostoutage->severity,csv_data_enclosure,csv_delimiter); 00381 printf("%s%s%s%s",csv_data_enclosure,(temp_hostoutage->hst->display_name!=NULL)?temp_hostoutage->hst->display_name:temp_hostoutage->hst->name,csv_data_enclosure,csv_delimiter); 00382 printf("%s%s%s%s",csv_data_enclosure,status,csv_data_enclosure,csv_delimiter); 00383 } else { 00384 printf("<TR CLASS='%s'>\n",bg_class); 00385 00386 printf("<TD CLASS='%s'>%d</TD>\n",bg_class,temp_hostoutage->severity); 00387 printf("<TD CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></TD>\n",bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_hostoutage->hst->name),(temp_hostoutage->hst->display_name!=NULL)?temp_hostoutage->hst->display_name:temp_hostoutage->hst->name); 00388 printf("<TD CLASS='host%s'>%s</TD>\n",status,status); 00389 } 00390 00391 total_comments=number_of_host_comments(temp_hostoutage->hst->name); 00392 if(content_type==JSON_CONTENT) { 00393 printf(" \"notes\": %d, ",total_comments); 00394 } else if(content_type==CSV_CONTENT) { 00395 printf("%s%d%s%s",csv_data_enclosure,total_comments,csv_data_enclosure,csv_delimiter); 00396 } else { 00397 if(total_comments>0){ 00398 snprintf(temp_buffer,sizeof(temp_buffer)-1,"This host has %d comment%s associated with it",total_comments,(total_comments==1)?"":"s"); 00399 temp_buffer[sizeof(temp_buffer)-1]='\x0'; 00400 printf("<TD CLASS='%s'><A HREF='%s?type=%d&host=%s#comments'><IMG SRC='%s%s' BORDER=0 ALT='%s' TITLE='%s'></A></TD>\n",bg_class,EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(temp_hostoutage->hst->name),url_images_path,COMMENT_ICON,temp_buffer,temp_buffer); 00401 } else 00402 printf("<TD CLASS='%s'>N/A</TD>\n",bg_class); 00403 } 00404 00405 00406 current_time=time(NULL); 00407 if(temp_hoststatus->last_state_change==(time_t)0) 00408 t=current_time-program_start; 00409 else 00410 t=current_time-temp_hoststatus->last_state_change; 00411 get_time_breakdown((unsigned long)t,&days,&hours,&minutes,&seconds); 00412 snprintf(state_duration,sizeof(state_duration)-1,"%2dd %2dh %2dm %2ds%s",days,hours,minutes,seconds,(temp_hoststatus->last_state_change==(time_t)0)?"+":""); 00413 state_duration[sizeof(state_duration)-1]='\x0'; 00414 00415 if(content_type==JSON_CONTENT) { 00416 printf(" \"state_duration\": \"%s\", ",state_duration); 00417 printf(" \"hosts_affected\": %d, ",temp_hostoutage->affected_child_hosts); 00418 printf(" \"services_affected\": %d }\n",temp_hostoutage->affected_child_services); 00419 } else if(content_type==CSV_CONTENT) { 00420 printf("%s%s%s%s",csv_data_enclosure,state_duration,csv_data_enclosure,csv_delimiter); 00421 printf("%s%d%s%s",csv_data_enclosure,temp_hostoutage->affected_child_hosts,csv_data_enclosure,csv_delimiter); 00422 printf("%s%d%s\n",csv_data_enclosure,temp_hostoutage->affected_child_services,csv_data_enclosure); 00423 } else { 00424 printf("<TD CLASS='%s'>%s</TD>\n",bg_class,state_duration); 00425 printf("<TD CLASS='%s'>%d</TD>\n",bg_class,temp_hostoutage->affected_child_hosts); 00426 printf("<TD CLASS='%s'>%d</TD>\n",bg_class,temp_hostoutage->affected_child_services); 00427 00428 printf("<TD CLASS='%s'>",bg_class); 00429 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='View status detail for this host' TITLE='View status detail for this host'></A>\n",STATUS_CGI,url_encode(temp_hostoutage->hst->name),url_images_path,STATUS_DETAIL_ICON); 00430 #ifdef USE_STATUSMAP 00431 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='View status map for this host and its children' TITLE='View status map for this host and its children'></A>\n",STATUSMAP_CGI,url_encode(temp_hostoutage->hst->name),url_images_path,STATUSMAP_ICON); 00432 #endif 00433 #ifdef USE_STATUSWRL 00434 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='View 3-D status map for this host and its children' TITLE='View 3-D status map for this host and its children'></A>\n",STATUSWRL_CGI,url_encode(temp_hostoutage->hst->name),url_images_path,STATUSWORLD_ICON); 00435 #endif 00436 #ifdef USE_TRENDS 00437 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='View trends for this host' TITLE='View trends for this host'></A>\n",TRENDS_CGI,url_encode(temp_hostoutage->hst->name),url_images_path,TRENDS_ICON); 00438 #endif 00439 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='View alert history for this host' TITLE='View alert history for this host'></A>\n",HISTORY_CGI,url_encode(temp_hostoutage->hst->name),url_images_path,HISTORY_ICON); 00440 printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='View notifications for this host' TITLE='View notifications for this host'></A>\n",NOTIFICATIONS_CGI,url_encode(temp_hostoutage->hst->name),url_images_path,NOTIFICATION_ICON); 00441 printf("</TD>\n"); 00442 00443 printf("</TR>\n"); 00444 } 00445 } 00446 00447 if(content_type!=CSV_CONTENT && content_type!=JSON_CONTENT) { 00448 printf("</TABLE>\n"); 00449 00450 printf("</DIV></P>\n"); 00451 00452 if(total_entries==0) 00453 printf("<DIV CLASS='itemTotalsTitle'>%d Blocking Outages Displayed</DIV>\n",total_entries); 00454 }else if (content_type==JSON_CONTENT){ 00455 printf("\n]\n"); 00456 } 00457 00458 /* free memory allocated to the host outage list */ 00459 free_hostoutage_list(); 00460 free_hostoutagesort_list(); 00461 00462 return; 00463 } 00464 00465 /* determine what hosts are causing network outages */ 00466 void find_hosts_causing_outages(void){ 00467 hoststatus *temp_hoststatus; 00468 host *temp_host; 00469 00470 /* check all hosts */ 00471 for(temp_hoststatus=hoststatus_list;temp_hoststatus!=NULL;temp_hoststatus=temp_hoststatus->next){ 00472 00473 /* check only hosts that are not up and not pending */ 00474 if(temp_hoststatus->status!=HOST_UP && temp_hoststatus->status!=HOST_PENDING){ 00475 00476 /* find the host entry */ 00477 temp_host=find_host(temp_hoststatus->host_name); 00478 00479 if(temp_host==NULL) 00480 continue; 00481 00482 if (is_authorized_for_host(temp_host,¤t_authdata)==FALSE) 00483 continue; 00484 00485 /* if the route to this host is not blocked, it is a causing an outage */ 00486 if(is_route_to_host_blocked(temp_host)==FALSE) 00487 add_hostoutage(temp_host); 00488 } 00489 } 00490 00491 return; 00492 } 00493 00494 /* adds a host outage entry */ 00495 void add_hostoutage(host *hst){ 00496 hostoutage *new_hostoutage; 00497 00498 /* allocate memory for a new structure */ 00499 new_hostoutage=(hostoutage *)malloc(sizeof(hostoutage)); 00500 00501 if(new_hostoutage==NULL) 00502 return; 00503 00504 new_hostoutage->hst=hst; 00505 new_hostoutage->severity=0; 00506 new_hostoutage->affected_child_hosts=0; 00507 new_hostoutage->affected_child_services=0; 00508 00509 /* add the structure to the head of the list in memory */ 00510 new_hostoutage->next=hostoutage_list; 00511 hostoutage_list=new_hostoutage; 00512 00513 return; 00514 } 00515 00516 /* frees all memory allocated to the host outage list */ 00517 void free_hostoutage_list(void){ 00518 hostoutage *this_hostoutage; 00519 hostoutage *next_hostoutage; 00520 00521 /* free all list members */ 00522 for(this_hostoutage=hostoutage_list;this_hostoutage!=NULL;this_hostoutage=next_hostoutage){ 00523 next_hostoutage=this_hostoutage->next; 00524 free(this_hostoutage); 00525 } 00526 00527 /* reset list pointer */ 00528 hostoutage_list=NULL; 00529 00530 return; 00531 } 00532 00533 /* frees all memory allocated to the host outage sort list */ 00534 void free_hostoutagesort_list(void){ 00535 hostoutagesort *this_hostoutagesort; 00536 hostoutagesort *next_hostoutagesort; 00537 00538 /* free all list members */ 00539 for(this_hostoutagesort=hostoutagesort_list;this_hostoutagesort!=NULL;this_hostoutagesort=next_hostoutagesort){ 00540 next_hostoutagesort=this_hostoutagesort->next; 00541 free(this_hostoutagesort); 00542 } 00543 00544 /* reset list pointer */ 00545 hostoutagesort_list=NULL; 00546 00547 return; 00548 } 00549 00550 /* calculates network outage effect of all hosts that are causing blockages */ 00551 void calculate_outage_effects(void){ 00552 hostoutage *temp_hostoutage; 00553 00554 /* check all hosts causing problems */ 00555 for(temp_hostoutage=hostoutage_list;temp_hostoutage!=NULL;temp_hostoutage=temp_hostoutage->next){ 00556 00557 /* calculate the outage effect of this particular hosts */ 00558 calculate_outage_effect_of_host(temp_hostoutage->hst,&temp_hostoutage->affected_child_hosts,&temp_hostoutage->affected_child_services); 00559 00560 temp_hostoutage->severity=(temp_hostoutage->affected_child_hosts+(temp_hostoutage->affected_child_services/service_severity_divisor)); 00561 } 00562 00563 return; 00564 } 00565 00566 /* calculates network outage effect of a particular host being down or unreachable */ 00567 void calculate_outage_effect_of_host(host *hst, int *affected_hosts, int *affected_services){ 00568 int total_child_hosts_affected=0; 00569 int total_child_services_affected=0; 00570 int temp_child_hosts_affected=0; 00571 int temp_child_services_affected=0; 00572 host *temp_host; 00573 00574 00575 /* find all child hosts of this host */ 00576 for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){ 00577 00578 /* skip this host if it is not a child */ 00579 if(is_host_immediate_child_of_host(hst,temp_host)==FALSE) 00580 continue; 00581 00582 /* calculate the outage effect of the child */ 00583 calculate_outage_effect_of_host(temp_host,&temp_child_hosts_affected,&temp_child_services_affected); 00584 00585 /* keep a running total of outage effects */ 00586 total_child_hosts_affected+=temp_child_hosts_affected; 00587 total_child_services_affected+=temp_child_services_affected; 00588 } 00589 00590 *affected_hosts=total_child_hosts_affected+1; 00591 *affected_services=total_child_services_affected+number_of_host_services(hst); 00592 00593 return; 00594 } 00595 00596 /* tests whether or not a host is "blocked" by upstream parents (host is already assumed to be down or unreachable) */ 00597 int is_route_to_host_blocked(host *hst){ 00598 hostsmember *temp_hostsmember; 00599 hoststatus *temp_hoststatus; 00600 00601 /* if the host has no parents, it is not being blocked by anyone */ 00602 if(hst->parent_hosts==NULL) 00603 return FALSE; 00604 00605 /* check all parent hosts */ 00606 for(temp_hostsmember=hst->parent_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){ 00607 00608 /* find the parent host's status */ 00609 temp_hoststatus=find_hoststatus(temp_hostsmember->host_name); 00610 00611 if(temp_hoststatus==NULL) 00612 continue; 00613 00614 /* at least one parent it up (or pending), so this host is not blocked */ 00615 if(temp_hoststatus->status==HOST_UP || temp_hoststatus->status==HOST_PENDING) 00616 return FALSE; 00617 } 00618 00619 return TRUE; 00620 } 00621 00622 /* calculates the number of services associated a particular host */ 00623 int number_of_host_services(host *hst){ 00624 int total_services=0; 00625 service *temp_service; 00626 00627 /* check all services */ 00628 for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){ 00629 00630 if(!strcmp(temp_service->host_name,hst->name)) 00631 total_services++; 00632 } 00633 00634 return total_services; 00635 } 00636 00637 /* sort the host outages by severity */ 00638 void sort_hostoutages(void){ 00639 hostoutagesort *last_hostoutagesort; 00640 hostoutagesort *new_hostoutagesort; 00641 hostoutagesort *temp_hostoutagesort; 00642 hostoutage *temp_hostoutage; 00643 00644 if(hostoutage_list==NULL) 00645 return; 00646 00647 /* sort all host outage entries */ 00648 for(temp_hostoutage=hostoutage_list;temp_hostoutage!=NULL;temp_hostoutage=temp_hostoutage->next){ 00649 00650 /* allocate memory for a new sort structure */ 00651 new_hostoutagesort=(hostoutagesort *)malloc(sizeof(hostoutagesort)); 00652 if(new_hostoutagesort==NULL) 00653 return; 00654 00655 new_hostoutagesort->outage=temp_hostoutage; 00656 00657 last_hostoutagesort=hostoutagesort_list; 00658 for(temp_hostoutagesort=hostoutagesort_list;temp_hostoutagesort!=NULL;temp_hostoutagesort=temp_hostoutagesort->next){ 00659 00660 if(new_hostoutagesort->outage->severity >= temp_hostoutagesort->outage->severity){ 00661 new_hostoutagesort->next=temp_hostoutagesort; 00662 if(temp_hostoutagesort==hostoutagesort_list) 00663 hostoutagesort_list=new_hostoutagesort; 00664 else 00665 last_hostoutagesort->next=new_hostoutagesort; 00666 break; 00667 } 00668 else 00669 last_hostoutagesort=temp_hostoutagesort; 00670 } 00671 00672 if(hostoutagesort_list==NULL){ 00673 new_hostoutagesort->next=NULL; 00674 hostoutagesort_list=new_hostoutagesort; 00675 } 00676 else if(temp_hostoutagesort==NULL){ 00677 new_hostoutagesort->next=NULL; 00678 last_hostoutagesort->next=new_hostoutagesort; 00679 } 00680 } 00681 00682 return; 00683 }