nagios/ 0000755 0001750 0001750 00000000000 12210155146 012603 5 ustar formorer formorer nagios/cgi/ 0000755 0001750 0001750 00000000000 12210155146 013345 5 ustar formorer formorer nagios/cgi/outages.c 0000644 0001750 0001750 00000050202 12210155146 015157 0 ustar formorer formorer /************************************************************************** * * OUTAGES.C - Nagios Network Outages CGI * * Copyright (c) 1999-2008 Ethan Galstad (egalstad@nagios.org) * Last Modified: 01-08-2008 * * License: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *************************************************************************/ #include "../include/config.h" #include "../include/common.h" #include "../include/objects.h" #include "../include/comments.h" #include "../include/statusdata.h" #include "../include/cgiutils.h" #include "../include/getcgi.h" #include "../include/cgiauth.h" extern int refresh_rate; extern time_t program_start; extern host *host_list; extern service *service_list; extern hoststatus *hoststatus_list; extern servicestatus *servicestatus_list; extern char main_config_file[MAX_FILENAME_LENGTH]; extern char url_html_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_logo_images_path[MAX_FILENAME_LENGTH]; extern char log_file[MAX_FILENAME_LENGTH]; /* HOSTOUTAGE structure */ typedef struct hostoutage_struct { host *hst; int severity; int affected_child_hosts; int affected_child_services; unsigned long monitored_time; unsigned long time_up; float percent_time_up; unsigned long time_down; float percent_time_down; unsigned long time_unreachable; float percent_time_unreachable; struct hostoutage_struct *next; } hostoutage; /* HOSTOUTAGESORT structure */ typedef struct hostoutagesort_struct { hostoutage *outage; struct hostoutagesort_struct *next; } hostoutagesort; void document_header(int); void document_footer(void); int process_cgivars(void); void display_network_outages(void); void find_hosts_causing_outages(void); void calculate_outage_effects(void); void calculate_outage_effect_of_host(host *, int *, int *); int is_route_to_host_blocked(host *); int number_of_host_services(host *); void add_hostoutage(host *); void sort_hostoutages(void); void free_hostoutage_list(void); void free_hostoutagesort_list(void); authdata current_authdata; hostoutage *hostoutage_list = NULL; hostoutagesort *hostoutagesort_list = NULL; int service_severity_divisor = 4; /* default = services are 1/4 as important as hosts */ int embedded = FALSE; int display_header = TRUE; int main(void) { int result = OK; /* get the arguments passed in the URL */ process_cgivars(); /* reset internal variables */ reset_cgi_vars(); /* read the CGI configuration file */ result = read_cgi_config_file(get_cgi_config_location()); if(result == ERROR) { document_header(FALSE); cgi_config_file_error(get_cgi_config_location()); document_footer(); return ERROR; } /* read the main configuration file */ result = read_main_config_file(main_config_file); if(result == ERROR) { document_header(FALSE); main_config_file_error(main_config_file); document_footer(); return ERROR; } /* read all object configuration data */ result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA); if(result == ERROR) { document_header(FALSE); object_data_error(); document_footer(); return ERROR; } /* read all status data */ result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA); if(result == ERROR) { document_header(FALSE); status_data_error(); document_footer(); free_memory(); return ERROR; } document_header(TRUE); /* get authentication information */ get_authentication_information(¤t_authdata); if(display_header == TRUE) { /* begin top table */ printf("
\n"); display_info_table("Network Outages", TRUE, ¤t_authdata); printf(" | \n"); /* middle column of top row */ printf("\n"); printf(" | \n"); /* right column of top row */ printf("\n"); /* display context-sensitive help */ display_context_help(CONTEXTHELP_OUTAGES); printf(" | \n"); /* end of top table */ printf("
Severity | Host | State | Notes | State Duration | # Hosts Affected | # Services Affected | Actions | \n"); printf("|
---|---|---|---|---|---|---|---|---|
%d | \n", bg_class, temp_hostoutage->severity); printf("%s | \n", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_hostoutage->hst->name), temp_hostoutage->hst->name); printf("%s | \n", status, status); total_comments = number_of_host_comments(temp_hostoutage->hst->name); if(total_comments > 0) { snprintf(temp_buffer, sizeof(temp_buffer) - 1, "This host has %d comment%s associated with it", total_comments, (total_comments == 1) ? "" : "s"); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; printf("N/A | \n", bg_class); current_time = time(NULL); if(temp_hoststatus->last_state_change == (time_t)0) t = current_time - program_start; else t = current_time - temp_hoststatus->last_state_change; get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds); snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : ""); state_duration[sizeof(state_duration) - 1] = '\x0'; printf("%s | \n", bg_class, state_duration); printf("%d | \n", bg_class, temp_hostoutage->affected_child_hosts); printf("%d | \n", bg_class, temp_hostoutage->affected_child_services); printf("", bg_class);
printf(" | \n");
printf("
Error: Could not open CGI configuration file '%s' for reading!
\n", get_cgi_config_location()); document_footer(); return ERROR; } /* read the main configuration file */ result = read_main_config_file(main_config_file); if(result == ERROR) { printf("Error: Could not open main configuration file '%s' for reading!
\n", main_config_file); document_footer(); return ERROR; } /* read all object configuration data */ result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA); if(result == ERROR) { printf("Error: Could not read some or all object configuration data!
\n"); document_footer(); return ERROR; } /* read all status data */ result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA); if(result == ERROR) { printf("Error: Could not read host and service status information!
\n"); document_footer(); free_memory(); return ERROR; } /* get authentication information */ get_authentication_information(¤t_authdata); /* decide what to display to the user */ if(display_type == DISPLAY_HOST && host_style == DISPLAY_HOST_SERVICES) display_host_services(); else if(display_type == DISPLAY_HOST) display_host(); else if(display_type == DISPLAY_SERVICE) display_service(); else if(display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_OVERVIEW) display_hostgroup_overview(); else if(display_type == DISPLAY_HOSTGROUP && hostgroup_style == DISPLAY_HOSTGROUP_SUMMARY) display_hostgroup_summary(); else if(display_type == DISPLAY_PING) display_ping(); else if(display_type == DISPLAY_TRACEROUTE) display_traceroute(); else if(display_type == DISPLAY_QUICKSTATS) display_quick_stats(); else if(display_type == DISPLAY_PROCESS) display_process(); else if(display_type == DISPLAY_ALL_PROBLEMS || display_type == DISPLAY_UNHANDLED_PROBLEMS) display_problems(); else display_index(); document_footer(); /* free all allocated memory */ free_memory(); return OK; } void document_header(void) { char date_time[MAX_DATETIME_LENGTH]; time_t expire_time; time_t current_time; time(¤t_time); printf("Cache-Control: no-store\r\n"); printf("Pragma: no-cache\r\n"); get_time_string(¤t_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME); printf("Last-Modified: %s\r\n", date_time); expire_time = (time_t)0L; get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME); printf("Expires: %s\r\n", date_time); printf("Content-type: text/vnd.wap.wml\r\n\r\n"); printf("\n"); printf("\n"); printf("Invalid host name/ip
\n"); result = ERROR; } if(strcmp(traceroute_address, "") && !is_valid_hostip(traceroute_address)) { printf("Invalid host name/ip
\n"); result = ERROR; } return result; } int is_valid_hostip(char *hostip) { char *valid_domain_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-"; if(strcmp(hostip, "") && strlen(hostip) == strspn(hostip, valid_domain_chars) && hostip[0] != '-' && hostip[strlen(hostip) - 1] != '-') return TRUE; return FALSE; } /* main intro screen */ void display_index(void) { /**** MAIN MENU SCREEN (CARD 1) ****/ printf("\n");
printf("Nagios
WAP Interface
\n");
printf("
\n", STATUSWML_CGI);
printf("
\n", STATUSWML_CGI);
printf("
\n", STATUSWML_CGI);
printf("
\n", STATUSWML_CGI);
printf("
\n", STATUSWML_CGI);
printf("
\n", STATUSWML_CGI);
printf("
\n");
printf("
\n");
printf("
\n");
printf("Network Tools:
\n");
printf("
\n", STATUSWML_CGI);
printf("
\n", STATUSWML_CGI);
printf("
\n");
printf("
\n");
printf("
\n");
printf("About
\n");
printf("
\n");
printf("Nagios %s
WAP Interface
\n", PROGRAM_VERSION);
printf("Copyright (C) 2001 Ethan Galstad
\n");
printf("egalstad@nagios.org
\n");
printf("License: GPL
\n");
printf("Based in part on features found in AskAround's Wireless Network Tools
\n");
printf("www.askaround.com
\n");
printf("
\n");
printf("View Host
\n");
printf("
\n");
printf("Host Name:
\n");
printf("\n");
printf("
\n");
printf("View Hostgroup
\n");
printf("
\n");
printf("Hostgroup Name:
\n");
printf("\n");
printf("
\n");
printf("Process Info
\n");
/* check authorization */
if(is_authorized_for_system_information(¤t_authdata) == FALSE) {
printf("Error: Not authorized for process info!\n");
printf("
\n");
printf("Process Commands
\n");
if(enable_notifications == FALSE)
printf("
\n", COMMAND_CGI, CMD_ENABLE_NOTIFICATIONS, CMDMODE_COMMIT);
else
printf("
\n", COMMAND_CGI, CMD_DISABLE_NOTIFICATIONS, CMDMODE_COMMIT);
if(execute_service_checks == FALSE)
printf("
\n", COMMAND_CGI, CMD_START_EXECUTING_SVC_CHECKS, CMDMODE_COMMIT);
else
printf("
\n", COMMAND_CGI, CMD_STOP_EXECUTING_SVC_CHECKS, CMDMODE_COMMIT);
printf("
\n");
printf("Quick Stats
\n");
printf("
\n");
printf("Host Totals:
\n");
printf("%d UP
\n", hosts_up);
printf("%d DOWN
\n", hosts_down);
printf("%d UNREACHABLE
\n", hosts_unreachable);
printf("%d PENDING
\n", hosts_pending);
printf("
\n");
printf("Service Totals:
\n");
printf("%d OK
\n", services_ok);
printf("%d WARNING
\n", services_warning);
printf("%d UNKNOWN
\n", services_unknown);
printf("%d CRITICAL
\n", services_critical);
printf("%d PENDING
\n", services_pending);
printf("
\n");
printf("
\n", STATUSWML_CGI, escape_string(hostgroup_name));
/* check all hostgroups */
for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
if(show_all_hostgroups == FALSE && strcmp(temp_hostgroup->group_name, hostgroup_name))
continue;
if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
continue;
printf("%s\n", temp_hostgroup->alias);
printf("
%s |
\n");
printf("
\n", STATUSWML_CGI, escape_string(hostgroup_name));
/* check all hostgroups */
for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
if(show_all_hostgroups == FALSE && strcmp(temp_hostgroup->group_name, hostgroup_name))
continue;
if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == FALSE)
continue;
printf("
Hosts: | "); found = 0; if(hosts_unreachable > 0) { printf("%d UNR", hosts_unreachable); found = 1; } if(hosts_down > 0) { printf("%s%d DWN", (found == 1) ? ", " : "", hosts_down); found = 1; } if(hosts_pending > 0) { printf("%s%d PND", (found == 1) ? ", " : "", hosts_pending); found = 1; } printf("%s%d UP", (found == 1) ? ", " : "", hosts_up); printf(" |
Services: | "); found = 0; if(services_critical > 0) { printf("%d CRI", services_critical); found = 1; } if(services_warning > 0) { printf("%s%d WRN", (found == 1) ? ", " : "", services_warning); found = 1; } if(services_unknown > 0) { printf("%s%d UNK", (found == 1) ? ", " : "", services_unknown); found = 1; } if(services_pending > 0) { printf("%s%d PND", (found == 1) ? ", " : "", services_pending); found = 1; } printf("%s%d OK", (found == 1) ? ", " : "", services_ok); printf(" |
\n");
printf("Host '%s'
\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("Error: Could not find host!\n");
printf("
Status: | "); 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(" |
Info: | %s |
Last Check: | %s |
Duration: | %s |
Properties: | "); 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(" |
\n");
printf("Host Commands
\n");
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_CHECK, CMDMODE_COMMIT);
else
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_CHECK, CMDMODE_COMMIT);
if(temp_hoststatus->notifications_enabled == FALSE)
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_NOTIFICATIONS, CMDMODE_COMMIT);
else
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_NOTIFICATIONS, CMDMODE_COMMIT);
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_SVC_CHECKS, CMDMODE_COMMIT);
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_SVC_CHECKS, CMDMODE_COMMIT);
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_ENABLE_HOST_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
printf("
\n", COMMAND_CGI, escape_string(host_name), CMD_DISABLE_HOST_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
printf("
\n");
printf("Acknowledge Problem
\n");
printf("
\n");
printf("Your Name:
\n");
printf("
\n", ((use_ssl_authentication) ? (getenv("SSL_CLIENT_S_DN_CN")) : (getenv("REMOTE_USER"))));
printf("Comment:
\n");
printf("\n");
printf("
\n");
printf("Host
\n", host_name, STATUSWML_CGI, escape_string(host_name));
printf("
%s |
\n");
printf("Service '%s' on host '%s'
\n", service_desc, host_name);
/* find the service */
temp_service = find_service(host_name, service_desc);
temp_servicestatus = find_servicestatus(host_name, service_desc);
if(temp_service == NULL || temp_servicestatus == NULL) {
printf("Error: Could not find service!\n");
printf("
Status: | "); if(temp_servicestatus->status == SERVICE_OK) printf("OK"); else if(temp_servicestatus->status == SERVICE_PENDING) printf("PENDING"); else if(temp_servicestatus->status == SERVICE_WARNING) printf("WARNING"); else if(temp_servicestatus->status == SERVICE_UNKNOWN) printf("UNKNOWN"); else if(temp_servicestatus->status == SERVICE_CRITICAL) printf("CRITICAL"); else printf("?"); printf(" |
Info: | %s |
Last Check: | %s |
Duration: | %s |
Properties: | "); found = 0; if(temp_servicestatus->checks_enabled == FALSE) { printf("%sChecks disabled", (found == 1) ? ", " : ""); found = 1; } if(temp_servicestatus->notifications_enabled == FALSE) { printf("%sNotifications disabled", (found == 1) ? ", " : ""); found = 1; } if(temp_servicestatus->problem_has_been_acknowledged == TRUE) { printf("%sProblem acknowledged", (found == 1) ? ", " : ""); found = 1; } if(temp_servicestatus->scheduled_downtime_depth > 0) { printf("%sIn scheduled downtime", (found == 1) ? ", " : ""); found = 1; } if(found == 0) printf("N/A"); printf(" |
\n");
printf("Service Commands
\n");
if(temp_servicestatus->status != SERVICE_OK && temp_servicestatus->status != SERVICE_PENDING)
printf("
\n", escape_string(service_desc), CMD_ENABLE_SVC_CHECK, CMDMODE_COMMIT);
}
else {
printf("
\n", escape_string(service_desc), CMD_DISABLE_SVC_CHECK, CMDMODE_COMMIT);
printf("
\n", escape_string(service_desc), (unsigned long)current_time, CMD_SCHEDULE_SVC_CHECK, CMDMODE_COMMIT);
}
if(temp_servicestatus->notifications_enabled == FALSE) {
printf("
\n", escape_string(service_desc), CMD_ENABLE_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
}
else {
printf("
\n", escape_string(service_desc), CMD_DISABLE_SVC_NOTIFICATIONS, CMDMODE_COMMIT);
}
printf("
\n");
printf("Acknowledge Problem
\n");
printf("
\n");
printf("Your Name:
\n");
printf("
\n", ((use_ssl_authentication) ? (getenv("SSL_CLIENT_S_DN_CN")) : (getenv("REMOTE_USER"))));
printf("Comment:
\n");
printf("\n");
printf("
\n");
printf("Ping Host
\n");
printf("
\n");
printf("Host Name/Address:
\n");
printf("\n");
printf("
\n");
printf("Results For Ping Of %s:
\n", ping_address);
printf("
\n");
if(ping_syntax == NULL)
printf("ping_syntax in CGI config file is NULL!\n");
else {
/* process macros in the ping syntax */
strcpy(buffer, "");
strncpy(input_buffer, ping_syntax, sizeof(input_buffer) - 1);
input_buffer[strlen(ping_syntax) - 1] = '\x0';
for(temp_ptr = my_strtok(input_buffer, "$"); temp_ptr != NULL; temp_ptr = my_strtok(NULL, "$")) {
if(in_macro == FALSE) {
if(strlen(buffer) + strlen(temp_ptr) < sizeof(buffer) - 1) {
strncat(buffer, temp_ptr, sizeof(buffer) - strlen(buffer) - 1);
buffer[sizeof(buffer) - 1] = '\x0';
}
in_macro = TRUE;
}
else {
if(strlen(buffer) + strlen(temp_ptr) < sizeof(buffer) - 1) {
if(!strcmp(temp_ptr, "HOSTADDRESS"))
strncat(buffer, ping_address, sizeof(buffer) - strlen(buffer) - 1);
}
in_macro = FALSE;
}
}
/* run the ping command */
fp = popen(buffer, "r");
if(fp) {
while(1) {
fgets(buffer, sizeof(buffer) - 1, fp);
if(feof(fp))
break;
strip(buffer);
if(odd) {
odd = 0;
printf("%s
\n", buffer);
}
else {
odd = 1;
printf("%s
\n", buffer);
}
}
}
else
printf("Error executing ping!\n");
pclose(fp);
}
printf("
\n");
printf("Traceroute
\n");
printf("
\n");
printf("Host Name/Address:
\n");
printf("\n");
printf("
\n");
printf("Results For Traceroute To %s:
\n", traceroute_address);
printf("
\n");
snprintf(buffer, sizeof(buffer) - 1, "%s %s", TRACEROUTE_COMMAND, traceroute_address);
buffer[sizeof(buffer) - 1] = '\x0';
fp = popen(buffer, "r");
if(fp) {
while(1) {
fgets(buffer, sizeof(buffer) - 1, fp);
if(feof(fp))
break;
strip(buffer);
if(odd) {
odd = 0;
printf("%s
\n", buffer);
}
else {
odd = 1;
printf("%s
\n", buffer);
}
}
}
else
printf("Error executing traceroute!\n");
pclose(fp);
printf("
\n");
printf("%s Problems
\n", (display_type == DISPLAY_ALL_PROBLEMS) ? "All" : "Unhandled");
printf("Host Problems:\n");
printf("
%s | |
No problems |
%s/%s | |
No problems |
\n");
printf(" %s \n", title);
time(¤t_time);
get_time_string(¤t_time, date_time, (int)sizeof(date_time), LONG_DATE_TIME);
printf("Last Updated: %s\n", date_time); if(refresh == TRUE) printf("Updated every %d seconds \n", refresh_rate); printf("Nagios® Core™ %s - www.nagios.org \n", PROGRAM_VERSION); if(current_authdata != NULL) printf("Logged in as %s \n", (!strcmp(current_authdata->username, "")) ? "?" : current_authdata->username); if(nagios_process_state != STATE_OK) printf(" Warning: Monitoring process may not be running! ", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
if(result == ERROR)
printf("Click here for more info. Warning: Could not read program status information! ");
else {
if(enable_notifications == FALSE)
printf("- Notifications are disabled ");
if(execute_service_checks == FALSE)
printf("- Service checks are disabled ");
}
printf(" |
Error: Could not open CGI config file '%s' for reading!
\n", config_file); printf("\n"); printf("Here are some things you should check in order to resolve this error:\n"); printf("
\n"); printf("\n"); printf("
\n"); printf("Make sure you read the documentation on installing and configuring Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at http://www.nagios.org.\n"); printf("
\n"); return; } /* displays an error if main config file could not be read */ void main_config_file_error(char *config_file) { printf("Error: Could not open main config file '%s' for reading!
\n", config_file); printf("\n"); printf("Here are some things you should check in order to resolve this error:\n"); printf("
\n"); printf("\n"); printf("
\n"); printf("Make sure you read the documentation on installing and configuring Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at http://www.nagios.org.\n"); printf("
\n"); return; } /* displays an error if object data could not be read */ void object_data_error(void) { printf("Error: Could not read object configuration data!
\n"); printf("\n"); printf("Here are some things you should check in order to resolve this error:\n"); printf("
\n"); printf("\n"); printf("
\n"); printf("Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at http://www.nagios.org.\n"); printf("
\n"); return; } /* displays an error if status data could not be read */ void status_data_error(void) { printf("Error: Could not read host and service status information!
\n"); printf("\n"); printf("The most common cause of this error message (especially for new users), is the fact that Nagios is not actually running. If Nagios is indeed not running, this is a normal error message. It simply indicates that the CGIs could not obtain the current status of hosts and services that are being monitored. If you've just installed things, make sure you read the documentation on starting Nagios.\n"); printf("
\n"); printf("\n"); printf("Some other things you should check in order to resolve this error include:\n"); printf("
\n"); printf("\n"); printf("
\n"); printf("Make sure you read the documentation on installing, configuring and running Nagios thoroughly before continuing. If all else fails, try sending a message to one of the mailing lists. More information can be found at http://www.nagios.org.\n"); printf("
\n"); return; } /* displays context-sensitive help window */ void display_context_help(char *chid) { char *icon = CONTEXT_HELP_ICON1; if(show_context_help == FALSE) return; /* change icon if necessary */ if(!strcmp(chid, CONTEXTHELP_TAC)) icon = CONTEXT_HELP_ICON2; printf("\n"); display_info_table("Tactical Status Overview", TRUE, ¤t_authdata); printf(" | \n"); /* middle column of top table - log file navigation options */ printf("\n"); printf(" | \n"); /* right hand column of top row */ printf("\n"); printf(" | \n"); /* end of top table */ printf("
\n"); printf("
\n"); display_info_table("Tactical Monitoring Overview", TRUE, ¤t_authdata); printf(" | \n"); /* right column */ printf("\n");
printf("
| \n");
printf("
\n");
/******* OUTAGES ********/
printf(" \n"); printf("
| \n");
/* right column */
printf("\n");
if(percent_host_health < HEALTH_CRITICAL_PERCENTAGE)
strncpy(host_health_image, THERM_CRITICAL_IMAGE, sizeof(host_health_image));
else if(percent_host_health < HEALTH_WARNING_PERCENTAGE)
strncpy(host_health_image, THERM_WARNING_IMAGE, sizeof(host_health_image));
else
strncpy(host_health_image, THERM_OK_IMAGE, sizeof(host_health_image));
host_health_image[sizeof(host_health_image) - 1] = '\x0';
if(percent_service_health < HEALTH_CRITICAL_PERCENTAGE)
strncpy(service_health_image, THERM_CRITICAL_IMAGE, sizeof(service_health_image));
else if(percent_service_health < HEALTH_WARNING_PERCENTAGE)
strncpy(service_health_image, THERM_WARNING_IMAGE, sizeof(service_health_image));
else
strncpy(service_health_image, THERM_OK_IMAGE, sizeof(service_health_image));
service_health_image[sizeof(service_health_image) - 1] = '\x0';
printf("
| \n");
printf("
\n"); printf("
Hosts | |||||||||||||||||||||||||
%d Down | \n", STATUS_CGI, HOST_DOWN, hosts_down); printf("%d Unreachable | \n", STATUS_CGI, HOST_UNREACHABLE, hosts_unreachable); printf("%d Up | \n", STATUS_CGI, HOST_UP, hosts_up); printf("%d Pending | \n", STATUS_CGI, HOST_PENDING, hosts_pending); printf("||||||||||||||||||||||
\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("
\n"); printf("
Services | ||||||||||||||||||||||||||||||||||||
%d Critical | \n", STATUS_CGI, SERVICE_CRITICAL, services_critical); printf("%d Warning | \n", STATUS_CGI, SERVICE_WARNING, services_warning); printf("%d Unknown | \n", STATUS_CGI, SERVICE_UNKNOWN, services_unknown); printf("%d Ok | \n", STATUS_CGI, SERVICE_OK, services_ok); printf("%d Pending | \n", STATUS_CGI, SERVICE_PENDING, services_pending); printf("||||||||||||||||||||||||||||||||
\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("
\n"); printf("
Monitoring Features | ||||||||||||||||||||||||||||||||||||||||||||||||
Flap Detection | \n"); printf("Notifications | \n"); printf("Event Handlers | \n"); printf("Active Checks | \n"); printf("Passive Checks | \n"); printf("||||||||||||||||||||||||||||||||||||||||||||
\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("\n");
printf("
| \n");
printf("
\n");
if(query_type == FIND_SERVICE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Notifications");
else if(query_type == FIND_HOST) {
if(find_all == TRUE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Notifications");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Notifications");
}
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Contact Notifications");
display_info_table(temp_buffer, FALSE, ¤t_authdata);
if(query_type == FIND_HOST || query_type == FIND_SERVICE) {
printf("
| \n");
/* middle column of top row */
printf("\n");
printf(" \n");
if(query_type == FIND_SERVICE)
printf("Service '%s' On Host '%s'", query_svc_description, query_host_name);
else if(query_type == FIND_HOST) {
if(find_all == TRUE)
printf("All Hosts and Services");
else
printf("Host '%s'", query_host_name);
}
else {
if(find_all == TRUE)
printf("All Contacts");
else
printf("Contact '%s'", query_contact_name);
}
printf(" \n");
printf("\n"); if(query_type == FIND_SERVICE) { snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s?%shost=%s&", NOTIFICATIONS_CGI, (use_lifo == FALSE) ? "oldestfirst&" : "", url_encode(query_host_name)); snprintf(temp_buffer2, sizeof(temp_buffer2) - 1, "service=%s&type=%d&", url_encode(query_svc_description), notification_options); strncat(temp_buffer, temp_buffer2, sizeof(temp_buffer) - strlen(temp_buffer) - 1); } else snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s?%s%s=%s&type=%d&", NOTIFICATIONS_CGI, (use_lifo == FALSE) ? "oldestfirst&" : "", (query_type == FIND_HOST) ? "host" : "contact", (query_type == FIND_HOST) ? url_encode(query_host_name) : url_encode(query_contact_name), notification_options); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; display_nav_table(temp_buffer, log_archive); printf(" | \n");
/* right hand column of top row */
printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
\n"); printf("
Host | \n"); printf("Service | \n"); printf("Type | \n"); printf("Time | \n"); printf("Contact | \n"); printf("Notification Command | \n"); printf("Information | \n"); printf("|
---|---|---|---|---|---|---|---|
%s | \n", (odd) ? "Even" : "Odd", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(host_name), host_name); if(notification_type == SERVICE_NOTIFICATION) { printf("%s | \n", url_encode(service_name), service_name); } else printf("N/A | \n", (odd) ? "Even" : "Odd"); printf("%s | \n", alert_level_class, alert_level); printf("%s | \n", (odd) ? "Even" : "Odd", date_time); printf("%s | \n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(contact_name), contact_name); printf("%s | \n", (odd) ? "Even" : "Odd", CONFIG_CGI, url_encode(method_name), method_name); printf("%s | \n", (odd) ? "Even" : "Odd", html_encode(temp_buffer, FALSE)); printf("
\n");
switch(display_type) {
case DISPLAY_HOST_AVAIL:
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Availability Report");
break;
case DISPLAY_SERVICE_AVAIL:
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Availability Report");
break;
case DISPLAY_HOSTGROUP_AVAIL:
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Hostgroup Availability Report");
break;
case DISPLAY_SERVICEGROUP_AVAIL:
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Servicegroup Availability Report");
break;
default:
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Availability Report");
break;
}
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_info_table(temp_buffer, FALSE, ¤t_authdata);
if(((display_type == DISPLAY_HOST_AVAIL && show_all_hosts == FALSE) || (display_type == DISPLAY_SERVICE_AVAIL && show_all_services == FALSE)) && get_date_parts == FALSE) {
printf("
| \n");
/* center column of top row */
printf("\n");
if(display_type != DISPLAY_NO_AVAIL && get_date_parts == FALSE) {
printf(" \n");
if(display_type == DISPLAY_HOST_AVAIL) {
if(show_all_hosts == TRUE)
printf("All Hosts");
else
printf("Host '%s'", host_name);
}
else if(display_type == DISPLAY_SERVICE_AVAIL) {
if(show_all_services == TRUE)
printf("All Services");
else
printf("Service '%s' On Host '%s'", svc_description, host_name);
}
else if(display_type == DISPLAY_HOSTGROUP_AVAIL) {
if(show_all_hostgroups == TRUE)
printf("All Hostgroups");
else
printf("Hostgroup '%s'", hostgroup_name);
}
else if(display_type == DISPLAY_SERVICEGROUP_AVAIL) {
if(show_all_servicegroups == TRUE)
printf("All Servicegroups");
else
printf("Servicegroup '%s'", servicegroup_name);
}
printf(" \n");
printf("\n"); printf(" \n"); get_time_string(&t1, start_timestring, sizeof(start_timestring) - 1, SHORT_DATE_TIME); get_time_string(&t2, end_timestring, sizeof(end_timestring) - 1, SHORT_DATE_TIME); printf(" %s to %s \n", start_timestring, end_timestring);
get_time_breakdown((time_t)(t2 - t1), &days, &hours, &minutes, &seconds);
printf("Duration: %dd %dh %dm %ds \n", days, hours, minutes, seconds);
}
printf(" | \n");
/* right hand column of top row */
printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
ENTERING COMPUTE_SUBJECT_DOWNTIME_TIMES: start=%lu, end=%lu, t1=%lu, t2=%lu
", start_time, end_time, t1, t2); #endif /* times are weird, so bail out... */ if(start_time > end_time) return; if(start_time < t1 || end_time > t2) return; /* find starting point in archived state list */ if(sd == NULL) { #ifdef DEBUG2 printf("TEMP_AS=SUBJECT->AS_LIST
"); #endif temp_as = subject->as_list; } else if(sd->misc_ptr == NULL) { #ifdef DEBUG2 printf("TEMP_AS=SUBJECT->AS_LIST
"); #endif temp_as = subject->as_list; } else if(sd->misc_ptr->next == NULL) { #ifdef DEBUG2 printf("TEMP_AS=SD->MISC_PTR
"); #endif temp_as = sd->misc_ptr; } else { #ifdef DEBUG2 printf("TEMP_AS=SD->MISC_PTR->NEXT
"); #endif temp_as = sd->misc_ptr->next; } /* initialize values */ part_start_time = start_time; if(temp_as == NULL) part_subject_state = AS_NO_DATA; else if(temp_as->processed_state == AS_PROGRAM_START || temp_as->processed_state == AS_PROGRAM_END || temp_as->processed_state == AS_NO_DATA) { #ifdef DEBUG2 printf("ENTRY TYPE #1: %d
", temp_as->entry_type); #endif part_subject_state = AS_NO_DATA; } else { #ifdef DEBUG2 printf("ENTRY TYPE #2: %d
", temp_as->entry_type); #endif part_subject_state = temp_as->processed_state; } #ifdef DEBUG2 printf("TEMP_AS=%s
", (temp_as == NULL) ? "NULL" : "Not NULL"); printf("SD=%s
", (sd == NULL) ? "NULL" : "Not NULL"); #endif /* temp_as now points to first event to possibly "break" this chunk */ for(; temp_as != NULL; temp_as = temp_as->next) { count++; last = temp_as; if(temp_before == NULL) { if(last->time_stamp > start_time) { if(last->time_stamp > end_time) compute_subject_downtime_part_times(start_time, end_time, part_subject_state, subject); else compute_subject_downtime_part_times(start_time, last->time_stamp, part_subject_state, subject); } temp_before = temp_as; saved_status = temp_as->entry_type; saved_stamp = temp_as->time_stamp; /* check if first time is before schedule downtime */ if(saved_stamp < start_time) saved_stamp = start_time; continue; } /* if status changed, we have to calculate */ if(saved_status != temp_as->entry_type) { /* is outside schedule time, use end schdule downtime */ if(temp_as->time_stamp > end_time) { if(saved_stamp < start_time) compute_subject_downtime_part_times(start_time, end_time, saved_status, subject); else compute_subject_downtime_part_times(saved_stamp, end_time, saved_status, subject); } else { if(saved_stamp < start_time) compute_subject_downtime_part_times(start_time, temp_as->time_stamp, saved_status, subject); else compute_subject_downtime_part_times(saved_stamp, temp_as->time_stamp, saved_status, subject); } saved_status = temp_as->entry_type; saved_stamp = temp_as->time_stamp; } } /* just one entry inside the scheduled downtime */ if(count == 0) compute_subject_downtime_part_times(start_time, end_time, part_subject_state, subject); else { /* is outside scheduled time, use end schdule downtime */ if(last->time_stamp > end_time) compute_subject_downtime_part_times(saved_stamp, end_time, saved_status, subject); else compute_subject_downtime_part_times(saved_stamp, last->time_stamp, saved_status, subject); } return; } /* computes downtime times */ void compute_subject_downtime_part_times(time_t start_time, time_t end_time, int subject_state, avail_subject *subject) { unsigned long state_duration; #ifdef DEBUG2 printf("ENTERING COMPUTE_SUBJECT_DOWNTIME_PART_TIMES\n"); #endif /* times are weird */ if(start_time > end_time) return; state_duration = (unsigned long)(end_time - start_time); switch(subject_state) { case AS_HOST_UP: subject->scheduled_time_up += state_duration; break; case AS_HOST_DOWN: subject->scheduled_time_down += state_duration; break; case AS_HOST_UNREACHABLE: subject->scheduled_time_unreachable += state_duration; break; case AS_SVC_OK: subject->scheduled_time_ok += state_duration; break; case AS_SVC_WARNING: subject->scheduled_time_warning += state_duration; break; case AS_SVC_UNKNOWN: subject->scheduled_time_unknown += state_duration; break; case AS_SVC_CRITICAL: subject->scheduled_time_critical += state_duration; break; default: subject->scheduled_time_indeterminate += state_duration; break; } #ifdef DEBUG2 printf("\tSUBJECT DOWNTIME: Host '%s', Service '%s', State=%d, Duration=%lu, Start=%lu\n", subject->host_name, (subject->service_description == NULL) ? "NULL" : subject->service_description, subject_state, state_duration, start_time); #endif return; } /* convert current host state to archived state value */ int convert_host_state_to_archived_state(int current_status) { if(current_status == HOST_UP) return AS_HOST_UP; if(current_status == HOST_DOWN) return AS_HOST_DOWN; if(current_status == HOST_UNREACHABLE) return AS_HOST_UNREACHABLE; return AS_NO_DATA; } /* convert current service state to archived state value */ int convert_service_state_to_archived_state(int current_status) { if(current_status == SERVICE_OK) return AS_SVC_OK; if(current_status == SERVICE_UNKNOWN) return AS_SVC_UNKNOWN; if(current_status == SERVICE_WARNING) return AS_SVC_WARNING; if(current_status == SERVICE_CRITICAL) return AS_SVC_CRITICAL; return AS_NO_DATA; } /* create list of subjects to collect availability data for */ void create_subject_list(void) { hostgroup *temp_hostgroup; hostsmember *temp_hgmember; servicegroup *temp_servicegroup; servicesmember *temp_sgmember; host *temp_host; service *temp_service; char *last_host_name = ""; /* we're displaying one or more hosts */ if(display_type == DISPLAY_HOST_AVAIL && host_name && strcmp(host_name, "")) { /* we're only displaying a specific host (and summaries for all services associated with it) */ if(show_all_hosts == FALSE) { add_subject(HOST_SUBJECT, host_name, NULL); for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) { if(!strcmp(temp_service->host_name, host_name)) add_subject(SERVICE_SUBJECT, host_name, temp_service->description); } } /* we're displaying all hosts */ else { for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next) add_subject(HOST_SUBJECT, temp_host->name, NULL); } } /* we're displaying a specific service */ else if(display_type == DISPLAY_SERVICE_AVAIL && svc_description && strcmp(svc_description, "")) { /* we're only displaying a specific service */ if(show_all_services == FALSE) add_subject(SERVICE_SUBJECT, host_name, svc_description); /* we're displaying all services */ else { for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) add_subject(SERVICE_SUBJECT, temp_service->host_name, temp_service->description); } } /* we're displaying one or more hostgroups (the host members of the groups) */ else if(display_type == DISPLAY_HOSTGROUP_AVAIL && hostgroup_name && strcmp(hostgroup_name, "")) { /* we're displaying all hostgroups */ if(show_all_hostgroups == TRUE) { for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) { for(temp_hgmember = temp_hostgroup->members; temp_hgmember != NULL; temp_hgmember = temp_hgmember->next) add_subject(HOST_SUBJECT, temp_hgmember->host_name, NULL); } } /* we're only displaying a specific hostgroup */ else { temp_hostgroup = find_hostgroup(hostgroup_name); if(temp_hostgroup != NULL) { for(temp_hgmember = temp_hostgroup->members; temp_hgmember != NULL; temp_hgmember = temp_hgmember->next) add_subject(HOST_SUBJECT, temp_hgmember->host_name, NULL); } } } /* we're displaying one or more servicegroups (the host and service members of the groups) */ else if(display_type == DISPLAY_SERVICEGROUP_AVAIL && servicegroup_name && strcmp(servicegroup_name, "")) { /* we're displaying all servicegroups */ if(show_all_servicegroups == TRUE) { for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) { for(temp_sgmember = temp_servicegroup->members; temp_sgmember != NULL; temp_sgmember = temp_sgmember->next) { add_subject(SERVICE_SUBJECT, temp_sgmember->host_name, temp_sgmember->service_description); if(strcmp(last_host_name, temp_sgmember->host_name)) add_subject(HOST_SUBJECT, temp_sgmember->host_name, NULL); last_host_name = temp_sgmember->host_name; } } } /* we're only displaying a specific servicegroup */ else { temp_servicegroup = find_servicegroup(servicegroup_name); if(temp_servicegroup != NULL) { for(temp_sgmember = temp_servicegroup->members; temp_sgmember != NULL; temp_sgmember = temp_sgmember->next) { add_subject(SERVICE_SUBJECT, temp_sgmember->host_name, temp_sgmember->service_description); if(strcmp(last_host_name, temp_sgmember->host_name)) add_subject(HOST_SUBJECT, temp_sgmember->host_name, NULL); last_host_name = temp_sgmember->host_name; } } } } return; } /* adds a subject */ void add_subject(int subject_type, char *hn, char *sd) { avail_subject *last_subject = NULL; avail_subject *temp_subject = NULL; avail_subject *new_subject = NULL; int is_authorized = FALSE; /* bail if we've already added the subject */ if(find_subject(subject_type, hn, sd)) return; /* see if the user is authorized to see data for this host or service */ if(subject_type == HOST_SUBJECT) is_authorized = is_authorized_for_host(find_host(hn), ¤t_authdata); else is_authorized = is_authorized_for_service(find_service(hn, sd), ¤t_authdata); if(is_authorized == FALSE) return; /* allocate memory for the new entry */ new_subject = (avail_subject *)malloc(sizeof(avail_subject)); if(new_subject == NULL) return; /* allocate memory for the host name */ if(hn != NULL) { new_subject->host_name = (char *)malloc(strlen(hn) + 1); if(new_subject->host_name != NULL) strcpy(new_subject->host_name, hn); } else new_subject->host_name = NULL; /* allocate memory for the service description */ if(sd != NULL) { new_subject->service_description = (char *)malloc(strlen(sd) + 1); if(new_subject->service_description != NULL) strcpy(new_subject->service_description, sd); } else new_subject->service_description = NULL; new_subject->type = subject_type; new_subject->earliest_state = AS_NO_DATA; new_subject->latest_state = AS_NO_DATA; new_subject->time_up = 0L; new_subject->time_down = 0L; new_subject->time_unreachable = 0L; new_subject->time_ok = 0L; new_subject->time_warning = 0L; new_subject->time_unknown = 0L; new_subject->time_critical = 0L; new_subject->scheduled_time_up = 0L; new_subject->scheduled_time_down = 0L; new_subject->scheduled_time_unreachable = 0L; new_subject->scheduled_time_ok = 0L; new_subject->scheduled_time_warning = 0L; new_subject->scheduled_time_unknown = 0L; new_subject->scheduled_time_critical = 0L; new_subject->scheduled_time_indeterminate = 0L; new_subject->time_indeterminate_nodata = 0L; new_subject->time_indeterminate_notrunning = 0L; new_subject->as_list = NULL; new_subject->as_list_tail = NULL; new_subject->sd_list = NULL; new_subject->last_known_state = AS_NO_DATA; /* add the new entry to the list in memory, sorted by host name */ last_subject = subject_list; for(temp_subject = subject_list; temp_subject != NULL; temp_subject = temp_subject->next) { if(strcmp(new_subject->host_name, temp_subject->host_name) < 0) { new_subject->next = temp_subject; if(temp_subject == subject_list) subject_list = new_subject; else last_subject->next = new_subject; break; } else last_subject = temp_subject; } if(subject_list == NULL) { new_subject->next = NULL; subject_list = new_subject; } else if(temp_subject == NULL) { new_subject->next = NULL; last_subject->next = new_subject; } return; } /* finds a specific subject */ avail_subject *find_subject(int type, char *hn, char *sd) { avail_subject *temp_subject; if(hn == NULL) return NULL; if(type == SERVICE_SUBJECT && sd == NULL) return NULL; for(temp_subject = subject_list; temp_subject != NULL; temp_subject = temp_subject->next) { if(temp_subject->type != type) continue; if(strcmp(hn, temp_subject->host_name)) continue; if(type == SERVICE_SUBJECT && strcmp(sd, temp_subject->service_description)) continue; return temp_subject; } return NULL; } /* adds an archived state entry to all subjects */ void add_global_archived_state(int entry_type, int state_type, time_t time_stamp, char *state_info) { avail_subject *temp_subject; for(temp_subject = subject_list; temp_subject != NULL; temp_subject = temp_subject->next) add_archived_state(entry_type, state_type, time_stamp, state_info, temp_subject); return; } /* adds an archived state entry to a specific subject */ void add_archived_state(int entry_type, int state_type, time_t time_stamp, char *state_info, avail_subject *subject) { archived_state *last_as = NULL; archived_state *temp_as = NULL; archived_state *new_as = NULL; /* allocate memory for the new entry */ new_as = (archived_state *)malloc(sizeof(archived_state)); if(new_as == NULL) return; /* allocate memory for the state info */ if(state_info != NULL) { new_as->state_info = (char *)malloc(strlen(state_info) + 1); if(new_as->state_info != NULL) strcpy(new_as->state_info, state_info); } else new_as->state_info = NULL; /* initialize the "processed state" value - this gets modified later for most entries */ if(entry_type != AS_PROGRAM_START && entry_type != AS_PROGRAM_END && entry_type != AS_NO_DATA) new_as->processed_state = entry_type; else new_as->processed_state = AS_NO_DATA; new_as->entry_type = entry_type; new_as->state_type = state_type; new_as->time_stamp = time_stamp; new_as->misc_ptr = NULL; /* add the new entry to the list in memory, sorted by time (more recent entries should appear towards end of list) */ last_as = subject->as_list; for(temp_as = subject->as_list; temp_as != NULL; temp_as = temp_as->next) { if(new_as->time_stamp < temp_as->time_stamp) { new_as->next = temp_as; if(temp_as == subject->as_list) subject->as_list = new_as; else last_as->next = new_as; break; } else last_as = temp_as; } if(subject->as_list == NULL) { new_as->next = NULL; subject->as_list = new_as; } else if(temp_as == NULL) { new_as->next = NULL; last_as->next = new_as; } /* update "tail" of the list - not really the tail, just last item added */ subject->as_list_tail = new_as; return; } /* adds a scheduled downtime entry to a specific subject */ void add_scheduled_downtime(int state_type, time_t time_stamp, avail_subject *subject) { archived_state *last_sd = NULL; archived_state *temp_sd = NULL; archived_state *new_sd = NULL; /* allocate memory for the new entry */ new_sd = (archived_state *)malloc(sizeof(archived_state)); if(new_sd == NULL) return; new_sd->state_info = NULL; new_sd->processed_state = state_type; new_sd->entry_type = state_type; new_sd->time_stamp = time_stamp; new_sd->misc_ptr = subject->as_list_tail; /* add the new entry to the list in memory, sorted by time (more recent entries should appear towards end of list) */ last_sd = subject->sd_list; for(temp_sd = subject->sd_list; temp_sd != NULL; temp_sd = temp_sd->next) { if(new_sd->time_stamp <= temp_sd->time_stamp) { new_sd->next = temp_sd; if(temp_sd == subject->sd_list) subject->sd_list = new_sd; else last_sd->next = new_sd; break; } else last_sd = temp_sd; } if(subject->sd_list == NULL) { new_sd->next = NULL; subject->sd_list = new_sd; } else if(temp_sd == NULL) { new_sd->next = NULL; last_sd->next = new_sd; } return; } /* frees memory allocated to all availability data */ void free_availability_data(void) { avail_subject *this_subject; avail_subject *next_subject; for(this_subject = subject_list; this_subject != NULL;) { next_subject = this_subject->next; if(this_subject->host_name != NULL) free(this_subject->host_name); if(this_subject->service_description != NULL) free(this_subject->service_description); free_archived_state_list(this_subject->as_list); free_archived_state_list(this_subject->sd_list); free(this_subject); this_subject = next_subject; } return; } /* frees memory allocated to the archived state list */ void free_archived_state_list(archived_state *as_list) { archived_state *this_as = NULL; archived_state *next_as = NULL; for(this_as = as_list; this_as != NULL;) { next_as = this_as->next; if(this_as->state_info != NULL) free(this_as->state_info); free(this_as); this_as = next_as; } as_list = NULL; return; } /* reads log files for archived state data */ void read_archived_state_data(void) { char filename[MAX_FILENAME_LENGTH]; int oldest_archive = 0; int newest_archive = 0; int current_archive = 0; /* determine oldest archive to use when scanning for data (include backtracked archives as well) */ oldest_archive = determine_archive_to_use_from_time(t1); if(log_rotation_method != LOG_ROTATION_NONE) oldest_archive += backtrack_archives; /* determine most recent archive to use when scanning for data */ newest_archive = determine_archive_to_use_from_time(t2); if(oldest_archive < newest_archive) oldest_archive = newest_archive; /* read in all the necessary archived logs (from most recent to earliest) */ for(current_archive = newest_archive; current_archive <= oldest_archive; current_archive++) { #ifdef DEBUG printf("Reading archive #%d\n", current_archive); #endif /* get the name of the log file that contains this archive */ get_log_archive_to_use(current_archive, filename, sizeof(filename) - 1); #ifdef DEBUG printf("Archive name: '%s'\n", filename); #endif /* scan the log file for archived state data */ scan_log_file_for_archived_state_data(filename); } return; } /* grabs archives state data from a log file */ void scan_log_file_for_archived_state_data(char *filename) { char *input = NULL; char *input2 = NULL; char entry_host_name[MAX_INPUT_BUFFER]; char entry_svc_description[MAX_INPUT_BUFFER]; char *plugin_output = NULL; char *temp_buffer = NULL; time_t time_stamp; mmapfile *thefile = NULL; avail_subject *temp_subject = NULL; int state_type = 0; if((thefile = mmap_fopen(filename)) == NULL) return; while(1) { /* free memory */ free(input); free(input2); input = NULL; input2 = NULL; /* read the next line */ if((input = mmap_fgets(thefile)) == NULL) break; strip(input); if((input2 = strdup(input)) == NULL) continue; temp_buffer = my_strtok(input2, "]"); time_stamp = (temp_buffer == NULL) ? (time_t)0 : (time_t)strtoul(temp_buffer + 1, NULL, 10); /* program starts/restarts */ if(strstr(input, " starting...")) add_global_archived_state(AS_PROGRAM_START, AS_NO_DATA, time_stamp, "Program start"); if(strstr(input, " restarting...")) add_global_archived_state(AS_PROGRAM_START, AS_NO_DATA, time_stamp, "Program restart"); /* program stops */ if(strstr(input, " shutting down...")) add_global_archived_state(AS_PROGRAM_END, AS_NO_DATA, time_stamp, "Normal program termination"); if(strstr(input, "Bailing out")) add_global_archived_state(AS_PROGRAM_END, AS_NO_DATA, time_stamp, "Abnormal program termination"); if(display_type == DISPLAY_HOST_AVAIL || display_type == DISPLAY_HOSTGROUP_AVAIL || display_type == DISPLAY_SERVICEGROUP_AVAIL) { /* normal host alerts and initial/current states */ if(strstr(input, "HOST ALERT:") || strstr(input, "INITIAL HOST STATE:") || strstr(input, "CURRENT HOST STATE:")) { /* get host name */ temp_buffer = my_strtok(NULL, ":"); temp_buffer = my_strtok(NULL, ";"); strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name)); entry_host_name[sizeof(entry_host_name) - 1] = '\x0'; /* see if there is a corresponding subject for this host */ temp_subject = find_subject(HOST_SUBJECT, entry_host_name, NULL); if(temp_subject == NULL) continue; /* state types */ if(strstr(input, ";SOFT;")) { if(include_soft_states == FALSE) continue; state_type = AS_SOFT_STATE; } if(strstr(input, ";HARD;")) state_type = AS_HARD_STATE; /* get the plugin output */ temp_buffer = my_strtok(NULL, ";"); temp_buffer = my_strtok(NULL, ";"); temp_buffer = my_strtok(NULL, ";"); plugin_output = my_strtok(NULL, "\n"); if(strstr(input, ";DOWN;")) add_archived_state(AS_HOST_DOWN, state_type, time_stamp, plugin_output, temp_subject); else if(strstr(input, ";UNREACHABLE;")) add_archived_state(AS_HOST_UNREACHABLE, state_type, time_stamp, plugin_output, temp_subject); else if(strstr(input, ";RECOVERY") || strstr(input, ";UP;")) add_archived_state(AS_HOST_UP, state_type, time_stamp, plugin_output, temp_subject); else add_archived_state(AS_NO_DATA, AS_NO_DATA, time_stamp, plugin_output, temp_subject); } /* scheduled downtime notices */ else if(strstr(input, "HOST DOWNTIME ALERT:")) { /* get host name */ temp_buffer = my_strtok(NULL, ":"); temp_buffer = my_strtok(NULL, ";"); strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name)); entry_host_name[sizeof(entry_host_name) - 1] = '\x0'; /* see if there is a corresponding subject for this host */ temp_subject = find_subject(HOST_SUBJECT, entry_host_name, NULL); if(temp_subject == NULL) continue; if(show_scheduled_downtime == FALSE) continue; if(strstr(input, ";STARTED;")) add_scheduled_downtime(AS_HOST_DOWNTIME_START, time_stamp, temp_subject); else add_scheduled_downtime(AS_HOST_DOWNTIME_END, time_stamp, temp_subject); } } if(display_type == DISPLAY_SERVICE_AVAIL || display_type == DISPLAY_HOST_AVAIL || display_type == DISPLAY_SERVICEGROUP_AVAIL) { /* normal service alerts and initial/current states */ if(strstr(input, "SERVICE ALERT:") || strstr(input, "INITIAL SERVICE STATE:") || strstr(input, "CURRENT SERVICE STATE:")) { /* get host name */ temp_buffer = my_strtok(NULL, ":"); temp_buffer = my_strtok(NULL, ";"); strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name)); entry_host_name[sizeof(entry_host_name) - 1] = '\x0'; /* get service description */ temp_buffer = my_strtok(NULL, ";"); strncpy(entry_svc_description, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(entry_svc_description)); entry_svc_description[sizeof(entry_svc_description) - 1] = '\x0'; /* see if there is a corresponding subject for this service */ temp_subject = find_subject(SERVICE_SUBJECT, entry_host_name, entry_svc_description); if(temp_subject == NULL) continue; /* state types */ if(strstr(input, ";SOFT;")) { if(include_soft_states == FALSE) continue; state_type = AS_SOFT_STATE; } if(strstr(input, ";HARD;")) state_type = AS_HARD_STATE; /* get the plugin output */ temp_buffer = my_strtok(NULL, ";"); temp_buffer = my_strtok(NULL, ";"); temp_buffer = my_strtok(NULL, ";"); plugin_output = my_strtok(NULL, "\n"); if(strstr(input, ";CRITICAL;")) add_archived_state(AS_SVC_CRITICAL, state_type, time_stamp, plugin_output, temp_subject); else if(strstr(input, ";WARNING;")) add_archived_state(AS_SVC_WARNING, state_type, time_stamp, plugin_output, temp_subject); else if(strstr(input, ";UNKNOWN;")) add_archived_state(AS_SVC_UNKNOWN, state_type, time_stamp, plugin_output, temp_subject); else if(strstr(input, ";RECOVERY;") || strstr(input, ";OK;")) add_archived_state(AS_SVC_OK, state_type, time_stamp, plugin_output, temp_subject); else add_archived_state(AS_NO_DATA, AS_NO_DATA, time_stamp, plugin_output, temp_subject); } /* scheduled service downtime notices */ else if(strstr(input, "SERVICE DOWNTIME ALERT:")) { /* get host name */ temp_buffer = my_strtok(NULL, ":"); temp_buffer = my_strtok(NULL, ";"); strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name)); entry_host_name[sizeof(entry_host_name) - 1] = '\x0'; /* get service description */ temp_buffer = my_strtok(NULL, ";"); strncpy(entry_svc_description, (temp_buffer == NULL) ? "" : temp_buffer, sizeof(entry_svc_description)); entry_svc_description[sizeof(entry_svc_description) - 1] = '\x0'; /* see if there is a corresponding subject for this service */ temp_subject = find_subject(SERVICE_SUBJECT, entry_host_name, entry_svc_description); if(temp_subject == NULL) continue; if(show_scheduled_downtime == FALSE) continue; if(strstr(input, ";STARTED;")) add_scheduled_downtime(AS_SVC_DOWNTIME_START, time_stamp, temp_subject); else add_scheduled_downtime(AS_SVC_DOWNTIME_END, time_stamp, temp_subject); } /* scheduled host downtime notices */ else if(strstr(input, "HOST DOWNTIME ALERT:")) { /* get host name */ temp_buffer = my_strtok(NULL, ":"); temp_buffer = my_strtok(NULL, ";"); strncpy(entry_host_name, (temp_buffer == NULL) ? "" : temp_buffer + 1, sizeof(entry_host_name)); entry_host_name[sizeof(entry_host_name) - 1] = '\x0'; /* this host downtime entry must be added to all service subjects associated with the host! */ for(temp_subject = subject_list; temp_subject != NULL; temp_subject = temp_subject->next) { if(temp_subject->type != SERVICE_SUBJECT) continue; if(strcmp(temp_subject->host_name, entry_host_name)) continue; if(show_scheduled_downtime == FALSE) continue; if(strstr(input, ";STARTED;")) add_scheduled_downtime(AS_HOST_DOWNTIME_START, time_stamp, temp_subject); else add_scheduled_downtime(AS_HOST_DOWNTIME_END, time_stamp, temp_subject); } } } } /* free memory and close the file */ free(input); free(input2); mmap_fclose(thefile); return; } void convert_timeperiod_to_times(int type) { time_t current_time; struct tm *t; /* get the current time */ time(¤t_time); t = localtime(¤t_time); t->tm_sec = 0; t->tm_min = 0; t->tm_hour = 0; t->tm_isdst = -1; switch(type) { case TIMEPERIOD_LAST24HOURS: t1 = current_time - (60 * 60 * 24); t2 = current_time; break; case TIMEPERIOD_TODAY: t1 = mktime(t); t2 = current_time; break; case TIMEPERIOD_YESTERDAY: t1 = (time_t)(mktime(t) - (60 * 60 * 24)); t2 = (time_t)mktime(t); break; case TIMEPERIOD_THISWEEK: t1 = (time_t)(mktime(t) - (60 * 60 * 24 * t->tm_wday)); t2 = current_time; break; case TIMEPERIOD_LASTWEEK: t1 = (time_t)(mktime(t) - (60 * 60 * 24 * t->tm_wday) - (60 * 60 * 24 * 7)); t2 = (time_t)(mktime(t) - (60 * 60 * 24 * t->tm_wday)); break; case TIMEPERIOD_THISMONTH: t->tm_mday = 1; t1 = mktime(t); t2 = current_time; break; case TIMEPERIOD_LASTMONTH: t->tm_mday = 1; t2 = mktime(t); if(t->tm_mon == 0) { t->tm_mon = 11; t->tm_year--; } else t->tm_mon--; t1 = mktime(t); break; case TIMEPERIOD_THISQUARTER: /* not implemented */ break; case TIMEPERIOD_LASTQUARTER: /* not implemented */ break; case TIMEPERIOD_THISYEAR: t->tm_mon = 0; t->tm_mday = 1; t1 = mktime(t); t2 = current_time; break; case TIMEPERIOD_LASTYEAR: t->tm_mon = 0; t->tm_mday = 1; t2 = mktime(t); t->tm_year--; t1 = mktime(t); break; case TIMEPERIOD_LAST7DAYS: t2 = current_time; t1 = current_time - (7 * 24 * 60 * 60); break; case TIMEPERIOD_LAST31DAYS: t2 = current_time; t1 = current_time - (31 * 24 * 60 * 60); break; default: break; } return; } void compute_report_times(void) { time_t current_time; struct tm *st; struct tm *et; /* get the current time */ time(¤t_time); st = localtime(¤t_time); st->tm_sec = start_second; st->tm_min = start_minute; st->tm_hour = start_hour; st->tm_mday = start_day; st->tm_mon = start_month - 1; st->tm_year = start_year - 1900; st->tm_isdst = -1; t1 = mktime(st); et = localtime(¤t_time); et->tm_sec = end_second; et->tm_min = end_minute; et->tm_hour = end_hour; et->tm_mday = end_day; et->tm_mon = end_month - 1; et->tm_year = end_year - 1900; et->tm_isdst = -1; t2 = mktime(et); } /* writes log entries to screen */ void write_log_entries(avail_subject *subject) { archived_state *temp_as; archived_state *temp_sd; time_t current_time; char start_date_time[MAX_DATETIME_LENGTH]; char end_date_time[MAX_DATETIME_LENGTH]; char duration[20]; char *bgclass = ""; char *ebgclass = ""; char *entry_type = ""; char *state_type = ""; int days; int hours; int minutes; int seconds; int odd = 0; if(output_format != HTML_OUTPUT) return; if(show_log_entries == FALSE) return; if(subject == NULL) return; time(¤t_time); /* inject all scheduled downtime entries into the main list for display purposes */ for(temp_sd = subject->sd_list; temp_sd != NULL; temp_sd = temp_sd->next) { switch(temp_sd->entry_type) { case AS_SVC_DOWNTIME_START: case AS_HOST_DOWNTIME_START: entry_type = "Start of scheduled downtime"; break; case AS_SVC_DOWNTIME_END: case AS_HOST_DOWNTIME_END: entry_type = "End of scheduled downtime"; break; default: entry_type = "?"; break; } add_archived_state(temp_sd->entry_type, AS_NO_DATA, temp_sd->time_stamp, entry_type, subject); } printf("Event Start Time | Event End Time | Event Duration | Event/State Type | Event/State Information |
---|---|---|---|---|
%s | ", bgclass, start_date_time); printf("%s | ", bgclass, end_date_time); printf("%s | ", bgclass, duration); printf("%s%s | ", ebgclass, entry_type, state_type); printf("%s | ", bgclass, (temp_as->state_info == NULL) ? "" : html_encode(temp_as->state_info, FALSE)); printf("
Host | %% Time Up | %% Time Down | %% Time Unreachable | %% Time Undetermined |
---|---|---|---|---|
", bgclass, bgclass); host_report_url(temp_subject->host_name, temp_subject->host_name); printf(" | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Average | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Host | %% Time Up | %% Time Down | %% Time Unreachable | %% Time Undetermined |
---|---|---|---|---|
", bgclass, bgclass); host_report_url(temp_subject->host_name, temp_subject->host_name); printf(" | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Average | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Host | Service | %% Time OK | %% Time Warning | %% Time Unknown | %% Time Critical | %% Time Undetermined |
---|---|---|---|---|---|---|
", bgclass, bgclass); if(strcmp(temp_subject->host_name, last_host)) host_report_url(temp_subject->host_name, temp_subject->host_name); printf(" | ", bgclass); service_report_url(temp_subject->host_name, temp_subject->service_description, temp_subject->service_description); printf(" | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Average | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
State | Type / Reason | Time | %% Total Time | %% Known Time |
---|---|---|---|---|
UP | "); printf("Unscheduled | %s | %2.3f%% | %2.3f%% |
Scheduled | %s | %2.3f%% | %2.3f%% | |
Total | %s | %2.3f%% | %2.3f%% | |
DOWN | "); printf("Unscheduled | %s | %2.3f%% | %2.3f%% |
Scheduled | %s | %2.3f%% | %2.3f%% | |
Total | %s | %2.3f%% | %2.3f%% | |
UNREACHABLE | "); printf("Unscheduled | %s | %2.3f%% | %2.3f%% |
Scheduled | %s | %2.3f%% | %2.3f%% | |
Total | %s | %2.3f%% | %2.3f%% | |
Undetermined | "); printf("Nagios Not Running | %s | %2.3f%% | |
Insufficient Data | %s | %2.3f%% | ||
Total | %s | %2.3f%% | ||
All | Total | %s | 100.000%% | 100.000%% |
Service | %% Time OK | %% Time Warning | %% Time Unknown | %% Time Critical | %% Time Undetermined |
---|---|---|---|---|---|
", bgclass, bgclass); service_report_url(temp_subject->host_name, temp_subject->service_description, temp_subject->service_description); printf(" | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Average | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Host | %% Time Up | %% Time Down | %% Time Unreachable | %% Time Undetermined |
---|---|---|---|---|
", bgclass, bgclass); host_report_url(temp_subject->host_name, temp_subject->host_name); printf(" | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Average | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
State | Type / Reason | Time | %% Total Time | %% Known Time |
---|---|---|---|---|
OK | "); printf("Unscheduled | %s | %2.3f%% | %2.3f%% |
Scheduled | %s | %2.3f%% | %2.3f%% | |
Total | %s | %2.3f%% | %2.3f%% | |
WARNING | "); printf("Unscheduled | %s | %2.3f%% | %2.3f%% |
Scheduled | %s | %2.3f%% | %2.3f%% | |
Total | %s | %2.3f%% | %2.3f%% | |
UNKNOWN | "); printf("Unscheduled | %s | %2.3f%% | %2.3f%% |
Scheduled | %s | %2.3f%% | %2.3f%% | |
Total | %s | %2.3f%% | %2.3f%% | |
CRITICAL | "); printf("Unscheduled | %s | %2.3f%% | %2.3f%% |
Scheduled | %s | %2.3f%% | %2.3f%% | |
Total | %s | %2.3f%% | %2.3f%% | |
Undetermined | "); /* printf("Unscheduled | %s | %2.3f%% | |
Scheduled | %s | %2.3f%% | Nagios Not Running | %s | %2.3f%% | \n", time_indeterminate_notrunning_string, percent_time_indeterminate_notrunning); printf(" |
Insufficient Data | %s | %2.3f%% | ||
Total | %s | %2.3f%% | ||
All | Total | %s | 100.000%% | 100.000%% |
Host | Service | %% Time OK | %% Time Warning | %% Time Unknown | %% Time Critical | %% Time Undetermined |
---|---|---|---|---|---|---|
", bgclass, bgclass); if(strcmp(temp_subject->host_name, last_host)) host_report_url(temp_subject->host_name, temp_subject->host_name); printf(" | ", bgclass); service_report_url(temp_subject->host_name, temp_subject->service_description, temp_subject->service_description); printf(" | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
Average | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% (%2.3f%%) | %2.3f%% |
\n");
if(display_type == DISPLAY_HOST_INFO)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Information");
else if(display_type == DISPLAY_SERVICE_INFO)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Information");
else if(display_type == DISPLAY_COMMENTS)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Comments");
else if(display_type == DISPLAY_PERFORMANCE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Performance Information");
else if(display_type == DISPLAY_HOSTGROUP_INFO)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Hostgroup Information");
else if(display_type == DISPLAY_SERVICEGROUP_INFO)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Servicegroup Information");
else if(display_type == DISPLAY_DOWNTIME)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Scheduled Downtime");
else if(display_type == DISPLAY_SCHEDULING_QUEUE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Check Scheduling Queue");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Nagios Process Information");
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_info_table(temp_buffer, TRUE, ¤t_authdata);
/* find the host */
if(display_type == DISPLAY_HOST_INFO || display_type == DISPLAY_SERVICE_INFO) {
temp_host = find_host(host_name);
grab_host_macros_r(mac, temp_host);
if(display_type == DISPLAY_SERVICE_INFO) {
temp_service = find_service(host_name, service_desc);
grab_service_macros_r(mac, temp_service);
}
/* write some Javascript helper functions */
if(temp_host != NULL) {
printf("\n");
}
}
/* find the hostgroup */
else if(display_type == DISPLAY_HOSTGROUP_INFO) {
temp_hostgroup = find_hostgroup(hostgroup_name);
grab_hostgroup_macros_r(mac, temp_hostgroup);
}
/* find the servicegroup */
else if(display_type == DISPLAY_SERVICEGROUP_INFO) {
temp_servicegroup = find_servicegroup(servicegroup_name);
grab_servicegroup_macros_r(mac, temp_servicegroup);
}
if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) {
printf("
| \n");
/* middle column of top row */
printf("\n");
if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) {
if(display_type == DISPLAY_HOST_INFO) {
printf(" Host \n");
printf("%s \n", temp_host->alias);
printf("(%s) \n", temp_host->name); if(temp_host->parent_hosts != NULL) { /* print all parent hosts */ printf(" Parents: \n");
for(temp_parenthost = temp_host->parent_hosts; temp_parenthost != NULL; temp_parenthost = temp_parenthost->next)
printf("\n", STATUS_CGI, url_encode(temp_parenthost->host_name), temp_parenthost->host_name);
printf(""); } printf(" Member of ");
for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == TRUE) {
if(found == TRUE)
printf(", ");
printf("%s", STATUS_CGI, url_encode(temp_hostgroup->group_name), temp_hostgroup->group_name);
found = TRUE;
}
}
if(found == FALSE)
printf("No hostgroups");
printf(" \n"); printf(" %s \n", temp_host->address);
}
if(display_type == DISPLAY_SERVICE_INFO) {
printf("Service %s On Host \n", service_desc);
printf("%s \n", temp_host->alias);
printf("(%s) \n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name), temp_host->name); printf(" Member of ");
for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
if(is_service_member_of_servicegroup(temp_servicegroup, temp_service) == TRUE) {
if(found == TRUE)
printf(", ");
printf("%s", STATUS_CGI, url_encode(temp_servicegroup->group_name), temp_servicegroup->group_name);
found = TRUE;
}
}
if(found == FALSE)
printf("No servicegroups.");
printf(" \n"); printf(" %s \n", temp_host->address);
}
if(display_type == DISPLAY_HOSTGROUP_INFO) {
printf("Hostgroup \n");
printf("%s \n", temp_hostgroup->alias);
printf("(%s) \n", temp_hostgroup->group_name);
if(temp_hostgroup->notes != NULL) {
process_macros_r(mac, temp_hostgroup->notes, &processed_string, 0);
printf("%s ", processed_string); free(processed_string); } } if(display_type == DISPLAY_SERVICEGROUP_INFO) { printf("Servicegroup \n");
printf("%s \n", temp_servicegroup->alias);
printf("(%s) \n", temp_servicegroup->group_name);
if(temp_servicegroup->notes != NULL) {
process_macros_r(mac, temp_servicegroup->notes, &processed_string, 0);
printf("%s ", processed_string); free(processed_string); } } if(display_type == DISPLAY_SERVICE_INFO) { if(temp_service->icon_image != NULL) { printf("", (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt, (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt); } if(temp_service->icon_image_alt != NULL) printf("( %s )\n", temp_service->icon_image_alt); if(temp_service->notes != NULL) { process_macros_r(mac, temp_service->notes, &processed_string, 0); printf(" %s \n", processed_string); free(processed_string); } } if(display_type == DISPLAY_HOST_INFO) { if(temp_host->icon_image != NULL) { printf("", (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt); } if(temp_host->icon_image_alt != NULL) printf("( %s )\n", temp_host->icon_image_alt); if(temp_host->notes != NULL) { process_macros_r(mac, temp_host->notes, &processed_string, 0); printf(" %s \n", processed_string); free(processed_string); } } } printf(" | \n");
/* right column of top row */
printf("\n"); if(display_type == DISPLAY_HOST_INFO && temp_host != NULL) { printf(" | \n"); /* end of top table */ printf("
\n");
printf(" Process Information \n");
printf("
| \n");
printf(" Process Commands \n");
printf("
|
\n");
printf(" Host State Information \n");
if(temp_hoststatus->has_been_checked == FALSE)
printf("This host has not yet been checked, so status information is not available. \n");
else {
printf("
| \n");
printf("\n");
printf("
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\n"); if(is_authorized_for_read_only(¤t_authdata) == FALSE) { /* display comments */ display_comments(HOST_COMMENT); } printf(" | \n"); printf("
\n");
printf(" Service State Information \n");
if(temp_svcstatus->has_been_checked == FALSE)
printf("This service has not yet been checked, so status information is not available. \n");
else {
printf("
| \n");
printf("\n");
printf("
| \n");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\n"); if(is_authorized_for_read_only(¤t_authdata) == FALSE) { /* display comments */ display_comments(SERVICE_COMMENT); } printf(" | \n"); printf("
\n"); /* right top panel */ printf(" | \n");
printf(" Hostgroup Commands \n");
if(nagios_process_state == STATE_OK && is_authorized_for_read_only(¤t_authdata) == FALSE) {
printf("
Your account does not have permissions to execute commands. \n"); } else { printf(" It appears as though Nagios is not running, so commands are temporarily unavailable... \n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
}
printf("\n"); printf("Click here to view Nagios process information | |||||||||||||||||
\n"); printf(" |
\n"); /* right top panel */ printf(" | \n");
printf(" Servicegroup Commands \n");
if(nagios_process_state == STATE_OK) {
printf("
It appears as though Nagios is not running, so commands are temporarily unavailable... \n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
}
printf("\n"); printf("Click here to view Nagios process information | |||||||||||||||||
\n"); printf(" |
Host Name | Entry Time | Author | Comment | Comment ID | Persistent | Type | Expires | Actions |
---|---|---|---|---|---|---|---|---|
%s | ", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name); printf("%s | %s | %s | %ld | %s | %s | %s | ", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); printf("|
There are no host comments |
Host Name | Service | Entry Time | Author | Comment | Comment ID | Persistent | Type | Expires | Actions |
---|---|---|---|---|---|---|---|---|---|
%s | ", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name); printf("%s | ", url_encode(temp_comment->service_description), temp_comment->service_description); printf("%s | %s | %s | %ld | %s | %s | %s | ", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A"); printf("|
There are no service comments |
Services Actively Checked: | \n");
printf("\n");
/* fake this so we don't divide by zero for just showing the table */
if(total_active_service_checks == 0)
total_active_service_checks = 1;
printf("
| \n");
printf("
| \n");
printf("|||||||||||||||||||||||||||||||||||||||||||||||||
Services Passively Checked: | \n");
printf("\n");
/* fake this so we don't divide by zero for just showing the table */
if(total_passive_service_checks == 0)
total_passive_service_checks = 1;
printf("
| \n");
printf("
| \n");
printf("|||||||||||||||||||||||||||||||||||||||||||||||||
Hosts Actively Checked: | \n");
printf("\n");
/* fake this so we don't divide by zero for just showing the table */
if(total_active_host_checks == 0)
total_active_host_checks = 1;
printf("
| \n");
printf("
| \n");
printf("|||||||||||||||||||||||||||||||||||||||||||||||||
Hosts Passively Checked: | \n");
printf("\n");
/* fake this so we don't divide by zero for just showing the table */
if(total_passive_host_checks == 0)
total_passive_host_checks = 1;
printf("
| \n");
printf("
| \n");
printf("|||||||||||||||||||||||||||||||||||||||||||||||||
Check Statistics: | \n");
printf("\n");
printf("
| \n");
printf("||||||||||||||||||||||||||||||||||||||||||||||||||
Buffer Usage: | \n");
printf("\n");
printf("
| \n");
printf("
", url_images_path, COMMENT_ICON); if(type == HOST_COMMENT) printf("", COMMAND_CGI, CMD_ADD_HOST_COMMENT, url_encode(host_name)); else { printf("", url_encode(service_desc)); } printf("Add a new comment | \n"); printf("", url_images_path, DELETE_ICON); if(type == HOST_COMMENT) printf("", COMMAND_CGI, CMD_DEL_ALL_HOST_COMMENTS, url_encode(host_name)); else { printf("", url_encode(service_desc)); } printf("Delete all comments | \n"); printf("
Host Name | Entry Time | Author | Comment | Start Time | End Time | Type | Duration | Downtime ID | Trigger ID | Actions |
---|---|---|---|---|---|---|---|---|---|---|
%s | ", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name); get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bg_class, date_time); printf("%s | ", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author); printf("%s | ", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment); get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bg_class, date_time); get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bg_class, date_time); printf("%s | ", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible"); get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds); printf("%dd %dh %dm %ds | ", bg_class, days, hours, minutes, seconds); printf("%lu | ", bg_class, temp_downtime->downtime_id); printf("", bg_class); if(temp_downtime->triggered_by == 0) printf("N/A"); else printf("%lu", temp_downtime->triggered_by); printf(" | \n"); printf("|
There are no hosts with scheduled downtime |
Host Name | Service | Entry Time | Author | Comment | Start Time | End Time | Type | Duration | Downtime ID | Trigger ID | Actions |
---|---|---|---|---|---|---|---|---|---|---|---|
%s | ", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name); printf("%s | ", url_encode(temp_downtime->service_description), temp_downtime->service_description); get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bg_class, date_time); printf("%s | ", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author); printf("%s | ", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment); get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bg_class, date_time); get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bg_class, date_time); printf("%s | ", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible"); get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds); printf("%dd %dh %dm %ds | ", bg_class, days, hours, minutes, seconds); printf("%lu | ", bg_class, temp_downtime->downtime_id); printf("", bg_class); if(temp_downtime->triggered_by == 0) printf("N/A"); else printf("%lu", temp_downtime->triggered_by); printf(" | \n"); printf("|
There are no services with scheduled downtime |
\n"); printf("
Host | ", temp_url, SORT_ASCENDING, SORT_HOSTNAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTNAME, url_images_path, DOWN_ARROW_ICON);
printf("Service | ", temp_url, SORT_ASCENDING, SORT_SERVICENAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_SERVICENAME, url_images_path, DOWN_ARROW_ICON);
printf("Last Check | ", temp_url, SORT_ASCENDING, SORT_LASTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_LASTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
printf("Next Check | ", temp_url, SORT_ASCENDING, SORT_NEXTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_NEXTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
printf("Type | Active Checks | Actions | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
%s | ", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_svcstatus->host_name), temp_svcstatus->host_name); printf("%s | ", url_encode(temp_svcstatus->description), temp_svcstatus->description); get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bgclass, (temp_svcstatus->last_check == (time_t)0) ? "N/A" : date_time); get_time_string(&temp_svcstatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bgclass, (temp_svcstatus->next_check == (time_t)0) ? "N/A" : date_time); printf("", bgclass); if(temp_svcstatus->check_options == CHECK_OPTION_NONE) printf("Normal "); else { if(temp_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION) printf("Forced "); if(temp_svcstatus->check_options & CHECK_OPTION_FRESHNESS_CHECK) printf("Freshness "); if(temp_svcstatus->check_options & CHECK_OPTION_ORPHAN_CHECK) printf("Orphan "); } printf(" | "); printf("%s | ", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("", bgclass);
if(temp_svcstatus->checks_enabled == TRUE) {
printf(" | \n");
}
/* get the host status */
else {
printf("%s | ", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_hststatus->host_name), temp_hststatus->host_name); printf("", bgclass); get_time_string(&temp_hststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf(" | %s | ", bgclass, (temp_hststatus->last_check == (time_t)0) ? "N/A" : date_time); get_time_string(&temp_hststatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME); printf("%s | ", bgclass, (temp_hststatus->next_check == (time_t)0) ? "N/A" : date_time); printf("", bgclass); if(temp_hststatus->check_options == CHECK_OPTION_NONE) printf("Normal "); else { if(temp_hststatus->check_options & CHECK_OPTION_FORCE_EXECUTION) printf("Forced "); if(temp_hststatus->check_options & CHECK_OPTION_FRESHNESS_CHECK) printf("Freshness "); if(temp_hststatus->check_options & CHECK_OPTION_ORPHAN_CHECK) printf("Orphan "); } printf(" | "); printf("%s | ", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED"); printf("", bgclass);
if(temp_hststatus->checks_enabled == TRUE) {
printf(" | \n");
}
printf("
\n");
if(display_type == DISPLAY_SERVICES)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Alert History");
else if(show_all_hosts == TRUE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Alert History");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Alert History");
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_info_table(temp_buffer, FALSE, ¤t_authdata);
printf("
| \n");
/* middle column of top row */
printf("\n");
printf(" \n");
if(display_type == DISPLAY_SERVICES)
printf("Service '%s' On Host '%s'", svc_description, host_name);
else if(show_all_hosts == TRUE)
printf("All Hosts and Services");
else
printf("Host '%s'", host_name);
printf(" \n");
printf("\n"); snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s?%shost=%s&type=%d&statetype=%d&", HISTORY_CGI, (use_lifo == FALSE) ? "oldestfirst&" : "", url_encode(host_name), history_options, state_options); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; if(display_type == DISPLAY_SERVICES) { snprintf(temp_buffer2, sizeof(temp_buffer2) - 1, "service=%s&", url_encode(svc_description)); temp_buffer2[sizeof(temp_buffer2) - 1] = '\x0'; strncat(temp_buffer, temp_buffer2, sizeof(temp_buffer) - strlen(temp_buffer) - 1); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; } display_nav_table(temp_buffer, log_archive); printf(" | \n");
/* right hand column of top row */
printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
%s | ", current_message_date); printf("
\n");
if(show_all_hosts == TRUE)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Network Map For All Hosts");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Network Map For Host %s", host_name);
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_info_table(temp_buffer, TRUE, ¤t_authdata);
printf("
| \n");
/* center column of top row */
printf("\n");
/* print image size and scaling info */
#ifdef DEBUG
printf(" \n");
printf("[ Raw Image Size: %d x %d pixels | Scaling Factor: %1.2lf | Scaled Image Size: %d x %d pixels ]", canvas_width, canvas_height, scaling_factor, (int)(canvas_width * scaling_factor), (int)(canvas_height * scaling_factor));
printf(" \n");
printf("\n");
printf("[ Canvas_x: %d | Canvas_y: %d | Canvas_width: %d | Canvas_height: %d ]", canvas_x, canvas_y, canvas_width, canvas_height);
printf(" \n");
#endif
/* zoom links */
if(user_supplied_canvas == FALSE && strcmp(host_name, "all") && display_header == TRUE) {
printf("\n");
zoom_width_granularity = ((total_image_width - MINIMUM_PROXIMITY_WIDTH) / 11);
if(zoom_width_granularity == 0)
zoom_width_granularity = 1;
zoom_height_granularity = ((total_image_height - MINIMUM_PROXIMITY_HEIGHT) / 11);
if(proximity_width <= 0)
current_zoom_granularity = 0;
else
current_zoom_granularity = (total_image_width - proximity_width) / zoom_width_granularity;
if(current_zoom_granularity > 10)
current_zoom_granularity = 10;
printf(" \n");
}
printf("
| \n");
/* right hand column of top row */
printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
%s | |
Name: | %s |
Alias: | %s |
Address: | %s |
State: | "); /* get the status of the host (pending, up, down, or unreachable) */ if(temp_status->status == HOST_DOWN) { printf("Down"); if(temp_status->problem_has_been_acknowledged == TRUE) printf(" (Acknowledged)"); printf(""); } else if(temp_status->status == HOST_UNREACHABLE) { printf("Unreachable"); if(temp_status->problem_has_been_acknowledged == TRUE) printf(" (Acknowledged)"); printf(""); } else if(temp_status->status == HOST_UP) printf("Up"); else if(temp_status->status == HOST_PENDING) printf("Pending"); printf(" |
Status Information: | %s |
State Duration: | %s |
Last Status Check: | %s |
Last State Change: | %s |
Parent Host(s): | "); if(hst->parent_hosts == NULL) printf("None (This is a root host)"); else { for(temp_hostsmember = hst->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) printf("%s%s", (temp_hostsmember == hst->parent_hosts) ? "" : ", ", html_encode(temp_hostsmember->host_name, TRUE)); } printf(" |
Immediate Child Hosts: | "); printf("%d", number_of_immediate_child_hosts(hst)); printf(" |
\n");
if(display_type == DISPLAY_HOST_HISTOGRAM)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Alert Histogram");
else if(display_type == DISPLAY_SERVICE_HISTOGRAM)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Alert Histogram");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host and Service Alert Histogram");
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_info_table(temp_buffer, FALSE, ¤t_authdata);
if(display_type != DISPLAY_NO_HISTOGRAM && input_type == GET_INPUT_NONE) {
printf("
| \n");
/* center column of top row */
printf("\n");
if(display_type != DISPLAY_NO_HISTOGRAM && input_type == GET_INPUT_NONE) {
printf(" \n");
if(display_type == DISPLAY_HOST_HISTOGRAM)
printf("Host '%s'", host_name);
else if(display_type == DISPLAY_SERVICE_HISTOGRAM)
printf("Service '%s' On Host '%s'", svc_description, host_name);
printf(" \n");
printf("\n"); printf(" \n"); get_time_string(&t1, start_timestring, sizeof(start_timestring) - 1, SHORT_DATE_TIME); get_time_string(&t2, end_timestring, sizeof(end_timestring) - 1, SHORT_DATE_TIME); printf(" %s to %s \n", start_timestring, end_timestring);
get_time_breakdown((time_t)(t2 - t1), &days, &hours, &minutes, &seconds);
printf("Duration: %dd %dh %dm %ds \n", days, hours, minutes, seconds);
}
printf(" | \n");
/* right hand column of top row */
printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
\n"); display_info_table("Configuration", FALSE, ¤t_authdata); printf(" | \n"); /* right hand column of top row */ printf("\n"); if(display_type != DISPLAY_NONE) { printf("\n"); } /* display context-sensitive help */ switch(display_type) { case DISPLAY_HOSTS: display_context_help(CONTEXTHELP_CONFIG_HOSTS); break; case DISPLAY_HOSTGROUPS: display_context_help(CONTEXTHELP_CONFIG_HOSTGROUPS); break; case DISPLAY_SERVICEGROUPS: display_context_help(CONTEXTHELP_CONFIG_SERVICEGROUPS); break; case DISPLAY_CONTACTS: display_context_help(CONTEXTHELP_CONFIG_CONTACTS); break; case DISPLAY_CONTACTGROUPS: display_context_help(CONTEXTHELP_CONFIG_CONTACTGROUPS); break; case DISPLAY_SERVICES: display_context_help(CONTEXTHELP_CONFIG_SERVICES); break; case DISPLAY_TIMEPERIODS: display_context_help(CONTEXTHELP_CONFIG_TIMEPERIODS); break; case DISPLAY_COMMANDS: display_context_help(CONTEXTHELP_CONFIG_COMMANDS); break; case DISPLAY_SERVICEDEPENDENCIES: display_context_help(CONTEXTHELP_CONFIG_SERVICEDEPENDENCIES); break; case DISPLAY_SERVICEESCALATIONS: display_context_help(CONTEXTHELP_CONFIG_HOSTESCALATIONS); break; case DISPLAY_HOSTDEPENDENCIES: display_context_help(CONTEXTHELP_CONFIG_HOSTDEPENDENCIES); break; case DISPLAY_HOSTESCALATIONS: display_context_help(CONTEXTHELP_CONFIG_HOSTESCALATIONS); break; case DISPLAY_COMMAND_EXPANSION: /* Reusing DISPLAY_COMMANDS help until further notice */ display_context_help(CONTEXTHELP_CONFIG_COMMANDS); break; default: display_context_help(CONTEXTHELP_CONFIG_MENU); break; } printf(" | \n"); /* end of top table */ printf("
Host Name | "); printf("Alias/Description | "); printf("Address | "); printf("Parent Hosts | "); printf("Max. Check Attempts | "); printf("Check Interval | \n"); printf("Retry Interval | \n"); printf("Host Check Command | "); printf("Check Period | "); printf("Obsess Over | \n"); printf("Enable Active Checks | \n"); printf("Enable Passive Checks | \n"); printf("Check Freshness | \n"); printf("Freshness Threshold | \n"); printf("Default Contacts/Groups | \n"); printf("Notification Interval | "); printf("First Notification Delay | "); printf("Notification Options | "); printf("Notification Period | "); printf("Event Handler | "); printf("Enable Event Handler | "); printf("Stalking Options | \n"); printf("Enable Flap Detection | "); printf("Low Flap Threshold | "); printf("High Flap Threshold | "); printf("Flap Detection Options | \n"); printf("Process Performance Data | "); printf("Enable Failure Prediction | "); printf("Failure Prediction Options | "); printf("Notes | "); printf("Notes URL | "); printf("Action URL | "); printf("2-D Coords | "); printf("3-D Coords | "); printf("Statusmap Image | "); printf("VRML Image | "); printf("Logo Image | "); printf("Image Alt | "); printf("Retention Options | "); printf("|||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
%s | \n", bg_class, url_encode(temp_host->name), CONFIG_CGI, url_encode(temp_host->name), html_encode(temp_host->name, FALSE)); printf("%s | \n", bg_class, html_encode(temp_host->alias, FALSE)); printf("%s | \n", bg_class, html_encode(temp_host->address, FALSE)); printf("", bg_class); for(temp_hostsmember = temp_host->parent_hosts; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) { if(temp_hostsmember != temp_host->parent_hosts) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_hostsmember->host_name), html_encode(temp_hostsmember->host_name, FALSE)); } if(temp_host->parent_hosts == NULL) printf(" "); printf(" | \n"); printf("%d | \n", bg_class, temp_host->max_attempts); get_interval_time_string(temp_host->check_interval, time_string, sizeof(time_string)); printf("%s | \n", bg_class, time_string); get_interval_time_string(temp_host->retry_interval, time_string, sizeof(time_string)); printf("%s | \n", bg_class, time_string); printf("", bg_class); if(temp_host->host_check_command == NULL) printf(" "); else /* printf("%s | \n",CONFIG_CGI,url_encode(strtok(temp_host->host_check_command,"!")),html_encode(temp_host->host_check_command,FALSE)); */ printf("%s\n", CONFIG_CGI, url_encode(temp_host->host_check_command), html_encode(temp_host->host_check_command, FALSE)); printf("\n"); printf("", bg_class); if(temp_host->check_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_host->check_period), html_encode(temp_host->check_period, FALSE)); printf(" | \n"); printf("%s | \n", bg_class, (temp_host->obsess_over_host == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_host->checks_enabled == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_host->accept_passive_host_checks == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_host->check_freshness == TRUE) ? "Yes" : "No"); printf("", bg_class); if(temp_host->freshness_threshold == 0) printf("Auto-determined value\n"); else printf("%d seconds\n", temp_host->freshness_threshold); printf(" | \n"); printf("", bg_class); /* find all the contacts for this host... */ contact = 0; for(temp_contactsmember = temp_host->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactsmember->contact_name), html_encode(temp_contactsmember->contact_name, FALSE)); } for(temp_contactgroupsmember = temp_host->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactgroupsmember->group_name), html_encode(temp_contactgroupsmember->group_name, FALSE)); } if(contact == 0) printf(" "); printf(" | \n"); get_interval_time_string(temp_host->notification_interval, time_string, sizeof(time_string)); printf("%s | \n", bg_class, (temp_host->notification_interval == 0) ? "No Re-notification" : html_encode(time_string, FALSE)); get_interval_time_string(temp_host->first_notification_delay, time_string, sizeof(time_string)); printf("%s | \n", bg_class, time_string); printf("", bg_class); options = 0; if(temp_host->notify_on_down == TRUE) { options = 1; printf("Down"); } if(temp_host->notify_on_unreachable == TRUE) { printf("%sUnreachable", (options) ? ", " : ""); options = 1; } if(temp_host->notify_on_recovery == TRUE) { printf("%sRecovery", (options) ? ", " : ""); options = 1; } if(temp_host->notify_on_flapping == TRUE) { printf("%sFlapping", (options) ? ", " : ""); options = 1; } if(temp_host->notify_on_downtime == TRUE) { printf("%sDowntime", (options) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("", bg_class); if(temp_host->notification_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_host->notification_period), html_encode(temp_host->notification_period, FALSE)); printf(" | \n"); printf("", bg_class); if(temp_host->event_handler == NULL) printf(" "); else /* printf("%s | \n",CONFIG_CGI,url_encode(strtok(temp_host->event_handler,"!")),html_encode(temp_host->event_handler,FALSE)); */ printf("%s\n", CONFIG_CGI, url_encode(temp_host->event_handler), html_encode(temp_host->event_handler, FALSE)); printf("\n"); printf("", bg_class); printf("%s\n", (temp_host->event_handler_enabled == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("", bg_class); options = 0; if(temp_host->stalk_on_up == TRUE) { options = 1; printf("Up"); } if(temp_host->stalk_on_down == TRUE) { printf("%sDown", (options) ? ", " : ""); options = 1; } if(temp_host->stalk_on_unreachable == TRUE) { printf("%sUnreachable", (options) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_host->flap_detection_enabled == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("", bg_class); if(temp_host->low_flap_threshold == 0.0) printf("Program-wide value\n"); else printf("%3.1f%%\n", temp_host->low_flap_threshold); printf(" | \n"); printf("", bg_class); if(temp_host->high_flap_threshold == 0.0) printf("Program-wide value\n"); else printf("%3.1f%%\n", temp_host->high_flap_threshold); printf(" | \n"); printf("", bg_class); options = 0; if(temp_host->flap_detection_on_up == TRUE) { options = 1; printf("Up"); } if(temp_host->flap_detection_on_down == TRUE) { printf("%sDown", (options) ? ", " : ""); options = 1; } if(temp_host->flap_detection_on_unreachable == TRUE) { printf("%sUnreachable", (options) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_host->process_performance_data == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_host->failure_prediction_enabled == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("%s | \n", bg_class, (temp_host->failure_prediction_options == NULL) ? " " : html_encode(temp_host->failure_prediction_options, FALSE)); printf("%s | ", bg_class, (temp_host->notes == NULL) ? " " : html_encode(temp_host->notes, FALSE)); printf("%s | ", bg_class, (temp_host->notes_url == NULL) ? " " : html_encode(temp_host->notes_url, FALSE)); printf("%s | ", bg_class, (temp_host->action_url == NULL) ? " " : html_encode(temp_host->action_url, FALSE)); if(temp_host->have_2d_coords == FALSE) printf("", bg_class); else printf(" | %d,%d | ", bg_class, temp_host->x_2d, temp_host->y_2d); if(temp_host->have_3d_coords == FALSE) printf("", bg_class); else printf(" | %.2f,%.2f,%.2f | ", bg_class, temp_host->x_3d, temp_host->y_3d, temp_host->z_3d); if(temp_host->statusmap_image == NULL) printf("", bg_class); else printf(" | ", bg_class); else printf(" | ", bg_class); else { process_macros_r(mac, temp_host->icon_image, &processed_string, 0); printf(" | %s | ", bg_class, (temp_host->icon_image_alt == NULL) ? " " : html_encode(temp_host->icon_image_alt, FALSE)); printf("", bg_class); options = 0; if(temp_host->retain_status_information == TRUE) { options = 1; printf("Status Information"); } if(temp_host->retain_nonstatus_information == TRUE) { printf("%sNon-Status Information", (options == 1) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("
\n"); printf("
Group Name | "); printf("Description | "); printf("Host Members | "); printf("Notes | "); printf("Notes URL | "); printf("Action URL | "); printf("
---|---|---|---|---|---|
%s | ", bg_class, html_encode(temp_hostgroup->group_name, FALSE)); printf("%s | \n", bg_class, html_encode(temp_hostgroup->alias, FALSE)); printf("", bg_class); /* find all the hosts that are members of this hostgroup... */ for(temp_hostsmember = temp_hostgroup->members; temp_hostsmember != NULL; temp_hostsmember = temp_hostsmember->next) { if(temp_hostsmember != temp_hostgroup->members) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_hostsmember->host_name), html_encode(temp_hostsmember->host_name, FALSE)); } printf(" | \n"); printf("%s | ", bg_class, (temp_hostgroup->notes == NULL) ? " " : html_encode(temp_hostgroup->notes, FALSE)); printf("%s | ", bg_class, (temp_hostgroup->notes_url == NULL) ? " " : html_encode(temp_hostgroup->notes_url, FALSE)); printf("%s | ", bg_class, (temp_hostgroup->action_url == NULL) ? " " : html_encode(temp_hostgroup->action_url, FALSE)); printf("
\n"); printf("
Group Name | "); printf("Description | "); printf("Service Members | "); printf("Notes | "); printf("Notes URL | "); printf("Action URL | "); printf("
---|---|---|---|---|---|
%s | ", bg_class, html_encode(temp_servicegroup->group_name, FALSE)); printf("%s | \n", bg_class, html_encode(temp_servicegroup->alias, FALSE)); printf("", bg_class); /* find all the services that are members of this servicegroup... */ for(temp_servicesmember = temp_servicegroup->members; temp_servicesmember != NULL; temp_servicesmember = temp_servicesmember->next) { printf("%s%s / ", (temp_servicesmember == temp_servicegroup->members) ? "" : ", ", CONFIG_CGI, url_encode(temp_servicesmember->host_name), html_encode(temp_servicesmember->host_name, FALSE)); printf("%s\n", url_encode(temp_servicesmember->service_description), html_encode(temp_servicesmember->service_description, FALSE)); } printf(" | \n"); printf("%s | ", bg_class, (temp_servicegroup->notes == NULL) ? " " : html_encode(temp_servicegroup->notes, FALSE)); printf("%s | ", bg_class, (temp_servicegroup->notes_url == NULL) ? " " : html_encode(temp_servicegroup->notes_url, FALSE)); printf("%s | ", bg_class, (temp_servicegroup->action_url == NULL) ? " " : html_encode(temp_servicegroup->action_url, FALSE)); printf("
\n"); printf("
Contact Name | "); printf("Alias | "); printf("Email Address | "); printf("Pager Address/Number | "); printf("Service Notification Options | "); printf("Host Notification Options | "); printf("Service Notification Period | "); printf("Host Notification Period | "); printf("Service Notification Commands | "); printf("Host Notification Commands | "); printf("Retention Options | "); printf("
---|---|---|---|---|---|---|---|---|---|---|
%s | \n", bg_class, url_encode(temp_contact->name), html_encode(temp_contact->name, FALSE)); printf("%s | \n", bg_class, html_encode(temp_contact->alias, FALSE)); printf("%s | \n", bg_class, (temp_contact->email == NULL) ? " " : url_encode(temp_contact->email), (temp_contact->email == NULL) ? " " : html_encode(temp_contact->email, FALSE)); printf("%s | \n", bg_class, (temp_contact->pager == NULL) ? " " : html_encode(temp_contact->pager, FALSE)); printf("", bg_class); options = 0; if(temp_contact->notify_on_service_unknown == TRUE) { options = 1; printf("Unknown"); } if(temp_contact->notify_on_service_warning == TRUE) { printf("%sWarning", (options) ? ", " : ""); options = 1; } if(temp_contact->notify_on_service_critical == TRUE) { printf("%sCritical", (options) ? ", " : ""); options = 1; } if(temp_contact->notify_on_service_recovery == TRUE) { printf("%sRecovery", (options) ? ", " : ""); options = 1; } if(temp_contact->notify_on_service_flapping == TRUE) { printf("%sFlapping", (options) ? ", " : ""); options = 1; } if(temp_contact->notify_on_service_downtime == TRUE) { printf("%sDowntime", (options) ? ", " : ""); options = 1; } if(!options) printf("None"); printf(" | \n"); printf("", bg_class); options = 0; if(temp_contact->notify_on_host_down == TRUE) { options = 1; printf("Down"); } if(temp_contact->notify_on_host_unreachable == TRUE) { printf("%sUnreachable", (options) ? ", " : ""); options = 1; } if(temp_contact->notify_on_host_recovery == TRUE) { printf("%sRecovery", (options) ? ", " : ""); options = 1; } if(temp_contact->notify_on_host_flapping == TRUE) { printf("%sFlapping", (options) ? ", " : ""); options = 1; } if(temp_contact->notify_on_host_downtime == TRUE) { printf("%sDowntime", (options) ? ", " : ""); options = 1; } if(!options) printf("None"); printf(" | \n"); printf("\n", bg_class); if(temp_contact->service_notification_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_contact->service_notification_period), html_encode(temp_contact->service_notification_period, FALSE)); printf(" | \n"); printf("\n", bg_class); if(temp_contact->host_notification_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_contact->host_notification_period), html_encode(temp_contact->host_notification_period, FALSE)); printf(" | \n"); printf("", bg_class); found = FALSE; for(temp_commandsmember = temp_contact->service_notification_commands; temp_commandsmember != NULL; temp_commandsmember = temp_commandsmember->next) { if(temp_commandsmember != temp_contact->service_notification_commands) printf(", "); /* printf("%s",CONFIG_CGI,url_encode(strtok(temp_commandsmember->command,"!")),html_encode(temp_commandsmember->command,FALSE)); */ printf("%s", CONFIG_CGI, url_encode(temp_commandsmember->command), html_encode(temp_commandsmember->command, FALSE)); found = TRUE; } if(found == FALSE) printf("None"); printf(" | \n"); printf("", bg_class); found = FALSE; for(temp_commandsmember = temp_contact->host_notification_commands; temp_commandsmember != NULL; temp_commandsmember = temp_commandsmember->next) { if(temp_commandsmember != temp_contact->host_notification_commands) printf(", "); /* printf("%s",CONFIG_CGI,url_encode(strtok(temp_commandsmember->command,"!")),html_encode(temp_commandsmember->command,FALSE)); */ printf("%s", CONFIG_CGI, url_encode(temp_commandsmember->command), html_encode(temp_commandsmember->command, FALSE)); found = TRUE; } if(found == FALSE) printf("None"); printf(" | \n"); printf("", bg_class); options = 0; if(temp_contact->retain_status_information == TRUE) { options = 1; printf("Status Information"); } if(temp_contact->retain_nonstatus_information == TRUE) { printf("%sNon-Status Information", (options == 1) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("
\n"); printf("
Group Name | \n"); printf("Description | \n"); printf("Contact Members | \n"); printf("
---|---|---|
%s | \n", bg_class, url_encode(temp_contactgroup->group_name), html_encode(temp_contactgroup->group_name, FALSE)); printf("%s | \n", bg_class, html_encode(temp_contactgroup->alias, FALSE)); /* find all the contact who are members of this contact group... */ printf("", bg_class); for(temp_contactsmember = temp_contactgroup->members; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { if(temp_contactsmember != temp_contactgroup->members) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactsmember->contact_name), html_encode(temp_contactsmember->contact_name, FALSE)); } printf(" | \n"); printf("
\n"); printf("
Service | "); printf("|||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Host | \n"); printf("Description | \n"); printf("Max. Check Attempts | \n"); printf("Normal Check Interval | \n"); printf("Retry Check Interal | \n"); printf("Check Command | \n"); printf("Check Period | \n"); printf("Parallelize | \n"); printf("Volatile | \n"); printf("Obsess Over | \n"); printf("Enable Active Checks | \n"); printf("Enable Passive Checks | \n"); printf("Check Freshness | \n"); printf("Freshness Threshold | \n"); printf("Default Contacts/Groups | \n"); printf("Enable Notifications | \n"); printf("Notification Interval | \n"); printf("First Notification Delay | \n"); printf("Notification Options | \n"); printf("Notification Period | \n"); printf("Event Handler | "); printf("Enable Event Handler | "); printf("Stalking Options | \n"); printf("Enable Flap Detection | "); printf("Low Flap Threshold | "); printf("High Flap Threshold | "); printf("Flap Detection Options | "); printf("Process Performance Data | "); printf("Enable Failure Prediction | "); printf("Failure Prediction Options | "); printf("Notes | "); printf("Notes URL | "); printf("Action URL | "); printf("Logo Image | "); printf("Image Alt | "); printf("Retention Options | "); printf("||
", url_encode(temp_service->description)); printf("%s | \n", CONFIG_CGI, url_encode(temp_service->host_name), html_encode(temp_service->host_name, FALSE)); printf("%s | \n", bg_class, html_encode(temp_service->description, FALSE)); printf("%d | \n", bg_class, temp_service->max_attempts); get_interval_time_string(temp_service->check_interval, time_string, sizeof(time_string)); printf("%s | \n", bg_class, time_string); get_interval_time_string(temp_service->retry_interval, time_string, sizeof(time_string)); printf("%s | \n", bg_class, time_string); strncpy(command_line, temp_service->service_check_command, sizeof(command_line)); command_line[sizeof(command_line) - 1] = '\x0'; command_name = strtok(strdup(command_line), "!"); /* printf("%s | \n",bg_class,CONFIG_CGI,url_encode(command_name),html_encode(command_line,FALSE)); */ printf("%s | \n", bg_class, CONFIG_CGI, url_encode(command_line), html_encode(command_line, FALSE)); free(command_name); printf("", bg_class); if(temp_service->check_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_service->check_period), html_encode(temp_service->check_period, FALSE)); printf(" | \n"); printf("%s | \n", bg_class, (temp_service->parallelize == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_service->is_volatile == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_service->obsess_over_service == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_service->checks_enabled == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_service->accept_passive_service_checks == TRUE) ? "Yes" : "No"); printf("%s | \n", bg_class, (temp_service->check_freshness == TRUE) ? "Yes" : "No"); printf("", bg_class); if(temp_service->freshness_threshold == 0) printf("Auto-determined value\n"); else printf("%d seconds\n", temp_service->freshness_threshold); printf(" | \n"); printf("", bg_class); contact = 0; for(temp_contactsmember = temp_service->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s", CONFIG_CGI, url_encode(temp_contactsmember->contact_name), html_encode(temp_contactsmember->contact_name, FALSE)); } for(temp_contactgroupsmember = temp_service->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactgroupsmember->group_name), html_encode(temp_contactgroupsmember->group_name, FALSE)); } if(contact == 0) printf(" "); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_service->notifications_enabled == TRUE) ? "Yes" : "No"); printf(" | \n"); get_interval_time_string(temp_service->notification_interval, time_string, sizeof(time_string)); printf("%s | \n", bg_class, (temp_service->notification_interval == 0) ? "No Re-notification" : html_encode(time_string, FALSE)); get_interval_time_string(temp_service->first_notification_delay, time_string, sizeof(time_string)); printf("%s | \n", bg_class, time_string); printf("", bg_class); options = 0; if(temp_service->notify_on_unknown == TRUE) { options = 1; printf("Unknown"); } if(temp_service->notify_on_warning == TRUE) { printf("%sWarning", (options) ? ", " : ""); options = 1; } if(temp_service->notify_on_critical == TRUE) { printf("%sCritical", (options) ? ", " : ""); options = 1; } if(temp_service->notify_on_recovery == TRUE) { printf("%sRecovery", (options) ? ", " : ""); options = 1; } if(temp_service->notify_on_flapping == TRUE) { printf("%sFlapping", (options) ? ", " : ""); options = 1; } if(temp_service->notify_on_downtime == TRUE) { printf("%sDowntime", (options) ? ", " : ""); options = 1; } if(!options) printf("None"); printf(" | \n"); printf("", bg_class); if(temp_service->notification_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_service->notification_period), html_encode(temp_service->notification_period, FALSE)); printf(" | \n"); printf("", bg_class); if(temp_service->event_handler == NULL) printf(" "); else /* printf("%s",CONFIG_CGI,url_encode(strtok(temp_service->event_handler,"!")),html_encode(temp_service->event_handler,FALSE)); */ printf("%s", CONFIG_CGI, url_encode(temp_service->event_handler), html_encode(temp_service->event_handler, FALSE)); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_service->event_handler_enabled == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("", bg_class); options = 0; if(temp_service->stalk_on_ok == TRUE) { options = 1; printf("Ok"); } if(temp_service->stalk_on_warning == TRUE) { printf("%sWarning", (options) ? ", " : ""); options = 1; } if(temp_service->stalk_on_unknown == TRUE) { printf("%sUnknown", (options) ? ", " : ""); options = 1; } if(temp_service->stalk_on_critical == TRUE) { printf("%sCritical", (options) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_service->flap_detection_enabled == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("", bg_class); if(temp_service->low_flap_threshold == 0.0) printf("Program-wide value\n"); else printf("%3.1f%%\n", temp_service->low_flap_threshold); printf(" | \n"); printf("", bg_class); if(temp_service->high_flap_threshold == 0.0) printf("Program-wide value\n"); else printf("%3.1f%%\n", temp_service->high_flap_threshold); printf(" | \n"); printf("", bg_class); options = 0; if(temp_service->flap_detection_on_ok == TRUE) { options = 1; printf("Ok"); } if(temp_service->flap_detection_on_warning == TRUE) { printf("%sWarning", (options) ? ", " : ""); options = 1; } if(temp_service->flap_detection_on_unknown == TRUE) { printf("%sUnknown", (options) ? ", " : ""); options = 1; } if(temp_service->flap_detection_on_critical == TRUE) { printf("%sCritical", (options) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_service->process_performance_data == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("", bg_class); printf("%s\n", (temp_service->failure_prediction_enabled == TRUE) ? "Yes" : "No"); printf(" | \n"); printf("%s | \n", bg_class, (temp_service->failure_prediction_options == NULL) ? " " : html_encode(temp_service->failure_prediction_options, FALSE)); printf("%s | ", bg_class, (temp_service->notes == NULL) ? " " : html_encode(temp_service->notes, FALSE)); printf("%s | ", bg_class, (temp_service->notes_url == NULL) ? " " : html_encode(temp_service->notes_url, FALSE)); printf("%s | ", bg_class, (temp_service->action_url == NULL) ? " " : html_encode(temp_service->action_url, FALSE)); if(temp_service->icon_image == NULL) printf("", bg_class); else { process_macros_r(mac, temp_service->icon_image, &processed_string, 0); printf(" | %s | ", bg_class, (temp_service->icon_image_alt == NULL) ? " " : html_encode(temp_service->icon_image_alt, FALSE)); printf("", bg_class); options = 0; if(temp_service->retain_status_information == TRUE) { options = 1; printf("Status Information"); } if(temp_service->retain_nonstatus_information == TRUE) { printf("%sNon-Status Information", (options == 1) ? ", " : ""); options = 1; } if(options == 0) printf("None"); printf(" | \n"); printf("
\n"); printf("
Name | \n"); printf("Alias/Description | \n"); printf("Exclusions | \n"); printf("Days/Dates | \n"); printf("Times | \n"); printf("
---|---|---|---|---|
%s | \n", bg_class, url_encode(temp_timeperiod->name), html_encode(temp_timeperiod->name, FALSE)); printf("%s | \n", bg_class, html_encode(temp_timeperiod->alias, FALSE)); printf("", bg_class); item = 0; for(temp_timeperiodexclusion = temp_timeperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) { item++; printf("%s%s", (item == 1) ? "" : ", ", url_encode(temp_timeperiodexclusion->timeperiod_name), html_encode(temp_timeperiodexclusion->timeperiod_name, FALSE)); } printf(" | "); printf("", bg_class); line = 0; for(x = 0; x < DATERANGE_TYPES; x++) { for(temp_daterange = temp_timeperiod->exceptions[x]; temp_daterange != NULL; temp_daterange = temp_daterange->next) { line++; if(line > 1) printf(" | |
\n", bg_class); switch(temp_daterange->type) { case DATERANGE_CALENDAR_DATE: printf("%d-%02d-%02d", temp_daterange->syear, temp_daterange->smon + 1, temp_daterange->smday); if((temp_daterange->smday != temp_daterange->emday) || (temp_daterange->smon != temp_daterange->emon) || (temp_daterange->syear != temp_daterange->eyear)) printf(" - %d-%02d-%02d", temp_daterange->eyear, temp_daterange->emon + 1, temp_daterange->emday); if(temp_daterange->skip_interval > 1) printf(" / %d", temp_daterange->skip_interval); break; case DATERANGE_MONTH_DATE: printf("%s %d", months[temp_daterange->smon], temp_daterange->smday); if((temp_daterange->smon != temp_daterange->emon) || (temp_daterange->smday != temp_daterange->emday)) { printf(" - %s %d", months[temp_daterange->emon], temp_daterange->emday); if(temp_daterange->skip_interval > 1) printf(" / %d", temp_daterange->skip_interval); } break; case DATERANGE_MONTH_DAY: printf("day %d", temp_daterange->smday); if(temp_daterange->smday != temp_daterange->emday) { printf(" - %d", temp_daterange->emday); if(temp_daterange->skip_interval > 1) printf(" / %d", temp_daterange->skip_interval); } break; case DATERANGE_MONTH_WEEK_DAY: printf("%s %d %s", days[temp_daterange->swday], temp_daterange->swday_offset, months[temp_daterange->smon]); if((temp_daterange->smon != temp_daterange->emon) || (temp_daterange->swday != temp_daterange->ewday) || (temp_daterange->swday_offset != temp_daterange->ewday_offset)) { printf(" - %s %d %s", days[temp_daterange->ewday], temp_daterange->ewday_offset, months[temp_daterange->emon]); if(temp_daterange->skip_interval > 1) printf(" / %d", temp_daterange->skip_interval); } break; case DATERANGE_WEEK_DAY: printf("%s %d", days[temp_daterange->swday], temp_daterange->swday_offset); if((temp_daterange->swday != temp_daterange->ewday) || (temp_daterange->swday_offset != temp_daterange->ewday_offset)) { printf(" - %s %d", days[temp_daterange->ewday], temp_daterange->ewday_offset); if(temp_daterange->skip_interval > 1) printf(" / %d", temp_daterange->skip_interval); } break; default: break; } printf(" | \n", bg_class); for(temp_timerange = temp_daterange->times; temp_timerange != NULL; temp_timerange = temp_timerange->next) { if(temp_timerange != temp_daterange->times) printf(", "); hours = temp_timerange->range_start / 3600; minutes = (temp_timerange->range_start - (hours * 3600)) / 60; seconds = temp_timerange->range_start - (hours * 3600) - (minutes * 60); snprintf(timestring, sizeof(timestring) - 1, "%02d:%02d:%02d", hours, minutes, seconds); timestring[sizeof(timestring) - 1] = '\x0'; printf("%s - ", timestring); hours = temp_timerange->range_end / 3600; minutes = (temp_timerange->range_end - (hours * 3600)) / 60; seconds = temp_timerange->range_end - (hours * 3600) - (minutes * 60); snprintf(timestring, sizeof(timestring) - 1, "%02d:%02d:%02d", hours, minutes, seconds); timestring[sizeof(timestring) - 1] = '\x0'; printf("%s", timestring); } printf(" | \n"); printf("|||
\n", bg_class); printf("%s", days[day]); printf(" | \n", bg_class); for(temp_timerange = temp_timeperiod->days[day]; temp_timerange != NULL; temp_timerange = temp_timerange->next) { if(temp_timerange != temp_timeperiod->days[day]) printf(", "); hours = temp_timerange->range_start / 3600; minutes = (temp_timerange->range_start - (hours * 3600)) / 60; seconds = temp_timerange->range_start - (hours * 3600) - (minutes * 60); snprintf(timestring, sizeof(timestring) - 1, "%02d:%02d:%02d", hours, minutes, seconds); timestring[sizeof(timestring) - 1] = '\x0'; printf("%s - ", timestring); hours = temp_timerange->range_end / 3600; minutes = (temp_timerange->range_end - (hours * 3600)) / 60; seconds = temp_timerange->range_end - (hours * 3600) - (minutes * 60); snprintf(timestring, sizeof(timestring) - 1, "%02d:%02d:%02d", hours, minutes, seconds); timestring[sizeof(timestring) - 1] = '\x0'; printf("%s", timestring); } printf(" | \n"); printf("
\n"); printf("
Dependent Service | "); printf("Master Service | "); printf("|||||
---|---|---|---|---|---|---|
Host | "); printf("Service | "); printf("Host | "); printf("Service | "); printf("Dependency Type | "); printf("Dependency Period | "); printf("Dependency Failure Options | "); printf("
%s | ", bg_class, CONFIG_CGI, url_encode(temp_sd->dependent_host_name), html_encode(temp_sd->dependent_host_name, FALSE)); printf("%s | \n", url_encode(temp_sd->dependent_service_description), html_encode(temp_sd->dependent_service_description, FALSE)); printf("%s | ", bg_class, CONFIG_CGI, url_encode(temp_sd->host_name), html_encode(temp_sd->host_name, FALSE)); printf("%s | \n", url_encode(temp_sd->service_description), html_encode(temp_sd->service_description, FALSE)); printf("%s | ", bg_class, (temp_sd->dependency_type == NOTIFICATION_DEPENDENCY) ? "Notification" : "Check Execution"); printf("", bg_class); if(temp_sd->dependency_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_sd->dependency_period), html_encode(temp_sd->dependency_period, FALSE)); printf(" | \n"); printf("", bg_class); options = FALSE; if(temp_sd->fail_on_ok == TRUE) { printf("Ok"); options = TRUE; } if(temp_sd->fail_on_warning == TRUE) { printf("%sWarning", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_sd->fail_on_unknown == TRUE) { printf("%sUnknown", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_sd->fail_on_critical == TRUE) { printf("%sCritical", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_sd->fail_on_pending == TRUE) { printf("%sPending", (options == TRUE) ? ", " : ""); options = TRUE; } printf(" | \n"); printf("
\n"); printf("
Service | "); printf("|||||||
---|---|---|---|---|---|---|---|
Host | "); printf("Description | "); printf("Contacts/Groups | "); printf("First Notification | "); printf("Last Notification | "); printf("Notification Interval | "); printf("Escalation Period | "); printf("Escalation Options | "); printf("
%s | ", bg_class, CONFIG_CGI, url_encode(temp_se->host_name), html_encode(temp_se->host_name, FALSE)); printf("%s | \n", url_encode(temp_se->description), html_encode(temp_se->description, FALSE)); printf("", bg_class); contact = 0; for(temp_contactsmember = temp_se->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactsmember->contact_name), html_encode(temp_contactsmember->contact_name, FALSE)); } for(temp_contactgroupsmember = temp_se->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactgroupsmember->group_name), html_encode(temp_contactgroupsmember->group_name, FALSE)); } if(contact == 0) printf(" "); printf(" | \n"); printf("%d | ", bg_class, temp_se->first_notification); printf("", bg_class); if(temp_se->last_notification == 0) printf("Infinity"); else printf("%d", temp_se->last_notification); printf(" | \n"); get_interval_time_string(temp_se->notification_interval, time_string, sizeof(time_string)); printf("", bg_class); if(temp_se->notification_interval == 0.0) printf("Notify Only Once (No Re-notification)"); else printf("%s", time_string); printf(" | \n"); printf("", bg_class); if(temp_se->escalation_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_se->escalation_period), html_encode(temp_se->escalation_period, FALSE)); printf(" | \n"); printf("", bg_class); options = FALSE; if(temp_se->escalate_on_warning == TRUE) { printf("%sWarning", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_se->escalate_on_unknown == TRUE) { printf("%sUnknown", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_se->escalate_on_critical == TRUE) { printf("%sCritical", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_se->escalate_on_recovery == TRUE) { printf("%sRecovery", (options == TRUE) ? ", " : ""); options = TRUE; } if(options == FALSE) printf("None"); printf(" | \n"); printf("
\n"); printf("
Dependent Host | "); printf("Master Host | "); printf("Dependency Type | "); printf("Dependency Period | "); printf("Dependency Failure Options | "); printf("
---|---|---|---|---|
%s | ", bg_class, CONFIG_CGI, url_encode(temp_hd->dependent_host_name), html_encode(temp_hd->dependent_host_name, FALSE)); printf("%s | ", bg_class, CONFIG_CGI, url_encode(temp_hd->host_name), html_encode(temp_hd->host_name, FALSE)); printf("%s | ", bg_class, (temp_hd->dependency_type == NOTIFICATION_DEPENDENCY) ? "Notification" : "Check Execution"); printf("", bg_class); if(temp_hd->dependency_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_hd->dependency_period), html_encode(temp_hd->dependency_period, FALSE)); printf(" | \n"); printf("", bg_class); options = FALSE; if(temp_hd->fail_on_up == TRUE) { printf("Up"); options = TRUE; } if(temp_hd->fail_on_down == TRUE) { printf("%sDown", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_hd->fail_on_unreachable == TRUE) { printf("%sUnreachable", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_hd->fail_on_pending == TRUE) { printf("%sPending", (options == TRUE) ? ", " : ""); options = TRUE; } printf(" | \n"); printf("
\n"); printf("
Host | "); printf("Contacts/Groups | "); printf("First Notification | "); printf("Last Notification | "); printf("Notification Interval | "); printf("Escalation Period | "); printf("Escalation Options | "); printf("
---|---|---|---|---|---|---|
%s | ", bg_class, CONFIG_CGI, url_encode(temp_he->host_name), html_encode(temp_he->host_name, FALSE)); printf("", bg_class); contact = 0; for(temp_contactsmember = temp_he->contacts; temp_contactsmember != NULL; temp_contactsmember = temp_contactsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactsmember->contact_name), html_encode(temp_contactsmember->contact_name, FALSE)); } for(temp_contactgroupsmember = temp_he->contact_groups; temp_contactgroupsmember != NULL; temp_contactgroupsmember = temp_contactgroupsmember->next) { contact++; if(contact > 1) printf(", "); printf("%s\n", CONFIG_CGI, url_encode(temp_contactgroupsmember->group_name), html_encode(temp_contactgroupsmember->group_name, FALSE)); } if(contact == 0) printf(" "); printf(" | \n"); printf("%d | ", bg_class, temp_he->first_notification); printf("", bg_class); if(temp_he->last_notification == 0) printf("Infinity"); else printf("%d", temp_he->last_notification); printf(" | \n"); get_interval_time_string(temp_he->notification_interval, time_string, sizeof(time_string)); printf("", bg_class); if(temp_he->notification_interval == 0.0) printf("Notify Only Once (No Re-notification)"); else printf("%s", time_string); printf(" | \n"); printf("", bg_class); if(temp_he->escalation_period == NULL) printf(" "); else printf("%s", CONFIG_CGI, url_encode(temp_he->escalation_period), html_encode(temp_he->escalation_period, FALSE)); printf(" | \n"); printf("", bg_class); options = FALSE; if(temp_he->escalate_on_down == TRUE) { printf("%sDown", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_he->escalate_on_unreachable == TRUE) { printf("%sUnreachable", (options == TRUE) ? ", " : ""); options = TRUE; } if(temp_he->escalate_on_recovery == TRUE) { printf("%sRecovery", (options == TRUE) ? ", " : ""); options = TRUE; } if(options == FALSE) printf("None"); printf(" | \n"); printf("
\n");
/* info table */
display_info_table("Current Network Status", TRUE, ¤t_authdata);
printf("
| \n");
/* middle column of top row */
printf("\n"); show_host_status_totals(); printf(" | \n"); /* right hand column of top row */ printf("\n"); show_service_status_totals(); printf(" | \n"); /* display context-sensitive help */ printf("\n"); if(display_type == DISPLAY_HOSTS) display_context_help(CONTEXTHELP_STATUS_DETAIL); else if(display_type == DISPLAY_SERVICEGROUPS) { if(group_style_type == STYLE_HOST_DETAIL) display_context_help(CONTEXTHELP_STATUS_DETAIL); else if(group_style_type == STYLE_OVERVIEW) display_context_help(CONTEXTHELP_STATUS_SGOVERVIEW); else if(group_style_type == STYLE_SUMMARY) display_context_help(CONTEXTHELP_STATUS_SGSUMMARY); else if(group_style_type == STYLE_GRID) display_context_help(CONTEXTHELP_STATUS_SGGRID); } else { if(group_style_type == STYLE_HOST_DETAIL) display_context_help(CONTEXTHELP_STATUS_HOST_DETAIL); else if(group_style_type == STYLE_OVERVIEW) display_context_help(CONTEXTHELP_STATUS_HGOVERVIEW); else if(group_style_type == STYLE_SUMMARY) display_context_help(CONTEXTHELP_STATUS_HGSUMMARY); else if(group_style_type == STYLE_GRID) display_context_help(CONTEXTHELP_STATUS_HGGRID); } printf(" | \n"); /* end of top table */ printf("
\n");
printf("
| ||||||||||
\n");
printf("
|
\n");
printf("
| ||||||||
\n");
printf("
|
\n"); if(display_header == TRUE) show_filters(); printf(" | "); printf("\n");
printf(" Service Status Details For ");
if(display_type == DISPLAY_HOSTS) {
if(show_all_hosts == TRUE)
printf("All Hosts");
else
printf("Host '%s'", host_name);
}
else if(display_type == DISPLAY_SERVICEGROUPS) {
if(show_all_servicegroups == TRUE)
printf("All Service Groups");
else
printf("Service Group '%s'", url_encode(servicegroup_name));
}
else {
if(show_all_hostgroups == TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'", hostgroup_name);
}
printf(" \n");
if(use_sort == TRUE) {
printf("Entries sorted by ");
if(sort_option == SORT_HOSTNAME)
printf("host name");
else if(sort_option == SORT_SERVICENAME)
printf("service name");
else if(sort_option == SORT_SERVICESTATUS)
printf("service status");
else if(sort_option == SORT_LASTCHECKTIME)
printf("last check time");
else if(sort_option == SORT_CURRENTATTEMPT)
printf("attempt number");
else if(sort_option == SORT_STATEDURATION)
printf("state duration");
printf(" (%s)\n", (sort_type == SORT_ASCENDING) ? "ascending" : "descending");
printf(" \n");
}
if(service_filter != NULL)
printf("Filtered By Services Matching \'%s\' ", service_filter);
printf(""); printf(" | \n");
printf("\n"); printf(" |
Host | ", temp_url, SORT_ASCENDING, SORT_HOSTNAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTNAME, url_images_path, DOWN_ARROW_ICON);
printf("Service | ", temp_url, SORT_ASCENDING, SORT_SERVICENAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_SERVICENAME, url_images_path, DOWN_ARROW_ICON);
printf("Status | ", temp_url, SORT_ASCENDING, SORT_SERVICESTATUS, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_SERVICESTATUS, url_images_path, DOWN_ARROW_ICON);
printf("Last Check | ", temp_url, SORT_ASCENDING, SORT_LASTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_LASTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
printf("Duration | ", temp_url, SORT_ASCENDING, SORT_STATEDURATION, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_STATEDURATION, url_images_path, DOWN_ARROW_ICON);
printf("Attempt | ", temp_url, SORT_ASCENDING, SORT_CURRENTATTEMPT, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_CURRENTATTEMPT, url_images_path, DOWN_ARROW_ICON);
printf("Status Information | \n"); printf("|||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
", host_status_bg_class);
printf("
| "); printf(" | \n"); /* grab macros */ grab_service_macros_r(mac, temp_service); /* service name column */ printf("", status_bg_class);
printf("
| \n");
/* state duration calculation... */
t = 0;
duration_error = FALSE;
if(temp_status->last_state_change == (time_t)0) {
if(program_start > current_time)
duration_error = TRUE;
else
t = current_time - program_start;
}
else {
if(temp_status->last_state_change > current_time)
duration_error = TRUE;
else
t = current_time - temp_status->last_state_change;
}
get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
if(duration_error == TRUE)
snprintf(state_duration, sizeof(state_duration) - 1, "???");
else
snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_status->last_state_change == (time_t)0) ? "+" : "");
state_duration[sizeof(state_duration) - 1] = '\x0';
/* the rest of the columns... */
printf("%s | \n", status_class, status); printf("%s | \n", status_bg_class, date_time); printf("%s | \n", status_bg_class, state_duration); printf("%d/%d | \n", status_bg_class, temp_status->current_attempt, temp_status->max_attempts); printf("", status_bg_class); printf("%s ", (temp_status->plugin_output == NULL) ? "" : html_encode(temp_status->plugin_output, TRUE)); /* if(enable_splunk_integration==TRUE) display_splunk_service_url(temp_service); */ printf(" | \n"); printf("
\n"); printf("
\n"); if(display_header == TRUE) show_filters(); printf(" | "); printf("\n");
printf(" Host Status Details For ");
if(show_all_hostgroups == TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'", hostgroup_name);
printf(" \n");
if(use_sort == TRUE) {
printf("Entries sorted by ");
if(sort_option == SORT_HOSTNAME)
printf("host name");
else if(sort_option == SORT_HOSTSTATUS)
printf("host status");
else if(sort_option == SORT_HOSTURGENCY)
printf("host urgency");
else if(sort_option == SORT_LASTCHECKTIME)
printf("last check time");
else if(sort_option == SORT_CURRENTATTEMPT)
printf("attempt number");
else if(sort_option == SORT_STATEDURATION)
printf("state duration");
printf(" (%s)\n", (sort_type == SORT_ASCENDING) ? "ascending" : "descending");
printf(" \n");
}
printf(""); printf(" | \n");
printf("\n"); printf(" |
Host | ", temp_url, SORT_ASCENDING, SORT_HOSTNAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTNAME, url_images_path, DOWN_ARROW_ICON);
printf("Status | ", temp_url, SORT_ASCENDING, SORT_HOSTSTATUS, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTSTATUS, url_images_path, DOWN_ARROW_ICON);
printf("Last Check | ", temp_url, SORT_ASCENDING, SORT_LASTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_LASTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
printf("Duration | ", temp_url, SORT_ASCENDING, SORT_STATEDURATION, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_STATEDURATION, url_images_path, DOWN_ARROW_ICON);
printf("Status Information | \n"); printf("||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
", status_class);
printf("
| \n");
/* state duration calculation... */
t = 0;
duration_error = FALSE;
if(temp_status->last_state_change == (time_t)0) {
if(program_start > current_time)
duration_error = TRUE;
else
t = current_time - program_start;
}
else {
if(temp_status->last_state_change > current_time)
duration_error = TRUE;
else
t = current_time - temp_status->last_state_change;
}
get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
if(duration_error == TRUE)
snprintf(state_duration, sizeof(state_duration) - 1, "???");
else
snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_status->last_state_change == (time_t)0) ? "+" : "");
state_duration[sizeof(state_duration) - 1] = '\x0';
/* the rest of the columns... */
printf("%s | \n", status_class, status); printf("%s | \n", status_bg_class, date_time); printf("%s | \n", status_bg_class, state_duration); printf("", status_bg_class); printf("%s ", (temp_status->plugin_output == NULL) ? "" : html_encode(temp_status->plugin_output, TRUE)); /* if(enable_splunk_integration==TRUE) display_splunk_host_url(temp_host); */ printf(" | \n"); printf("
\n"); printf("
\n"); show_filters(); printf(" | "); printf("\n");
printf(" Service Overview For ");
if(show_all_servicegroups == TRUE)
printf("All Service Groups");
else
printf("Service Group '%s'", servicegroup_name);
printf(" \n");
printf(""); printf(" | \n");
printf("\n"); printf(" |
\n"); show_servicegroup_overview(temp_servicegroup); user_has_seen_something = TRUE; printf(" | \n"); if(current_column == overview_columns) printf("\n"); printf("\n"); } printf(" |
\n"); printf("
\n"); if(is_authorized_for_servicegroup(temp_servicegroup, ¤t_authdata) == TRUE) { show_servicegroup_overview(temp_servicegroup); user_has_seen_something = TRUE; } printf(" |
\n"); printf("
Host | Status | Services | Actions | \n"); printf("
---|
\n"); printf("
\n"); show_filters(); printf(" | "); printf("\n");
printf(" Status Summary For ");
if(show_all_servicegroups == TRUE)
printf("All Service Groups");
else
printf("Service Group '%s'", servicegroup_name);
printf(" \n");
printf(""); printf(" | \n");
printf("\n"); printf(" |
Service Group | Host Status Summary | Service Status Summary | \n"); printf("
---|
%d UP | ", STATUS_CGI, url_encode(temp_servicegroup->group_name), HOST_UP, host_properties, hosts_up); printf("||||||
| \n");
printf("||||||
| \n");
printf("||||||
%d PENDING |
%d OK | |||||||
| \n");
printf("|||||||
| \n");
printf("|||||||
| \n");
printf("|||||||
%d PENDING |
\n"); printf("
\n"); show_filters(); printf(" | "); printf("\n");
printf(" Status Grid For ");
if(show_all_servicegroups == TRUE)
printf("All Service Groups");
else
printf("Service Group '%s'", servicegroup_name);
printf(" \n");
printf(""); printf(" | \n");
printf("\n"); printf(" |
\n"); printf("
Host | Services | Actions | |||||
---|---|---|---|---|---|---|---|
", host_status_class);
printf("
| \n");
printf("", host_status_class);
/* display all services on the host that are part of the hostgroup */
current_item = 1;
for(temp_member2 = temp_member; temp_member2 != NULL; temp_member2 = temp_member2->next) {
/* bail out if we've reached the end of the services that are associated with this servicegroup */
if(strcmp(temp_member2->host_name, temp_host->name))
break;
if(current_item > max_grid_width && max_grid_width > 0) {
printf(" \n"); current_item = 1; } /* get the status of the service */ temp_servicestatus = find_servicestatus(temp_member2->host_name, temp_member2->service_description); if(temp_servicestatus == NULL) service_status_class = "NULL"; else if(temp_servicestatus->status == SERVICE_OK) service_status_class = "OK"; else if(temp_servicestatus->status == SERVICE_WARNING) service_status_class = "WARNING"; else if(temp_servicestatus->status == SERVICE_UNKNOWN) service_status_class = "UNKNOWN"; else if(temp_servicestatus->status == SERVICE_CRITICAL) service_status_class = "CRITICAL"; else service_status_class = "PENDING"; printf("%s ", url_encode(temp_servicestatus->description), service_status_class, temp_servicestatus->description); current_item++; } /* actions */ printf(" | ", host_status_class);
/* grab macros */
grab_host_macros_r(mac, temp_host);
printf("\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name));
printf(" | \n");
printf("
\n"); printf("
\n"); show_filters(); printf(" | "); printf("\n");
printf(" Service Overview For ");
if(show_all_hostgroups == TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'", hostgroup_name);
printf(" \n");
printf(""); printf(" | \n");
printf("\n"); printf(" |
\n"); show_hostgroup_overview(temp_hostgroup); user_has_seen_something = TRUE; printf(" | \n"); if(current_column == overview_columns) printf("\n"); printf("\n"); } printf(" |
\n"); printf("
\n"); if(is_authorized_for_hostgroup(temp_hostgroup, ¤t_authdata) == TRUE) { show_hostgroup_overview(temp_hostgroup); user_has_seen_something = TRUE; } printf(" |
\n"); printf("
Host | Status | Services | Actions | \n"); printf("
---|
%s | \n", status_bg_class, STATUS_CGI, url_encode(hststatus->host_name), temp_host->address, hststatus->host_name); if(temp_host->icon_image != NULL) { printf("\n", status_bg_class); printf(" | ", status_bg_class);
printf("", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(hststatus->host_name));
printf(" | \n");
}
printf("
%d OK |
%d WARNING |
%d UNKNOWN |
%d CRITICAL |
%d PENDING |
\n"); printf("
\n"); show_filters(); printf(" | "); printf("\n");
printf(" Status Summary For ");
if(show_all_hostgroups == TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'", hostgroup_name);
printf(" \n");
printf(""); printf(" | \n");
printf("\n"); printf(" |
Host Group | Host Status Summary | Service Status Summary | \n"); printf("
---|
%d UP | ", STATUS_CGI, url_encode(temp_hostgroup->group_name), HOST_UP, host_properties, hosts_up); printf("||||||
| \n");
printf("||||||
| \n");
printf("||||||
%d PENDING |
%d OK | |||||||
| \n");
printf("|||||||
| \n");
printf("|||||||
| \n");
printf("|||||||
%d PENDING |
\n"); printf("
\n"); show_filters(); printf(" | "); printf("\n");
printf(" Status Grid For ");
if(show_all_hostgroups == TRUE)
printf("All Host Groups");
else
printf("Host Group '%s'", hostgroup_name);
printf(" \n");
printf(""); printf(" | \n");
printf("\n"); printf(" |
\n"); printf("
Host | Services | Actions | ||||||
---|---|---|---|---|---|---|---|---|
", host_status_class);
printf("
| \n");
printf("", host_status_class);
/* display all services on the host */
current_item = 1;
for(temp_service = service_list; temp_service; temp_service = temp_service->next) {
/* skip this service if it's not associate with the host */
if(strcmp(temp_service->host_name, temp_host->name))
continue;
if(current_item > max_grid_width && max_grid_width > 0) {
printf(" \n"); current_item = 1; } /* grab macros */ grab_service_macros_r(mac, temp_service); /* get the status of the service */ temp_servicestatus = find_servicestatus(temp_service->host_name, temp_service->description); if(temp_servicestatus == NULL) service_status_class = "NULL"; else if(temp_servicestatus->status == SERVICE_OK) service_status_class = "OK"; else if(temp_servicestatus->status == SERVICE_WARNING) service_status_class = "WARNING"; else if(temp_servicestatus->status == SERVICE_UNKNOWN) service_status_class = "UNKNOWN"; else if(temp_servicestatus->status == SERVICE_CRITICAL) service_status_class = "CRITICAL"; else service_status_class = "PENDING"; printf("%s ", url_encode(temp_servicestatus->description), service_status_class, temp_servicestatus->description); current_item++; } printf(" | \n");
/* actions */
printf("", host_status_class);
printf("\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name));
printf(" | \n");
printf("
\n");
printf("
|
\n"); snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Alert Summary Report"); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; display_info_table(temp_buffer, FALSE, ¤t_authdata); printf(" | \n"); /* center column of top row */ printf("\n");
if(generate_report == TRUE) {
printf(" \n");
if(display_type == REPORT_TOP_ALERTS)
printf("Top Alert Producers");
else if(display_type == REPORT_ALERT_TOTALS || display_type == REPORT_HOSTGROUP_ALERT_TOTALS || display_type == REPORT_SERVICEGROUP_ALERT_TOTALS || display_type == REPORT_HOST_ALERT_TOTALS || display_type == REPORT_SERVICE_ALERT_TOTALS)
printf("Alert Totals");
else
printf("Most Recent Alerts");
if(show_all_hostgroups == FALSE)
printf(" For Hostgroup '%s'", target_hostgroup_name);
else if(show_all_servicegroups == FALSE)
printf(" For Servicegroup '%s'", target_servicegroup_name);
else if(show_all_hosts == FALSE)
printf(" For Host '%s'", target_host_name);
printf(" \n");
printf("\n"); get_time_string(&t1, start_timestring, sizeof(start_timestring) - 1, SHORT_DATE_TIME); get_time_string(&t2, end_timestring, sizeof(end_timestring) - 1, SHORT_DATE_TIME); printf(" %s to %s \n", start_timestring, end_timestring);
get_time_breakdown((time_t)(t2 - t1), &days, &hours, &minutes, &seconds);
printf("Duration: %dd %dh %dm %ds \n", days, hours, minutes, seconds);
}
printf(" | \n");
/* right hand column of top row */
printf("\n");
if(generate_report == TRUE) {
printf("
| \n");
/* end of top table */
printf("
Time | Alert Type | Host | Service | State | State Type | Information | |
---|---|---|---|---|---|---|---|
%s | ", bgclass, date_time); printf("%s | ", bgclass, (temp_event->event_type == AE_HOST_ALERT) ? "Host Alert" : "Service Alert"); printf("%s | ", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_event->host_name), temp_event->host_name); if(temp_event->event_type == AE_HOST_ALERT) printf("N/A | ", bgclass); else { printf("%s | ", url_encode(temp_event->service_description), temp_event->service_description); } switch(temp_event->entry_type) { case AE_HOST_UP: status_bgclass = "hostUP"; status = "UP"; break; case AE_HOST_DOWN: status_bgclass = "hostDOWN"; status = "DOWN"; break; case AE_HOST_UNREACHABLE: status_bgclass = "hostUNREACHABLE"; status = "UNREACHABLE"; break; case AE_SERVICE_OK: status_bgclass = "serviceOK"; status = "OK"; break; case AE_SERVICE_WARNING: status_bgclass = "serviceWARNING"; status = "WARNING"; break; case AE_SERVICE_UNKNOWN: status_bgclass = "serviceUNKNOWN"; status = "UNKNOWN"; break; case AE_SERVICE_CRITICAL: status_bgclass = "serviceCRITICAL"; status = "CRITICAL"; break; default: status_bgclass = bgclass; status = "???"; break; } printf("%s | ", status_bgclass, status); printf("%s | ", bgclass, (temp_event->state_type == AE_SOFT_STATE) ? "SOFT" : "HARD"); printf("%s | ", bgclass, temp_event->event_info); printf("
\n");
printf("
|
\n");
printf("
|
\n");
printf("
|
\n");
printf("
|
\n");
printf("
|
Rank | Producer Type | Host | Service | Total Alerts | |
---|---|---|---|---|---|
#%d | ", bgclass, current_item); printf("%s | ", bgclass, (temp_producer->producer_type == AE_HOST_PRODUCER) ? "Host" : "Service"); printf("%s | ", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_producer->host_name), temp_producer->host_name); if(temp_producer->producer_type == AE_HOST_PRODUCER) printf("N/A | ", bgclass); else { printf("%s | ", url_encode(temp_producer->service_description), temp_producer->service_description); } printf("%d | ", bgclass, temp_producer->total_alerts); printf("
\n");
if(display_type == DISPLAY_HOST_TRENDS)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host State Trends");
else if(display_type == DISPLAY_SERVICE_TRENDS)
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service State Trends");
else
snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host and Service State Trends");
temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
display_info_table(temp_buffer, FALSE, ¤t_authdata);
if(timeperiod_type == TIMEPERIOD_NEXTPROBLEM) {
archived_state *temp_as;
time_t problem_t1, problem_t2 = 0;
t1 = t2;
t2 = current_time;
read_archived_state_data();
problem_found = FALSE;
if(display_type == DISPLAY_HOST_TRENDS) {
for(temp_as = as_list; temp_as != NULL; temp_as = temp_as->next) {
if((temp_as->entry_type == HOST_DOWN || temp_as->entry_type == HOST_UNREACHABLE) && temp_as->time_stamp > t1) {
problem_t1 = temp_as->time_stamp;
problem_found = TRUE;
break;
}
}
if(problem_found == TRUE) {
for(; temp_as != NULL; temp_as = temp_as->next) {
if(temp_as->entry_type == AS_HOST_UP && temp_as->time_stamp > problem_t1) {
problem_t2 = temp_as->time_stamp;
break;
}
}
}
}
else {
for(temp_as = as_list; temp_as != NULL; temp_as = temp_as->next) {
if((temp_as->entry_type == AS_SVC_UNKNOWN || temp_as->entry_type == AS_SVC_CRITICAL || temp_as->entry_type == AS_SVC_WARNING) && temp_as->time_stamp > t1) {
problem_t1 = temp_as->time_stamp;
problem_found = TRUE;
break;
}
}
if(problem_found == TRUE) {
for(; temp_as != NULL; temp_as = temp_as->next) {
if(temp_as->entry_type == AS_SVC_OK && temp_as->time_stamp > problem_t1) {
problem_t2 = temp_as->time_stamp;
break;
}
}
}
}
if(problem_found == TRUE) {
time_t margin;
if(problem_t2 == 0) {
margin = 12 * 60 * 60;
problem_t2 = problem_t1;
}
else
margin = (problem_t2 - problem_t1) / 2;
t1 = problem_t1 - margin;
t2 = problem_t2 + margin;
}
}
if(timeperiod_type == TIMEPERIOD_NEXTPROBLEM && problem_found == FALSE) {
t1 = old_t1;
t2 = old_t2;
}
if(display_type != DISPLAY_NO_TRENDS && input_type == GET_INPUT_NONE) {
printf("
| \n");
/* center column of top row */
printf("\n");
if(display_type != DISPLAY_NO_TRENDS && input_type == GET_INPUT_NONE) {
printf(" \n");
if(display_type == DISPLAY_HOST_TRENDS)
printf("Host '%s'", host_name);
else if(display_type == DISPLAY_SERVICE_TRENDS)
printf("Service '%s' On Host '%s'", svc_description, host_name);
printf(" \n");
printf("\n"); printf(" \n"); get_time_string(&t1, start_timestring, sizeof(start_timestring) - 1, SHORT_DATE_TIME); get_time_string(&t2, end_timestring, sizeof(end_timestring) - 1, SHORT_DATE_TIME); printf(" %s to %s \n", start_timestring, end_timestring);
get_time_breakdown((time_t)(t2 - t1), &days, &hours, &minutes, &seconds);
printf("Duration: %dd %dh %dm %ds \n", days, hours, minutes, seconds);
}
printf(" | \n");
/* right hand column of top row */
printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
\n"); display_info_table((log_rotation_method == LOG_ROTATION_NONE || log_archive == 0) ? "Current Event Log" : "Archived Event Log", FALSE, ¤t_authdata); printf(" | \n"); /* middle column of top table - log file navigation options */ printf("\n"); snprintf(temp_buffer, sizeof(temp_buffer) - 1, "%s?%s", SHOWLOG_CGI, (use_lifo == FALSE) ? "oldestfirst&" : ""); temp_buffer[sizeof(temp_buffer) - 1] = '\x0'; display_nav_table(temp_buffer, log_archive); printf(" | \n"); /* right hand column of top row */ printf("\n"); printf("\n"); printf(" | \n"); /* end of top table */ printf("
%s | ", current_message_date); printf("
Error: Could not open CGI config file!
\n"); else cgi_config_file_error(get_cgi_config_location()); document_footer(); return ERROR; } /* read the main configuration file */ result = read_main_config_file(main_config_file); if(result == ERROR) { document_header(FALSE); if(content_type == WML_CONTENT) printf("Error: Could not open main config file!
\n"); else main_config_file_error(main_config_file); document_footer(); return ERROR; } /* This requires the date_format parameter in the main config file */ if(strcmp(start_time_string, "")) string_to_time(start_time_string, &start_time); if(strcmp(end_time_string, "")) string_to_time(end_time_string, &end_time); /* read all object configuration data */ result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA); if(result == ERROR) { document_header(FALSE); if(content_type == WML_CONTENT) printf("Error: Could not read object config data!
\n"); else object_data_error(); document_footer(); return ERROR; } document_header(TRUE); /* get authentication information */ get_authentication_information(¤t_authdata); if(display_header == TRUE) { /* begin top table */ printf("\n"); display_info_table("External Command Interface", FALSE, ¤t_authdata); printf(" | \n"); /* center column of the first row */ printf("\n"); printf(" | \n"); /* right column of the first row */ printf("\n"); /* display context-sensitive help */ if(command_mode == CMDMODE_COMMIT) display_context_help(CONTEXTHELP_CMD_COMMIT); else display_context_help(CONTEXTHELP_CMD_INPUT); printf(" | \n"); /* end of top table */ printf("
Error: No command specified!
\n"); else printf("\n"); printf("
\n");
printf(" Command Options \n");
printf("
| \n");
printf("\n"); /* show information about the command... */ show_command_help(cmd); printf(" | \n"); printf("
Error: Authentication is not enabled!
\n"); else { printf("\n"); printf("
Error: You're not authorized to commit that command!
\n"); else { printf("%s
\n", error_string); else { printf("Error: Nagios is not checking external commands!
\n"); else { printf("Your command was submitted sucessfully...
\n"); else { printf("An error occurred while committing your command!
\n"); else { printf("Error: Could not stat() external command file!
\n"); else { printf("Error: Could not open command file for update!
\n"); else { printf("\n"); /* decide what information to print out... */ switch(cmd) { case CMD_ADD_HOST_COMMENT: printf("This command is used to add a comment for the specified host. If you work with other administrators, you may find it useful to share information about a host\n"); printf("that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will be automatically be deleted\n"); printf("the next time Nagios is restarted.\n"); break; case CMD_ADD_SVC_COMMENT: printf("This command is used to add a comment for the specified service. If you work with other administrators, you may find it useful to share information about a host\n"); printf("or service that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will automatically be\n"); printf("deleted the next time Nagios is restarted.\n"); break; case CMD_DEL_HOST_COMMENT: printf("This command is used to delete a specific host comment.\n"); break; case CMD_DEL_SVC_COMMENT: printf("This command is used to delete a specific service comment.\n"); break; case CMD_DELAY_HOST_NOTIFICATION: printf("This command is used to delay the next problem notification that is sent out for the specified host. The notification delay will be disregarded if\n"); printf("the host changes state before the next notification is scheduled to be sent out. This command has no effect if the host is currently UP.\n"); break; case CMD_DELAY_SVC_NOTIFICATION: printf("This command is used to delay the next problem notification that is sent out for the specified service. The notification delay will be disregarded if\n"); printf("the service changes state before the next notification is scheduled to be sent out. This command has no effect if the service is currently in an OK state.\n"); break; case CMD_SCHEDULE_SVC_CHECK: printf("This command is used to schedule the next check of a particular service. Nagios will re-queue the service to be checked at the time you specify.\n"); printf("If you select the force check option, Nagios will force a check of the service regardless of both what time the scheduled check occurs and whether or not checks are enabled for the service.\n"); break; case CMD_ENABLE_SVC_CHECK: printf("This command is used to enable active checks of a service.\n"); break; case CMD_DISABLE_SVC_CHECK: printf("This command is used to disable active checks of a service.\n"); break; case CMD_DISABLE_NOTIFICATIONS: printf("This command is used to disable host and service notifications on a program-wide basis.\n"); break; case CMD_ENABLE_NOTIFICATIONS: printf("This command is used to enable host and service notifications on a program-wide basis.\n"); break; case CMD_SHUTDOWN_PROCESS: printf("This command is used to shutdown the Nagios process. Note: Once the Nagios has been shutdown, it cannot be restarted via the web interface!\n"); break; case CMD_RESTART_PROCESS: printf("This command is used to restart the Nagios process. Executing a restart command is equivalent to sending the process a HUP signal.\n"); printf("All information will be flushed from memory, the configuration files will be re-read, and Nagios will start monitoring with the new configuration information.\n"); break; case CMD_ENABLE_HOST_SVC_CHECKS: printf("This command is used to enable active checks of all services associated with the specified host. This does not enable checks of the host unless you check the 'Enable for host too' option.\n"); break; case CMD_DISABLE_HOST_SVC_CHECKS: printf("This command is used to disable active checks of all services associated with the specified host. When a service is disabled Nagios will not monitor the service. Doing this will prevent any notifications being sent out for\n"); printf("the specified service while it is disabled. In order to have Nagios check the service in the future you will have to re-enable the service.\n"); printf("Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with. This does not disable checks of the host unless you check the 'Disable for host too' option.\n"); break; case CMD_SCHEDULE_HOST_SVC_CHECKS: printf("This command is used to scheduled the next check of all services on the specified host. If you select the force check option, Nagios will force a check of all services on the host regardless of both what time the scheduled checks occur and whether or not checks are enabled for those services.\n"); break; case CMD_DEL_ALL_HOST_COMMENTS: printf("This command is used to delete all comments associated with the specified host.\n"); break; case CMD_DEL_ALL_SVC_COMMENTS: printf("This command is used to delete all comments associated with the specified service.\n"); break; case CMD_ENABLE_SVC_NOTIFICATIONS: printf("This command is used to enable notifications for the specified service. Notifications will only be sent out for the\n"); printf("service state types you defined in your service definition.\n"); break; case CMD_DISABLE_SVC_NOTIFICATIONS: printf("This command is used to prevent notifications from being sent out for the specified service. You will have to re-enable notifications\n"); printf("for this service before any alerts can be sent out in the future.\n"); break; case CMD_ENABLE_HOST_NOTIFICATIONS: printf("This command is used to enable notifications for the specified host. Notifications will only be sent out for the\n"); printf("host state types you defined in your host definition. Note that this command does not enable notifications\n"); printf("for services associated with this host.\n"); break; case CMD_DISABLE_HOST_NOTIFICATIONS: printf("This command is used to prevent notifications from being sent out for the specified host. You will have to re-enable notifications for this host\n"); printf("before any alerts can be sent out in the future. Note that this command does not disable notifications for services associated with this host.\n"); break; case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST: printf("This command is used to enable notifications for all hosts and services that lie \"beyond\" the specified host\n"); printf("(from the view of Nagios).\n"); break; case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST: printf("This command is used to temporarily prevent notifications from being sent out for all hosts and services that lie\n"); printf("\"beyond\" the specified host (from the view of Nagios).\n"); break; case CMD_ENABLE_HOST_SVC_NOTIFICATIONS: printf("This command is used to enable notifications for all services on the specified host. Notifications will only be sent out for the\n"); printf("service state types you defined in your service definition. This does not enable notifications for the host unless you check the 'Enable for host too' option.\n"); break; case CMD_DISABLE_HOST_SVC_NOTIFICATIONS: printf("This command is used to prevent notifications from being sent out for all services on the specified host. You will have to re-enable notifications for\n"); printf("all services associated with this host before any alerts can be sent out in the future. This does not prevent notifications from being sent out about the host unless you check the 'Disable for host too' option.\n"); break; case CMD_ACKNOWLEDGE_HOST_PROBLEM: printf("This command is used to acknowledge a host problem. When a host problem is acknowledged, future notifications about problems are temporarily disabled until the host changes from its current state.\n"); printf("If you want acknowledgement to disable notifications until the host recovers, check the 'Sticky Acknowledgement' checkbox.\n"); printf("Contacts for this host will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the host.\n"); printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the host comment to remain once the acknowledgement is removed, check\n"); printf("the 'Persistent Comment' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n"); break; case CMD_ACKNOWLEDGE_SVC_PROBLEM: printf("This command is used to acknowledge a service problem. When a service problem is acknowledged, future notifications about problems are temporarily disabled until the service changes from its current state.\n"); printf("If you want acknowledgement to disable notifications until the service recovers, check the 'Sticky Acknowledgement' checkbox.\n"); printf("Contacts for this service will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the service.\n"); printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the service comment to remain once the acknowledgement is removed, check\n"); printf("the 'Persistent Comment' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n"); break; case CMD_START_EXECUTING_SVC_CHECKS: printf("This command is used to resume execution of active service checks on a program-wide basis. Individual services which are disabled will still not be checked.\n"); break; case CMD_STOP_EXECUTING_SVC_CHECKS: printf("This command is used to temporarily stop Nagios from actively executing any service checks. This will have the side effect of preventing any notifications from being sent out (for any and all services and hosts).\n"); printf("Service checks will not be executed again until you issue a command to resume service check execution.\n"); break; case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS: printf("This command is used to make Nagios start accepting passive service check results that it finds in the external command file\n"); break; case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS: printf("This command is use to make Nagios stop accepting passive service check results that it finds in the external command file. All passive check results that are found will be ignored.\n"); break; case CMD_ENABLE_PASSIVE_SVC_CHECKS: printf("This command is used to allow Nagios to accept passive service check results that it finds in the external command file for this particular service.\n"); break; case CMD_DISABLE_PASSIVE_SVC_CHECKS: printf("This command is used to stop Nagios accepting passive service check results that it finds in the external command file for this particular service. All passive check results that are found for this service will be ignored.\n"); break; case CMD_ENABLE_EVENT_HANDLERS: printf("This command is used to allow Nagios to run host and service event handlers.\n"); break; case CMD_DISABLE_EVENT_HANDLERS: printf("This command is used to temporarily prevent Nagios from running any host or service event handlers.\n"); break; case CMD_ENABLE_SVC_EVENT_HANDLER: printf("This command is used to allow Nagios to run the service event handler for a particular service when necessary (if one is defined).\n"); break; case CMD_DISABLE_SVC_EVENT_HANDLER: printf("This command is used to temporarily prevent Nagios from running the service event handler for a particular service.\n"); break; case CMD_ENABLE_HOST_EVENT_HANDLER: printf("This command is used to allow Nagios to run the host event handler for a particular service when necessary (if one is defined).\n"); break; case CMD_DISABLE_HOST_EVENT_HANDLER: printf("This command is used to temporarily prevent Nagios from running the host event handler for a particular host.\n"); break; case CMD_ENABLE_HOST_CHECK: printf("This command is used to enable active checks of this host.\n"); break; case CMD_DISABLE_HOST_CHECK: printf("This command is used to temporarily prevent Nagios from actively checking the status of a particular host. If Nagios needs to check the status of this host, it will assume that it is in the same state that it was in before checks were disabled.\n"); break; case CMD_START_OBSESSING_OVER_SVC_CHECKS: printf("This command is used to have Nagios start obsessing over service checks. Read the documentation on distributed monitoring for more information on this.\n"); break; case CMD_STOP_OBSESSING_OVER_SVC_CHECKS: printf("This command is used stop Nagios from obsessing over service checks.\n"); break; case CMD_REMOVE_HOST_ACKNOWLEDGEMENT: printf("This command is used to remove an acknowledgement for a particular host problem. Once the acknowledgement is removed, notifications may start being\n"); printf("sent out about the host problem. \n"); break; case CMD_REMOVE_SVC_ACKNOWLEDGEMENT: printf("This command is used to remove an acknowledgement for a particular service problem. Once the acknowledgement is removed, notifications may start being\n"); printf("sent out about the service problem.\n"); break; case CMD_PROCESS_SERVICE_CHECK_RESULT: printf("This command is used to submit a passive check result for a particular service. It is particularly useful for resetting security-related services to OK states once they have been dealt with.\n"); break; case CMD_PROCESS_HOST_CHECK_RESULT: printf("This command is used to submit a passive check result for a particular host.\n"); break; case CMD_SCHEDULE_HOST_DOWNTIME: printf("This command is used to schedule downtime for a particular host. During the specified downtime, Nagios will not send notifications out about the host.\n"); printf("When the scheduled downtime expires, Nagios will send out notifications for this host as it normally would. Scheduled downtimes are preserved\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss.\n"); printf("If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the host goes down or becomes unreachable (sometime between the\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n"); break; case CMD_SCHEDULE_HOST_SVC_DOWNTIME: printf("This command is used to schedule downtime for all services on a particular host. During the specified downtime, Nagios will not send notifications out about the host.\n"); printf("Normally, a host in downtime will not send alerts about any services in a failed state. This option will explicitly set downtime for all services for this host.\n"); printf("When the scheduled downtime expires, Nagios will send out notifications for this host as it normally would. Scheduled downtimes are preserved\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss.\n"); printf("If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the host goes down or becomes unreachable (sometime between the\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n"); break; case CMD_SCHEDULE_SVC_DOWNTIME: printf("This command is used to schedule downtime for a particular service. During the specified downtime, Nagios will not send notifications out about the service.\n"); printf("When the scheduled downtime expires, Nagios will send out notifications for this service as it normally would. Scheduled downtimes are preserved\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss.\n"); printf("If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the service enters a non-OK state (sometime between the\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n"); break; case CMD_ENABLE_HOST_FLAP_DETECTION: printf("This command is used to enable flap detection for a specific host. If flap detection is disabled on a program-wide basis, this will have no effect,\n"); break; case CMD_DISABLE_HOST_FLAP_DETECTION: printf("This command is used to disable flap detection for a specific host.\n"); break; case CMD_ENABLE_SVC_FLAP_DETECTION: printf("This command is used to enable flap detection for a specific service. If flap detection is disabled on a program-wide basis, this will have no effect,\n"); break; case CMD_DISABLE_SVC_FLAP_DETECTION: printf("This command is used to disable flap detection for a specific service.\n"); break; case CMD_ENABLE_FLAP_DETECTION: printf("This command is used to enable flap detection for hosts and services on a program-wide basis. Individual hosts and services may have flap detection disabled.\n"); break; case CMD_DISABLE_FLAP_DETECTION: printf("This command is used to disable flap detection for hosts and services on a program-wide basis.\n"); break; case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS: printf("This command is used to enable notifications for all services in the specified hostgroup. Notifications will only be sent out for the\n"); printf("service state types you defined in your service definitions. This does not enable notifications for the hosts in this hostgroup unless you check the 'Enable for hosts too' option.\n"); break; case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS: printf("This command is used to prevent notifications from being sent out for all services in the specified hostgroup. You will have to re-enable notifications for\n"); printf("all services in this hostgroup before any alerts can be sent out in the future. This does not prevent notifications from being sent out about the hosts in this hostgroup unless you check the 'Disable for hosts too' option.\n"); break; case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS: printf("This command is used to enable notifications for all hosts in the specified hostgroup. Notifications will only be sent out for the\n"); printf("host state types you defined in your host definitions.\n"); break; case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS: printf("This command is used to prevent notifications from being sent out for all hosts in the specified hostgroup. You will have to re-enable notifications for\n"); printf("all hosts in this hostgroup before any alerts can be sent out in the future.\n"); break; case CMD_ENABLE_HOSTGROUP_SVC_CHECKS: printf("This command is used to enable active checks of all services in the specified hostgroup. This does not enable active checks of the hosts in the hostgroup unless you check the 'Enable for hosts too' option.\n"); break; case CMD_DISABLE_HOSTGROUP_SVC_CHECKS: printf("This command is used to disable active checks of all services in the specified hostgroup. This does not disable checks of the hosts in the hostgroup unless you check the 'Disable for hosts too' option.\n"); break; case CMD_DEL_HOST_DOWNTIME: printf("This command is used to cancel active or pending scheduled downtime for the specified host.\n"); break; case CMD_DEL_SVC_DOWNTIME: printf("This command is used to cancel active or pending scheduled downtime for the specified service.\n"); break; case CMD_ENABLE_FAILURE_PREDICTION: printf("This command is used to enable failure prediction for hosts and services on a program-wide basis. Individual hosts and services may have failure prediction disabled.\n"); break; case CMD_DISABLE_FAILURE_PREDICTION: printf("This command is used to disable failure prediction for hosts and services on a program-wide basis.\n"); break; case CMD_ENABLE_PERFORMANCE_DATA: printf("This command is used to enable the processing of performance data for hosts and services on a program-wide basis. Individual hosts and services may have performance data processing disabled.\n"); break; case CMD_DISABLE_PERFORMANCE_DATA: printf("This command is used to disable the processing of performance data for hosts and services on a program-wide basis.\n"); break; case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME: printf("This command is used to schedule downtime for all hosts in a particular hostgroup. During the specified downtime, Nagios will not send notifications out about the hosts.\n"); printf("When the scheduled downtime expires, Nagios will send out notifications for the hosts as it normally would. Scheduled downtimes are preserved\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss.\n"); printf("If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); break; case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME: printf("This command is used to schedule downtime for all services in a particular hostgroup. During the specified downtime, Nagios will not send notifications out about the services.\n"); printf("When the scheduled downtime expires, Nagios will send out notifications for the services as it normally would. Scheduled downtimes are preserved\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss.\n"); printf("If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the hostgroup, check the 'Schedule downtime for hosts too' option.\n"); break; case CMD_START_EXECUTING_HOST_CHECKS: printf("This command is used to enable active host checks on a program-wide basis.\n"); break; case CMD_STOP_EXECUTING_HOST_CHECKS: printf("This command is used to disable active host checks on a program-wide basis.\n"); break; case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS: printf("This command is used to have Nagios start obsessing over host checks. Read the documentation on distributed monitoring for more information on this.\n"); break; case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS: printf("This command is used to stop Nagios from obsessing over host checks.\n"); break; case CMD_ENABLE_PASSIVE_HOST_CHECKS: printf("This command is used to allow Nagios to accept passive host check results that it finds in the external command file for a particular host.\n"); break; case CMD_DISABLE_PASSIVE_HOST_CHECKS: printf("This command is used to stop Nagios from accepting passive host check results that it finds in the external command file for a particular host. All passive check results that are found for this host will be ignored.\n"); break; case CMD_START_OBSESSING_OVER_HOST_CHECKS: printf("This command is used to have Nagios start obsessing over host checks. Read the documentation on distributed monitoring for more information on this.\n"); break; case CMD_STOP_OBSESSING_OVER_HOST_CHECKS: printf("This command is used to stop Nagios from obsessing over host checks.\n"); break; case CMD_SCHEDULE_HOST_CHECK: printf("This command is used to schedule the next check of a particular host. Nagios will re-queue the host to be checked at the time you specify.\n"); printf("If you select the force check option, Nagios will force a check of the host regardless of both what time the scheduled check occurs and whether or not checks are enabled for the host.\n"); break; case CMD_START_OBSESSING_OVER_SVC: printf("This command is used to have Nagios start obsessing over a particular service.\n"); break; case CMD_STOP_OBSESSING_OVER_SVC: printf("This command is used to stop Nagios from obsessing over a particular service.\n"); break; case CMD_START_OBSESSING_OVER_HOST: printf("This command is used to have Nagios start obsessing over a particular host.\n"); break; case CMD_STOP_OBSESSING_OVER_HOST: printf("This command is used to stop Nagios from obsessing over a particular host.\n"); break; case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS: printf("This command is used to enable notifications for all services in the specified servicegroup. Notifications will only be sent out for the\n"); printf("service state types you defined in your service definitions. This does not enable notifications for the hosts in this servicegroup unless you check the 'Enable for hosts too' option.\n"); break; case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS: printf("This command is used to prevent notifications from being sent out for all services in the specified servicegroup. You will have to re-enable notifications for\n"); printf("all services in this servicegroup before any alerts can be sent out in the future. This does not prevent notifications from being sent out about the hosts in this servicegroup unless you check the 'Disable for hosts too' option.\n"); break; case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS: printf("This command is used to enable notifications for all hosts in the specified servicegroup. Notifications will only be sent out for the\n"); printf("host state types you defined in your host definitions.\n"); break; case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS: printf("This command is used to prevent notifications from being sent out for all hosts in the specified servicegroup. You will have to re-enable notifications for\n"); printf("all hosts in this servicegroup before any alerts can be sent out in the future.\n"); break; case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS: printf("This command is used to enable active checks of all services in the specified servicegroup. This does not enable active checks of the hosts in the servicegroup unless you check the 'Enable for hosts too' option.\n"); break; case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS: printf("This command is used to disable active checks of all services in the specified servicegroup. This does not disable checks of the hosts in the servicegroup unless you check the 'Disable for hosts too' option.\n"); break; case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME: printf("This command is used to schedule downtime for all hosts in a particular servicegroup. During the specified downtime, Nagios will not send notifications out about the hosts.\n"); printf("When the scheduled downtime expires, Nagios will send out notifications for the hosts as it normally would. Scheduled downtimes are preserved\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss.\n"); printf("If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); break; case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME: printf("This command is used to schedule downtime for all services in a particular servicegroup. During the specified downtime, Nagios will not send notifications out about the services.\n"); printf("When the scheduled downtime expires, Nagios will send out notifications for the services as it normally would. Scheduled downtimes are preserved\n"); printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss.\n"); printf("If you select the fixed option, the downtime will be in effect between the start and end times you specify. If you do not select the fixed\n"); printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n"); printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n"); printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the servicegroup, check the 'Schedule downtime for hosts too' option.\n"); break; case CMD_SEND_CUSTOM_HOST_NOTIFICATION: case CMD_SEND_CUSTOM_SVC_NOTIFICATION: printf("This command is used to send a custom notification about the specified %s. Useful in emergencies when you need to notify admins of an issue regarding a monitored system or service.\n", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service"); printf("Custom notifications normally follow the regular notification logic in Nagios. Selecting the Forced option will force the notification to be sent out, regardless of the time restrictions, whether or not notifications are enabled, etc. Selecting the Broadcast option causes the notification to be sent out to all normal (non-escalated) and escalated contacts. These options allow you to override the normal notification logic if you need to get an important message out.\n"); break; default: printf("Sorry, but no information is available for this command."); } printf(" |
$num_items = 10; $rss = fetch_rss($url); $items = array_slice($rss->items, 0, $num_items); foreach ( $items as $item ) {
# Magpie throws USER_WARNINGS only # so you can cloak these, by only showing ERRORs error_reporting(E_ERROR); # check the return value of fetch_rss() $rss = fetch_rss($url); if ( $rss ) { ...display rss feed... } else { echo "An error occured! " . "Consider donating more $$$ for restoration of services." . "<br>Error Message: " . magpie_error(); }
# you can also do this in your php.ini file ini_set('display_errors', 0);
require_once('rss_utils.inc'); # get all headlines published today $today = getdate(); # today, 12AM $date = mktime(0,0,0,$today['mon'], $today['mday'], $today['year']); $rss = fetch_rss($url); foreach ( $rss->items as $item ) { $published = parse_w3cdtf($item['dc']['date']); if ( $published >= $date ) { echo "Title: " . $item['title']; echo "Published: " . date("h:i:s A", $published); echo "<p>"; } }
parse_w3cdtf()
is defined in
rss_utils.inc
, and parses RSS style dates into Unix epoch
seconds.
fetch_rss()
which takes a URL and returns a
parsed RSS object, but what if you want to parse a file stored locally that
doesn't have a URL?
require_once('rss_parse.inc'); $rss_file = 'some_rss_file.rdf'; $rss_string = read_file($rss_file); $rss = new MagpieRSS( $rss_string ); if ( $rss and !$rss->ERROR) { ...display rss... } else { echo "Error: " . $rss->ERROR; } # efficiently read a file into a string # in php >= 4.3.0 you can simply use file_get_contents() # function read_file($filename) { $fh = fopen($filename, 'r') or die($php_errormsg); $rss_string = fread($fh, filesize($filename) ); fclose($fh); return $rss_string; }
fetch_rss()
. We read the contents of the RSS file into a
string, and pass it to the parser constructor. Notice also that error handling
is subtly different.
MagpieRSS is compatible with RSS .9 through RSS 1.0, and supports the RSS 1.0's modules. (with a few exceptions)
require('rss_fetch.inc'); $rss = fetch_rss($url);
fetch_rss()
)
around the library.
parse_w3cdtf()
, for parsing W3CDTF into epoch seconds.
This makes it very simple support the varied versions of RSS simply, but forces the consumer of a RSS feed to be cognizant of how it is structured.(at least if you want to do something fancy)
Magpie parses a RSS feed into a simple object, with 4 fields:
channel
, items
, image
, and
textinput
.
$rss->channel
contains key-value pairs of all tags, without
nested tags, found between the root tag (<rdf:RDF>, or <rss>)
and the end of the document.
$rss->items
is an array of associative arrays, each one
describing a single item. An example that looks like:
<item rdf:about="http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257"> <title>Weekly Peace Vigil</title> <link>http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257</link> <description>Wear a white ribbon</description> <dc:subject>Peace</dc:subject> <ev:startdate>2002-06-01T11:00:00</ev:startdate> <ev:location>Northampton, MA</ev:location> <ev:enddate>2002-06-01T12:00:00</ev:enddate> <ev:type>Protest</ev:type> </item>
Is parsed, and pushed on the $rss->items
array as:
array( title => 'Weekly Peace Vigil', link => 'http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257', description => 'Wear a white ribbon', dc => array ( subject => 'Peace' ), ev => array ( startdate => '2002-06-01T11:00:00', enddate => '2002-06-01T12:00:00', type => 'Protest', location => 'Northampton, MA' ) );
$rss->image
and $rss-textinput
are associative arrays
including name-value pairs for anything found between the respective parent
tags.
require_once 'rss_fetch.inc'; $url = 'http://magpie.sf.net/samples/imc.1-0.rdf'; $rss = fetch_rss($url); echo "Site: ", $rss->channel['title'], "<br>\n"; foreach ($rss->items as $item ) { $title = $item[title]; $url = $item[link]; echo "<a href=$url>$title</a></li><br>\n"; }More soon....in the meantime you can check out a cool tool built with MagpieRSS, version 0.1.
coded by: kellan (at) protest.net, feedback is always appreciated.
nagios/html/includes/rss/NEWS 0000644 0001750 0001750 00000003507 12210155146 016670 0 ustar formorer formorer MagpieRSS News
MAGPIERSS 0.51 RELEASED
* important bugfix!
* fix "silent failure" when PHP doesn't have zlib
FEED ON FEEDS USES MAGPIE
* web-based RSS aggregator built with Magpie
* easy to install, easy to use.
http://minutillo.com/steve/feedonfeeds/
MAGPIERSS 0.5 RELEASED
* supports transparent HTTP gzip content negotiation for reduced bandwidth usage
* quashed some undefined index notices
MAGPIERSS 0.46 RELEASED
* minor release, more error handling clean up
* documentation fixes, simpler example
* new trouble shooting guide for installation and usage problems
http://magpierss.sourceforge.net/TROUBLESHOOTING
MAGPIE NEWS AS RSS
* releases, bug fixes, releated stories in RSS
MAGPIERSS COOKBOOK: SIMPLE PHP RSS HOW TOS
* answers some of the most frequently asked Magpie questions
* feedback, suggestions, requests, recipes welcome
http://magpierss.sourceforge.net/cookbook.html
MAGPIERSS 0.4 RELEASED!
* improved error handling, more flexibility for script authors, backwards compatible
* new and better examples! including using MagpieRSS and Smarty
* new Smarty plugin for RSS date parsing
http://smarty.php.net
INFINITE PENGUIN NOW SUPPORTS MAGPIE 0.3
* simple, sophisticated RSS viewer
* includes auto-generated javascript ticker from RSS feed
http://www.infinitepenguins.net/rss/
TRAUMWIND RELEASES REX BACKEND FOR MAGPIERSS
* drop in support using regex based XML parser
* parses improperly formed XML that chokes expat
http://traumwind.de/blog/magpie/magpie_alike.php
MAGPIERSS 0.3 RELEASED!
* Support added for HTTP Conditional GETs.
http://fishbowl.pastiche.org/archives/001132.html
MAGPIERSS 0.2!
* Major clean up of the code. Easier to use.
* Simpler install on shared hosts.
* Better documentation and comments.
nagios/html/includes/rss/cookbook 0000644 0001750 0001750 00000005730 12210155146 017722 0 ustar formorer formorer MAGPIERSS RECIPES: Cooking with Corbies
"Four and twenty blackbirds baked in a pie."
1. LIMIT THE NUMBER OF HEADLINES(AKA ITEMS) RETURNED.
PROBLEM:
You want to display the 10 (or 3) most recent headlines, but the RSS feed
contains 15.
SOLUTION:
$num_items = 10;
$rss = fetch_rss($url);
$items = array_slice($rss->items, 0, $num_items);
DISCUSSION:
Rather then trying to limit the number of items Magpie parses, a much simpler,
and more flexible approach is to take a "slice" of the array of items. And
array_slice() is smart enough to do the right thing if the feed has less items
then $num_items.
See: http://www.php.net/array_slice
2. DISPLAY A CUSTOM ERROR MESSAGE IF SOMETHING GOES WRONG
PROBLEM:
You don't want Magpie's error messages showing up if something goes wrong.
SOLUTION:
# Magpie throws USER_WARNINGS only
# so you can cloak these, by only showing ERRORs
error_reporting(E_ERROR);
# check the return value of fetch_rss()
$rss = fetch_rss($url);
if ( $rss ) {
...display rss feed...
}
else {
echo "An error occured! " .
"Consider donating more $$$ for restoration of services." .
"
Error Message: " . magpie_error();
}
DISCUSSION:
MagpieRSS triggers a warning in a number of circumstances. The 2 most common
circumstances are: if the specified RSS file isn't properly formed (usually
because it includes illegal HTML), or if Magpie can't download the remote RSS
file, and there is no cached version.
If you don't want your users to see these warnings change your error_reporting
settings to only display ERRORs. Another option is to turn off display_error,
so that WARNINGs, and NOTICEs still go to the error_log but not to the webpages.
You can do this with:
ini_set('display_errors', 0);
See: http://www.php.net/error_reporting,
http://www.php.net/ini_set,
http://www.php.net/manual/en/ref.errorfunc.php
3. GENERATE A NEW RSS FEED
PROBLEM:
Create an RSS feed for other people to use.
SOLUTION:
Use Useful Inc's RSSWriter (http://usefulinc.com/rss/rsswriter/)
DISCUSSION:
An example of turning a Magpie parsed RSS object back into an RSS file is forth
coming. In the meantime RSSWriter has great documentation.
4. DISPLAY HEADLINES MORE RECENT THEN X DATE
PROBLEM:
You only want to display headlines that were published on, or after a certain
date.
SOLUTION:
require 'rss_utils.inc';
# get all headlines published today
$today = getdate();
# today, 12AM
$date = mktime(0,0,0,$today['mon'], $today['mday'], $today['year']);
$rss = fetch_rss($url);
foreach ( $rss->items as $item ) {
$published = parse_w3cdtf($item['dc']['date']);
if ( $published >= $date ) {
echo "Title: " . $item['title'];
echo "Published: " . date("h:i:s A", $published);
echo "
";
}
}
DISCUSSION:
This recipe only works for RSS 1.0 feeds that include the ";
echo "";
foreach ($rss->items as $item) {
$href = $item['link'];
$title = $item['title'];
echo "
";
DESCRIPTION
MapieRSS is an XML-based RSS parser in PHP. It attempts to be "PHP-like",
and simple to use.
Some features include:
* supports RSS 0.9 - 1.0, with limited RSS 2.0 support
* supports namespaces, and modules, including mod_content and mod_event
* open minded [1]
* simple, functional interface, to object oriented backend parser
* automatic caching of parsed RSS objects makes its easy to integrate
* supports conditional GET with Last-Modified, and ETag
* uses constants for easy override of default behaviour
* heavily commented
1. By open minded I mean Magpie will accept any tag it finds in good faith that
it was supposed to be here. For strict validation, look elsewhere.
GETTING STARTED
COPYRIGHT:
Copyright(c) 2002 kellan@protest.net. All rights reserved.
This software is released under the GNU General Public License.
Please read the disclaimer at the top of the Snoopy.class.inc file.
nagios/html/includes/rss/ChangeLog 0000644 0001750 0001750 00000022025 12210155146 017737 0 ustar formorer formorer 2005-10-28 14:11 kellan
* extlib/Snoopy.class.inc: a better solution
2005-10-28 11:51 kellan
* extlib/Snoopy.class.inc: fix arbtriary code execution
vulnerability when using curl+ssl
http://www.sec-consult.com/216.html
2005-03-08 10:46 kellan
* rss_parse.inc: fix bug w/ atom and date normalization
2005-02-09 14:59 kellan
* rss_fetch.inc: fix stale cache bug
2005-01-28 02:27 kellan
* rss_parse.inc: support php w/o array_change_case
2005-01-23 20:02 kellan
* rss_fetch.inc: fix cache bug introduced by charset encoding
2005-01-12 09:14 kellan
* rss_cache.inc, rss_fetch.inc: more sanity checks for when things
go wrong
2004-12-12 13:44 kellan
* INSTALL, rss_cache.inc, rss_utils.inc: detab
2004-11-23 20:15 kellan
* rss_parse.inc: fix calling iconv instead of mb_convert_encoding
2004-11-22 02:11 kellan
* CHANGES, ChangeLog, rss_parse.inc, scripts/magpie_debug.php: last
bit of tidying
2004-11-22 01:45 kellan
* rss_fetch.inc: detab, bump version
2004-11-22 01:43 kellan
* rss_parse.inc: was filtering too much
2004-11-22 00:03 kellan
* rss_fetch.inc, rss_parse.inc: cache on $url . $output_encoding
otherwise we can get munged output
2004-11-21 23:52 kellan
* rss_parse.inc: add WARNING
2004-11-21 23:45 kellan
* rss_parse.inc: don't set ERROR on notice or warning (rss_fetch
dies on parse errors)
2004-11-21 23:44 kellan
* rss_fetch.inc: add encoding defines (fix timeout error reporting)
2004-11-21 20:21 kellan
* rss_parse.inc: incorporate steve's patch
2004-11-21 19:26 kellan
* rss_parse.inc: remove old debugging functions, totally
arbitrarily. might break stuff. can't really explain why i'm
doing this.
2004-10-28 15:52 kellan
* rss_parse.inc: fixed '=' instead of '=='
2004-10-26 00:48 kellan
* rss_parse.inc: chance epoch to timestamp to conform w/ php naming
conventions
2004-06-15 12:00 kellan
* rss_parse.inc: [no log message]
2004-04-26 14:16 kellan
* rss_fetch.inc: bump version
2004-04-26 12:36 kellan
* rss_parse.inc: fix field doubling
2004-04-24 17:47 kellan
* CHANGES, ChangeLog: updated
2004-04-24 17:35 kellan
* rss_fetch.inc: bumped version
2004-04-24 16:52 kellan
* rss_parse.inc: support arbitrary atom content constructs
some refactoring
2004-04-24 16:15 kellan
* rss_parse.inc: support summary content contstruct. add normalize
function
2004-03-27 16:29 kellan
* extlib/Snoopy.class.inc: accept self-signed certs
2004-03-27 12:53 kellan
* extlib/Snoopy.class.inc: fixed SSL support * set status * set
error on bad curl
(also ripped out big chunks of dead weight (submit_form) which
were getting in my way
2004-01-25 02:25 kellan
* rss_parse.inc: make RSS 1.0's rdf:about available
2004-01-25 02:07 kellan
* rss_parse.inc: clean up text, and line formats. add support item
rdf:about
2004-01-24 23:40 kellan
* CHANGES, ChangeLog: update changes
2004-01-24 23:37 kellan
* rss_fetch.inc: updated version
2004-01-24 23:35 kellan
* rss_parse.inc: whitespace
2004-01-24 23:23 kellan
* extlib/Snoopy.class.inc: support badly formatted http headers
2004-01-24 23:20 kellan
* rss_parse.inc: added alpha atom parsing support
2003-06-25 22:34 kellan
* extlib/Snoopy.class.inc: fixed fread 4.3.2 compatibility problems
2003-06-13 11:31 kellan
* rss_fetch.inc: reset cache on 304
2003-06-12 21:37 kellan
* rss_cache.inc, rss_fetch.inc, rss_parse.inc, rss_utils.inc:
bumped up version numbers
2003-06-12 21:32 kellan
* htdocs/index.html: updated news
2003-06-12 21:27 kellan
* NEWS: a manual blog :)
2003-06-12 21:22 kellan
* htdocs/index.html: fully qualified img
2003-06-12 21:20 kellan
* htdocs/index.html: clean up. added badge.
2003-06-12 21:04 kellan
* rss_utils.inc: clean up regex
2003-06-12 21:02 kellan
* rss_cache.inc: suppress some warnings
2003-05-30 20:44 kellan
* extlib/Snoopy.class.inc: more comments, cleaned up notice
2003-05-30 15:14 kellan
* extlib/Snoopy.class.inc: don't advertise gzip support if the user
hasn't built php with gzinflate support
2003-05-12 22:32 kellan
* ChangeLog: changes
2003-05-12 22:11 kellan
* htdocs/index.html: announce 0.5
2003-05-12 21:42 kellan
* htdocs/index.html: change
2003-05-12 21:39 kellan
* rss_fetch.inc: use gzip
2003-05-12 21:37 kellan
* extlib/Snoopy.class.inc: added support gzip encoded content
negoiation
2003-05-12 21:32 kellan
* rss_cache.inc, rss_fetch.inc, rss_parse.inc, rss_utils.inc: fixed
typoes
2003-04-26 21:44 kellan
* rss_parse.inc: fix minor typo
2003-04-18 08:19 kellan
* htdocs/cookbook.html: updated cookbook to show more code for
limiting items
2003-03-03 16:02 kellan
* rss_parse.inc, scripts/magpie_slashbox.php: committed (or
adpated) patch from Nicola (www.technick.com) to quell 'Undefined
Indexes' notices
2003-03-03 15:59 kellan
* rss_fetch.inc: commited patch from nicola (www.technick.com) to
quell 'undefined indexes' notices.
* Magpie now automatically includes its version in the
user-agent, & whether cacheing is turned on.
2003-02-12 01:22 kellan
* CHANGES, ChangeLog: ChangeLog now auto-generated by cvs2cl
2003-02-12 00:21 kellan
* rss_fetch.inc: better errors, hopefully stomped on pesky notices
2003-02-12 00:19 kellan
* rss_parse.inc: check to see is xml is supported, if not die
also throw better xml errors
2003-02-12 00:18 kellan
* rss_cache.inc: hopefully cleared up some notices that were being
thrown into the log
fixed a debug statement that was being called as an error
2003-02-12 00:15 kellan
* scripts/: magpie_simple.php, magpie_slashbox.php: moved
magpie_simple to magpie_slashbox, and replaced it with a simpler
demo.
2003-02-12 00:02 kellan
* INSTALL, README, TROUBLESHOOTING: Improved documentation. Better
install instructions.
TROUBLESHOOTING cover common installation and usage problems
2003-01-22 14:40 kellan
* htdocs/cookbook.html: added cookbook.html
2003-01-21 23:47 kellan
* cookbook: a magpie cookbook
2003-01-20 10:09 kellan
* ChangeLog: updated
2003-01-20 09:23 kellan
* scripts/simple_smarty.php: minor clean up
2003-01-20 09:15 kellan
* scripts/README: added smarty url
2003-01-20 09:14 kellan
* magpie_simple.php, htdocs/index.html, scripts/README,
scripts/magpie_debug.php, scripts/magpie_simple.php,
scripts/simple_smarty.php,
scripts/smarty_plugin/modifier.rss_date_parse.php,
scripts/templates/simple.smarty: Added scripts directory for
examples on how to use MagpieRSS
magpie_simple - is a simple example magpie_debug - spew all the
information from a parsed RSS feed simple_smary - example of
using magpie with Smarty template system
smarty_plugin/modifier.rss_date_parse.php - support file for the
smarty demo templates/simple.smary - template for the smarty demo
2003-01-20 09:11 kellan
* rss_fetch.inc, rss_parse.inc: changes to error handling to give
script authors more access to magpie's errors.
added method magpie_error() to retrieve global MAGPIE_ERROR
variable for when fetch_rss() returns false
2002-10-26 19:02 kellan
* htdocs/index.html: putting the website under source control
2002-10-26 18:43 kellan
* AUTHORS, ChangeLog, INSTALL, README: some documentation to make
it all look official :)
2002-10-25 23:04 kellan
* magpie_simple.php: quxx
2002-10-25 23:04 kellan
* rss_parse.inc: added support for textinput and image
2002-10-25 19:23 kellan
* magpie_simple.php, rss_cache.inc, rss_fetch.inc, rss_parse.inc,
rss_utils.inc: switched to using Snoopy for fetching remote RSS
files.
added support for conditional gets
2002-10-25 19:22 kellan
* rss_cache.inc, rss_fetch.inc, rss_parse.inc, rss_utils.inc:
Change comment style to slavishly imitate the phpinsider style
found in Smarty and Snoopy :)
2002-10-25 19:18 kellan
* extlib/Snoopy.class.inc: added Snoopy in order to support
conditional gets
2002-10-23 23:19 kellan
* magpie_simple.php, rss_cache.inc, rss_fetch.inc, rss_parse.inc:
MAJOR CLEANUP!
* rss_fetch got rid of the options array, replaced it with a more
PHP-like solution of using defines. constants are setup, with
defaults, in the function init()
got rid of the idiom of passing back an array, its was awkward to
deal with in PHP, and unusual (and consquently confusing to
people). now i return true/false values, and try to setup error
string where appropiate (rss_cache has the most complete example
of this)
change the logic for interacting with the cache
* rss_cache major re-working of how error are handled. tried to
make the code more resillient. the cache is now much more aware
of MAX_AGE, where before this was being driven out of rss_fetch
(which was silly)
* rss_parse properly handles xml parse errors. used to sail
along blithely unaware.
2002-09-11 11:11 kellan
* rss_cache.inc, rss_parse.inc, magpie_simple.php, rss_fetch.inc,
rss_utils.inc: Initial revision
2002-09-11 11:11 kellan
* rss_cache.inc, rss_parse.inc, magpie_simple.php, rss_fetch.inc,
rss_utils.inc: initial import
nagios/html/includes/rss/rss_cache.inc 0000644 0001750 0001750 00000014350 12210155146 020614 0 ustar formorer formorer
* Version: 0.51
* License: GPL
*
* The lastest version of MagpieRSS can be obtained from:
* http://magpierss.sourceforge.net
*
* For questions, help, comments, discussion, etc., please join the
* Magpie mailing list:
* http://lists.sourceforge.net/lists/listinfo/magpierss-general
*
*/
class RSSCache {
var $BASE_CACHE = './cache'; // where the cache files are stored
var $MAX_AGE = 3600; // when are files stale, default one hour
var $ERROR = ""; // accumulate error messages
function RSSCache ($base='', $age='') {
if ( $base ) {
$this->BASE_CACHE = $base;
}
if ( $age ) {
$this->MAX_AGE = $age;
}
// attempt to make the cache directory
if ( ! file_exists( $this->BASE_CACHE ) ) {
$status = @mkdir( $this->BASE_CACHE, 0755 );
// if make failed
if ( ! $status ) {
$this->error(
"Cache couldn't make dir '" . $this->BASE_CACHE . "'."
);
}
}
}
/*=======================================================================*\
Function: set
Purpose: add an item to the cache, keyed on url
Input: url from wich the rss file was fetched
Output: true on sucess
\*=======================================================================*/
function set ($url, $rss) {
$this->ERROR = "";
$cache_file = $this->file_name( $url );
$fp = @fopen( $cache_file, 'w' );
if ( ! $fp ) {
$this->error(
"Cache unable to open file for writing: $cache_file"
);
return 0;
}
$data = $this->serialize( $rss );
fwrite( $fp, $data );
fclose( $fp );
return $cache_file;
}
/*=======================================================================*\
Function: get
Purpose: fetch an item from the cache
Input: url from wich the rss file was fetched
Output: cached object on HIT, false on MISS
\*=======================================================================*/
function get ($url) {
$this->ERROR = "";
$cache_file = $this->file_name( $url );
if ( ! file_exists( $cache_file ) ) {
$this->debug(
"Cache doesn't contain: $url (cache file: $cache_file)"
);
return 0;
}
$fp = @fopen($cache_file, 'r');
if ( ! $fp ) {
$this->error(
"Failed to open cache file for reading: $cache_file"
);
return 0;
}
if ($filesize = filesize($cache_file) ) {
$data = fread( $fp, filesize($cache_file) );
$rss = $this->unserialize( $data );
return $rss;
}
return 0;
}
/*=======================================================================*\
Function: check_cache
Purpose: check a url for membership in the cache
and whether the object is older then MAX_AGE (ie. STALE)
Input: url from wich the rss file was fetched
Output: cached object on HIT, false on MISS
\*=======================================================================*/
function check_cache ( $url ) {
$this->ERROR = "";
$filename = $this->file_name( $url );
if ( file_exists( $filename ) ) {
// find how long ago the file was added to the cache
// and whether that is longer then MAX_AGE
$mtime = filemtime( $filename );
$age = time() - $mtime;
if ( $this->MAX_AGE > $age ) {
// object exists and is current
return 'HIT';
}
else {
// object exists but is old
return 'STALE';
}
}
else {
// object does not exist
return 'MISS';
}
}
function cache_age( $cache_key ) {
$filename = $this->file_name( $url );
if ( file_exists( $filename ) ) {
$mtime = filemtime( $filename );
$age = time() - $mtime;
return $age;
}
else {
return -1;
}
}
/*=======================================================================*\
Function: serialize
\*=======================================================================*/
function serialize ( $rss ) {
return serialize( $rss );
}
/*=======================================================================*\
Function: unserialize
\*=======================================================================*/
function unserialize ( $data ) {
return unserialize( $data );
}
/*=======================================================================*\
Function: file_name
Purpose: map url to location in cache
Input: url from wich the rss file was fetched
Output: a file name
\*=======================================================================*/
function file_name ($url) {
$filename = md5( $url );
return join( DIRECTORY_SEPARATOR, array( $this->BASE_CACHE, $filename ) );
}
/*=======================================================================*\
Function: error
Purpose: register error
\*=======================================================================*/
function error ($errormsg, $lvl=E_USER_WARNING) {
// append PHP's error message if track_errors enabled
if ( isset($php_errormsg) ) {
$errormsg .= " ($php_errormsg)";
}
$this->ERROR = $errormsg;
if ( MAGPIE_DEBUG ) {
trigger_error( $errormsg, $lvl);
}
else {
error_log( $errormsg, 0);
}
}
function debug ($debugmsg, $lvl=E_USER_NOTICE) {
if ( MAGPIE_DEBUG ) {
$this->error("MagpieRSS [debug] $debugmsg", $lvl);
}
}
}
?>
nagios/html/includes/rss/CHANGES 0000644 0001750 0001750 00000002127 12210155146 017161 0 ustar formorer formorer Version 0.72
-----------
- fix security exploit: http://www.sec-consult.com/216.html
Version 0.7
-----------
- support for input and output charset encoding
based on the work in FoF, uses iconv or mbstring if available
-
Version 0.6
-----------
- basic support for Atom syndication format
including support for Atom content constructs
- fixed support for private feeds (HTTP Auth and SSL)
(thanks to silverorange.com for providing test feeds)
- support for some broken webservers
Version 0.52
-----------
- support GZIP content negoiation
- PHP 4.3.2 support
Version 0.4
-----------
- improved error handling, better access for script authors
- included example scripts of working with MagpieRSS
- new Smarty plugin for RSS date parsing
Version 0.3
-----------
- added support for conditional gets (Last-Modified, ETag)
- now use Snoopy to handle fetching RSS files
Version 0.2
-----------
- MAJOR CLEAN UP
- removed kludgy $options array in favour of constants
- phased out returning arrays
- added better error handling
- re-worked comments
nagios/html/includes/rss/extlib/ 0000755 0001750 0001750 00000000000 12210155146 017453 5 ustar formorer formorer nagios/html/includes/rss/extlib/Snoopy.class.inc 0000644 0001750 0001750 00000065412 12210155146 022551 0 ustar formorer formorer
Copyright (c): 1999-2000 ispi, all rights reserved
Version: 1.0
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
You may contact the author of Snoopy by e-mail at:
monte@ispi.net
Or, write to:
Monte Ohrt
CTO, ispi
237 S. 70th suite 220
Lincoln, NE 68510
The latest version of Snoopy can be obtained from:
http://snoopy.sourceforge.com
*************************************************/
class Snoopy
{
/**** Public variables ****/
/* user definable vars */
var $host = "www.php.net"; // host name we are connecting to
var $port = 80; // port we are connecting to
var $proxy_host = ""; // proxy host to use
var $proxy_port = ""; // proxy port to use
var $agent = "Snoopy v1.0"; // agent we masquerade as
var $referer = ""; // referer info to pass
var $cookies = array(); // array of cookies to pass
// $cookies["username"]="joe";
var $rawheaders = array(); // array of raw headers to send
// $rawheaders["Content-type"]="text/html";
var $maxredirs = 5; // http redirection depth maximum. 0 = disallow
var $lastredirectaddr = ""; // contains address of last redirected address
var $offsiteok = true; // allows redirection off-site
var $maxframes = 0; // frame content depth maximum. 0 = disallow
var $expandlinks = true; // expand links to fully qualified URLs.
// this only applies to fetchlinks()
// or submitlinks()
var $passcookies = true; // pass set cookies back through redirects
// NOTE: this currently does not respect
// dates, domains or paths.
var $user = ""; // user for http authentication
var $pass = ""; // password for http authentication
// http accept types
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
var $results = ""; // where the content is put
var $error = ""; // error messages sent here
var $response_code = ""; // response code returned from server
var $headers = array(); // headers returned from server sent here
var $maxlength = 500000; // max return data length (body)
var $read_timeout = 0; // timeout on read operations, in seconds
// supported only since PHP 4 Beta 4
// set to 0 to disallow timeouts
var $timed_out = false; // if a read operation timed out
var $status = 0; // http request status
var $curl_path = "/usr/bin/curl";
// Snoopy will use cURL for fetching
// SSL content if a full system path to
// the cURL binary is supplied here.
// set to false if you do not have
// cURL installed. See http://curl.haxx.se
// for details on installing cURL.
// Snoopy does *not* use the cURL
// library functions built into php,
// as these functions are not stable
// as of this Snoopy release.
// send Accept-encoding: gzip?
var $use_gzip = true;
/**** Private variables ****/
var $_maxlinelen = 4096; // max line length (headers)
var $_httpmethod = "GET"; // default http request method
var $_httpversion = "HTTP/1.0"; // default http request version
var $_submit_method = "POST"; // default submit method
var $_submit_type = "application/x-www-form-urlencoded"; // default submit type
var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type
var $_redirectaddr = false; // will be set if page fetched is a redirect
var $_redirectdepth = 0; // increments on an http redirect
var $_frameurls = array(); // frame src urls
var $_framedepth = 0; // increments on frame depth
var $_isproxy = false; // set if using a proxy server
var $_fp_timeout = 30; // timeout for socket connection
/*======================================================================*\
Function: fetch
Purpose: fetch the contents of a web page
(and possibly other protocols in the
future like ftp, nntp, gopher, etc.)
Input: $URI the location of the page to fetch
Output: $this->results the output text from the fetch
\*======================================================================*/
function fetch($URI)
{
//preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
$URI_PARTS = parse_url($URI);
if (!empty($URI_PARTS["user"]))
$this->user = $URI_PARTS["user"];
if (!empty($URI_PARTS["pass"]))
$this->pass = $URI_PARTS["pass"];
switch($URI_PARTS["scheme"])
{
case "http":
$this->host = $URI_PARTS["host"];
if(!empty($URI_PARTS["port"]))
$this->port = $URI_PARTS["port"];
if($this->_connect($fp))
{
if($this->_isproxy)
{
// using proxy, send entire URI
$this->_httprequest($URI,$fp,$URI,$this->_httpmethod);
}
else
{
$path = $URI_PARTS["path"].(isset($URI_PARTS["query"]) ? "?".$URI_PARTS["query"] : "");
// no proxy, send only the path
$this->_httprequest($path, $fp, $URI, $this->_httpmethod);
}
$this->_disconnect($fp);
if($this->_redirectaddr)
{
/* url was redirected, check if we've hit the max depth */
if($this->maxredirs > $this->_redirectdepth)
{
// only follow redirect if it's on this site, or offsiteok is true
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
{
/* follow the redirect */
$this->_redirectdepth++;
$this->lastredirectaddr=$this->_redirectaddr;
$this->fetch($this->_redirectaddr);
}
}
}
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
{
$frameurls = $this->_frameurls;
$this->_frameurls = array();
while(list(,$frameurl) = each($frameurls))
{
if($this->_framedepth < $this->maxframes)
{
$this->fetch($frameurl);
$this->_framedepth++;
}
else
break;
}
}
}
else
{
return false;
}
return true;
break;
case "https":
if(!$this->curl_path || (!is_executable($this->curl_path))) {
$this->error = "Bad curl ($this->curl_path), can't fetch HTTPS \n";
return false;
}
$this->host = $URI_PARTS["host"];
if(!empty($URI_PARTS["port"]))
$this->port = $URI_PARTS["port"];
if($this->_isproxy)
{
// using proxy, send entire URI
$this->_httpsrequest($URI,$URI,$this->_httpmethod);
}
else
{
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : "");
// no proxy, send only the path
$this->_httpsrequest($path, $URI, $this->_httpmethod);
}
if($this->_redirectaddr)
{
/* url was redirected, check if we've hit the max depth */
if($this->maxredirs > $this->_redirectdepth)
{
// only follow redirect if it's on this site, or offsiteok is true
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
{
/* follow the redirect */
$this->_redirectdepth++;
$this->lastredirectaddr=$this->_redirectaddr;
$this->fetch($this->_redirectaddr);
}
}
}
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0)
{
$frameurls = $this->_frameurls;
$this->_frameurls = array();
while(list(,$frameurl) = each($frameurls))
{
if($this->_framedepth < $this->maxframes)
{
$this->fetch($frameurl);
$this->_framedepth++;
}
else
break;
}
}
return true;
break;
default:
// not a valid protocol
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
return false;
break;
}
return true;
}
/*======================================================================*\
Private functions
\*======================================================================*/
/*======================================================================*\
Function: _striplinks
Purpose: strip the hyperlinks from an html document
Input: $document document to strip.
Output: $match an array of the links
\*======================================================================*/
function _striplinks($document)
{
preg_match_all("'<\s*a\s+.*href\s*=\s* # find ]+)) # if quote found, match up to next matching
# quote, otherwise match up to next space
'isx",$document,$links);
// catenate the non-empty matches from the conditional subpattern
while(list($key,$val) = each($links[2]))
{
if(!empty($val))
$match[] = $val;
}
while(list($key,$val) = each($links[3]))
{
if(!empty($val))
$match[] = $val;
}
// return the links
return $match;
}
/*======================================================================*\
Function: _stripform
Purpose: strip the form elements from an html document
Input: $document document to strip.
Output: $match an array of the links
\*======================================================================*/
function _stripform($document)
{
preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
// catenate the matches
$match = implode("\r\n",$elements[0]);
// return the links
return $match;
}
/*======================================================================*\
Function: _striptext
Purpose: strip the text from an html document
Input: $document document to strip.
Output: $text the resulting text
\*======================================================================*/
function _striptext($document)
{
// I didn't use preg eval (//e) since that is only available in PHP 4.0.
// so, list your entities one by one here. I included some of the
// more common ones.
$search = array("''si", // strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // strip out html tags
"'([\r\n])[\s]+'", // strip out white space
"'&(quote|#34);'i", // replace html entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i"
);
$replace = array( "",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169));
$text = preg_replace($search,$replace,$document);
return $text;
}
/*======================================================================*\
Function: _expandlinks
Purpose: expand each link into a fully qualified URL
Input: $links the links to qualify
$URI the full URI to get the base from
Output: $expandedLinks the expanded links
\*======================================================================*/
function _expandlinks($links,$URI)
{
preg_match("/^[^\?]+/",$URI,$match);
$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
$search = array( "|^http://".preg_quote($this->host)."|i",
"|^(?!http://)(\/)?(?!mailto:)|i",
"|/\./|",
"|/[^\/]+/\.\./|"
);
$replace = array( "",
$match."/",
"/",
"/"
);
$expandedLinks = preg_replace($search,$replace,$links);
return $expandedLinks;
}
/*======================================================================*\
Function: _httprequest
Purpose: go get the http data from the server
Input: $url the url to fetch
$fp the current open file pointer
$URI the full URI
$body body contents to send if any (POST)
Output:
\*======================================================================*/
function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
{
if($this->passcookies && $this->_redirectaddr)
$this->setcookies();
$URI_PARTS = parse_url($URI);
if(empty($url))
$url = "/";
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
if(!empty($this->agent))
$headers .= "User-Agent: ".$this->agent."\r\n";
if(!empty($this->host) && !isset($this->rawheaders['Host']))
$headers .= "Host: ".$this->host."\r\n";
if(!empty($this->accept))
$headers .= "Accept: ".$this->accept."\r\n";
if($this->use_gzip) {
// make sure PHP was built with --with-zlib
// and we can handle gzipp'ed data
if ( function_exists(gzinflate) ) {
$headers .= "Accept-encoding: gzip\r\n";
}
else {
trigger_error(
"use_gzip is on, but PHP was built without zlib support.".
" Requesting file(s) without gzip encoding.",
E_USER_NOTICE);
}
}
if(!empty($this->referer))
$headers .= "Referer: ".$this->referer."\r\n";
if(!empty($this->cookies))
{
if(!is_array($this->cookies))
$this->cookies = (array)$this->cookies;
reset($this->cookies);
if ( count($this->cookies) > 0 ) {
$cookie_headers .= 'Cookie: ';
foreach ( $this->cookies as $cookieKey => $cookieVal ) {
$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
}
$headers .= substr($cookie_headers,0,-2) . "\r\n";
}
}
if(!empty($this->rawheaders))
{
if(!is_array($this->rawheaders))
$this->rawheaders = (array)$this->rawheaders;
while(list($headerKey,$headerVal) = each($this->rawheaders))
$headers .= $headerKey.": ".$headerVal."\r\n";
}
if(!empty($content_type)) {
$headers .= "Content-type: $content_type";
if ($content_type == "multipart/form-data")
$headers .= "; boundary=".$this->_mime_boundary;
$headers .= "\r\n";
}
if(!empty($body))
$headers .= "Content-length: ".strlen($body)."\r\n";
if(!empty($this->user) || !empty($this->pass))
$headers .= "Authorization: BASIC ".base64_encode($this->user.":".$this->pass)."\r\n";
$headers .= "\r\n";
// set the read timeout if needed
if ($this->read_timeout > 0)
socket_set_timeout($fp, $this->read_timeout);
$this->timed_out = false;
fwrite($fp,$headers.$body,strlen($headers.$body));
$this->_redirectaddr = false;
unset($this->headers);
// content was returned gzip encoded?
$is_gzipped = false;
while($currentHeader = fgets($fp,$this->_maxlinelen))
{
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
{
$this->status=-100;
return false;
}
// if($currentHeader == "\r\n")
if(preg_match("/^\r?\n$/", $currentHeader) )
break;
// if a header begins with Location: or URI:, set the redirect
if(preg_match("/^(Location:|URI:)/i",$currentHeader))
{
// get URL portion of the redirect
preg_match("/^(Location:|URI:)\s+(.*)/",chop($currentHeader),$matches);
// look for :// in the Location header to see if hostname is included
if(!preg_match("|\:\/\/|",$matches[2]))
{
// no host in the path, so prepend
$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port;
// eliminate double slash
if(!preg_match("|^/|",$matches[2]))
$this->_redirectaddr .= "/".$matches[2];
else
$this->_redirectaddr .= $matches[2];
}
else
$this->_redirectaddr = $matches[2];
}
if(preg_match("|^HTTP/|",$currentHeader))
{
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
{
$this->status= $status[1];
}
$this->response_code = $currentHeader;
}
if (preg_match("/Content-Encoding: gzip/", $currentHeader) ) {
$is_gzipped = true;
}
$this->headers[] = $currentHeader;
}
# $results = fread($fp, $this->maxlength);
$results = "";
while ( $data = fread($fp, $this->maxlength) ) {
$results .= $data;
if (
strlen($results) > $this->maxlength ) {
break;
}
}
// gunzip
if ( $is_gzipped ) {
// per http://www.php.net/manual/en/function.gzencode.php
$results = substr($results, 10);
$results = gzinflate($results);
}
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
{
$this->status=-100;
return false;
}
// check if there is a a redirect meta tag
if(preg_match("']*?content[\s]*=[\s]*[\"\']?\d+;[\s]+URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
{
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
}
// have we hit our frame depth and is there frame src to fetch?
if(($this->_framedepth < $this->maxframes) && preg_match_all("']+)'i",$results,$match))
{
$this->results[] = $results;
for($x=0; $x";
print_r($rss);
echo "
";
?>