Example #1
0
/* 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;
}
Example #2
0
/* 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(&current_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;
	}
Example #3
0
/* 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(&current_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;
	}
Example #4
0
/* 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;
}