示例#1
0
/* determine what hosts are causing network outages */
void find_hosts_causing_outages(void) {
	hoststatus *temp_hoststatus;
	host *temp_host;

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

		/* check only hosts that are not up and not pending */
		if (temp_hoststatus->status != HOST_UP && temp_hoststatus->status != HOST_PENDING) {

			/* find the host entry */
			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 the route to this host is not blocked, it is a causing an outage */
			if (is_route_to_host_blocked(temp_host) == FALSE)
				add_hostoutage(temp_host);
		}
	}

	return;
}
示例#2
0
/* check if user is authorized to view information about all hosts in a particular hostgroup */
int is_authorized_for_hostgroup(hostgroup *hg, authdata *authinfo) {
	hostsmember *temp_hostsmember;
	host *temp_host;

	if(hg == NULL)
		return FALSE;

	/* CHANGED in 2.0 - user must be authorized for ALL hosts in a hostgroup, not just one */
	/* see if user is authorized for all hosts in the hostgroup */
	/*
	for(temp_hostsmember = hg->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
		temp_host = find_host(temp_hostsmember->host_name);
		if(is_authorized_for_host(temp_host, authinfo) == FALSE)
			return FALSE;
		}
	*/
	/* Reverted for 3.3.2 - must only be a member of one hostgroup */
	for(temp_hostsmember = hg->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) {
		temp_host = find_host(temp_hostsmember->host_name);
		if(is_authorized_for_host(temp_host, authinfo) == TRUE)
			return TRUE;
		}

	/*return TRUE;*/
	return FALSE;
	}
示例#3
0
/* draw links between hosts */
void draw_host_links(void) {
	host *parent_host;
	host *child_host;

	if(use_links == FALSE)
		return;

	for(child_host = host_list; child_host != NULL; child_host = child_host->next) {

		if(child_host->have_3d_coords == FALSE)
			continue;

		/* check authorization */
		if(is_authorized_for_host(child_host, &current_authdata) == FALSE)
			continue;

		/* draw a link from this host to all of its parent hosts */
		for(parent_host = host_list; parent_host != NULL; parent_host = parent_host->next) {

			if(is_host_immediate_child_of_host(child_host, parent_host) == TRUE) {

				if(parent_host->have_3d_coords == FALSE)
					continue;

				/* check authorization */
				if(is_authorized_for_host(parent_host, &current_authdata) == FALSE)
					continue;

				/* draw the link between the child and parent hosts */
				draw_host_link(parent_host, parent_host->x_3d, parent_host->y_3d, parent_host->z_3d, child_host->x_3d, child_host->y_3d, child_host->z_3d);
				}
			}
		}


	return;
	}
示例#4
0
/* check if user is authorized to view information about a particular service */
int is_authorized_for_service(service *svc, authdata *authinfo) {
	host *temp_host;
	contact *temp_contact;

	if(svc == NULL)
		return FALSE;

	/* if we're not using authentication, fake it */
	if(use_authentication == FALSE)
		return TRUE;

	/* if this user has not authenticated return error */
	if(authinfo->authenticated == FALSE)
		return FALSE;

	/* if this user is authorized for all services, they are for this one... */
	if(is_authorized_for_all_services(authinfo) == TRUE)
		return TRUE;

	/* find the host */
	temp_host = find_host(svc->host_name);
	if(temp_host == NULL)
		return FALSE;

	/* if this user is authorized for this host, they are for all services on it as well... */
	if(is_authorized_for_host(temp_host, authinfo) == TRUE)
		return TRUE;

	/* find the contact */
	temp_contact = find_contact(authinfo->username);

	/* see if this user is a contact for the service */
	if(is_contact_for_service(svc, temp_contact) == TRUE)
		return TRUE;

	/* see if this user is an escalated contact for the service */
	if(is_escalated_contact_for_service(svc, temp_contact) == TRUE)
		return TRUE;

	return FALSE;
	}
示例#5
0
/* check is the current user is authorized to issue commands relating to a particular host */
int is_authorized_for_host_commands(host *hst, authdata *authinfo) {
	contact *temp_contact;

	if(hst == NULL)
		return FALSE;

	/* if we're not using authentication, fake it */
	if(use_authentication == FALSE)
		return TRUE;

	/* if this user has not authenticated return error */
	if(authinfo->authenticated == FALSE)
		return FALSE;

	/* the user is authorized if they have rights to the host */
	if(is_authorized_for_host(hst, authinfo) == TRUE) {

		/* find the contact */
		temp_contact = find_contact(authinfo->username);

		/* reject if contact is not allowed to issue commands */
		if(temp_contact && temp_contact->can_submit_commands == FALSE)
			return FALSE;

		/* this user is a contact for the host, so they have permission... */
		if(is_contact_for_host(hst, temp_contact) == TRUE)
			return TRUE;

		/* this user is an escalated contact for the host, so they have permission... */
		if(is_escalated_contact_for_host(hst, temp_contact) == TRUE)
			return TRUE;

		/* this user is not a contact for the host, so they must have been given explicit permissions to all host commands */
		if(authinfo->authorized_for_all_host_commands == TRUE)
			return TRUE;
		}

	return FALSE;
	}
