Esempio n. 1
0
/* tests whether or not a host is "blocked" by upstream parents (host is already assumed to be down or unreachable) */
int is_route_to_host_blocked(host *hst) {
	hostsmember *temp_hostsmember;
	hoststatus *temp_hoststatus;

	/* if the host has no parents, it is not being blocked by anyone */
	if (hst->parent_hosts == NULL)
		return FALSE;

	/* check all parent hosts */
	for (temp_hostsmember = hst->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {

		/* find the parent host's status */
		temp_hoststatus = find_hoststatus(temp_hostsmember->host_name);

		if (temp_hoststatus == NULL)
			continue;

		/* at least one parent is up (or pending), so this host is not blocked */
		if (temp_hoststatus->status == HOST_UP || temp_hoststatus->status == HOST_PENDING)
			return FALSE;
	}

	return TRUE;
}
Esempio n. 2
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;
}
Esempio n. 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'>看起来像是你没有权限查看您所请求的信息...</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;
	}
Esempio n. 4
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;
	}
Esempio n. 5
0
/* displays hostgroup status summary */
void display_hostgroup_summary(void) {
	hostgroup *temp_hostgroup;
	hostsmember *temp_member;
	host *temp_host;
	hoststatus *temp_hoststatus;
	service *temp_service;
	servicestatus *temp_servicestatus;
	int hosts_unreachable = 0;
	int hosts_down = 0;
	int hosts_up = 0;
	int hosts_pending = 0;
	int services_critical = 0;
	int services_unknown = 0;
	int services_warning = 0;
	int services_ok = 0;
	int services_pending = 0;
	int found = 0;


	/**** MAIN SCREEN (CARD 1) ****/
	printf("<card id='card1' title='Status Summary'>\n");
	printf("<p align='center' mode='nowrap'>\n");

	printf("<b><anchor title='Status Summary'>Status Summary<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='overview'/></go></anchor></b><br/><br/>\n", STATUSWML_CGI, escape_string(hostgroup_name));

	/* check all hostgroups */
	for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {

		if(show_all_hostgroups == FALSE && strcmp(temp_hostgroup->group_name, hostgroup_name))
			continue;

		if(is_authorized_for_hostgroup(temp_hostgroup, &current_authdata) == FALSE)
			continue;

		printf("<b><anchor title='%s'>%s<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='overview'/></go></anchor></b>\n", temp_hostgroup->group_name, temp_hostgroup->alias, STATUSWML_CGI, temp_hostgroup->group_name);

		printf("<table columns='2' align='LL'>\n");

		hosts_up = 0;
		hosts_pending = 0;
		hosts_down = 0;
		hosts_unreachable = 0;

		services_ok = 0;
		services_pending = 0;
		services_warning = 0;
		services_unknown = 0;
		services_critical = 0;

		/* check all hosts in this hostgroup */
		for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {

			temp_host = find_host(temp_member->host_name);
			if(temp_host == NULL)
				continue;

			if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
				continue;

			temp_hoststatus = find_hoststatus(temp_host->name);
			if(temp_hoststatus == NULL)
				continue;

			if(temp_hoststatus->status == HOST_UNREACHABLE)
				hosts_unreachable++;
			else if(temp_hoststatus->status == HOST_DOWN)
				hosts_down++;
			else if(temp_hoststatus->status == HOST_PENDING)
				hosts_pending++;
			else
				hosts_up++;

			/* check all services on this host */
			for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {

				if(strcmp(temp_service->host_name, temp_host->name))
					continue;

				if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
					continue;

				temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description);
				if(temp_servicestatus == NULL)
					continue;

				if(temp_servicestatus->status == SERVICE_CRITICAL)
					services_critical++;
				else if(temp_servicestatus->status == SERVICE_UNKNOWN)
					services_unknown++;
				else if(temp_servicestatus->status == SERVICE_WARNING)
					services_warning++;
				else if(temp_servicestatus->status == SERVICE_PENDING)
					services_pending++;
				else
					services_ok++;
				}
			}

		printf("<tr><td>Hosts:</td><td>");
		found = 0;
		if(hosts_unreachable > 0) {
			printf("%d UNR", hosts_unreachable);
			found = 1;
			}
		if(hosts_down > 0) {
			printf("%s%d DWN", (found == 1) ? ", " : "", hosts_down);
			found = 1;
			}
		if(hosts_pending > 0) {
			printf("%s%d PND", (found == 1) ? ", " : "", hosts_pending);
			found = 1;
			}
		printf("%s%d UP", (found == 1) ? ", " : "", hosts_up);
		printf("</td></tr>\n");
		printf("<tr><td>Services:</td><td>");
		found = 0;
		if(services_critical > 0) {
			printf("%d CRI", services_critical);
			found = 1;
			}
		if(services_warning > 0) {
			printf("%s%d WRN", (found == 1) ? ", " : "", services_warning);
			found = 1;
			}
		if(services_unknown > 0) {
			printf("%s%d UNK", (found == 1) ? ", " : "", services_unknown);
			found = 1;
			}
		if(services_pending > 0) {
			printf("%s%d PND", (found == 1) ? ", " : "", services_pending);
			found = 1;
			}
		printf("%s%d OK", (found == 1) ? ", " : "", services_ok);
		printf("</td></tr>\n");

		printf("</table>\n");

		printf("<br/>\n");
		}

	if(show_all_hostgroups == FALSE)
		printf("<b><anchor title='View All Hostgroups'>View All Hostgroups<go href='%s' method='post'><postfield name='hostgroup' value='all'/><postfield name='style' value='summary'/></go></anchor></b>\n", STATUSWML_CGI);

	printf("</p>\n");

	printf("</card>\n");

	return;
	}
