Пример #1
0
/* handle process events */
static int handle_process_events( int event_type, void *data ) {
    int x=0;
    struct nebstruct_process_struct *ps;

    gm_log( GM_LOG_TRACE, "handle_process_events(%i, data)\n", event_type );

    ps = ( struct nebstruct_process_struct * )data;
    if ( ps->type == NEBTYPE_PROCESS_EVENTLOOPSTART ) {

        register_neb_callbacks();
        start_threads();
        send_now = TRUE;

        /* verify names of supplied groups
         * this cannot be done befor naemon has finished reading his config
         * verify local servicegroups names
         */
        while ( mod_gm_opt->local_servicegroups_list[x] != NULL ) {
            servicegroup * temp_servicegroup = find_servicegroup( mod_gm_opt->local_servicegroups_list[x] );
            if( temp_servicegroup == NULL ) {
                gm_log( GM_LOG_INFO, "Warning: servicegroup '%s' does not exist, possible typo?\n", mod_gm_opt->local_servicegroups_list[x] );
            }
            x++;
        }

        /* verify local hostgroup names */
        x = 0;
        while ( mod_gm_opt->local_hostgroups_list[x] != NULL ) {
            hostgroup * temp_hostgroup = find_hostgroup( mod_gm_opt->local_hostgroups_list[x] );
            if( temp_hostgroup == NULL ) {
                gm_log( GM_LOG_INFO, "Warning: hostgroup '%s' does not exist, possible typo?\n", mod_gm_opt->local_hostgroups_list[x] );
            }
            x++;
        }

        /* verify servicegroups names */
        x = 0;
        while ( mod_gm_opt->servicegroups_list[x] != NULL ) {
            servicegroup * temp_servicegroup = find_servicegroup( mod_gm_opt->servicegroups_list[x] );
            if( temp_servicegroup == NULL ) {
                gm_log( GM_LOG_INFO, "Warning: servicegroup '%s' does not exist, possible typo?\n", mod_gm_opt->servicegroups_list[x] );
            }
            x++;
        }

        /* verify hostgroup names */
        x = 0;
        while ( mod_gm_opt->hostgroups_list[x] != NULL ) {
            hostgroup * temp_hostgroup = find_hostgroup( mod_gm_opt->hostgroups_list[x] );
            if( temp_hostgroup == NULL ) {
                gm_log( GM_LOG_INFO, "Warning: hostgroup '%s' does not exist, possible typo?\n", mod_gm_opt->hostgroups_list[x] );
            }
            x++;
        }
    }

    return NEB_OK;
}
Пример #2
0
int main(int argc, char **argv) {
    int result;
    int error = FALSE;
    char *buffer = NULL;
    int display_license = FALSE;
    int display_help = FALSE;
    int c = 0;
    struct tm *tm;
    time_t now;
    char datestring[256];
    host *temp_host = NULL;
    hostgroup *temp_hostgroup = NULL;
    hostsmember *temp_member = NULL;

    plan(4);

    /* reset program variables */
    reset_variables();

    printf("Reading configuration data...\n");

    config_file = strdup("smallconfig/icinga.cfg");
    /* read in the configuration files (main config file, resource and object config files) */
    result = read_main_config_file(config_file);
    ok(result == OK, "Read main configuration file okay - if fails, use icinga -v to check");

    result = read_all_object_data(config_file);
    ok(result == OK, "Read all object config files");

    result = pre_flight_check();
    ok(result == OK, "Preflight check okay");

    for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
        c++;
        //printf("Hostgroup=%s\n", temp_hostgroup->group_name);
    }
    ok(c == 2, "Found all hostgroups");

    temp_hostgroup = find_hostgroup("hostgroup1");
    for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
        //printf("host pointer=%d\n", temp_member->host_ptr);
    }

    temp_hostgroup = find_hostgroup("hostgroup2");
    for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
        //printf("host pointer=%d\n", temp_member->host_ptr);
    }

    cleanup();

    my_free(config_file);

    return exit_status();
}
Пример #3
0
static int map_hostgroup_hosts(const char *hg_name)
{
	struct hostgroup *hg;
	struct hostsmember *m;

	if (!(hg = find_hostgroup(hg_name))) {
		printf("Failed to locate hostgroup '%s'\n", hg_name);
		return -1;
	}
	for (m = hg->members; m; m = m->next) {
		struct host *h = m->host_ptr;
		bitmap_set(map.hosts, h->id);
	}
	return 0;
}
Пример #4
0
static int nsplit_cache_stuff(const char *orig_groups)
{
	int ngroups = 0;
	char *groups, *comma, *grp;

	if (!orig_groups)
		return EXIT_FAILURE;

	grp = groups = strdup(orig_groups);
	for (grp = groups; grp != NULL; grp = comma ? comma + 1 : NULL) {
		if ((comma = strchr(grp, ',')))
			* comma = 0;
		ngroups++;
		if (map_hostgroup_hosts(grp) < 0)
			return -1;

		/* restore the string so we can iterate it once more */
		if (comma)
			*comma = ',';
	} while (grp);

	/* from here on out, all hosts are tagged. */
	timing_point("%lu hosts mapped in %d hostgroups\n",
	             bitmap_count_set_bits(map.hosts), ngroups);
	for (grp = groups; grp != NULL; grp = comma ? comma + 1 : NULL) {
		struct hostgroup *hg;
		struct hostsmember *m;
		if ((comma = strchr(grp, ',')))
			* comma = 0;
		hg = find_hostgroup(grp);
		cached.hostgroups++;
		fcache_hostgroup(fp, hg);
		bitmap_set(map.hostgroups, hg->id);
		for (m = hg->members; m; m = m->next) {
			nsplit_cache_host(m->host_ptr);
		}
	} while (grp);

	return 0;
}
Пример #5
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;
}
Пример #6
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;
}
Пример #7
0
/* return the prefered target function for our worker */
static void set_target_queue( host *hst, service *svc ) {
    int x=0;
    customvariablesmember *temp_customvariablesmember = NULL;

    /* empty our target */
    target_queue[0] = '\x0';

    /* grab target queue from custom variable */
    if( mod_gm_opt->queue_cust_var ) {
        if( svc ) {
            temp_customvariablesmember = svc->custom_variables;
            for(; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
                if(!strcmp(mod_gm_opt->queue_cust_var, temp_customvariablesmember->variable_name)) {
                    if(!strcmp(temp_customvariablesmember->variable_value, "local")) {
                        gm_log( GM_LOG_TRACE, "bypassing local check from service custom variable\n" );
                        return;
                    }
                    gm_log( GM_LOG_TRACE, "got target queue from service custom variable: %s\n", temp_customvariablesmember->variable_value );
                    snprintf( target_queue, GM_BUFFERSIZE-1, "%s", temp_customvariablesmember->variable_value );
                    return;
                }
            }
        }

        /* search in host custom variables */
        temp_customvariablesmember = hst->custom_variables;
        for(; temp_customvariablesmember != NULL; temp_customvariablesmember = temp_customvariablesmember->next) {
            if(!strcmp(mod_gm_opt->queue_cust_var, temp_customvariablesmember->variable_name)) {
                if(!strcmp(temp_customvariablesmember->variable_value, "local")) {
                    gm_log( GM_LOG_TRACE, "bypassing local check from host custom variable\n" );
                    return;
                }
                gm_log( GM_LOG_TRACE, "got target queue from host custom variable: %s\n", temp_customvariablesmember->variable_value );
                snprintf( target_queue, GM_BUFFERSIZE-1, "%s", temp_customvariablesmember->variable_value );
                return;
            }
        }
    }

    /* look for matching local servicegroups */
    if ( svc ) {
        while ( mod_gm_opt->local_servicegroups_list[x] != NULL ) {
            servicegroup * temp_servicegroup = find_servicegroup( mod_gm_opt->local_servicegroups_list[x] );
            if ( is_service_member_of_servicegroup( temp_servicegroup,svc )==TRUE ) {
                gm_log( GM_LOG_TRACE, "service is member of local servicegroup: %s\n", mod_gm_opt->local_servicegroups_list[x] );
                return;
            }
            x++;
        }
    }

    /* look for matching local hostgroups */
    x = 0;
    while ( mod_gm_opt->local_hostgroups_list[x] != NULL ) {
        hostgroup * temp_hostgroup = find_hostgroup( mod_gm_opt->local_hostgroups_list[x] );
        if ( is_host_member_of_hostgroup( temp_hostgroup,hst )==TRUE ) {
            gm_log( GM_LOG_TRACE, "server is member of local hostgroup: %s\n", mod_gm_opt->local_hostgroups_list[x] );
            return;
        }
        x++;
    }

    /* look for matching servicegroups */
    x = 0;
    if ( svc ) {
        while ( mod_gm_opt->servicegroups_list[x] != NULL ) {
            servicegroup * temp_servicegroup = find_servicegroup( mod_gm_opt->servicegroups_list[x] );
            if ( is_service_member_of_servicegroup( temp_servicegroup,svc )==TRUE ) {
                gm_log( GM_LOG_TRACE, "service is member of servicegroup: %s\n", mod_gm_opt->servicegroups_list[x] );
                snprintf( target_queue, GM_BUFFERSIZE-1, "servicegroup_%s", mod_gm_opt->servicegroups_list[x] );
                return;
            }
            x++;
        }
    }

    /* look for matching hostgroups */
    x = 0;
    while ( mod_gm_opt->hostgroups_list[x] != NULL ) {
        hostgroup * temp_hostgroup = find_hostgroup( mod_gm_opt->hostgroups_list[x] );
        if ( is_host_member_of_hostgroup( temp_hostgroup,hst )==TRUE ) {
            gm_log( GM_LOG_TRACE, "server is member of hostgroup: %s\n", mod_gm_opt->hostgroups_list[x] );
            snprintf( target_queue, GM_BUFFERSIZE-1, "hostgroup_%s", mod_gm_opt->hostgroups_list[x] );
            return;
        }
        x++;
    }

    if ( svc ) {
        /* pass into the general service queue */
        if ( mod_gm_opt->services == GM_ENABLED && svc ) {
            snprintf( target_queue, GM_BUFFERSIZE-1, "service" );
            return;
        }
    }
    else {
        /* pass into the general host queue */
        if ( mod_gm_opt->hosts == GM_ENABLED ) {
            snprintf( target_queue, GM_BUFFERSIZE-1, "host" );
            return;
        }
    }

    return;
}
Пример #8
0
int main(int argc, char **argv) {
	int result;
	int error = FALSE;
	char *buffer = NULL;
	int display_license = FALSE;
	int display_help = FALSE;
	int c = 0;
	struct tm *tm;
	time_t now;
	char datestring[256];
	host *temp_host = NULL;
	hostgroup *temp_hostgroup = NULL;
	hostsmember *temp_member = NULL;

	plan_tests(14);

	/* reset program variables */
	reset_variables();

	printf("Reading configuration data...\n");

	config_file = strdup("smallconfig/nagios.cfg");
	/* read in the configuration files (main config file, resource and object config files) */
	result = read_main_config_file(config_file);
	ok(result == OK, "Read main configuration file okay - if fails, use nagios -v to check");

	result = read_all_object_data(config_file);
	ok(result == OK, "Read all object config files");

	result = pre_flight_check();
	ok(result == OK, "Preflight check okay");

	for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
		c++;
		//printf("Hostgroup=%s\n", temp_hostgroup->group_name);
		}
	ok(c == 2, "Found all hostgroups");

	temp_hostgroup = find_hostgroup("hostgroup1");
	for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
		//printf("host pointer=%d\n", temp_member->host_ptr);
		}

	temp_hostgroup = find_hostgroup("hostgroup2");
	for(temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
		//printf("host pointer=%d\n", temp_member->host_ptr);
		}

	temp_host = find_host("host1");
	ok(temp_host->current_state == 0, "State is assumed OK on initial load");

	xrddefault_retention_file = strdup("smallconfig/retention.dat");
	ok(xrddefault_read_state_information() == OK, "Reading retention data");

	ok(temp_host->current_state == 1, "State changed due to retention file settings");

	ok(find_host_comment(418) != NULL, "Found host comment id 418");
	ok(find_service_comment(419) != NULL, "Found service comment id 419");
	ok(find_service_comment(420) == NULL, "Did not find service comment id 420 as not persistent");
	ok(find_host_comment(1234567888) == NULL, "No such host comment");

	ok(find_host_downtime(1102) != NULL, "Found host downtime id 1102");
	ok(find_service_downtime(1110) != NULL, "Found service downtime 1110");
	ok(find_host_downtime(1234567888) == NULL, "No such host downtime");

	cleanup();

	my_free(config_file);

	return exit_status();
	}
