/* shows all hosts that are causing network outages */ void display_network_outages(void) { int number_of_problem_hosts = 0; int number_of_blocking_problem_hosts = 0; hostoutagesort *temp_hostoutagesort; hostoutage *temp_hostoutage; hoststatus *temp_hoststatus; affected_host * temp_affected_host; int odd = 0; char *bg_class = ""; char *status = ""; int days; int hours; int minutes; int seconds; int total_comments; time_t t; time_t current_time; char state_duration[48]; int total_entries = 0; int json_start = TRUE; /* find all hosts that are causing network outages */ find_hosts_causing_outages(); /* calculate outage effects */ calculate_outage_effects(); /* sort the outage list by severity */ sort_hostoutages(); /* count the number of top-level hosts that are down and the ones that are actually blocking children hosts */ for (temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) { number_of_problem_hosts++; if (temp_hostoutage->affected_child_hosts > 1) number_of_blocking_problem_hosts++; } if (content_type == JSON_CONTENT) { printf("\"outages\": [\n"); } else if (content_type == CSV_CONTENT) { printf("%sSEVERITY%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter); printf("%sHOST%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter); printf("%sSTATE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter); printf("%sNOTES%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter); printf("%sSTATE_DURATION%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter); printf("%sHOSTS_AFFECTED%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter); printf("%sSERVICES_AFFECTED%s\n", csv_data_enclosure, csv_data_enclosure); } else { /* display the problem hosts... */ printf("<table border='0' cellspacing='0' cellpadding='0' align='center'><tr><td width='33%%'></td><td width='33%%'><div class='dataTitle'>Blocking Outages</div><td width='33%%'>"); /* add export to csv link */ printf("<div style='padding-right:6px;' class='csv_export_link'>"); print_export_link(CSV_CONTENT, OUTAGES_CGI, NULL); print_export_link(JSON_CONTENT, OUTAGES_CGI, NULL); print_export_link(HTML_CONTENT, OUTAGES_CGI, NULL); printf("</div></td></tr></table>\n"); printf("<table border='0' class='data'>\n"); printf("<tr>\n"); 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"); printf("</tr>\n"); } for (temp_hostoutagesort = hostoutagesort_list; temp_hostoutagesort != NULL; temp_hostoutagesort = temp_hostoutagesort->next) { temp_hostoutage = temp_hostoutagesort->outage; if (temp_hostoutage == NULL) continue; /* skip hosts that are not blocking anyone */ if (temp_hostoutage->affected_child_hosts <= 1) continue; temp_hoststatus = find_hoststatus(temp_hostoutage->hst->name); if (temp_hoststatus == NULL) continue; /* make sure we only caught valid state types */ if (temp_hoststatus->status != HOST_DOWN && temp_hoststatus->status != HOST_UNREACHABLE) continue; total_entries++; if (odd == 0) { odd = 1; bg_class = "dataOdd"; } else { odd = 0; bg_class = "dataEven"; } if (temp_hoststatus->status == HOST_UNREACHABLE) status = "UNREACHABLE"; else if (temp_hoststatus->status == HOST_DOWN) status = "DOWN"; if (content_type == JSON_CONTENT) { // always add a comma, except for the first line if (json_start == FALSE) printf(",\n"); json_start = FALSE; printf("{ \"severity\": %d, ", temp_hostoutage->severity); printf(" \"host_name\": \"%s\", ", json_encode(temp_hostoutage->hst->name)); printf(" \"host_display_name\": \"%s\", ", (temp_hostoutage->hst->display_name != NULL) ? json_encode(temp_hostoutage->hst->display_name) : json_encode(temp_hostoutage->hst->name)); printf(" \"state\": \"%s\", ", status); } else if (content_type == CSV_CONTENT) { printf("%s%d%s%s", csv_data_enclosure, temp_hostoutage->severity, csv_data_enclosure, csv_delimiter); printf("%s%s%s%s", csv_data_enclosure, temp_hostoutage->hst->name, csv_data_enclosure, csv_delimiter); printf("%s%s%s%s", csv_data_enclosure, status, csv_data_enclosure, csv_delimiter); } else { printf("<tr class='%s'>\n", bg_class); printf("<td class='%s'>%d</td>\n", bg_class, temp_hostoutage->severity); 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); printf("<td class='host%s'>%s</td>\n", status, status); } total_comments = number_of_host_comments(temp_hostoutage->hst->name); if (content_type == JSON_CONTENT) { printf(" \"notes\": %d, ", total_comments); } else if (content_type == CSV_CONTENT) { printf("%s%d%s%s", csv_data_enclosure, total_comments, csv_data_enclosure, csv_delimiter); } else { if (total_comments > 0) print_comment_icon(temp_hostoutage->hst->name, NULL); else printf("<td class='%s'>N/A</td>\n", bg_class); } current_time = time(NULL); if (temp_hoststatus->last_state_change == (time_t)0) t = current_time - program_start; else t = current_time - temp_hoststatus->last_state_change; get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : ""); state_duration[sizeof(state_duration)-1] = '\x0'; if (content_type == JSON_CONTENT) { printf(" \"state_duration\": \"%s\", ", state_duration); printf(" \"hosts_affected\": %d, ", temp_hostoutage->affected_child_hosts); printf(" \"services_affected\": %d }\n", temp_hostoutage->affected_child_services); } else if (content_type == CSV_CONTENT) { printf("%s%s%s%s", csv_data_enclosure, state_duration, csv_data_enclosure, csv_delimiter); printf("%s%d%s%s", csv_data_enclosure, temp_hostoutage->affected_child_hosts, csv_data_enclosure, csv_delimiter); printf("%s%d%s\n", csv_data_enclosure, temp_hostoutage->affected_child_services, csv_data_enclosure); } else { printf("<td class='%s'>%s</td>\n", bg_class, state_duration); printf("<td class='%s'>%d</td>\n", bg_class, temp_hostoutage->affected_child_hosts); printf("<td class='%s'>%d</td>\n", bg_class, temp_hostoutage->affected_child_services); printf("<td class='%s'>", bg_class); 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); #ifdef USE_STATUSMAP 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); #endif #ifdef USE_TRENDS 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); #endif 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); 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); /* add Link to acknowledge all affected hosts */ printf("<a href='%s?cmd_typ=%d&host=%s", CMD_CGI, CMD_ACKNOWLEDGE_HOST_PROBLEM, url_encode(temp_hostoutage->hst->name)); for (temp_affected_host = temp_hostoutage->affected_hosts; temp_affected_host != NULL; temp_affected_host = temp_affected_host->next) printf("&host=%s", url_encode(temp_affected_host->host_name)); printf("'><img src='%s%s' border='0' alt='Acknowledge All Affected Hosts' title='Acknowledge All Affected Hosts'></a>\n", url_images_path, ACKNOWLEDGEMENT_ICON); printf("</td>\n"); printf("</tr>\n"); } } if (content_type != CSV_CONTENT && content_type != JSON_CONTENT) { printf("</table>\n"); if (total_entries == 0) printf("<div class='itemTotalsTitle'>%d Blocking Outages Displayed</div>\n", total_entries); } else if (content_type == JSON_CONTENT) { printf("\n]\n"); } /* free memory allocated to the host outage list */ free_hostoutage_list(); free_hostoutagesort_list(); return; }
/* shows all hosts that are causing network outages */ void display_network_outages(void) { char temp_buffer[MAX_INPUT_BUFFER]; int number_of_problem_hosts = 0; int number_of_blocking_problem_hosts = 0; hostoutagesort *temp_hostoutagesort; hostoutage *temp_hostoutage; hoststatus *temp_hoststatus; int odd = 0; const char *bg_class = ""; const char *status = ""; int days; int hours; int minutes; int seconds; int total_comments; time_t t; time_t current_time; char state_duration[48]; int total_entries = 0; /* user must be authorized for all hosts.. */ /* if(is_authorized_for_all_hosts(¤t_authdata) == FALSE) { printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information you requested...</DIV></P>\n"); printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>"); printf("and check the authorization options in your CGI configuration file.</DIV></P>\n"); return; } */ /* find all hosts that are causing network outages */ find_hosts_causing_outages(); /* calculate outage effects */ calculate_outage_effects(); /* sort the outage list by severity */ sort_hostoutages(); /* count the number of top-level hosts that are down and the ones that are actually blocking children hosts */ for(temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) { number_of_problem_hosts++; if(temp_hostoutage->affected_child_hosts > 1) number_of_blocking_problem_hosts++; } /* display the problem hosts... */ printf("<P><DIV ALIGN=CENTER>\n"); printf("<DIV CLASS='dataTitle'>Blocking Outages</DIV>\n"); printf("<TABLE BORDER=0 CLASS='data'>\n"); printf("<TR>\n"); 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"); printf("</TR>\n"); for(temp_hostoutagesort = hostoutagesort_list; temp_hostoutagesort != NULL; temp_hostoutagesort = temp_hostoutagesort->next) { temp_hostoutage = temp_hostoutagesort->outage; if(temp_hostoutage == NULL) continue; /* skip hosts that are not blocking anyone */ if(temp_hostoutage->affected_child_hosts <= 1) continue; temp_hoststatus = find_hoststatus(temp_hostoutage->hst->name); if(temp_hoststatus == NULL) continue; /* make sure we only caught valid state types */ if(temp_hoststatus->status != SD_HOST_DOWN && temp_hoststatus->status != SD_HOST_UNREACHABLE) continue; total_entries++; if(odd == 0) { odd = 1; bg_class = "dataOdd"; } else { odd = 0; bg_class = "dataEven"; } if(temp_hoststatus->status == SD_HOST_UNREACHABLE) status = "UNREACHABLE"; else if(temp_hoststatus->status == SD_HOST_DOWN) status = "DOWN"; printf("<TR CLASS='%s'>\n", bg_class); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->severity); 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->name); printf("<TD CLASS='host%s'>%s</TD>\n", status, status); total_comments = number_of_host_comments(temp_hostoutage->hst->name); if(total_comments > 0) { snprintf(temp_buffer, sizeof(temp_buffer) - 1, "This host has %d comment%s associated with it", total_comments, (total_comments == 1) ? "" : "s"); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; 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); } else printf("<TD CLASS='%s'>N/A</TD>\n", bg_class); current_time = time(NULL); if(temp_hoststatus->last_state_change == (time_t)0) t = current_time - program_start; else t = current_time - temp_hoststatus->last_state_change; get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : ""); state_duration[sizeof(state_duration) - 1] = '\x0'; printf("<TD CLASS='%s'>%s</TD>\n", bg_class, state_duration); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->affected_child_hosts); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->affected_child_services); printf("<TD CLASS='%s'>", bg_class); 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); #ifdef USE_STATUSMAP 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); #endif #ifdef USE_STATUSWRL 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", STATUSWORLD_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, STATUSWORLD_ICON); #endif #ifdef USE_TRENDS 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); #endif 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); 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); printf("</TD>\n"); printf("</TR>\n"); } printf("</TABLE>\n"); printf("</DIV></P>\n"); if(total_entries == 0) printf("<DIV CLASS='itemTotalsTitle'>%d Blocking Outages Displayed</DIV>\n", total_entries); /* free memory allocated to the host outage list */ free_hostoutage_list(); free_hostoutagesort_list(); return; }
/* shows all hosts that are causing network outages */ void display_network_outages(void) { int number_of_problem_hosts = 0; int number_of_blocking_problem_hosts = 0; hostoutagesort *temp_hostoutagesort; hostoutage *temp_hostoutage; hoststatus *temp_hoststatus; affected_host * temp_affected_host; int odd = 0; char *bg_class = ""; char *status = ""; int days; int hours; int minutes; int seconds; int total_comments; time_t t; time_t current_time; char state_duration[48]; int total_entries = 0; int json_start = TRUE; /* find all hosts that are causing network outages */ find_hosts_causing_outages(); /* calculate outage effects */ calculate_outage_effects(); /* sort the outage list by severity */ sort_hostoutages(); /* count the number of top-level hosts that are down and the ones that are actually blocking children hosts */ for (temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) { number_of_problem_hosts++; if (temp_hostoutage->affected_child_hosts > 1) number_of_blocking_problem_hosts++; } if (content_type == JSON_CONTENT) { printf("\"中断\": [\n"); } else if (content_type == CSV_CONTENT) { printf("%s严重性%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); printf("%s主机%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); printf("%s状态%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); printf("%s备注%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); printf("%s状态持续时间%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); printf("%s受影响的主机%s%s",csv_data_enclosure,csv_data_enclosure,csv_delimiter); printf("%s受影响的服务%s\n",csv_data_enclosure,csv_data_enclosure); } else { /* display the problem hosts... */ printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 align='center'><TR><TD WIDTH='33%%'></TD><TD WIDTH='33%%'><DIV CLASS='dataTitle'>阻塞中断</DIV><TD WIDTH='33%%'>"); /* add export to csv link */ printf("<DIV style='padding-right:6px;' class='csv_export_link'>"); print_export_link(CSV_CONTENT, OUTAGES_CGI, NULL); print_export_link(JSON_CONTENT, OUTAGES_CGI, NULL); print_export_link(HTML_CONTENT, OUTAGES_CGI, NULL); printf("</DIV></TD></TR></TABLE>\n"); printf("<TABLE BORDER=0 CLASS='data'>\n"); printf("<TR>\n"); printf("<TH CLASS='data'>严重性</TH><TH CLASS='data'>主机</TH><TH CLASS='data'>状态</TH><TH CLASS='data'>备注</TH><TH CLASS='data'>状态持续时间</TH><TH CLASS='data'># 受影响的主机</TH><TH CLASS='data'># 受影响的服务</TH><TH CLASS='data'>动作</TH>\n"); printf("</TR>\n"); } for (temp_hostoutagesort = hostoutagesort_list; temp_hostoutagesort != NULL; temp_hostoutagesort = temp_hostoutagesort->next) { temp_hostoutage = temp_hostoutagesort->outage; if (temp_hostoutage == NULL) continue; /* skip hosts that are not blocking anyone */ if (temp_hostoutage->affected_child_hosts <= 1) continue; temp_hoststatus = find_hoststatus(temp_hostoutage->hst->name); if (temp_hoststatus == NULL) continue; /* make sure we only caught valid state types */ if (temp_hoststatus->status != HOST_DOWN && temp_hoststatus->status != HOST_UNREACHABLE) continue; total_entries++; if (odd == 0) { odd = 1; bg_class = "dataOdd"; } else { odd = 0; bg_class = "dataEven"; } if (temp_hoststatus->status == HOST_UNREACHABLE) status = "不可达"; else if (temp_hoststatus->status == HOST_DOWN) status = "宕机"; if (content_type == JSON_CONTENT) { // always add a comma, except for the first line if (json_start == FALSE) printf(",\n"); json_start = FALSE; printf("{ \"严重性\": %d, ", temp_hostoutage->severity); printf(" \"主机名称\": \"%s\", ", json_encode(temp_hostoutage->hst->name)); printf(" \"主机显示名称\": \"%s\", ", (temp_hostoutage->hst->display_name != NULL) ? json_encode(temp_hostoutage->hst->display_name) : json_encode(temp_hostoutage->hst->name)); printf(" \"状态\": \"%s\", ", status); } else if (content_type == CSV_CONTENT) { printf("%s%d%s%s", csv_data_enclosure, temp_hostoutage->severity, csv_data_enclosure, csv_delimiter); printf("%s%s%s%s", csv_data_enclosure, temp_hostoutage->hst->name, csv_data_enclosure, csv_delimiter); printf("%s%s%s%s", csv_data_enclosure, status, csv_data_enclosure, csv_delimiter); } else { printf("<TR CLASS='%s'>\n", bg_class); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->severity); 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); printf("<TD CLASS='host%s'>%s</TD>\n", status, status); } total_comments = number_of_host_comments(temp_hostoutage->hst->name); if (content_type == JSON_CONTENT) { printf(" \"备注\": %d, ", total_comments); } else if (content_type == CSV_CONTENT) { printf("%s%d%s%s", csv_data_enclosure, total_comments, csv_data_enclosure, csv_delimiter); } else { if (total_comments > 0) print_comment_icon(temp_hostoutage->hst->name, NULL); else printf("<TD CLASS='%s'>无</TD>\n", bg_class); } current_time = time(NULL); if (temp_hoststatus->last_state_change == (time_t)0) t = current_time - program_start; else t = current_time - temp_hoststatus->last_state_change; get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); snprintf(state_duration, sizeof(state_duration) - 1, "%2d日 %2d时 %2d分 %2d秒%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : ""); state_duration[sizeof(state_duration)-1] = '\x0'; if (content_type == JSON_CONTENT) { printf(" \"状态持续时间\": \"%s\", ", state_duration); printf(" \"受影响的主机\": %d, ", temp_hostoutage->affected_child_hosts); printf(" \"受影响的服务\": %d }\n", temp_hostoutage->affected_child_services); } else if (content_type == CSV_CONTENT) { printf("%s%s%s%s", csv_data_enclosure, state_duration, csv_data_enclosure, csv_delimiter); printf("%s%d%s%s", csv_data_enclosure, temp_hostoutage->affected_child_hosts, csv_data_enclosure, csv_delimiter); printf("%s%d%s\n", csv_data_enclosure, temp_hostoutage->affected_child_services, csv_data_enclosure); } else { printf("<TD CLASS='%s'>%s</TD>\n", bg_class, state_duration); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->affected_child_hosts); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->affected_child_services); printf("<TD CLASS='%s'>", bg_class); printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机的状态详情' TITLE='查看该主机的状态详情'></A>\n", STATUS_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, STATUS_DETAIL_ICON); #ifdef USE_STATUSMAP printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机以及子主机的状态图' TITLE='查看该主机以及子主机的状态图'></A>\n", STATUSMAP_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, STATUSMAP_ICON); #endif #ifdef USE_TRENDS printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机趋势' TITLE='查看该主机趋势'></A>\n", TRENDS_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, TRENDS_ICON); #endif printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机的警告历史' TITLE='查看该主机的警告历史'></A>\n", HISTORY_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, HISTORY_ICON); printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机的通知' TITLE='查看该主机的通知'></A>\n", NOTIFICATIONS_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, NOTIFICATION_ICON); /* add Link to acknowledge all affected hosts */ printf("<a href='%s?cmd_typ=%d&host=%s", CMD_CGI, CMD_ACKNOWLEDGE_HOST_PROBLEM, url_encode(temp_hostoutage->hst->name)); for (temp_affected_host = temp_hostoutage->affected_hosts; temp_affected_host != NULL; temp_affected_host = temp_affected_host->next) printf("&host=%s", url_encode(temp_affected_host->host_name)); printf("'><img src='%s%s' border=0 ALT='确认所有受影响的的主机' TITLE='确认所有受影响的的主机'></a>\n", url_images_path, ACKNOWLEDGEMENT_ICON); printf("</TD>\n"); printf("</TR>\n"); } } if (content_type != CSV_CONTENT && content_type != JSON_CONTENT) { printf("</TABLE>\n"); if (total_entries == 0) printf("<DIV CLASS='itemTotalsTitle'>显示%d阻塞中断</DIV>\n", total_entries); } else if (content_type == JSON_CONTENT) { printf("\n]\n"); } /* free memory allocated to the host outage list */ free_hostoutage_list(); free_hostoutagesort_list(); return; }
/* shows all hosts that are causing network outages */ void display_network_outages(void) { char temp_buffer[MAX_INPUT_BUFFER]; int number_of_problem_hosts = 0; int number_of_blocking_problem_hosts = 0; hostoutagesort *temp_hostoutagesort; hostoutage *temp_hostoutage; hoststatus *temp_hoststatus; int odd = 0; const char *bg_class = ""; const char *status = ""; int days; int hours; int minutes; int seconds; int total_comments; time_t t; time_t current_time; char state_duration[48]; int total_entries = 0; /* user must be authorized for all hosts.. */ if(is_authorized_for_all_hosts(¤t_authdata) == FALSE) { printf("<P><DIV CLASS='errorMessage'>看起来像是你没有权限查看您所请求的信息...</DIV></P>\n"); printf("<P><DIV CLASS='errorDescription'>如果你认为这是一个错误,请检查HTTP服务器访问CGI的身份验证要求<br>"); printf("并在你的CGI的配置文件中检查授权选项。</DIV></P>\n"); return; } /* find all hosts that are causing network outages */ find_hosts_causing_outages(); /* calculate outage effects */ calculate_outage_effects(); /* sort the outage list by severity */ sort_hostoutages(); /* count the number of top-level hosts that are down and the ones that are actually blocking children hosts */ for(temp_hostoutage = hostoutage_list; temp_hostoutage != NULL; temp_hostoutage = temp_hostoutage->next) { number_of_problem_hosts++; if(temp_hostoutage->affected_child_hosts > 1) number_of_blocking_problem_hosts++; } /* display the problem hosts... */ printf("<P><DIV ALIGN=CENTER>\n"); printf("<DIV CLASS='dataTitle'>阻塞中断</DIV>\n"); printf("<TABLE BORDER=0 CLASS='data'>\n"); printf("<TR>\n"); printf("<TH CLASS='data'>严重性</TH><TH CLASS='data'>主机</TH><TH CLASS='data'>状态</TH><TH CLASS='data'>备注</TH><TH CLASS='data'>状态持续时间</TH><TH CLASS='data'>#影响的主机</TH><TH CLASS='data'>#影响的服务</TH><TH CLASS='data'>动作</TH>\n"); printf("</TR>\n"); for(temp_hostoutagesort = hostoutagesort_list; temp_hostoutagesort != NULL; temp_hostoutagesort = temp_hostoutagesort->next) { temp_hostoutage = temp_hostoutagesort->outage; if(temp_hostoutage == NULL) continue; /* skip hosts that are not blocking anyone */ if(temp_hostoutage->affected_child_hosts <= 1) continue; temp_hoststatus = find_hoststatus(temp_hostoutage->hst->name); if(temp_hoststatus == NULL) continue; /* make sure we only caught valid state types */ if(temp_hoststatus->status != SD_HOST_DOWN && temp_hoststatus->status != SD_HOST_UNREACHABLE) continue; total_entries++; if(odd == 0) { odd = 1; bg_class = "dataOdd"; } else { odd = 0; bg_class = "dataEven"; } if(temp_hoststatus->status == SD_HOST_UNREACHABLE) status = "UNREACHABLE"; else if(temp_hoststatus->status == SD_HOST_DOWN) status = "DOWN"; printf("<TR CLASS='%s'>\n", bg_class); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->severity); 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->name); printf("<TD CLASS='host%s'>%s</TD>\n", status, status); total_comments = number_of_host_comments(temp_hostoutage->hst->name); if(total_comments > 0) { snprintf(temp_buffer, sizeof(temp_buffer) - 1, "该主机共有%d相关的注释", total_comments); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; 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); } else printf("<TD CLASS='%s'>N/A</TD>\n", bg_class); current_time = time(NULL); if(temp_hoststatus->last_state_change == (time_t)0) t = current_time - program_start; else t = current_time - temp_hoststatus->last_state_change; get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); snprintf(state_duration, sizeof(state_duration) - 1, "%2d日%2d时%2d分%2d秒%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : ""); state_duration[sizeof(state_duration) - 1] = '\x0'; printf("<TD CLASS='%s'>%s</TD>\n", bg_class, state_duration); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->affected_child_hosts); printf("<TD CLASS='%s'>%d</TD>\n", bg_class, temp_hostoutage->affected_child_services); printf("<TD CLASS='%s'>", bg_class); printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机的详细状态' TITLE='查看该主机的详细状态'></A>\n", STATUS_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, STATUS_DETAIL_ICON); #ifdef USE_STATUSMAP printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机以及子节点主机的状态图' TITLE='查看该主机以及子节点主机的状态图'></A>\n", STATUSMAP_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, STATUSMAP_ICON); #endif #ifdef USE_STATUSWRL printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机以及子节点主机的3D状态图' TITLE='查看该主机以及子节点主机的3D状态图'></A>\n", STATUSWORLD_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, STATUSWORLD_ICON); #endif #ifdef USE_TRENDS printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机趋势' TITLE='查看该主机趋势'></A>\n", TRENDS_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, TRENDS_ICON); #endif printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='该主机的警告历史信息' TITLE='该主机的警告历史信息'></A>\n", HISTORY_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, HISTORY_ICON); printf("<A HREF='%s?host=%s'><IMG SRC='%s%s' BORDER=0 ALT='查看该主机的通知' TITLE='查看该主机的通知'></A>\n", NOTIFICATIONS_CGI, url_encode(temp_hostoutage->hst->name), url_images_path, NOTIFICATION_ICON); printf("</TD>\n"); printf("</TR>\n"); } printf("</TABLE>\n"); printf("</DIV></P>\n"); if(total_entries == 0) printf("<DIV CLASS='itemTotalsTitle'>%d 条阻塞中断</DIV>\n", total_entries); /* free memory allocated to the host outage list */ free_hostoutage_list(); free_hostoutagesort_list(); return; }
void test_host_commands(void) { char *host_name = "host1"; host *target_host = NULL; int pre = 0, prev_comment_id = next_comment_id; unsigned int prev_downtime_id; time_t check_time =0; char *cmdstr = NULL; target_host = find_host(host_name); target_host->obsess = FALSE; pre = number_of_host_comments(host_name); ok(CMD_ERROR_OK == process_external_command2(CMD_ADD_HOST_COMMENT, check_time, "host1;0;myself;my comment"), "process_external_command2: ADD_HOST_COMMENT"); ok(pre+1 == number_of_host_comments(host_name), "ADD_HOST_COMMENT (through process_external_command2) adds a host comment"); ++pre; ok(CMD_ERROR_OK == process_external_command1("[1234567890] ADD_HOST_COMMENT;host1;0;myself;my comment"), "core command: ADD_HOST_COMMENT"); ok(pre+1 == number_of_host_comments(host_name), "ADD_HOST_COMMENT adds a host comment"); nm_asprintf(&cmdstr, "[1234567890] DEL_HOST_COMMENT;%i", prev_comment_id); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: DEL_HOST_COMMENT"); free(cmdstr); ok(pre == number_of_host_comments(host_name), "DEL_HOST_COMMENT deletes a host comment"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DELAY_HOST_NOTIFICATION;host1;1927587190"), "core command: DELAY_HOST_NOTIFICATION"); ok(1927587190 == target_host->next_notification, "DELAY_HOST_NOTIFICATION delays host notifications"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_HOST_SVC_CHECKS;host1"), "core command: DISABLE_HOST_SVC_CHECKS"); ok(!target_host->services->service_ptr->checks_enabled, "DISABLE_HOST_SVC_CHECKS disables active checks for services on a host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] ENABLE_HOST_SVC_CHECKS;host1"), "core command: ENABLE_HOST_SVC_CHECKS"); ok(target_host->services->service_ptr->checks_enabled, "ENABLE_HOST_SVC_CHECKS enables active checks for services on a host"); check_time = target_host->services->service_ptr->next_check - 20; nm_asprintf(&cmdstr, "[1234567890] SCHEDULE_HOST_SVC_CHECKS;host1;%llu", (long long unsigned int)check_time); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: SCHEDULE_HOST_SVC_CHECKS"); ok(check_time == target_host->services->service_ptr->next_check, "SCHEDULE_HOST_SVC_CHECKS schedules host service checks"); free(cmdstr); assert(CMD_ERROR_OK == process_external_command1("[1234567890] ADD_HOST_COMMENT;host1;0;myself;comment 1")); assert(CMD_ERROR_OK == process_external_command1("[1234567890] ADD_HOST_COMMENT;host1;1;myself;comment 2")); assert(CMD_ERROR_OK == process_external_command1("[1234567890] ADD_HOST_COMMENT;host1;0;myself;comment 3")); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DEL_ALL_HOST_COMMENTS;host1"), "core command: DEL_ALL_HOST_COMMENTS"); ok(0 == number_of_host_comments(host_name), "DEL_ALL_HOST_COMMENTS deletes all host comments"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_HOST_NOTIFICATIONS;host1"), "core command: DISABLE_HOST_NOTIFICATIONS"); ok(!target_host->notifications_enabled, "DISABLE_HOST_NOTIFICATIONS disables host notifications"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] ENABLE_HOST_NOTIFICATIONS;host1"), "core command: ENABLE_HOST_NOTIFICATIONS"); ok(target_host->notifications_enabled, "ENABLE_HOST_NOTIFICATIONS enables host notifications"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST;host1"), "core command: DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST"); ok(!((find_host("childofhost1"))->notifications_enabled), "DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST disables notifications beyond host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST;host1"), "core command: ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST"); ok(((find_host("childofhost1"))->notifications_enabled), "ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST enables notifications beyond host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_HOST_SVC_NOTIFICATIONS;host1"), "core command: DISABLE_HOST_SVC_NOTIFICATIONS"); ok(!(target_host->services->service_ptr->notifications_enabled), "DISABLE_HOST_SVC_NOTIFICATIONS disables notifications for services on a host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] ENABLE_HOST_SVC_NOTIFICATIONS;host1"), "core command: ENABLE_HOST_SVC_NOTIFICATIONS"); ok(target_host->services->service_ptr->notifications_enabled, "ENABLE_HOST_SVC_NOTIFICATIONS enables notifications for services on a host"); target_host->current_state = STATE_DOWN; ok(CMD_ERROR_OK == process_external_command1("[1234567890] ACKNOWLEDGE_HOST_PROBLEM;host1;2;0;0;myself;my ack comment"), "core command: ACKNOWLEDGE_HOST_PROBLEM"); ok(target_host->problem_has_been_acknowledged, "ACKNOWLEDGE_HOST_PROBLEM acknowledges a host problem"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] REMOVE_HOST_ACKNOWLEDGEMENT;host1"), "core command: REMOVE_HOST_ACKNOWLEDGEMENT"); ok(!target_host->problem_has_been_acknowledged, "REMOVE_HOST_ACKNOWLEDGEMENT removes a host acknowledgement"); target_host->current_state = STATE_UP; ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_HOST_EVENT_HANDLER;host1"), "core command: DISABLE_HOST_EVENT_HANDLER"); ok(!target_host->event_handler_enabled, "DISABLE_HOST_EVENT_HANDLER disables event handler for a host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] ENABLE_HOST_EVENT_HANDLER;host1"), "core command: ENABLE_HOST_EVENT_HANDLER"); ok(target_host->event_handler_enabled, "ENABLE_HOST_EVENT_HANDLER enables event handler for a host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_HOST_CHECK;host1"), "core command: DISABLE_HOST_CHECK"); ok(!target_host->checks_enabled, "DISABLE_HOST_CHECK disables active host checks"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] ENABLE_HOST_CHECK;host1"), "core command: ENABLE_HOST_CHECK"); ok(target_host->checks_enabled, "ENABLE_HOST_CHECK enables active host checks"); check_time = target_host->services->service_ptr->next_check + 2000; nm_asprintf(&cmdstr, "[1234567890] SCHEDULE_FORCED_HOST_SVC_CHECKS;host1;%llu", (unsigned long long int)check_time); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: SCHEDULE_FORCED_HOST_SVC_CHECKS"); ok(check_time == target_host->services->service_ptr->next_check, "SCHEDULE_FORCED_HOST_SVC_CHECKS schedules forced checks for services on a host"); free(cmdstr); prev_downtime_id = next_downtime_id; nm_asprintf(&cmdstr, "[1234567890] SCHEDULE_HOST_DOWNTIME;host1;%llu;%llu;1;0;0;myself;my downtime comment", (unsigned long long int)time(NULL), (unsigned long long int)time(NULL) + 1500); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: SCHEDULE_HOST_DOWNTIME"); ok(prev_downtime_id != next_downtime_id, "SCHEDULE_HOST_DOWNTIME schedules one new downtime"); ok(NULL != find_host_downtime(prev_downtime_id), "SCHEDULE_HOST_DOWNTIME schedules downtime for a host"); free(cmdstr); nm_asprintf(&cmdstr, "[1234567890] DEL_HOST_DOWNTIME;%i", prev_downtime_id); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: DEL_HOST_DOWNTIME"); ok(!find_host_downtime(prev_downtime_id), "DEL_HOST_DOWNTIME deletes a scheduled host downtime"); free(cmdstr); ok(CMD_ERROR_OK == process_external_command1("[1234567890] DISABLE_HOST_FLAP_DETECTION;host1"), "core command: DISABLE_HOST_FLAP_DETECTION"); ok(!target_host->flap_detection_enabled, "DISABLE_HOST_FLAP_DETECTION disables host flap detection"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] ENABLE_HOST_FLAP_DETECTION;host1"), "core command: ENABLE_HOST_FLAP_DETECTION"); ok(target_host->flap_detection_enabled, "ENABLE_HOST_FLAP_DETECTION enables host flap detection"); assert(NULL == find_service_downtime(0)); nm_asprintf(&cmdstr, "[1234567890] SCHEDULE_HOST_SVC_DOWNTIME;host1;%llu;%llu;1;0;0;myself;my downtime comment", (unsigned long long int)time(NULL), (unsigned long long int)time(NULL) + 1500); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: SCHEDULE_HOST_SVC_DOWNTIME"); strcmp(host_name, find_service_downtime(0)->host_name); ok(0 == 0, "SCHEDULE_HOST_SVC_DOWNTIME schedules downtime for services on a host"); free(cmdstr); ok(CMD_ERROR_OK == process_external_command1("[1234567890] PROCESS_HOST_CHECK_RESULT;host1;1;some plugin output"), "core command: PROCESS_HOST_CHECK_RESULT"); ok(target_host->current_state == STATE_DOWN, "PROCESS_HOST_CHECK_RESULT processes host check results"); check_time = target_host->next_check - 20; nm_asprintf(&cmdstr, "[1234567890] SCHEDULE_HOST_CHECK;host1;%llu", (unsigned long long int)check_time); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: SCHEDULE_HOST_CHECK"); ok(check_time == target_host->next_check, "SCHEDULE_HOST_CHECK schedules a host check"); free(cmdstr); nm_asprintf(&cmdstr, "[1234567890] SCHEDULE_HOST_CHECK;host1;%llu", (unsigned long long int)check_time); ok(CMD_ERROR_OK == process_external_command1(cmdstr), "core command: SCHEDULE_FORCED_HOST_CHECK"); ok(check_time == target_host->next_check, "SCHEDULE_FORCED_HOST_CHECK schedules a host check"); free(cmdstr); assert(!(target_host->obsess)); ok(CMD_ERROR_OK == process_external_command1("[1234567890] START_OBSESSING_OVER_HOST;host1"), "core command: START_OBSESSING_OVER_HOST"); ok(target_host->obsess, "START_OBSESSING_OVER_HOST enables OCHP for host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] STOP_OBSESSING_OVER_HOST;host1"), "core command: STOP_OBSESSING_OVER_HOST"); ok(!target_host->obsess, "STOP_OBSESSING_OVER_HOST disables OCHP for host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] CHANGE_NORMAL_HOST_CHECK_INTERVAL;host1;42"), "core command: CHANGE_NORMAL_HOST_CHECK_INTERVAL"); ok(42 == target_host->check_interval, "CHANGE_NORMAL_HOST_CHECK_INTERVAL changes the host check inteval for host"); ok(CMD_ERROR_OK == process_external_command1("[1234567890] CHANGE_MAX_HOST_CHECK_ATTEMPTS;host1;9"), "core command: CHANGE_MAX_HOST_CHECK_ATTEMPTS"); ok(9 == target_host->max_attempts, "CHANGE_MAX_HOST_CHECK_ATTEMPTS changes the maximum number of check attempts for host"); }