Esempio n. 6
0
/* displays host status */
void display_host(void) {
	host *temp_host;
	hoststatus *temp_hoststatus;
	char last_check[MAX_DATETIME_LENGTH];
	int days;
	int hours;
	int minutes;
	int seconds;
	time_t current_time;
	time_t t;
	char state_duration[48];
	int found;

	/**** MAIN SCREEN (CARD 1) ****/
	printf("<card id='card1' title='Host Status'>\n");
	printf("<p align='center' mode='nowrap'>\n");
	printf("<b>Host '%s'</b><br/>\n", host_name);

	/* find the host */
	temp_host = find_host(host_name);
	temp_hoststatus = find_hoststatus(host_name);
	if(temp_host == NULL || temp_hoststatus == NULL) {

		printf("<b>Error: Could not find host!</b>\n");
		printf("</p>\n");
		printf("</card>\n");
		return;
		}

	/* check authorization */
	if(is_authorized_for_host(temp_host, &current_authdata) == FALSE) {

		printf("<b>Error: Not authorized for host!</b>\n");
		printf("</p>\n");
		printf("</card>\n");
		return;
		}


	printf("<table columns='2' align='LL'>\n");

	printf("<tr><td>Status:</td><td>");
	if(temp_hoststatus->status == HOST_UP)
		printf("UP");
	else if(temp_hoststatus->status == HOST_PENDING)
		printf("PENDING");
	else if(temp_hoststatus->status == HOST_DOWN)
		printf("DOWN");
	else if(temp_hoststatus->status == HOST_UNREACHABLE)
		printf("UNREACHABLE");
	else
		printf("?");
	printf("</td></tr>\n");

	printf("<tr><td>Info:</td><td>%s</td></tr>\n", temp_hoststatus->plugin_output);

	get_time_string(&temp_hoststatus->last_check, last_check, sizeof(last_check) - 1, SHORT_DATE_TIME);
	printf("<tr><td>Last Check:</td><td>%s</td></tr>\n", last_check);

	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) ? "+" : "");
	printf("<tr><td>Duration:</td><td>%s</td></tr>\n", state_duration);

	printf("<tr><td>Properties:</td><td>");
	found = 0;
	if(temp_hoststatus->checks_enabled == FALSE) {
		printf("%sChecks disabled", (found == 1) ? ", " : "");
		found = 1;
		}
	if(temp_hoststatus->notifications_enabled == FALSE) {
		printf("%sNotifications disabled", (found == 1) ? ", " : "");
		found = 1;
		}
	if(temp_hoststatus->problem_has_been_acknowledged == TRUE) {
		printf("%sProblem acknowledged", (found == 1) ? ", " : "");
		found = 1;
		}
	if(temp_hoststatus->scheduled_downtime_depth > 0) {
		printf("%sIn scheduled downtime", (found == 1) ? ", " : "");
		found = 1;
		}
	if(found == 0)
		printf("N/A");
	printf("</td></tr>\n");

	printf("</table>\n");
	printf("<br/>\n");
	printf("<b><anchor title='View Services'>View Services<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='style' value='servicedetail'/></go></anchor></b>\n", STATUSWML_CGI, escape_string(host_name));
	printf("<b><anchor title='Host Commands'>Host Commands<go href='#card2'/></anchor></b>\n");
	printf("</p>\n");

	printf("</card>\n");


	/**** COMMANDS SCREEN (CARD 2) ****/
	printf("<card id='card2' title='Host Commands'>\n");
	printf("<p align='center' mode='nowrap'>\n");
	printf("<b>Host Commands</b><br/>\n");

	printf("<b><anchor title='Ping Host'>Ping Host<go href='%s' method='post'><postfield name='ping' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address);
	printf("<b><anchor title='Traceroute'>Traceroute<go href='%s' method='post'><postfield name='traceroute' value='%s'/></go></anchor></b>\n", STATUSWML_CGI, temp_host->address);

	if(temp_hoststatus->status != HOST_UP && temp_hoststatus->status != HOST_PENDING)
		printf("<b><anchor title='Acknowledge Problem'>Acknowledge Problem<go href='#card3'/></anchor></b>\n");

	if(temp_hoststatus->checks_enabled == FALSE)
		printf("<b><anchor title='Enable Host Checks'>Enable Host Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_CHECK, CMDMODE_COMMIT);
	else
		printf("<b><anchor title='Disable Host Checks'>Disable Host Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_CHECK, CMDMODE_COMMIT);

	if(temp_hoststatus->notifications_enabled == FALSE)
		printf("<b><anchor title='Enable Host Notifications'>Enable Host Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_NOTIFICATIONS, CMDMODE_COMMIT);
	else
		printf("<b><anchor title='Disable Host Notifications'>Disable Host Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_NOTIFICATIONS, CMDMODE_COMMIT);


	printf("<b><anchor title='Enable All Service Checks'>Enable All Service Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_SVC_CHECKS, CMDMODE_COMMIT);

	printf("<b><anchor title='Disable All Service Checks'>Disable All Service Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_SVC_CHECKS, CMDMODE_COMMIT);

	printf("<b><anchor title='Enable All Service Notifications'>Enable All Service Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_SVC_NOTIFICATIONS, CMDMODE_COMMIT);

	printf("<b><anchor title='Disable All Service Notifications'>Disable All Service Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_SVC_NOTIFICATIONS, CMDMODE_COMMIT);

	printf("</p>\n");

	printf("</card>\n");


	/**** ACKNOWLEDGEMENT SCREEN (CARD 3) ****/
	printf("<card id='card3' title='Acknowledge Problem'>\n");
	printf("<p align='center' mode='nowrap'>\n");
	printf("<b>Acknowledge Problem</b><br/>\n");
	printf("</p>\n");

	printf("<p align='center' mode='wrap'>\n");
	printf("<b>Your Name:</b><br/>\n");
	printf("<input name='name' value='%s' /><br/>\n", ((use_ssl_authentication) ? (getenv("SSL_CLIENT_S_DN_CN")) : (getenv("REMOTE_USER"))));
	printf("<b>Comment:</b><br/>\n");
	printf("<input name='comment' value='acknowledged by WAP'/>\n");

	printf("<do type='accept'>\n");
	printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='com_author' value='$(name)'/><postfield name='com_data' value='$(comment)'/><postfield name='persistent' value=''/><postfield name='send_notification' value=''/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go>\n", COMMAND_CGI, escape_string(host_name), CMD_ACKNOWLEDGE_HOST_PROBLEM, CMDMODE_COMMIT);
	printf("</do>\n");

	printf("</p>\n");

	printf("</card>\n");

	return;
	}
Esempio n. 7
0
/* displays hostgroup status overview */
void display_hostgroup_overview(void) {
	hostgroup *temp_hostgroup;
	hostsmember *temp_member;
	host *temp_host;
	hoststatus *temp_hoststatus;


	/**** MAIN SCREEN (CARD 1) ****/
	printf("<card id='card1' title='Status Overview'>\n");
	printf("<p align='center' mode='nowrap'>\n");

	printf("<b><anchor title='Status Overview'>Status Overview<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='summary'/></go></anchor></b><br/><br/>\n", STATUSWML_CGI, escape_string(hostgroup_name));

	/* check all hostgroups */
	for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {

		if(show_all_hostgroups == FALSE && strcmp(temp_hostgroup->group_name, hostgroup_name))
			continue;

		if(is_authorized_for_hostgroup(temp_hostgroup, &current_authdata) == FALSE)
			continue;

		printf("<b>%s</b>\n", temp_hostgroup->alias);

		printf("<table columns='2' align='LL'>\n");

		/* check all hosts in this hostgroup */
		for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {

			temp_host = find_host(temp_member->host_name);
			if(temp_host == NULL)
				continue;

			if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
				continue;

			temp_hoststatus = find_hoststatus(temp_host->name);
			if(temp_hoststatus == NULL)
				continue;

			printf("<tr><td><anchor title='%s'>", temp_host->name);
			if(temp_hoststatus->status == HOST_UP)
				printf("UP");
			else if(temp_hoststatus->status == HOST_PENDING)
				printf("PND");
			else if(temp_hoststatus->status == HOST_DOWN)
				printf("DWN");
			else if(temp_hoststatus->status == HOST_UNREACHABLE)
				printf("UNR");
			else
				printf("???");
			printf("<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></td>", STATUSWML_CGI, temp_host->name);
			printf("<td>%s</td></tr>\n", temp_host->name);
			}

		printf("</table>\n");

		printf("<br/>\n");
		}

	if(show_all_hostgroups == FALSE)
		printf("<b><anchor title='View All Hostgroups'>View All Hostgroups<go href='%s' method='post'><postfield name='hostgroup' value='all'/><postfield name='style' value='overview'/></go></anchor></b>\n", STATUSWML_CGI);

	printf("</p>\n");
	printf("</card>\n");

	return;
	}
Esempio n. 8
0
/* displays quick stats */
void display_quick_stats(void) {
	host *temp_host;
	hoststatus *temp_hoststatus;
	service *temp_service;
	servicestatus *temp_servicestatus;
	int hosts_unreachable = 0;
	int hosts_down = 0;
	int hosts_up = 0;
	int hosts_pending = 0;
	int services_critical = 0;
	int services_unknown = 0;
	int services_warning = 0;
	int services_ok = 0;
	int services_pending = 0;


	/**** MAIN SCREEN (CARD 1) ****/
	printf("<card id='card1' title='Quick Stats'>\n");
	printf("<p align='center' mode='nowrap'>\n");
	printf("<b>Quick Stats</b><br/>\n");
	printf("</p>\n");

	/* check all hosts */
	for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) {

		if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
			continue;

		temp_hoststatus = find_hoststatus(temp_host->name);
		if(temp_hoststatus == NULL)
			continue;

		if(temp_hoststatus->status == HOST_UNREACHABLE)
			hosts_unreachable++;
		else if(temp_hoststatus->status == HOST_DOWN)
			hosts_down++;
		else if(temp_hoststatus->status == HOST_PENDING)
			hosts_pending++;
		else
			hosts_up++;
		}

	/* check all services */
	for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {

		if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
			continue;

		temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description);
		if(temp_servicestatus == NULL)
			continue;

		if(temp_servicestatus->status == SERVICE_CRITICAL)
			services_critical++;
		else if(temp_servicestatus->status == SERVICE_UNKNOWN)
			services_unknown++;
		else if(temp_servicestatus->status == SERVICE_WARNING)
			services_warning++;
		else if(temp_servicestatus->status == SERVICE_PENDING)
			services_pending++;
		else
			services_ok++;
		}

	printf("<p align='left' mode='nowrap'>\n");

	printf("<b>Host Totals</b>:<br/>\n");
	printf("%d UP<br/>\n", hosts_up);
	printf("%d DOWN<br/>\n", hosts_down);
	printf("%d UNREACHABLE<br/>\n", hosts_unreachable);
	printf("%d PENDING<br/>\n", hosts_pending);

	printf("<br/>\n");

	printf("<b>Service Totals:</b><br/>\n");
	printf("%d OK<br/>\n", services_ok);
	printf("%d WARNING<br/>\n", services_warning);
	printf("%d UNKNOWN<br/>\n", services_unknown);
	printf("%d CRITICAL<br/>\n", services_critical);
	printf("%d PENDING<br/>\n", services_pending);

	printf("</p>\n");

	printf("</card>\n");

	return;
	}
Esempio n. 9
0
/* displays problems */
void display_problems(void) {
	host *temp_host;
	service *temp_service;
	hoststatus *temp_hoststatus;
	int total_host_problems = 0;
	servicestatus *temp_servicestatus;
	int total_service_problems = 0;

	/**** MAIN SCREEN (CARD 1) ****/
	printf("<card id='card1' title='%s Problems'>\n", (display_type == DISPLAY_ALL_PROBLEMS) ? "All" : "Unhandled");
	printf("<p align='center' mode='nowrap'>\n");
	printf("<b>%s Problems</b><br/><br/>\n", (display_type == DISPLAY_ALL_PROBLEMS) ? "All" : "Unhandled");

	printf("<b>Host Problems:</b>\n");

	printf("<table columns='2' align='LL'>\n");

	/* check all hosts */
	for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {

		temp_host = find_host(temp_hoststatus->host_name);
		if(temp_host == NULL)
			continue;

		if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
			continue;

		if(temp_hoststatus->status == HOST_UP || temp_hoststatus->status == HOST_PENDING)
			continue;

		if(display_type == DISPLAY_UNHANDLED_PROBLEMS) {
			if(temp_hoststatus->problem_has_been_acknowledged == TRUE)
				continue;
			if(temp_hoststatus->notifications_enabled == FALSE)
				continue;
			if(temp_hoststatus->scheduled_downtime_depth > 0)
				continue;
			}

		total_host_problems++;

		printf("<tr><td><anchor title='%s'>", temp_host->name);
		if(temp_hoststatus->status == HOST_DOWN)
			printf("DWN");
		else if(temp_hoststatus->status == HOST_UNREACHABLE)
			printf("UNR");
		else
			printf("???");
		printf("<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></td>", STATUSWML_CGI, temp_host->name);
		printf("<td>%s</td></tr>\n", temp_host->name);
		}

	if(total_host_problems == 0)
		printf("<tr><td>No problems</td></tr>\n");

	printf("</table>\n");

	printf("<br/>\n");


	printf("<b>Svc Problems:</b>\n");

	printf("<table columns='2' align='LL'>\n");

	/* check all services */
	for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {

		temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
		if(temp_service == NULL)
			continue;

		if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
			continue;

		if(temp_servicestatus->status == SERVICE_OK || temp_servicestatus->status == SERVICE_PENDING)
			continue;

		if(display_type == DISPLAY_UNHANDLED_PROBLEMS) {
			if(temp_servicestatus->problem_has_been_acknowledged == TRUE)
				continue;
			if(temp_servicestatus->notifications_enabled == FALSE)
				continue;
			if(temp_servicestatus->scheduled_downtime_depth > 0)
				continue;
			if((temp_hoststatus = find_hoststatus(temp_service->host_name))) {
				if(temp_hoststatus->scheduled_downtime_depth > 0)
					continue;
				if(temp_hoststatus->problem_has_been_acknowledged == TRUE)
					continue;
				}
			}

		total_service_problems++;

		printf("<tr><td><anchor title='%s'>", temp_servicestatus->description);
		if(temp_servicestatus->status == SERVICE_CRITICAL)
			printf("CRI");
		else if(temp_servicestatus->status == SERVICE_WARNING)
			printf("WRN");
		else if(temp_servicestatus->status == SERVICE_UNKNOWN)
			printf("UNK");
		else
			printf("???");
		printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='service' value='%s'/></go></anchor></td>", STATUSWML_CGI, temp_service->host_name, temp_service->description);
		printf("<td>%s/%s</td></tr>\n", temp_service->host_name, temp_service->description);
		}

	if(total_service_problems == 0)
		printf("<tr><td>No problems</td></tr>\n");

	printf("</table>\n");

	printf("</p>\n");

	printf("</card>\n");

	return;
	}
Esempio n. 10
0
/* draws a host */
void draw_host(host *temp_host) {
	hoststatus *temp_hoststatus = NULL;
	char state_string[16] = "";
	double x, y, z;
	char *vrml_safe_hostname = NULL;
	int a, ch;

	if(temp_host == NULL)
		return;

	/* make sure we have the coordinates */
	if(temp_host->have_3d_coords == FALSE)
		return;
	else {
		x = temp_host->x_3d;
		y = temp_host->y_3d;
		z = temp_host->z_3d;
		}

	/* make the host name safe for embedding in VRML */
	vrml_safe_hostname = (char *)strdup(temp_host->name);
	if(vrml_safe_hostname == NULL)
		return;
	for(a = 0; vrml_safe_hostname[a] != '\x0'; a++) {
		ch = vrml_safe_hostname[a];
		if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9'))
			vrml_safe_hostname[a] = '_';
		}

	/* see if user is authorized to view this host  */
	if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
		return;

	/* get the status of the host */
	temp_hoststatus = find_hoststatus(temp_host->name);

	printf("\n");


	/* host object */
	printf("Anchor{\n");
	printf("children[\n");

	printf("Transform {\n");
	printf("translation %2.2f %2.2f %2.2f\n", x, y, z);
	printf("children [\n");

	printf("DEF Host%s Shape{\n", vrml_safe_hostname);
	printf("appearance Appearance{\n");
	printf("material DEF HostMat%s Material{\n", vrml_safe_hostname);
	if(temp_hoststatus == NULL)
		printf("emissiveColor 0.2 0.2 0.2\ndiffuseColor 0.2 0.2 0.2\n");
	else if(temp_hoststatus->status == SD_HOST_UP)
		printf("emissiveColor 0.2 1.0 0.2\ndiffuseColor 0.2 1.0 0.2\n");
	else
		printf("emissiveColor 1.0 0.2 0.2\ndiffuseColor 1.0 0.2 0.2\n");
	printf("transparency 0.4\n");
	printf("}\n");
	if(use_textures == TRUE && temp_host->vrml_image != NULL) {
		printf("texture ImageTexture{\n");
		printf("url \"%s%s\"\n", url_logo_images_path, temp_host->vrml_image);
		printf("}\n");
		}
	printf("}\n");
	printf("geometry Box{\n");
	printf("size %2.2f %2.2f %2.2f\n", node_width, node_width, node_width);
	printf("}\n");
	printf("}\n");

	printf("]\n");
	printf("}\n");

	printf("]\n");
	printf("description \"View status details for host '%s' (%s)\"\n", temp_host->name, temp_host->alias);
	printf("url \"%s?host=%s\"\n", STATUS_CGI, temp_host->name);
	printf("}\n");


	/* draw status text */
	if(use_text == TRUE) {

		printf("\n");
		printf("Transform{\n");
		printf("translation %2.3f %2.3f %2.3f\n", x, y + DEFAULT_NODE_WIDTH, z);
		printf("children[\n");
		printf("HostText{\n");

		if(temp_hoststatus != NULL) {
			if(temp_hoststatus->status == SD_HOST_UP)
				printf("font_color 0 1 0\n");
			else if(temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE)
				printf("font_color 1 0 0\n");
			}
		printf("the_text [\"%s\", \"%s\", ", temp_host->name, temp_host->alias);
		if(temp_hoststatus == NULL)
			strcpy(state_string, "UNKNOWN");
		else {
			if(temp_hoststatus->status == SD_HOST_DOWN)
				strcpy(state_string, "DOWN");
			else if(temp_hoststatus->status == SD_HOST_UNREACHABLE)
				strcpy(state_string, "UNREACHABLE");
			else if(temp_hoststatus->status == HOST_PENDING)
				strcpy(state_string, "PENDING");
			else
				strcpy(state_string, "UP");
			}
		printf("\"%s\"]\n", state_string);

		printf("}\n");
		printf("]\n");
		printf("}\n");
		}

	/* host is down or unreachable, so make it fade in and out */
	if(temp_hoststatus != NULL && (temp_hoststatus->status == SD_HOST_DOWN || temp_hoststatus->status == SD_HOST_UNREACHABLE))
		printf("ROUTE ProblemTimer.fraction_changed TO HostMat%s.set_transparency\n", vrml_safe_hostname);

	free(vrml_safe_hostname);

	return;
	}
Esempio n. 11
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;
}