示例#6
0
void display_notifications(void) {
	char *temp_buffer;
	char *error_text = NULL;
	char date_time[MAX_DATETIME_LENGTH];
	char alert_level[MAX_INPUT_BUFFER];
	char alert_level_class[MAX_INPUT_BUFFER];
	char contact_name[MAX_INPUT_BUFFER];
	char service_name[MAX_INPUT_BUFFER];
	char host_name[MAX_INPUT_BUFFER];
	char method_name[MAX_INPUT_BUFFER];
	char displayed_host_name[MAX_INPUT_BUFFER];
	char displayed_service_desc[MAX_INPUT_BUFFER];
	int show_entry;
	int total_notifications = 0;
	int displayed_entries = 0;
	int notification_detail_type = NOTIFICATION_SERVICE_CRITICAL;
	int status = READLOG_OK;
	int odd = 0;
	int json_start = TRUE;
	host *temp_host = NULL;
	service *temp_service = NULL;
	hostgroup *temp_hostgroup = NULL;
	servicegroup *temp_servicegroup = NULL;
	logentry *temp_entry = NULL;
	logentry *entry_list = NULL;
	logfilter *filter_list = NULL;

	if (query_type == DISPLAY_HOSTGROUPS) {

		temp_hostgroup = find_hostgroup(query_hostgroup_name);

		if (temp_hostgroup == NULL) {
			print_generic_error_message("There are no host groups with this name defined.", NULL, 0);
			return;
		}
		/* make sure the user is authorized to view this hostgroup */
		if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, &current_authdata) == FALSE) {
			print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
			return;
		}
	}

	if (query_type == DISPLAY_SERVICEGROUPS) {

		temp_servicegroup = find_servicegroup(query_servicegroup_name);

		if (temp_servicegroup == NULL) {
			print_generic_error_message("There are no service groups with this name defined.", NULL, 0);
			return;
		}
		/* make sure the user is authorized to view this servicegroup */
		if (show_partial_servicegroups == FALSE && is_authorized_for_servicegroup(temp_servicegroup, &current_authdata) == FALSE) {
			print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
			return;
		}
	}

	add_log_filter(&filter_list, LOGENTRY_HOST_NOTIFICATION, LOGFILTER_INCLUDE);
	add_log_filter(&filter_list, LOGENTRY_SERVICE_NOTIFICATION, LOGFILTER_INCLUDE);

	/* scan the log file for notification data */
	status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, reverse, ts_start, ts_end);

	free_log_filters(&filter_list);

	/* dealing with errors */
	if (status == READLOG_ERROR_WARNING) {
		if (error_text != NULL) {
			print_generic_error_message(error_text, NULL, 0);
			my_free(error_text);
		} else
			print_generic_error_message("Unkown error!", NULL, 0);
	}

	if (status == READLOG_ERROR_MEMORY)
			print_generic_error_message("Out of memory...", "showing all I could get!", 0);

	if (status == READLOG_ERROR_FATAL) {
		if (error_text != NULL) {
			print_generic_error_message(error_text, NULL, 0);
			my_free(error_text);
		}

		return;

	/* now we start displaying the notification entries */
	} else {
		if (content_type == JSON_CONTENT) {
			if (status != READLOG_OK)
				printf(",\n");
			printf("\"notifications\": [\n");
		} else if (content_type == CSV_CONTENT) {
			printf("%sHOST%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
			printf("%sSERVICE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
			printf("%sTYPE%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
			printf("%sTIME%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
			printf("%sCONTACT%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
			printf("%sNOTIFICATION_COMMAND%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
			printf("%sINFORMATION%s\n", csv_data_enclosure, csv_data_enclosure);
		} else {
			printf("<table border='0' class='notifications' align='center'>\n");

			/* add export to csv, json, link */
			printf("<tr><td colspan='7'>");
			printf("<table width='100%%' cellspacing='0' cellpadding='0'><tr><td width='33%%'></td><td width='33%%' nowrap>");
			printf("<div class='page_selector'>\n");
			printf("<div id='page_navigation_copy'></div>");
			page_limit_selector(result_start);
			printf("</div>\n");
			printf("</td><td width='33%%' align='right' style='padding-right:2px'>\n");
			printf("<div class='csv_export_link'>");
			print_export_link(CSV_CONTENT, NOTIFICATIONS_CGI, NULL);
			print_export_link(JSON_CONTENT, NOTIFICATIONS_CGI, NULL);
			print_export_link(HTML_CONTENT, NOTIFICATIONS_CGI, NULL);
			printf("</div></td></tr></table>");

			printf("<tr>\n");
			printf("<th class='notifications'>Host</th>\n");
			printf("<th class='notifications'>Service</th>\n");
			printf("<th class='notifications'>Type</th>\n");
			printf("<th class='notifications'>Time</th>\n");
			printf("<th class='notifications'>Contact</th>\n");
			printf("<th class='notifications'>Notification Command</th>\n");
			printf("<th class='notifications'>Information</th>\n");
			printf("</tr>\n");
		}

		/* check all entries */
		for (temp_entry = entry_list; temp_entry != NULL; temp_entry = temp_entry->next) {

			/* get the date/time */
			get_time_string(&temp_entry->timestamp, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
			strip(date_time);

			/* get the contact name */
			temp_buffer = (char *)strtok(temp_entry->entry_text, ":");
			temp_buffer = (char *)strtok(NULL, ";");
			snprintf(contact_name, sizeof(contact_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer + 1);
			contact_name[sizeof(contact_name) - 1] = '\x0';

			/* get the host name */
			temp_buffer = (char *)strtok(NULL, ";");
			snprintf(host_name, sizeof(host_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
			host_name[sizeof(host_name) - 1] = '\x0';

			/* get the service name */
			service_name[0] = '\x0';
			if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION) {
				temp_buffer = (char *)strtok(NULL, ";");
				snprintf(service_name, sizeof(service_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
				service_name[sizeof(service_name) - 1] = '\x0';
			}

			/* get the alert level */
			temp_buffer = (char *)strtok(NULL, ";");
			snprintf(alert_level, sizeof(alert_level), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
			alert_level[sizeof(alert_level) - 1] = '\x0';

			if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION) {

				if (!strcmp(alert_level, "CRITICAL")) {
					notification_detail_type = NOTIFICATION_SERVICE_CRITICAL;
					strcpy(alert_level_class, "CRITICAL");
				} else if (!strcmp(alert_level, "WARNING")) {
					notification_detail_type = NOTIFICATION_SERVICE_WARNING;
					strcpy(alert_level_class, "WARNING");
				} else if (!strcmp(alert_level, "RECOVERY") || !strcmp(alert_level, "OK")) {
					strcpy(alert_level, "OK");
					notification_detail_type = NOTIFICATION_SERVICE_RECOVERY;
					strcpy(alert_level_class, "OK");
				} else if (strstr(alert_level, "CUSTOM (")) {
					notification_detail_type = NOTIFICATION_SERVICE_CUSTOM;
					strcpy(alert_level_class, "CUSTOM");
				} else if (strstr(alert_level, "ACKNOWLEDGEMENT (")) {
					notification_detail_type = NOTIFICATION_SERVICE_ACK;
					strcpy(alert_level_class, "ACKNOWLEDGEMENT");
				} else if (strstr(alert_level, "FLAPPINGSTART (")) {
					strcpy(alert_level, "FLAPPING START");
					notification_detail_type = NOTIFICATION_SERVICE_FLAP;
					strcpy(alert_level_class, "UNKNOWN");
				} else if (strstr(alert_level, "FLAPPINGSTOP (")) {
					strcpy(alert_level, "FLAPPING STOP");
					notification_detail_type = NOTIFICATION_SERVICE_FLAP;
					strcpy(alert_level_class, "UNKNOWN");
				} else {
					strcpy(alert_level, "UNKNOWN");
					notification_detail_type = NOTIFICATION_SERVICE_UNKNOWN;
					strcpy(alert_level_class, "UNKNOWN");
				}
			} else {

				if (!strcmp(alert_level, "DOWN")) {
					strncpy(alert_level, "HOST DOWN", sizeof(alert_level));
					strcpy(alert_level_class, "HOSTDOWN");
					notification_detail_type = NOTIFICATION_HOST_DOWN;
				} else if (!strcmp(alert_level, "UNREACHABLE")) {
					strncpy(alert_level, "HOST UNREACHABLE", sizeof(alert_level));
					strcpy(alert_level_class, "HOSTUNREACHABLE");
					notification_detail_type = NOTIFICATION_HOST_UNREACHABLE;
				} else if (!strcmp(alert_level, "RECOVERY") || !strcmp(alert_level, "UP")) {
					strncpy(alert_level, "HOST UP", sizeof(alert_level));
					strcpy(alert_level_class, "HOSTUP");
					notification_detail_type = NOTIFICATION_HOST_RECOVERY;
				} else if (strstr(alert_level, "CUSTOM (")) {
					strcpy(alert_level_class, "HOSTCUSTOM");
					notification_detail_type = NOTIFICATION_HOST_CUSTOM;
				} else if (strstr(alert_level, "ACKNOWLEDGEMENT (")) {
					strcpy(alert_level_class, "HOSTACKNOWLEDGEMENT");
					notification_detail_type = NOTIFICATION_HOST_ACK;
				} else if (strstr(alert_level, "FLAPPINGSTART (")) {
					strcpy(alert_level, "FLAPPING START");
					strcpy(alert_level_class, "UNKNOWN");
					notification_detail_type = NOTIFICATION_HOST_FLAP;
				} else if (strstr(alert_level, "FLAPPINGSTOP (")) {
					strcpy(alert_level, "FLAPPING STOP");
					strcpy(alert_level_class, "UNKNOWN");
					notification_detail_type = NOTIFICATION_HOST_FLAP;
				}
			}

			/* get the method name */
			temp_buffer = (char *)strtok(NULL, ";");
			snprintf(method_name, sizeof(method_name), "%s", (temp_buffer == NULL) ? "" : temp_buffer);
			method_name[sizeof(method_name) - 1] = '\x0';

			/* move to the informational message */
			temp_buffer = strtok(NULL, ";");

			show_entry = FALSE;

			/* if we're searching by contact, filter out unwanted contact */
			if (query_type == DISPLAY_CONTACTS) {
				if (find_all == TRUE)
					show_entry = TRUE;
				else if (!strcmp(query_contact_name, contact_name))
					show_entry = TRUE;
			}

			/* search host */
			else if (query_type == DISPLAY_HOSTS) {
				if (find_all == TRUE)
					show_entry = TRUE;
				else if (!strcmp(query_host_name, host_name))
					show_entry = TRUE;
			}

			/* searching service */
			else if (query_type == DISPLAY_SERVICES) {
				if (!strcmp(query_host_name, host_name) && !strcmp(query_svc_description, service_name))
					show_entry = TRUE;
			}

			/* Set TRUE here, get's checked later on */
			else if (query_type == DISPLAY_HOSTGROUPS || query_type == DISPLAY_SERVICEGROUPS) {
				show_entry = TRUE;
			}

			if (show_entry == TRUE) {
				if (notification_options == NOTIFICATION_ALL)
					show_entry = TRUE;
				else if (notification_options == NOTIFICATION_HOST_ALL && temp_entry->type == LOGENTRY_HOST_NOTIFICATION)
					show_entry = TRUE;
				else if (notification_options == NOTIFICATION_SERVICE_ALL && temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION)
					show_entry = TRUE;
				else if (notification_detail_type & notification_options)
					show_entry = TRUE;
				else
					show_entry = FALSE;
			}

			/* make sure user has authorization to view this notification */
			temp_host = find_host(host_name);
			if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION)
				temp_service = find_service(host_name, service_name);

			if (temp_host != NULL) {
				snprintf(displayed_host_name, sizeof(displayed_host_name), "%s", (temp_host->display_name != NULL && content_type == HTML_CONTENT) ? temp_host->display_name : temp_host->name);
				displayed_host_name[sizeof(displayed_host_name) - 1] = '\x0';

				if (temp_entry->type == LOGENTRY_HOST_NOTIFICATION) {
					if (is_authorized_for_host(temp_host, &current_authdata) == FALSE)
						show_entry = FALSE;
					else if (query_type == DISPLAY_HOSTGROUPS && is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
						show_entry = FALSE;
					else if (query_type == DISPLAY_SERVICEGROUPS && is_host_member_of_servicegroup(temp_servicegroup, temp_host) == FALSE)
						show_entry = FALSE;
				} else {
					if (temp_service != NULL) {
						snprintf(displayed_service_desc, sizeof(displayed_service_desc), "%s", (temp_service->display_name != NULL && content_type == HTML_CONTENT) ? temp_service->display_name : temp_service->description);
						displayed_service_desc[sizeof(displayed_service_desc) - 1] = '\x0';

						if (is_authorized_for_service(temp_service, &current_authdata) == FALSE)
							show_entry = FALSE;
						else if (query_type == DISPLAY_HOSTGROUPS && is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
							show_entry = FALSE;
						else if (query_type == DISPLAY_SERVICEGROUPS && is_service_member_of_servicegroup(temp_servicegroup, temp_service) == FALSE)
							show_entry = FALSE;
					} else {
						if (is_authorized_for_all_services(&current_authdata) == FALSE)
							show_entry = FALSE;

						snprintf(displayed_service_desc, sizeof(displayed_service_desc), "%s", service_name);
						displayed_service_desc[sizeof(displayed_service_desc) - 1] = '\x0';
					}
				}
			} else {
				if (temp_entry->type == LOGENTRY_HOST_NOTIFICATION) {
					if (is_authorized_for_all_hosts(&current_authdata) == FALSE)
						show_entry = FALSE;
				} else {
					if (is_authorized_for_all_services(&current_authdata) == FALSE)
						show_entry = FALSE;

					snprintf(displayed_service_desc, sizeof(displayed_service_desc), "%s", service_name);
					displayed_service_desc[sizeof(displayed_service_desc) - 1] = '\x0';
				}

				snprintf(displayed_host_name, sizeof(displayed_host_name), "%s", host_name);
				displayed_host_name[sizeof(displayed_host_name) - 1] = '\x0';
			}

			if (show_entry == TRUE) {

				if (result_limit != 0  && (((total_notifications + 1) < result_start) || (total_notifications >= ((result_start + result_limit) - 1)))) {
					total_notifications++;
					continue;
				}

				displayed_entries++;
				total_notifications++;

				if (odd)
					odd = 0;
				else
					odd = 1;

				if (content_type == JSON_CONTENT) {
					if (json_start == FALSE)
						printf(",\n");
					printf("{\"host_name\": \"%s\", ", json_encode(temp_host->name));
					printf("\"host_display_name\": \"%s\", ", (temp_host->display_name != NULL) ? json_encode(temp_host->display_name) : json_encode(temp_host->name));
					if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION) {
						printf("\"service_description\": \"%s\", ", json_encode(temp_service->description));
						printf("\"service_display_name\": \"%s\", ", (temp_service->display_name != NULL) ? json_encode(temp_service->display_name) : json_encode(temp_service->description));
					} else {
						printf("\"service_description\": null, ");
						printf("\"service_display_name\": null, ");
					}
					printf("\"type\": \"%s\", ", alert_level);
					printf("\"time\": \"%s\", ", date_time);
					printf("\"contact\": \"%s\", ", json_encode(contact_name));
					printf("\"notification_command\": \"%s\", ", json_encode(method_name));
					printf("\"information\": \"%s\"}", json_encode(escape_newlines(temp_buffer)));
				} else if (content_type == CSV_CONTENT) {
					printf("%s%s%s%s", csv_data_enclosure, displayed_host_name, csv_data_enclosure, csv_delimiter);
					if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION)
						printf("%s%s%s%s", csv_data_enclosure, displayed_service_desc, csv_data_enclosure, csv_delimiter);
					else
						printf("%sN/A%s%s", csv_data_enclosure, csv_data_enclosure, csv_delimiter);
					printf("%s%s%s%s", csv_data_enclosure, alert_level, csv_data_enclosure, csv_delimiter);
					printf("%s%s%s%s", csv_data_enclosure, date_time, csv_data_enclosure, csv_delimiter);
					printf("%s%s%s%s", csv_data_enclosure, contact_name, csv_data_enclosure, csv_delimiter);
					printf("%s%s%s%s", csv_data_enclosure, method_name, csv_data_enclosure, csv_delimiter);
					printf("%s%s%s\n", csv_data_enclosure, escape_newlines(temp_buffer), csv_data_enclosure);
				} else {
					printf("<tr class='notifications%s'>\n", (odd) ? "Even" : "Odd");
					if (temp_host != NULL)
						printf("<td class='notifications%s'><a href='%s?type=%d&amp;host=%s'>%s</a></td>\n", (odd) ? "Even" : "Odd", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(host_name), displayed_host_name);
					else
						printf("<td class='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", displayed_host_name);
					if (temp_entry->type == LOGENTRY_SERVICE_NOTIFICATION) {
						if (temp_service != NULL) {
							printf("<td class='notifications%s'><a href='%s?type=%d&amp;host=%s", (odd) ? "Even" : "Odd", EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(host_name));
							printf("&amp;service=%s'>%s</a></td>\n", url_encode(service_name), displayed_service_desc);
						} else
							printf("<td class='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", displayed_service_desc);

					} else
						printf("<td class='notifications%s'>N/A</td>\n", (odd) ? "Even" : "Odd");
					printf("<td class='notifications%s'>%s</td>\n", alert_level_class, alert_level);
					printf("<td class='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", date_time);
					printf("<td class='notifications%s'><a href='%s?type=contacts#%s'>%s</a></td>\n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(contact_name), contact_name);
					printf("<td class='notifications%s'><a href='%s?type=commands#%s'>%s</a></td>\n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(method_name), method_name);
					printf("<td class='notifications%s'>%s</td>\n", (odd) ? "Even" : "Odd", html_encode(temp_buffer, FALSE));
					printf("</tr>\n");
				}
				if (json_start == TRUE)
					json_start = FALSE;
			}
		}
	}

	free_log_entries(&entry_list);

	if (content_type != CSV_CONTENT && content_type != JSON_CONTENT) {
		printf("</table>\n");

		if (total_notifications == 0) {
			printf("<div class='errorMessage' style='text-align:center;'>No notifications have been recorded");
			if (find_all == FALSE) {
				if (query_type == DISPLAY_SERVICES)
					printf(" for this service");
				else if (query_type == DISPLAY_CONTACTS)
					printf(" for this contact");
				else
					printf(" for this host");
			}
			printf(" in log files for selected date.</div>");
		}

		page_num_selector(result_start, total_notifications, displayed_entries);

	} else if (content_type == JSON_CONTENT) {
		printf("\n]\n");
	}

	return;
}
示例#7
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;
	}
示例#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;
	}
示例#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;
	}
示例#10
0
void get_history(void) {
	mmapfile *thefile = NULL;
	char image[MAX_INPUT_BUFFER];
	char image_alt[MAX_INPUT_BUFFER];
	char *input = NULL;
	char *input2 = NULL;
	char match1[MAX_INPUT_BUFFER];
	char match2[MAX_INPUT_BUFFER];
	int found_line = FALSE;
	int system_message = FALSE;
	int display_line = FALSE;
	time_t t;
	char date_time[MAX_DATETIME_LENGTH];
	char *temp_buffer = NULL;
	int history_type = SERVICE_HISTORY;
	int history_detail_type = HISTORY_SERVICE_CRITICAL;
	char *entry_host_name = NULL;
	char *entry_service_desc = NULL;
	host *temp_host = NULL;
	service *temp_service = NULL;
	int result = 0;

	char last_message_date[MAX_INPUT_BUFFER] = "";
	char current_message_date[MAX_INPUT_BUFFER] = "";
	struct tm *time_ptr = NULL;


	if(use_lifo == TRUE) {
		result = read_file_into_lifo(log_file_to_use);
		if(result != LIFO_OK) {
			if(result == LIFO_ERROR_MEMORY) {
				printf("<P><DIV CLASS='warningMessage'>Not enough memory to reverse log file - displaying history in natural order...</DIV></P>\n");
				}
			else if(result == LIFO_ERROR_FILE) {
				printf("<HR><P><DIV CLASS='errorMessage'>Error: Cannot open log file '%s' for reading!</DIV></P><HR>", log_file_to_use);
				return;
				}
			use_lifo = FALSE;
			}
		}

	if(use_lifo == FALSE) {

		if((thefile = mmap_fopen(log_file_to_use)) == NULL) {
			printf("<HR><P><DIV CLASS='errorMessage'>Error: Cannot open log file '%s' for reading!</DIV></P><HR>", log_file_to_use);
			return;
			}
		}

	printf("<P><DIV CLASS='logEntries'>\n");

	while(1) {

		my_free(input);
		my_free(input2);

		if(use_lifo == TRUE) {
			if((input = pop_lifo()) == NULL)
				break;
			}
		else {
			if((input = mmap_fgets(thefile)) == NULL)
				break;
			}

		strip(input);

		strcpy(image, "");
		strcpy(image_alt, "");
		system_message = FALSE;

		if((input2 = (char *)strdup(input)) == NULL)
			continue;

		/* service state alerts */
		if(strstr(input, "SERVICE ALERT:")) {

			history_type = SERVICE_HISTORY;

			/* get host and service names */
			temp_buffer = my_strtok(input2, "]");
			temp_buffer = my_strtok(NULL, ":");
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_host_name = strdup(temp_buffer + 1);
			else
				entry_host_name = NULL;
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_service_desc = strdup(temp_buffer);
			else
				entry_service_desc = NULL;

			if(strstr(input, ";CRITICAL;")) {
				strncpy(image, CRITICAL_ICON, sizeof(image));
				strncpy(image_alt, CRITICAL_ICON_ALT, sizeof(image_alt));
				history_detail_type = HISTORY_SERVICE_CRITICAL;
				}
			else if(strstr(input, ";WARNING;")) {
				strncpy(image, WARNING_ICON, sizeof(image));
				strncpy(image_alt, WARNING_ICON_ALT, sizeof(image_alt));
				history_detail_type = HISTORY_SERVICE_WARNING;
				}
			else if(strstr(input, ";UNKNOWN;")) {
				strncpy(image, UNKNOWN_ICON, sizeof(image));
				strncpy(image_alt, UNKNOWN_ICON_ALT, sizeof(image_alt));
				history_detail_type = HISTORY_SERVICE_UNKNOWN;
				}
			else if(strstr(input, ";RECOVERY;") || strstr(input, ";OK;")) {
				strncpy(image, OK_ICON, sizeof(image));
				strncpy(image_alt, OK_ICON_ALT, sizeof(image_alt));
				history_detail_type = HISTORY_SERVICE_RECOVERY;
				}
			}

		/* service flapping alerts */
		else if(strstr(input, "SERVICE FLAPPING ALERT:")) {

			if(display_flapping_alerts == FALSE)
				continue;

			history_type = SERVICE_FLAPPING_HISTORY;

			/* get host and service names */
			temp_buffer = my_strtok(input2, "]");
			temp_buffer = my_strtok(NULL, ":");
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_host_name = strdup(temp_buffer + 1);
			else
				entry_host_name = NULL;
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_service_desc = strdup(temp_buffer);
			else
				entry_service_desc = NULL;

			strncpy(image, FLAPPING_ICON, sizeof(image));

			if(strstr(input, ";STARTED;"))
				strncpy(image_alt, "Service started flapping", sizeof(image_alt));
			else if(strstr(input, ";STOPPED;"))
				strncpy(image_alt, "Service stopped flapping", sizeof(image_alt));
			else if(strstr(input, ";DISABLED;"))
				strncpy(image_alt, "Service flap detection disabled", sizeof(image_alt));
			}

		/* service downtime alerts */
		else if(strstr(input, "SERVICE DOWNTIME ALERT:")) {

			if(display_downtime_alerts == FALSE)
				continue;

			history_type = SERVICE_DOWNTIME_HISTORY;

			/* get host and service names */
			temp_buffer = my_strtok(input2, "]");
			temp_buffer = my_strtok(NULL, ":");
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_host_name = strdup(temp_buffer + 1);
			else
				entry_host_name = NULL;
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_service_desc = strdup(temp_buffer);
			else
				entry_service_desc = NULL;

			strncpy(image, SCHEDULED_DOWNTIME_ICON, sizeof(image));

			if(strstr(input, ";STARTED;"))
				strncpy(image_alt, "Service entered a period of scheduled downtime", sizeof(image_alt));
			else if(strstr(input, ";STOPPED;"))
				strncpy(image_alt, "Service exited from a period of scheduled downtime", sizeof(image_alt));
			else if(strstr(input, ";CANCELLED;"))
				strncpy(image_alt, "Service scheduled downtime has been cancelled", sizeof(image_alt));
			}

		/* host state alerts */
		else if(strstr(input, "HOST ALERT:")) {

			history_type = HOST_HISTORY;

			/* get host name */
			temp_buffer = my_strtok(input2, "]");
			temp_buffer = my_strtok(NULL, ":");
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_host_name = strdup(temp_buffer + 1);
			else
				entry_host_name = NULL;

			if(strstr(input, ";DOWN;")) {
				strncpy(image, HOST_DOWN_ICON, sizeof(image));
				strncpy(image_alt, HOST_DOWN_ICON_ALT, sizeof(image_alt));
				history_detail_type = HISTORY_HOST_DOWN;
				}
			else if(strstr(input, ";UNREACHABLE;")) {
				strncpy(image, HOST_UNREACHABLE_ICON, sizeof(image));
				strncpy(image_alt, HOST_UNREACHABLE_ICON_ALT, sizeof(image_alt));
				history_detail_type = HISTORY_HOST_UNREACHABLE;
				}
			else if(strstr(input, ";RECOVERY") || strstr(input, ";UP;")) {
				strncpy(image, HOST_UP_ICON, sizeof(image));
				strncpy(image_alt, HOST_UP_ICON_ALT, sizeof(image_alt));
				history_detail_type = HISTORY_HOST_RECOVERY;
				}
			}

		/* host flapping alerts */
		else if(strstr(input, "HOST FLAPPING ALERT:")) {

			if(display_flapping_alerts == FALSE)
				continue;

			history_type = HOST_FLAPPING_HISTORY;

			/* get host name */
			temp_buffer = my_strtok(input2, "]");
			temp_buffer = my_strtok(NULL, ":");
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_host_name = strdup(temp_buffer + 1);
			else
				entry_host_name = NULL;

			strncpy(image, FLAPPING_ICON, sizeof(image));

			if(strstr(input, ";STARTED;"))
				strncpy(image_alt, "Host started flapping", sizeof(image_alt));
			else if(strstr(input, ";STOPPED;"))
				strncpy(image_alt, "Host stopped flapping", sizeof(image_alt));
			else if(strstr(input, ";DISABLED;"))
				strncpy(image_alt, "Host flap detection disabled", sizeof(image_alt));
			}

		/* host downtime alerts */
		else if(strstr(input, "HOST DOWNTIME ALERT:")) {

			if(display_downtime_alerts == FALSE)
				continue;

			history_type = HOST_DOWNTIME_HISTORY;

			/* get host name */
			temp_buffer = my_strtok(input2, "]");
			temp_buffer = my_strtok(NULL, ":");
			temp_buffer = my_strtok(NULL, ";");
			if(temp_buffer)
				entry_host_name = strdup(temp_buffer + 1);
			else
				entry_host_name = NULL;

			strncpy(image, SCHEDULED_DOWNTIME_ICON, sizeof(image));

			if(strstr(input, ";STARTED;"))
				strncpy(image_alt, "Host entered a period of scheduled downtime", sizeof(image_alt));
			else if(strstr(input, ";STOPPED;"))
				strncpy(image_alt, "Host exited from a period of scheduled downtime", sizeof(image_alt));
			else if(strstr(input, ";CANCELLED;"))
				strncpy(image_alt, "Host scheduled downtime has been cancelled", sizeof(image_alt));
			}

		else if(display_system_messages == FALSE)
			continue;

		/* program start */
		else if(strstr(input, " starting...")) {
			strncpy(image, START_ICON, sizeof(image));
			strncpy(image_alt, START_ICON_ALT, sizeof(image_alt));
			system_message = TRUE;
			}

		/* normal program termination */
		else if(strstr(input, " shutting down...")) {
			strncpy(image, STOP_ICON, sizeof(image));
			strncpy(image_alt, STOP_ICON_ALT, sizeof(image_alt));
			system_message = TRUE;
			}

		/* abnormal program termination */
		else if(strstr(input, "Bailing out")) {
			strncpy(image, STOP_ICON, sizeof(image));
			strncpy(image_alt, STOP_ICON_ALT, sizeof(image_alt));
			system_message = TRUE;
			}

		/* program restart */
		else if(strstr(input, " restarting...")) {
			strncpy(image, RESTART_ICON, sizeof(image));
			strncpy(image_alt, RESTART_ICON_ALT, sizeof(image_alt));
			system_message = TRUE;
			}

		image[sizeof(image) - 1] = '\x0';
		image_alt[sizeof(image_alt) - 1] = '\x0';

		/* get the timestamp */
		temp_buffer = strtok(input, "]");
		t = (temp_buffer == NULL) ? 0L : strtoul(temp_buffer + 1, NULL, 10);

		time_ptr = localtime(&t);
		strftime(current_message_date, sizeof(current_message_date), "%B %d, %Y %H:00\n", time_ptr);
		current_message_date[sizeof(current_message_date) - 1] = '\x0';

		get_time_string(&t, date_time, sizeof(date_time), SHORT_DATE_TIME);
		strip(date_time);

		temp_buffer = strtok(NULL, "\n");

		if(strcmp(image, "")) {

			display_line = FALSE;

			if(system_message == TRUE)
				display_line = TRUE;

			else if(display_type == DISPLAY_HOSTS) {

				if(history_type == HOST_HISTORY || history_type == SERVICE_HISTORY) {
					snprintf(match1, sizeof( match1), 
							" HOST ALERT: %s;", host_name);
					snprintf(match2, sizeof( match2), 
							" SERVICE ALERT: %s;", host_name);
					}
				else if(history_type == HOST_FLAPPING_HISTORY || history_type == SERVICE_FLAPPING_HISTORY) {
					snprintf(match1, sizeof( match1), 
							" HOST FLAPPING ALERT: %s;", host_name);
					snprintf(match2, sizeof( match2), 
							" SERVICE FLAPPING ALERT: %s;", host_name);
					}
				else if(history_type == HOST_DOWNTIME_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY) {
					snprintf(match1, sizeof( match1), 
							" HOST DOWNTIME ALERT: %s;", host_name);
					snprintf(match2, sizeof( match2), 
							" SERVICE DOWNTIME ALERT: %s;", host_name);
					}

				if(show_all_hosts == TRUE)
					display_line = TRUE;
				else if(strstr(temp_buffer, match1))
					display_line = TRUE;
				else if(strstr(temp_buffer, match2))
					display_line = TRUE;

				if(display_line == TRUE) {
					if(history_options == HISTORY_ALL)
						display_line = TRUE;
					else if(history_options == HISTORY_HOST_ALL && (history_type == HOST_HISTORY || history_type == HOST_FLAPPING_HISTORY || history_type == HOST_DOWNTIME_HISTORY))
						display_line = TRUE;
					else if(history_options == HISTORY_SERVICE_ALL && (history_type == SERVICE_HISTORY || history_type == SERVICE_FLAPPING_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY))
						display_line = TRUE;
					else if((history_type == HOST_HISTORY || history_type == SERVICE_HISTORY) && (history_detail_type & history_options))
						display_line = TRUE;
					else
						display_line = FALSE;
					}

				/* check alert state types */
				if(display_line == TRUE && (history_type == HOST_HISTORY || history_type == SERVICE_HISTORY)) {
					if(state_options == STATE_ALL)
						display_line = TRUE;
					else if((state_options & STATE_SOFT) && strstr(temp_buffer, ";SOFT;"))
						display_line = TRUE;
					else if((state_options & STATE_HARD) && strstr(temp_buffer, ";HARD;"))
						display_line = TRUE;
					else
						display_line = FALSE;
					}
				}

			else if(display_type == DISPLAY_SERVICES) {

				if(history_type == SERVICE_HISTORY)
					snprintf(match1, sizeof( match1), " SERVICE ALERT: %s;%s;", host_name, svc_description);
				else if(history_type == SERVICE_FLAPPING_HISTORY)
					snprintf(match1, sizeof( match1), " SERVICE FLAPPING ALERT: %s;%s;", host_name, svc_description);
				else if(history_type == SERVICE_DOWNTIME_HISTORY)
					snprintf(match1, sizeof( match1), " SERVICE DOWNTIME ALERT: %s;%s;", host_name, svc_description);

				if(strstr(temp_buffer, match1) && (history_type == SERVICE_HISTORY || history_type == SERVICE_FLAPPING_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY))
					display_line = TRUE;

				if(display_line == TRUE) {
					if(history_options == HISTORY_ALL || history_options == HISTORY_SERVICE_ALL)
						display_line = TRUE;
					else if(history_options & history_detail_type)
						display_line = TRUE;
					else
						display_line = FALSE;
					}

				/* check alert state type */
				if(display_line == TRUE && history_type == SERVICE_HISTORY) {

					if(state_options == STATE_ALL)
						display_line = TRUE;
					else if((state_options & STATE_SOFT) && strstr(temp_buffer, ";SOFT;"))
						display_line = TRUE;
					else if((state_options & STATE_HARD) && strstr(temp_buffer, ";HARD;"))
						display_line = TRUE;
					else
						display_line = FALSE;
					}
				}


			/* make sure user is authorized to view this host or service information */
			if(system_message == FALSE) {

				if(history_type == HOST_HISTORY || history_type == HOST_FLAPPING_HISTORY || history_type == HOST_DOWNTIME_HISTORY) {
					temp_host = find_host(entry_host_name);
					if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
						display_line = FALSE;

					}
				else {
					temp_service = find_service(entry_host_name, entry_service_desc);
					if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
						display_line = FALSE;
					}
				}

			/* display the entry if we should... */
			if(display_line == TRUE) {

				if(strcmp(last_message_date, current_message_date) != 0 && display_timebreaks == TRUE) {
					printf("</DIV><BR CLEAR='all' />\n");
					printf("<DIV CLASS='dateTimeBreak'>\n");
					printf("<table border=0 width=95%%><tr>");
					printf("<td width=40%%><hr width=100%%></td>");
					printf("<td align=center CLASS='dateTimeBreak'>%s</td>", current_message_date);
					printf("<td width=40%%><hr width=100%%></td>");
					printf("</tr></table>\n");
					printf("</DIV>\n");
					printf("<BR CLEAR='all' /><DIV CLASS='logEntries'>\n");
					strncpy(last_message_date, current_message_date, sizeof(last_message_date));
					last_message_date[sizeof(last_message_date) - 1] = '\x0';
					}

				if(display_frills == TRUE)
					printf("<img align='left' src='%s%s' alt='%s' title='%s' />", url_images_path, image, image_alt, image_alt);
				printf("[%s] %s", date_time, html_encode(temp_buffer, FALSE));
				if(enable_splunk_integration == TRUE) {
					printf("&nbsp;&nbsp;&nbsp;");
					display_splunk_generic_url(temp_buffer, 2);
					}
				printf("<br clear='all' />\n");

				found_line = TRUE;
				}
			}

		/* free memory */
		free(entry_host_name);
		entry_host_name = NULL;
		free(entry_service_desc);
		entry_service_desc = NULL;
		}

	printf("</DIV></P>\n");

	if(found_line == FALSE) {
		printf("<HR>\n");
		printf("<P><DIV CLASS='warningMessage'>No history information was found ");
		if(display_type == DISPLAY_HOSTS)
			printf("%s", (show_all_hosts == TRUE) ? "" : "for this host ");
		else
			printf("for this service ");
		printf("in %s log file</DIV></P>", (log_archive == 0) ? "the current" : "this archived");
		}

	printf("<HR>\n");

	my_free(input);
	my_free(input2);

	if(use_lifo == TRUE)
		free_lifo_memory();
	else
		mmap_fclose(thefile);

	return;
	}
示例#11
0
void show_history(void) {
    char image[MAX_INPUT_BUFFER];
    char image_alt[MAX_INPUT_BUFFER];
    char match1[MAX_INPUT_BUFFER];
    char match2[MAX_INPUT_BUFFER];
    char date_time[MAX_DATETIME_LENGTH];
    char last_message_date[MAX_INPUT_BUFFER] = "";
    char current_message_date[MAX_INPUT_BUFFER] = "";
    char *temp_buffer = NULL;
    char *entry_host_name = NULL;
    char *entry_service_desc = NULL;
    char *error_text = NULL;
    int system_message = FALSE;
    int display_line = FALSE;
    int history_type = SERVICE_HISTORY;
    int history_detail_type = HISTORY_SERVICE_CRITICAL;
    int status = READLOG_OK;
    int displayed_entries = 0;
    int total_entries = 0;
    host *temp_host = NULL;
    service *temp_service = NULL;
    hostgroup *temp_hostgroup = NULL;
    servicegroup *temp_servicegroup = NULL;
    logentry *temp_entry = NULL;
    struct tm *time_ptr = NULL;
    logentry *entry_list = NULL;
    logfilter *filter_list = NULL;


    if (display_type == DISPLAY_HOSTGROUPS) {

        temp_hostgroup = find_hostgroup(hostgroup_name);

        if (temp_hostgroup == NULL) {
            print_generic_error_message("There are no host groups with this name defined.", NULL, 0);
            return;
        }
        /* make sure the user is authorized to view this hostgroup */
        if (show_partial_hostgroups == FALSE && is_authorized_for_hostgroup(temp_hostgroup, &current_authdata) == FALSE) {
            print_generic_error_message("It appears as though you do not have permission to view information for the host group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
            return;
        }
    }

    if (display_type == DISPLAY_SERVICEGROUPS) {

        temp_servicegroup = find_servicegroup(servicegroup_name);

        if (temp_servicegroup == NULL) {
            print_generic_error_message("There are no service groups with this name defined.", NULL, 0);
            return;
        }
        /* make sure the user is authorized to view this servicegroup */
        if (is_authorized_for_servicegroup(temp_servicegroup, &current_authdata) == FALSE) {
            print_generic_error_message("It appears as though you do not have permission to view information for the service group you requested...", "If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI and check the authorization options in your CGI configuration file.", 0);
            return;
        }
    }

    add_log_filter(&filter_list, LOGENTRY_SERVICE_CRITICAL, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_WARNING, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_UNKNOWN, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_RECOVERY, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_OK, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_STARTED, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_STOPPED, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_STARTED, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_STOPPED, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SERVICE_DOWNTIME_CANCELLED, LOGFILTER_INCLUDE);

    if (display_type == DISPLAY_HOSTS || display_type == DISPLAY_HOSTGROUPS) {
        add_log_filter(&filter_list, LOGENTRY_HOST_DOWN, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_UNREACHABLE, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_RECOVERY, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_UP, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STARTED, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STOPPED, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_STOPPED, LOGFILTER_INCLUDE);
        add_log_filter(&filter_list, LOGENTRY_HOST_FLAPPING_DISABLED, LOGFILTER_INCLUDE);
    }

    /* system log entries */
    add_log_filter(&filter_list, LOGENTRY_STARTUP, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_SHUTDOWN, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_BAILOUT, LOGFILTER_INCLUDE);
    add_log_filter(&filter_list, LOGENTRY_RESTART, LOGFILTER_INCLUDE);


    /* scan the log file for archived state data */
    status = get_log_entries(&entry_list, &filter_list, &error_text, NULL, reverse, ts_start, ts_end);


    /* dealing with errors */
    if (status == READLOG_ERROR_WARNING) {
        if (error_text != NULL) {
            print_generic_error_message(error_text, NULL, 0);
            my_free(error_text);
        } else
            print_generic_error_message("Unkown error!", NULL, 0);
    }

    if (status == READLOG_ERROR_MEMORY)
        print_generic_error_message("Out of memory...", "showing all I could get!", 0);


    if (status == READLOG_ERROR_FATAL) {
        if (error_text != NULL) {
            print_generic_error_message(error_text, NULL, 0);
            my_free(error_text);
        }

        return;

        /* now we start displaying the log entries */
    } else {

        printf("<table width='100%%' cellspacing=0 cellpadding=0><tr><td width='33%%'></td><td width='33%%' nowrap>");
        printf("<div class='page_selector' id='hist_page_selector'>\n");
        printf("<div id='page_navigation_copy'></div>");
        page_limit_selector(result_start);
        printf("</div>\n");
        printf("</td><td width='33%%' align='right' style='padding-right:2px'>\n");
        print_export_link(HTML_CONTENT, HISTORY_CGI, NULL);
        printf("</td></tr></table>");

        printf("<DIV CLASS='logEntries'>\n");

        for (temp_entry = entry_list; temp_entry != NULL; temp_entry = temp_entry->next) {

            strcpy(image, "");
            strcpy(image_alt, "");
            system_message = FALSE;

            switch (temp_entry->type) {

            /* service state alerts */
            case LOGENTRY_SERVICE_CRITICAL:
            case LOGENTRY_SERVICE_WARNING:
            case LOGENTRY_SERVICE_UNKNOWN:
            case LOGENTRY_SERVICE_RECOVERY:
            case LOGENTRY_SERVICE_OK:

                history_type = SERVICE_HISTORY;

                /* get host and service names */
                temp_buffer = my_strtok(temp_entry->entry_text, ":");
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_host_name = strdup(temp_buffer + 1);
                else
                    entry_host_name = NULL;

                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_service_desc = strdup(temp_buffer);
                else
                    entry_service_desc = NULL;

                if (temp_entry->type == LOGENTRY_SERVICE_CRITICAL) {
                    strcpy(image, CRITICAL_ICON);
                    strcpy(image_alt, CRITICAL_ICON_ALT);
                    history_detail_type = HISTORY_SERVICE_CRITICAL;
                } else if (temp_entry->type == LOGENTRY_SERVICE_WARNING) {
                    strcpy(image, WARNING_ICON);
                    strcpy(image_alt, WARNING_ICON_ALT);
                    history_detail_type = HISTORY_SERVICE_WARNING;
                } else if (temp_entry->type == LOGENTRY_SERVICE_UNKNOWN) {
                    strcpy(image, UNKNOWN_ICON);
                    strcpy(image_alt, UNKNOWN_ICON_ALT);
                    history_detail_type = HISTORY_SERVICE_UNKNOWN;
                } else if (temp_entry->type == LOGENTRY_SERVICE_RECOVERY || temp_entry->type == LOGENTRY_SERVICE_OK) {
                    strcpy(image, OK_ICON);
                    strcpy(image_alt, OK_ICON_ALT);
                    history_detail_type = HISTORY_SERVICE_RECOVERY;
                }
                break;

            /* service flapping alerts */
            case LOGENTRY_SERVICE_FLAPPING_STARTED:
            case LOGENTRY_SERVICE_FLAPPING_STOPPED:
            case LOGENTRY_SERVICE_FLAPPING_DISABLED:

                if (display_flapping_alerts == FALSE)
                    continue;

                history_type = SERVICE_FLAPPING_HISTORY;

                /* get host and service names */
                temp_buffer = my_strtok(temp_entry->entry_text, ":");
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_host_name = strdup(temp_buffer + 1);
                else
                    entry_host_name = NULL;
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_service_desc = strdup(temp_buffer);
                else
                    entry_service_desc = NULL;

                strcpy(image, FLAPPING_ICON);

                if (temp_entry->type == LOGENTRY_SERVICE_FLAPPING_STARTED)
                    strcpy(image_alt, "Service started flapping");
                else if (temp_entry->type == LOGENTRY_SERVICE_FLAPPING_STOPPED)
                    strcpy(image_alt, "Service stopped flapping");
                else if (temp_entry->type == LOGENTRY_SERVICE_FLAPPING_DISABLED)
                    strcpy(image_alt, "Service flap detection disabled");

                break;

            /* service downtime alerts */
            case LOGENTRY_SERVICE_DOWNTIME_STARTED:
            case LOGENTRY_SERVICE_DOWNTIME_STOPPED:
            case LOGENTRY_SERVICE_DOWNTIME_CANCELLED:

                if (display_downtime_alerts == FALSE)
                    continue;

                history_type = SERVICE_DOWNTIME_HISTORY;

                /* get host and service names */
                temp_buffer = my_strtok(temp_entry->entry_text, ":");
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_host_name = strdup(temp_buffer + 1);
                else
                    entry_host_name = NULL;
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_service_desc = strdup(temp_buffer);
                else
                    entry_service_desc = NULL;

                strcpy(image, DOWNTIME_ICON);

                if (temp_entry->type == LOGENTRY_SERVICE_DOWNTIME_STARTED)
                    strcpy(image_alt, "Service entered a period of scheduled downtime");
                else if (temp_entry->type == LOGENTRY_SERVICE_DOWNTIME_STOPPED)
                    strcpy(image_alt, "Service exited from a period of scheduled downtime");
                else if (temp_entry->type == LOGENTRY_SERVICE_DOWNTIME_CANCELLED)
                    strcpy(image_alt, "Service scheduled downtime has been cancelled");

                break;

            /* host state alerts */
            case LOGENTRY_HOST_DOWN:
            case LOGENTRY_HOST_UNREACHABLE:
            case LOGENTRY_HOST_RECOVERY:
            case LOGENTRY_HOST_UP:

                history_type = HOST_HISTORY;

                /* get host name */
                temp_buffer = my_strtok(temp_entry->entry_text, ":");
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_host_name = strdup(temp_buffer + 1);
                else
                    entry_host_name = NULL;

                if (temp_entry->type == LOGENTRY_HOST_DOWN) {
                    strcpy(image, HOST_DOWN_ICON);
                    strcpy(image_alt, HOST_DOWN_ICON_ALT);
                    history_detail_type = HISTORY_HOST_DOWN;
                } else if (temp_entry->type == LOGENTRY_HOST_UNREACHABLE) {
                    strcpy(image, HOST_UNREACHABLE_ICON);
                    strcpy(image_alt, HOST_UNREACHABLE_ICON_ALT);
                    history_detail_type = HISTORY_HOST_UNREACHABLE;
                } else if (temp_entry->type == LOGENTRY_HOST_RECOVERY || temp_entry->type == LOGENTRY_HOST_UP) {
                    strcpy(image, HOST_UP_ICON);
                    strcpy(image_alt, HOST_UP_ICON_ALT);
                    history_detail_type = HISTORY_HOST_RECOVERY;
                }

                break;

            /* host flapping alerts */
            case LOGENTRY_HOST_FLAPPING_STARTED:
            case LOGENTRY_HOST_FLAPPING_STOPPED:
            case LOGENTRY_HOST_FLAPPING_DISABLED:

                if (display_flapping_alerts == FALSE)
                    continue;

                history_type = HOST_FLAPPING_HISTORY;

                /* get host name */
                temp_buffer = my_strtok(temp_entry->entry_text, ":");
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_host_name = strdup(temp_buffer + 1);
                else
                    entry_host_name = NULL;

                strcpy(image, FLAPPING_ICON);

                if (temp_entry->type == LOGENTRY_HOST_FLAPPING_STARTED)
                    strcpy(image_alt, "Host started flapping");
                else if (temp_entry->type == LOGENTRY_HOST_FLAPPING_STOPPED)
                    strcpy(image_alt, "Host stopped flapping");
                else if (temp_entry->type == LOGENTRY_HOST_FLAPPING_DISABLED)
                    strcpy(image_alt, "Host flap detection disabled");

                break;

            /* host downtime alerts */
            case LOGENTRY_HOST_DOWNTIME_STARTED:
            case LOGENTRY_HOST_DOWNTIME_STOPPED:
            case LOGENTRY_HOST_DOWNTIME_CANCELLED:

                if (display_downtime_alerts == FALSE)
                    continue;

                history_type = HOST_DOWNTIME_HISTORY;

                /* get host name */
                temp_buffer = my_strtok(temp_entry->entry_text, ":");
                temp_buffer = my_strtok(NULL, ";");
                if (temp_buffer)
                    entry_host_name = strdup(temp_buffer + 1);
                else
                    entry_host_name = NULL;

                strcpy(image, DOWNTIME_ICON);

                if (temp_entry->type == LOGENTRY_HOST_DOWNTIME_STARTED)
                    strcpy(image_alt, "Host entered a period of scheduled downtime");
                else if (temp_entry->type == LOGENTRY_HOST_DOWNTIME_STOPPED)
                    strcpy(image_alt, "Host exited from a period of scheduled downtime");
                else if (temp_entry->type == LOGENTRY_HOST_DOWNTIME_CANCELLED)
                    strcpy(image_alt, "Host scheduled downtime has been cancelled");

                break;


            /* program start */
            case LOGENTRY_STARTUP:
                if (display_system_messages == FALSE)
                    continue;
                strcpy(image, START_ICON);
                strcpy(image_alt, START_ICON_ALT);
                system_message = TRUE;
                break;

            /* program termination */
            case LOGENTRY_SHUTDOWN:
            case LOGENTRY_BAILOUT:
                if (display_system_messages == FALSE)
                    continue;
                strcpy(image, STOP_ICON);
                strcpy(image_alt, STOP_ICON_ALT);
                system_message = TRUE;
                break;

            /* program restart */
            case LOGENTRY_RESTART:
                if (display_system_messages == FALSE)
                    continue;
                strcpy(image, RESTART_ICON);
                strcpy(image_alt, RESTART_ICON_ALT);
                system_message = TRUE;
                break;
            }

            image[sizeof(image) - 1] = '\x0';
            image_alt[sizeof(image_alt) - 1] = '\x0';

            /* get the timestamp */
            time_ptr = localtime(&temp_entry->timestamp);
            strftime(current_message_date, sizeof(current_message_date), "%B %d, %Y %H:00\n", time_ptr);
            current_message_date[sizeof(current_message_date) - 1] = '\x0';

            get_time_string(&temp_entry->timestamp, date_time, sizeof(date_time), SHORT_DATE_TIME);
            strip(date_time);

            if (strcmp(image, "")) {

                display_line = FALSE;

                if (system_message == TRUE)
                    display_line = TRUE;

                else if (display_type == DISPLAY_HOSTS || display_type == DISPLAY_HOSTGROUPS) {

                    if (history_type == HOST_HISTORY || history_type == SERVICE_HISTORY) {
                        snprintf(match1, sizeof(match1), " HOST ALERT: %s;", host_name);
                        snprintf(match2, sizeof(match2), " SERVICE ALERT: %s;", host_name);
                    } else if (history_type == HOST_FLAPPING_HISTORY || history_type == SERVICE_FLAPPING_HISTORY) {
                        snprintf(match1, sizeof(match1), " HOST FLAPPING ALERT: %s;", host_name);
                        snprintf(match2, sizeof(match2), " SERVICE FLAPPING ALERT: %s;", host_name);
                    } else if (history_type == HOST_DOWNTIME_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY) {
                        snprintf(match1, sizeof(match1), " HOST DOWNTIME ALERT: %s;", host_name);
                        snprintf(match2, sizeof(match2), " SERVICE DOWNTIME ALERT: %s;", host_name);
                    }

                    if (show_all_hosts == TRUE)
                        display_line = TRUE;
                    else if (strstr(temp_entry->entry_text, match1))
                        display_line = TRUE;
                    else if (strstr(temp_entry->entry_text, match2))
                        display_line = TRUE;

                    if (display_line == TRUE) {
                        if (history_options == HISTORY_ALL)
                            display_line = TRUE;
                        else if (history_options == HISTORY_HOST_ALL && (history_type == HOST_HISTORY || history_type == HOST_FLAPPING_HISTORY || history_type == HOST_DOWNTIME_HISTORY))
                            display_line = TRUE;
                        else if (history_options == HISTORY_SERVICE_ALL && (history_type == SERVICE_HISTORY || history_type == SERVICE_FLAPPING_HISTORY || history_type == SERVICE_DOWNTIME_HISTORY))
                            display_line = TRUE;
                        else if ((history_type == HOST_HISTORY || history_type == SERVICE_HISTORY) && (history_detail_type & history_options))
                            display_line = TRUE;
                        else
                            display_line = FALSE;
                    }

                    /* check alert state types */
                    if (display_line == TRUE && (history_type == HOST_HISTORY || history_type == SERVICE_HISTORY)) {
                        if (state_options == STATE_ALL)
                            display_line = TRUE;
                        else if ((state_options & STATE_SOFT) && strstr(temp_entry->entry_text, ";SOFT;"))
                            display_line = TRUE;
                        else if ((state_options & STATE_HARD) && strstr(temp_entry->entry_text, ";HARD;"))
                            display_line = TRUE;
                        else
                            display_line = FALSE;
                    }
                }

                else if (display_type == DISPLAY_SERVICES || display_type == DISPLAY_SERVICEGROUPS) {

                    if (history_type == SERVICE_HISTORY)
                        snprintf(match1, sizeof(match1), " SERVICE ALERT: %s;%s;", host_name, service_desc);
                    else if (history_type == SERVICE_FLAPPING_HISTORY)
                        snprintf(match1, sizeof(match1), " SERVICE FLAPPING ALERT: %s;%s;", host_name, service_desc);
                    else if (history_type == SERVICE_DOWNTIME_HISTORY)
                        snprintf(match1, sizeof(match1), " SERVICE DOWNTIME ALERT: %s;%s;", host_name, service_desc);

                    if (display_type == DISPLAY_SERVICEGROUPS)
                        display_line = TRUE;
                    else if (strstr(temp_entry->entry_text, match1))
                        display_line = TRUE;

                    if (history_type != SERVICE_HISTORY && history_type != SERVICE_FLAPPING_HISTORY && history_type != SERVICE_DOWNTIME_HISTORY)
                        display_line = FALSE;

                    if (display_line == TRUE) {
                        if (history_options == HISTORY_ALL || history_options == HISTORY_SERVICE_ALL)
                            display_line = TRUE;
                        else if (history_options & history_detail_type)
                            display_line = TRUE;
                        else
                            display_line = FALSE;
                    }

                    /* check alert state type */
                    if (display_line == TRUE && history_type == SERVICE_HISTORY) {

                        if (state_options == STATE_ALL)
                            display_line = TRUE;
                        else if ((state_options & STATE_SOFT) && strstr(temp_entry->entry_text, ";SOFT;"))
                            display_line = TRUE;
                        else if ((state_options & STATE_HARD) && strstr(temp_entry->entry_text, ";HARD;"))
                            display_line = TRUE;
                        else
                            display_line = FALSE;
                    }
                }

                /* make sure user is authorized to view this log entry */
                if (display_line == TRUE) {

                    if (system_message == TRUE) {
                        if (is_authorized_for_system_information(&current_authdata) == FALSE)
                            display_line = FALSE;
                    } else {
                        temp_host = find_host(entry_host_name);

                        if (history_type == HOST_HISTORY || history_type == HOST_FLAPPING_HISTORY || history_type == HOST_DOWNTIME_HISTORY) {
                            if (is_authorized_for_host(temp_host, &current_authdata) == FALSE)
                                display_line = FALSE;
                            else if (display_type == DISPLAY_HOSTGROUPS && is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
                                display_line = FALSE;
                        } else {
                            temp_service = find_service(entry_host_name, entry_service_desc);
                            if (is_authorized_for_service(temp_service, &current_authdata) == FALSE)
                                display_line = FALSE;
                            else if (display_type == DISPLAY_HOSTGROUPS && is_host_member_of_hostgroup(temp_hostgroup, temp_host) == FALSE)
                                display_line = FALSE;
                            else if (display_type == DISPLAY_SERVICEGROUPS && is_service_member_of_servicegroup(temp_servicegroup, temp_service) == FALSE)
                                display_line = FALSE;
                        }
                    }
                }

                /* display the entry if we should... */
                if (display_line == TRUE) {

                    if (result_limit != 0  && (((total_entries + 1) < result_start) || (total_entries >= ((result_start + result_limit) - 1)))) {
                        total_entries++;
                        continue;
                    }

                    displayed_entries++;
                    total_entries++;

                    if (strcmp(last_message_date, current_message_date) != 0 && display_timebreaks == TRUE) {
                        printf("</DIV><BR CLEAR='all' />\n");
                        printf("<DIV CLASS='dateTimeBreak'>\n");
                        printf("<table border=0 width=95%%><tr>");
                        printf("<td width=40%%><hr width=100%%></td>");
                        printf("<td align=center CLASS='dateTimeBreak'>%s</td>", current_message_date);
                        printf("<td width=40%%><hr width=100%%></td>");
                        printf("</tr></table>\n");
                        printf("</DIV>\n");
                        printf("<BR CLEAR='all' /><DIV CLASS='logEntries'>\n");
                        strncpy(last_message_date, current_message_date, sizeof(last_message_date));
                        last_message_date[sizeof(last_message_date) - 1] = '\x0';
                    }

                    if (display_frills == TRUE)
                        printf("<img align='left' src='%s%s' alt='%s' title='%s' />", url_images_path, image, image_alt, image_alt);
                    printf("[%s] %s", date_time, html_encode(temp_entry->entry_text, FALSE));
                    if (enable_splunk_integration == TRUE) {
                        printf("&nbsp;&nbsp;&nbsp;");
                        display_splunk_generic_url(temp_entry->entry_text, 2);
                    }
                    printf("<br clear='all' />\n");
                }
            }

            /* free memory */
            free(entry_host_name);
            entry_host_name = NULL;
            free(entry_service_desc);
            entry_service_desc = NULL;
        }
    }

    free_log_entries(&entry_list);

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

    if (total_entries == 0) {
        printf("<HR>\n");
        printf("<DIV CLASS='errorMessage' style='text-align:center'>No history information was found ");
        if (display_type == DISPLAY_HOSTS)
            printf("%s", (show_all_hosts == TRUE) ? "" : "for this host ");
        else
            printf("for this service ");
        printf("in log files for selected date.</DIV>");
        printf("<script type='text/javascript'>document.getElementById('hist_page_selector').style.display='none';</script>");
    } else {
        printf("<HR>\n");
        page_num_selector(result_start, total_entries, displayed_entries);
    }

    return;
}
示例#12
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;
	}
示例#13
0
/* draw process icon */
void draw_process_icon(void) {
	host *child_host;

	if(draw_nagios_icon == FALSE)
		return;

	/* draw process icon */
	printf("\n");


	printf("Anchor{\n");
	printf("children[\n");

	printf("Transform {\n");
	printf("translation %2.2f %2.2f %2.2f\n", nagios_icon_x, nagios_icon_y, 0.0);
	printf("children [\n");

	printf("DEF ProcessNode Shape{\n");
	printf("appearance Appearance{\n");
	printf("material Material{\n");
	printf("emissiveColor 0.5 0.5 0.5\n");
	printf("diffuseColor 0.5 0.5 0.5\n");
	printf("transparency 0.2\n");
	printf("}\n");
	if(use_textures == TRUE) {
		printf("texture ImageTexture{\n");
		printf("url \"%s%s\"\n", url_logo_images_path, NAGIOS_VRML_IMAGE);
		printf("}\n");
		}
	printf("}\n");
	printf("geometry Box{\n");
	printf("size %2.2f %2.2f %2.2f\n", node_width * 3.0, node_width * 3.0, node_width * 3.0);
	printf("}\n");
	printf("}\n");

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

	printf("]\n");
	printf("description \"View Nagios Process Information\"\n");
	printf("url \"%s?type=%d\"\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
	printf("}\n");


	if(use_links == FALSE)
		return;

	/* draw links to immediate child hosts */
	for(child_host = host_list; child_host != NULL; child_host = child_host->next) {

		if(child_host->have_3d_coords == FALSE)
			continue;

		/* check authorization */
		if(is_authorized_for_host(child_host, &current_authdata) == FALSE)
			continue;

		/* draw a link to the host */
		if(is_host_immediate_child_of_host(NULL, child_host) == TRUE)
			draw_host_link(NULL, nagios_icon_x, nagios_icon_y, 0.0, child_host->x_3d, child_host->y_3d, child_host->z_3d);
		}

	return;
	}
示例#14
0
void display_notifications(void) {
    mmapfile *thefile=NULL;
    char *input=NULL;
    char *temp_buffer;
    char date_time[MAX_DATETIME_LENGTH];
    char alert_level[MAX_INPUT_BUFFER];
    char alert_level_class[MAX_INPUT_BUFFER];
    char contact_name[MAX_INPUT_BUFFER];
    char service_name[MAX_INPUT_BUFFER];
    char host_name[MAX_INPUT_BUFFER];
    char method_name[MAX_INPUT_BUFFER];
    int show_entry;
    int total_notifications;
    int notification_type=SERVICE_NOTIFICATION;
    int notification_detail_type=NOTIFICATION_SERVICE_CRITICAL;
    int odd=0;
    time_t t;
    host *temp_host;
    service *temp_service;
    int result;

    if(use_lifo==TRUE) {
        result=read_file_into_lifo(log_file_to_use);
        if(result!=LIFO_OK) {
            if(result==LIFO_ERROR_MEMORY) {
                printf("<P><DIV CLASS='warningMessage'>Not enough memory to reverse log file - displaying notifications in natural order...</DIV></P>");
            }
            else if(result==LIFO_ERROR_FILE) {
                printf("<P><DIV CLASS='errorMessage'>Error: Cannot open log file '%s' for reading!</DIV></P>",log_file_to_use);
                return;
            }
            use_lifo=FALSE;
        }
    }

    if(use_lifo==FALSE) {

        if((thefile=mmap_fopen(log_file_to_use))==NULL) {
            printf("<P><DIV CLASS='errorMessage'>Error: Cannot open log file '%s' for reading!</DIV></P>",log_file_to_use);
            return;
        }
    }

    printf("<p>\n");
    printf("<div align='center'>\n");

    printf("<table border=0 CLASS='notifications'>\n");
    printf("<tr>\n");
    printf("<th CLASS='notifications'>Host</th>\n");
    printf("<th CLASS='notifications'>Service</th>\n");
    printf("<th CLASS='notifications'>Type</th>\n");
    printf("<th CLASS='notifications'>Time</th>\n");
    printf("<th CLASS='notifications'>Contact</th>\n");
    printf("<th CLASS='notifications'>Notification Command</th>\n");
    printf("<th CLASS='notifications'>Information</th>\n");
    printf("</tr>\n");

    total_notifications=0;

    while(1) {

        free(input);

        if(use_lifo==TRUE) {
            if((input=pop_lifo())==NULL)
                break;
        }
        else {
            if((input=mmap_fgets(thefile))==NULL)
                break;
        }

        strip(input);

        /* see if this line contains the notification event string */
        if(strstr(input,HOST_NOTIFICATION_STRING)||strstr(input,SERVICE_NOTIFICATION_STRING)) {

            if(strstr(input,HOST_NOTIFICATION_STRING))
                notification_type=HOST_NOTIFICATION;
            else
                notification_type=SERVICE_NOTIFICATION;

            /* get the date/time */
            temp_buffer=(char *)strtok(input,"]");
            t=(time_t)(temp_buffer==NULL)?0L:strtoul(temp_buffer+1,NULL,10);
            get_time_string(&t,date_time,(int)sizeof(date_time),SHORT_DATE_TIME);
            strip(date_time);

            /* get the contact name */
            temp_buffer=(char *)strtok(NULL,":");
            temp_buffer=(char *)strtok(NULL,";");
            snprintf(contact_name,sizeof(contact_name),"%s",(temp_buffer==NULL)?"":temp_buffer+1);
            contact_name[sizeof(contact_name)-1]='\x0';

            /* get the host name */
            temp_buffer=(char *)strtok(NULL,";");
            snprintf(host_name,sizeof(host_name),"%s",(temp_buffer==NULL)?"":temp_buffer);
            host_name[sizeof(host_name)-1]='\x0';

            /* get the service name */
            if(notification_type==SERVICE_NOTIFICATION) {
                temp_buffer=(char *)strtok(NULL,";");
                snprintf(service_name,sizeof(service_name),"%s",(temp_buffer==NULL)?"":temp_buffer);
                service_name[sizeof(service_name)-1]='\x0';
            }

            /* get the alert level */
            temp_buffer=(char *)strtok(NULL,";");
            snprintf(alert_level,sizeof(alert_level),"%s",(temp_buffer==NULL)?"":temp_buffer);
            alert_level[sizeof(alert_level)-1]='\x0';

            if(notification_type==SERVICE_NOTIFICATION) {

                if(!strcmp(alert_level,"CRITICAL")) {
                    notification_detail_type=NOTIFICATION_SERVICE_CRITICAL;
                    strcpy(alert_level_class,"CRITICAL");
                }
                else if(!strcmp(alert_level,"WARNING")) {
                    notification_detail_type=NOTIFICATION_SERVICE_WARNING;
                    strcpy(alert_level_class,"WARNING");
                }
                else if(!strcmp(alert_level,"RECOVERY") || !strcmp(alert_level,"OK")) {
                    strcpy(alert_level,"OK");
                    notification_detail_type=NOTIFICATION_SERVICE_RECOVERY;
                    strcpy(alert_level_class,"OK");
                }
                else if(strstr(alert_level,"CUSTOM (")) {
                    notification_detail_type=NOTIFICATION_SERVICE_CUSTOM;
                    strcpy(alert_level_class,"CUSTOM");
                }
                else if(strstr(alert_level,"ACKNOWLEDGEMENT (")) {
                    notification_detail_type=NOTIFICATION_SERVICE_ACK;
                    strcpy(alert_level_class,"ACKNOWLEDGEMENT");
                }
                else if(strstr(alert_level,"FLAPPINGSTART (")) {
                    strcpy(alert_level,"FLAPPING START");
                    notification_detail_type=NOTIFICATION_SERVICE_FLAP;
                    strcpy(alert_level_class,"UNKNOWN");
                }
                else if(strstr(alert_level,"FLAPPINGSTOP (")) {
                    strcpy(alert_level,"FLAPPING STOP");
                    notification_detail_type=NOTIFICATION_SERVICE_FLAP;
                    strcpy(alert_level_class,"UNKNOWN");
                }
                else {
                    strcpy(alert_level,"UNKNOWN");
                    notification_detail_type=NOTIFICATION_SERVICE_UNKNOWN;
                    strcpy(alert_level_class,"UNKNOWN");
                }
            }

            else {

                if(!strcmp(alert_level,"DOWN")) {
                    strncpy(alert_level,"HOST DOWN",sizeof(alert_level));
                    strcpy(alert_level_class,"HOSTDOWN");
                    notification_detail_type=NOTIFICATION_HOST_DOWN;
                }
                else if(!strcmp(alert_level,"UNREACHABLE")) {
                    strncpy(alert_level,"HOST UNREACHABLE",sizeof(alert_level));
                    strcpy(alert_level_class,"HOSTUNREACHABLE");
                    notification_detail_type=NOTIFICATION_HOST_UNREACHABLE;
                }
                else if(!strcmp(alert_level,"RECOVERY") || !strcmp(alert_level,"UP")) {
                    strncpy(alert_level,"HOST UP",sizeof(alert_level));
                    strcpy(alert_level_class,"HOSTUP");
                    notification_detail_type=NOTIFICATION_HOST_RECOVERY;
                }
                else if(strstr(alert_level,"CUSTOM (")) {
                    strcpy(alert_level_class,"HOSTCUSTOM");
                    notification_detail_type=NOTIFICATION_HOST_CUSTOM;
                }
                else if(strstr(alert_level,"ACKNOWLEDGEMENT (")) {
                    strcpy(alert_level_class,"HOSTACKNOWLEDGEMENT");
                    notification_detail_type=NOTIFICATION_HOST_ACK;
                }
                else if(strstr(alert_level,"FLAPPINGSTART (")) {
                    strcpy(alert_level,"FLAPPING START");
                    strcpy(alert_level_class,"UNKNOWN");
                    notification_detail_type=NOTIFICATION_HOST_FLAP;
                }
                else if(strstr(alert_level,"FLAPPINGSTOP (")) {
                    strcpy(alert_level,"FLAPPING STOP");
                    strcpy(alert_level_class,"UNKNOWN");
                    notification_detail_type=NOTIFICATION_HOST_FLAP;
                }
            }

            /* get the method name */
            temp_buffer=(char *)strtok(NULL,";");
            snprintf(method_name,sizeof(method_name),"%s",(temp_buffer==NULL)?"":temp_buffer);
            method_name[sizeof(method_name)-1]='\x0';

            /* move to the informational message */
            temp_buffer=strtok(NULL,";");

            show_entry=FALSE;

            /* if we're searching by contact, filter out unwanted contact */
            if(query_type==FIND_CONTACT) {
                if(find_all==TRUE)
                    show_entry=TRUE;
                else if(!strcmp(query_contact_name,contact_name))
                    show_entry=TRUE;
            }

            else if(query_type==FIND_HOST) {
                if(find_all==TRUE)
                    show_entry=TRUE;
                else if(!strcmp(query_host_name,host_name))
                    show_entry=TRUE;
            }

            else if(query_type==FIND_SERVICE) {
                if(!strcmp(query_host_name,host_name) && !strcmp(query_svc_description,service_name))
                    show_entry=TRUE;
            }

            if(show_entry==TRUE) {
                if(notification_options==NOTIFICATION_ALL)
                    show_entry=TRUE;
                else if(notification_options==NOTIFICATION_HOST_ALL && notification_type==HOST_NOTIFICATION)
                    show_entry=TRUE;
                else if(notification_options==NOTIFICATION_SERVICE_ALL && notification_type==SERVICE_NOTIFICATION)
                    show_entry=TRUE;
                else if(notification_detail_type & notification_options)
                    show_entry=TRUE;
                else
                    show_entry=FALSE;
            }

            /* make sure user has authorization to view this notification */
            if(notification_type==HOST_NOTIFICATION) {
                temp_host=find_host(host_name);
                if(is_authorized_for_host(temp_host,&current_authdata)==FALSE)
                    show_entry=FALSE;
            }
            else {
                temp_service=find_service(host_name,service_name);
                if(is_authorized_for_service(temp_service,&current_authdata)==FALSE)
                    show_entry=FALSE;
            }

            if(show_entry==TRUE) {

                total_notifications++;

                if(odd) {
                    odd=0;
                    printf("<tr CLASS='notificationsOdd'>\n");
                }
                else {
                    odd=1;
                    printf("<tr CLASS='notificationsEven'>\n");
                }
                printf("<td CLASS='notifications%s'><a href='%s?type=%d&host=%s'>%s</a></td>\n",(odd)?"Even":"Odd",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(host_name),host_name);
                if(notification_type==SERVICE_NOTIFICATION) {
                    printf("<td CLASS='notifications%s'><a href='%s?type=%d&host=%s",(odd)?"Even":"Odd",EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(host_name));
                    printf("&service=%s'>%s</a></td>\n",url_encode(service_name),service_name);
                }
                else
                    printf("<td CLASS='notifications%s'>N/A</td>\n",(odd)?"Even":"Odd");
                printf("<td CLASS='notifications%s'>%s</td>\n",alert_level_class,alert_level);
                printf("<td CLASS='notifications%s'>%s</td>\n",(odd)?"Even":"Odd",date_time);
                printf("<td CLASS='notifications%s'><a href='%s?type=contacts#%s'>%s</a></td>\n",(odd)?"Even":"Odd",CONFIG_CGI,url_encode(contact_name),contact_name);
                printf("<td CLASS='notifications%s'><a href='%s?type=commands#%s'>%s</a></td>\n",(odd)?"Even":"Odd",CONFIG_CGI,url_encode(method_name),method_name);
                printf("<td CLASS='notifications%s'>%s</td>\n",(odd)?"Even":"Odd",html_encode(temp_buffer,FALSE));
                printf("</tr>\n");
            }
        }
    }


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

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

    if(total_notifications==0) {
        printf("<P><DIV CLASS='errorMessage'>No notifications have been recorded");
        if(find_all==FALSE) {
            if(query_type==FIND_SERVICE)
                printf(" for this service");
            else if(query_type==FIND_CONTACT)
                printf(" for this contact");
            else
                printf(" for this host");
        }
        printf(" in %s log file</DIV></P>",(log_archive==0)?"the current":"this archived");
    }

    free(input);

    if(use_lifo==TRUE)
        free_lifo_memory();
    else
        mmap_fclose(thefile);

    return;
}