Пример #9
0
int main(int argc, char **argv)
{
	int result;
	int c = 0;
	struct host *host1, *host2;
	hostgroup *temp_hostgroup = NULL;
	hostsmember *temp_member = NULL;

	plan_tests(19);

	/* reset program variables */
	reset_variables();

	/*
	 * avoid updating the checked-in retention data
	 * file when testing
	 */
	retain_state_information = FALSE;

	printf("Reading configuration data...\n");

	config_file = strdup(get_default_config_file());
	config_file_dir = nspath_absolute_dirname(config_file, NULL);
	/* read in the configuration files (main config file, resource and object config files) */
	result = read_main_config_file(config_file);
	ok(result == OK, "Read main configuration file okay - if fails, use nagios -v to check");

	result = read_all_object_data(config_file);
	ok(result == OK, "Read all object config files");

	result = pre_flight_check();
	ok(result == OK, "Preflight check okay");

	for (temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
		c++;
		//printf("Hostgroup=%s\n", temp_hostgroup->group_name);
	}
	ok(c == 2, "Found all hostgroups");

	temp_hostgroup = find_hostgroup("hostgroup1");
	for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
		//printf("host pointer=%d\n", temp_member->host_ptr);
	}

	temp_hostgroup = find_hostgroup("hostgroup2");
	for (temp_member = temp_hostgroup->members; temp_member != NULL; temp_member = temp_member->next) {
		//printf("host pointer=%d\n", temp_member->host_ptr);
	}

	host1 = find_host("host1");
	host2 = find_host("host2");
	ok(host1 != NULL && host2 != NULL, "find_host() should work");
	ok(host1->current_state == 0, "State is assumed OK on initial load");
	ok(host1->notifications_enabled == 1, "host1 notifications_enabled set from config");
	ok(host2->notifications_enabled == 1, "host2 notifications_enabled set from config");

	initialize_retention_data(NULL);
	initialize_downtime_data();
	init_event_queue();
	ok(xrddefault_read_state_information() == OK, "Reading retention data");

	ok(host1->current_state == 1, "State changed due to retention file settings");
	ok(host1->notifications_enabled == 1, "Config change should override notifications_enabled for host1");
	ok(host2->notifications_enabled == 0, "Retention data should win on no config change");

	ok(find_host_comment(418) != NULL, "Found host comment id 418");
	ok(find_service_comment(419) != NULL, "Found service comment id 419");
	ok(find_service_comment(420) == NULL, "Did not find service comment id 420 as not persistent");
	ok(find_host_comment(1234567888) == NULL, "No such host comment");

	ok(find_host_downtime(1102) != NULL, "Found host downtime id 1102");
	ok(find_service_downtime(1110) != NULL, "Found service downtime 1110");
	ok(find_host_downtime(1234567888) == NULL, "No such host downtime");

	cleanup();

	my_free(config_file);

	return exit_status();
}