Displaying most recent %d of %d total matching alerts\n", item_limit, total_items);
printf("
\n");
printf("
\n");
printf("Time | Alert Type | Host | Service | State | State Type | Information |
\n");
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next, current_item++) {
if(current_item >= item_limit && item_limit > 0)
break;
if(odd) {
odd = 0;
bgclass = "Odd";
}
else {
odd = 1;
bgclass = "Even";
}
printf("", bgclass);
get_time_string(&temp_event->time_stamp, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
printf("%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");
return;
}
/* displays alerts totals */
void display_alert_totals(void) {
int hard_host_up_alerts = 0;
int soft_host_up_alerts = 0;
int hard_host_down_alerts = 0;
int soft_host_down_alerts = 0;
int hard_host_unreachable_alerts = 0;
int soft_host_unreachable_alerts = 0;
int hard_service_ok_alerts = 0;
int soft_service_ok_alerts = 0;
int hard_service_warning_alerts = 0;
int soft_service_warning_alerts = 0;
int hard_service_unknown_alerts = 0;
int soft_service_unknown_alerts = 0;
int hard_service_critical_alerts = 0;
int soft_service_critical_alerts = 0;
archived_event *temp_event;
/************************/
/**** OVERALL TOTALS ****/
/************************/
/* process all events */
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) {
/* host alerts */
if(temp_event->event_type == AE_HOST_ALERT) {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_HOST_UP)
soft_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
soft_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
soft_host_unreachable_alerts++;
}
else {
if(temp_event->entry_type == AE_HOST_UP)
hard_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
hard_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
hard_host_unreachable_alerts++;
}
}
/* service alerts */
else {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_SERVICE_OK)
soft_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
soft_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
soft_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
soft_service_critical_alerts++;
}
else {
if(temp_event->entry_type == AE_SERVICE_OK)
hard_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
hard_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
hard_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
hard_service_critical_alerts++;
}
}
}
printf("
\n");
printf("
\n");
printf("
Overall Totals
\n");
printf("
\n");
printf("
\n");
printf("\n");
printf("\n");
if(alert_types & AE_HOST_ALERT) {
printf("\n");
printf(" Host Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("UP | %d | %d | %d | \n", soft_host_up_alerts, hard_host_up_alerts, soft_host_up_alerts + hard_host_up_alerts);
printf("DOWN | %d | %d | %d | \n", soft_host_down_alerts, hard_host_down_alerts, soft_host_down_alerts + hard_host_down_alerts);
printf("UNREACHABLE | %d | %d | %d | \n", soft_host_unreachable_alerts, hard_host_unreachable_alerts, soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf("All States | %d | %d | %d | \n", soft_host_up_alerts + soft_host_down_alerts + soft_host_unreachable_alerts, hard_host_up_alerts + hard_host_down_alerts + hard_host_unreachable_alerts, soft_host_up_alerts + hard_host_up_alerts + soft_host_down_alerts + hard_host_down_alerts + soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
if(alert_types & AE_SERVICE_ALERT) {
printf("\n");
printf(" Service Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("OK | %d | %d | %d | \n", soft_service_ok_alerts, hard_service_ok_alerts, soft_service_ok_alerts + hard_service_ok_alerts);
printf("WARNING | %d | %d | %d | \n", soft_service_warning_alerts, hard_service_warning_alerts, soft_service_warning_alerts + hard_service_warning_alerts);
printf("UNKNOWN | %d | %d | %d | \n", soft_service_unknown_alerts, hard_service_unknown_alerts, soft_service_unknown_alerts + hard_service_unknown_alerts);
printf("CRITICAL | %d | %d | %d | \n", soft_service_critical_alerts, hard_service_critical_alerts, soft_service_critical_alerts + hard_service_critical_alerts);
printf("All States | %d | %d | %d | \n", soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts, hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts, soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts + hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
printf(" \n");
printf(" \n");
printf(" |
\n");
printf("
\n");
return;
}
/* displays hostgroup alert totals */
void display_hostgroup_alert_totals(void) {
hostgroup *temp_hostgroup;
/**************************/
/**** HOSTGROUP TOTALS ****/
/**************************/
printf("
\n");
printf("
\n");
printf("
Totals By Hostgroup
\n");
if(show_all_hostgroups == FALSE)
display_specific_hostgroup_alert_totals(target_hostgroup);
else {
for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next)
display_specific_hostgroup_alert_totals(temp_hostgroup);
}
printf("
\n");
return;
}
/* displays alert totals for a specific hostgroup */
void display_specific_hostgroup_alert_totals(hostgroup *grp) {
int hard_host_up_alerts = 0;
int soft_host_up_alerts = 0;
int hard_host_down_alerts = 0;
int soft_host_down_alerts = 0;
int hard_host_unreachable_alerts = 0;
int soft_host_unreachable_alerts = 0;
int hard_service_ok_alerts = 0;
int soft_service_ok_alerts = 0;
int hard_service_warning_alerts = 0;
int soft_service_warning_alerts = 0;
int hard_service_unknown_alerts = 0;
int soft_service_unknown_alerts = 0;
int hard_service_critical_alerts = 0;
int soft_service_critical_alerts = 0;
archived_event *temp_event;
host *temp_host;
if(grp == NULL)
return;
/* make sure the user is authorized to view this hostgroup */
if(is_authorized_for_hostgroup(grp, ¤t_authdata) == FALSE)
return;
/* process all events */
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) {
temp_host = find_host(temp_event->host_name);
if(is_host_member_of_hostgroup(grp, temp_host) == FALSE)
continue;
/* host alerts */
if(temp_event->event_type == AE_HOST_ALERT) {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_HOST_UP)
soft_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
soft_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
soft_host_unreachable_alerts++;
}
else {
if(temp_event->entry_type == AE_HOST_UP)
hard_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
hard_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
hard_host_unreachable_alerts++;
}
}
/* service alerts */
else {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_SERVICE_OK)
soft_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
soft_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
soft_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
soft_service_critical_alerts++;
}
else {
if(temp_event->entry_type == AE_SERVICE_OK)
hard_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
hard_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
hard_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
hard_service_critical_alerts++;
}
}
}
printf("
\n");
printf("
\n");
printf("\n");
printf("Hostgroup '%s' (%s) | \n", grp->group_name, grp->alias);
printf("\n");
if(alert_types & AE_HOST_ALERT) {
printf("\n");
printf(" Host Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("UP | %d | %d | %d | \n", soft_host_up_alerts, hard_host_up_alerts, soft_host_up_alerts + hard_host_up_alerts);
printf("DOWN | %d | %d | %d | \n", soft_host_down_alerts, hard_host_down_alerts, soft_host_down_alerts + hard_host_down_alerts);
printf("UNREACHABLE | %d | %d | %d | \n", soft_host_unreachable_alerts, hard_host_unreachable_alerts, soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf("All States | %d | %d | %d | \n", soft_host_up_alerts + soft_host_down_alerts + soft_host_unreachable_alerts, hard_host_up_alerts + hard_host_down_alerts + hard_host_unreachable_alerts, soft_host_up_alerts + hard_host_up_alerts + soft_host_down_alerts + hard_host_down_alerts + soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
if(alert_types & AE_SERVICE_ALERT) {
printf("\n");
printf(" Service Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("OK | %d | %d | %d | \n", soft_service_ok_alerts, hard_service_ok_alerts, soft_service_ok_alerts + hard_service_ok_alerts);
printf("WARNING | %d | %d | %d | \n", soft_service_warning_alerts, hard_service_warning_alerts, soft_service_warning_alerts + hard_service_warning_alerts);
printf("UNKNOWN | %d | %d | %d | \n", soft_service_unknown_alerts, hard_service_unknown_alerts, soft_service_unknown_alerts + hard_service_unknown_alerts);
printf("CRITICAL | %d | %d | %d | \n", soft_service_critical_alerts, hard_service_critical_alerts, soft_service_critical_alerts + hard_service_critical_alerts);
printf("All States | %d | %d | %d | \n", soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts, hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts, soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts + hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
printf(" \n");
printf(" \n");
printf(" |
\n");
return;
}
/* displays host alert totals */
void display_host_alert_totals(void) {
host *temp_host;
/*********************/
/**** HOST TOTALS ****/
/*********************/
printf("
\n");
printf("
\n");
printf("
Totals By Host
\n");
if(show_all_hosts == FALSE)
display_specific_host_alert_totals(target_host);
else {
for(temp_host = host_list; temp_host != NULL; temp_host = temp_host->next)
display_specific_host_alert_totals(temp_host);
}
printf("
\n");
return;
}
/* displays alert totals for a specific host */
void display_specific_host_alert_totals(host *hst) {
int hard_host_up_alerts = 0;
int soft_host_up_alerts = 0;
int hard_host_down_alerts = 0;
int soft_host_down_alerts = 0;
int hard_host_unreachable_alerts = 0;
int soft_host_unreachable_alerts = 0;
int hard_service_ok_alerts = 0;
int soft_service_ok_alerts = 0;
int hard_service_warning_alerts = 0;
int soft_service_warning_alerts = 0;
int hard_service_unknown_alerts = 0;
int soft_service_unknown_alerts = 0;
int hard_service_critical_alerts = 0;
int soft_service_critical_alerts = 0;
archived_event *temp_event;
if(hst == NULL)
return;
/* make sure the user is authorized to view this host */
if(is_authorized_for_host(hst, ¤t_authdata) == FALSE)
return;
if(show_all_hostgroups == FALSE && target_hostgroup != NULL) {
if(is_host_member_of_hostgroup(target_hostgroup, hst) == FALSE)
return;
}
/* process all events */
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) {
if(strcmp(temp_event->host_name, hst->name))
continue;
/* host alerts */
if(temp_event->event_type == AE_HOST_ALERT) {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_HOST_UP)
soft_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
soft_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
soft_host_unreachable_alerts++;
}
else {
if(temp_event->entry_type == AE_HOST_UP)
hard_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
hard_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
hard_host_unreachable_alerts++;
}
}
/* service alerts */
else {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_SERVICE_OK)
soft_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
soft_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
soft_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
soft_service_critical_alerts++;
}
else {
if(temp_event->entry_type == AE_SERVICE_OK)
hard_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
hard_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
hard_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
hard_service_critical_alerts++;
}
}
}
printf("
\n");
printf("
\n");
printf("\n");
printf("Host '%s' (%s) | \n", hst->name, hst->alias);
printf("\n");
if(alert_types & AE_HOST_ALERT) {
printf("\n");
printf(" Host Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("UP | %d | %d | %d | \n", soft_host_up_alerts, hard_host_up_alerts, soft_host_up_alerts + hard_host_up_alerts);
printf("DOWN | %d | %d | %d | \n", soft_host_down_alerts, hard_host_down_alerts, soft_host_down_alerts + hard_host_down_alerts);
printf("UNREACHABLE | %d | %d | %d | \n", soft_host_unreachable_alerts, hard_host_unreachable_alerts, soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf("All States | %d | %d | %d | \n", soft_host_up_alerts + soft_host_down_alerts + soft_host_unreachable_alerts, hard_host_up_alerts + hard_host_down_alerts + hard_host_unreachable_alerts, soft_host_up_alerts + hard_host_up_alerts + soft_host_down_alerts + hard_host_down_alerts + soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
if(alert_types & AE_SERVICE_ALERT) {
printf("\n");
printf(" Service Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("OK | %d | %d | %d | \n", soft_service_ok_alerts, hard_service_ok_alerts, soft_service_ok_alerts + hard_service_ok_alerts);
printf("WARNING | %d | %d | %d | \n", soft_service_warning_alerts, hard_service_warning_alerts, soft_service_warning_alerts + hard_service_warning_alerts);
printf("UNKNOWN | %d | %d | %d | \n", soft_service_unknown_alerts, hard_service_unknown_alerts, soft_service_unknown_alerts + hard_service_unknown_alerts);
printf("CRITICAL | %d | %d | %d | \n", soft_service_critical_alerts, hard_service_critical_alerts, soft_service_critical_alerts + hard_service_critical_alerts);
printf("All States | %d | %d | %d | \n", soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts, hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts, soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts + hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
printf(" \n");
printf(" \n");
printf(" |
\n");
return;
}
/* displays servicegroup alert totals */
void display_servicegroup_alert_totals(void) {
servicegroup *temp_servicegroup;
/**************************/
/**** SERVICEGROUP TOTALS ****/
/**************************/
printf("
\n");
printf("
\n");
printf("
Totals By Servicegroup
\n");
if(show_all_servicegroups == FALSE)
display_specific_servicegroup_alert_totals(target_servicegroup);
else {
for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next)
display_specific_servicegroup_alert_totals(temp_servicegroup);
}
printf("
\n");
return;
}
/* displays alert totals for a specific servicegroup */
void display_specific_servicegroup_alert_totals(servicegroup *grp) {
int hard_host_up_alerts = 0;
int soft_host_up_alerts = 0;
int hard_host_down_alerts = 0;
int soft_host_down_alerts = 0;
int hard_host_unreachable_alerts = 0;
int soft_host_unreachable_alerts = 0;
int hard_service_ok_alerts = 0;
int soft_service_ok_alerts = 0;
int hard_service_warning_alerts = 0;
int soft_service_warning_alerts = 0;
int hard_service_unknown_alerts = 0;
int soft_service_unknown_alerts = 0;
int hard_service_critical_alerts = 0;
int soft_service_critical_alerts = 0;
archived_event *temp_event;
host *temp_host;
service *temp_service;
if(grp == NULL)
return;
/* make sure the user is authorized to view this servicegroup */
if(is_authorized_for_servicegroup(grp, ¤t_authdata) == FALSE)
return;
/* process all events */
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) {
if(temp_event->event_type == AE_HOST_ALERT) {
temp_host = find_host(temp_event->host_name);
if(is_host_member_of_servicegroup(grp, temp_host) == FALSE)
continue;
}
else {
temp_service = find_service(temp_event->host_name, temp_event->service_description);
if(is_service_member_of_servicegroup(grp, temp_service) == FALSE)
continue;
}
/* host alerts */
if(temp_event->event_type == AE_HOST_ALERT) {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_HOST_UP)
soft_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
soft_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
soft_host_unreachable_alerts++;
}
else {
if(temp_event->entry_type == AE_HOST_UP)
hard_host_up_alerts++;
else if(temp_event->entry_type == AE_HOST_DOWN)
hard_host_down_alerts++;
else if(temp_event->entry_type == AE_HOST_UNREACHABLE)
hard_host_unreachable_alerts++;
}
}
/* service alerts */
else {
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_SERVICE_OK)
soft_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
soft_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
soft_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
soft_service_critical_alerts++;
}
else {
if(temp_event->entry_type == AE_SERVICE_OK)
hard_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
hard_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
hard_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
hard_service_critical_alerts++;
}
}
}
printf("
\n");
printf("
\n");
printf("\n");
printf("Servicegroup '%s' (%s) | \n", grp->group_name, grp->alias);
printf("\n");
if(alert_types & AE_HOST_ALERT) {
printf("\n");
printf(" Host Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("UP | %d | %d | %d | \n", soft_host_up_alerts, hard_host_up_alerts, soft_host_up_alerts + hard_host_up_alerts);
printf("DOWN | %d | %d | %d | \n", soft_host_down_alerts, hard_host_down_alerts, soft_host_down_alerts + hard_host_down_alerts);
printf("UNREACHABLE | %d | %d | %d | \n", soft_host_unreachable_alerts, hard_host_unreachable_alerts, soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf("All States | %d | %d | %d | \n", soft_host_up_alerts + soft_host_down_alerts + soft_host_unreachable_alerts, hard_host_up_alerts + hard_host_down_alerts + hard_host_unreachable_alerts, soft_host_up_alerts + hard_host_up_alerts + soft_host_down_alerts + hard_host_down_alerts + soft_host_unreachable_alerts + hard_host_unreachable_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
if(alert_types & AE_SERVICE_ALERT) {
printf("\n");
printf(" Service Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("OK | %d | %d | %d | \n", soft_service_ok_alerts, hard_service_ok_alerts, soft_service_ok_alerts + hard_service_ok_alerts);
printf("WARNING | %d | %d | %d | \n", soft_service_warning_alerts, hard_service_warning_alerts, soft_service_warning_alerts + hard_service_warning_alerts);
printf("UNKNOWN | %d | %d | %d | \n", soft_service_unknown_alerts, hard_service_unknown_alerts, soft_service_unknown_alerts + hard_service_unknown_alerts);
printf("CRITICAL | %d | %d | %d | \n", soft_service_critical_alerts, hard_service_critical_alerts, soft_service_critical_alerts + hard_service_critical_alerts);
printf("All States | %d | %d | %d | \n", soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts, hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts, soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts + hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
printf(" \n");
printf(" \n");
printf(" |
\n");
return;
}
/* displays service alert totals */
void display_service_alert_totals(void) {
service *temp_service;
/************************/
/**** SERVICE TOTALS ****/
/************************/
printf("
\n");
printf("
\n");
printf("
Totals By Service
\n");
for(temp_service = service_list; temp_service != NULL; temp_service = temp_service->next)
display_specific_service_alert_totals(temp_service);
printf("
\n");
return;
}
/* displays alert totals for a specific service */
void display_specific_service_alert_totals(service *svc) {
int hard_service_ok_alerts = 0;
int soft_service_ok_alerts = 0;
int hard_service_warning_alerts = 0;
int soft_service_warning_alerts = 0;
int hard_service_unknown_alerts = 0;
int soft_service_unknown_alerts = 0;
int hard_service_critical_alerts = 0;
int soft_service_critical_alerts = 0;
archived_event *temp_event;
host *temp_host;
if(svc == NULL)
return;
/* make sure the user is authorized to view this service */
if(is_authorized_for_service(svc, ¤t_authdata) == FALSE)
return;
if(show_all_hostgroups == FALSE && target_hostgroup != NULL) {
temp_host = find_host(svc->host_name);
if(is_host_member_of_hostgroup(target_hostgroup, temp_host) == FALSE)
return;
}
if(show_all_hosts == FALSE && target_host != NULL) {
if(strcmp(target_host->name, svc->host_name))
return;
}
/* process all events */
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) {
if(temp_event->event_type != AE_SERVICE_ALERT)
continue;
if(strcmp(temp_event->host_name, svc->host_name) || strcmp(temp_event->service_description, svc->description))
continue;
/* service alerts */
if(temp_event->state_type == AE_SOFT_STATE) {
if(temp_event->entry_type == AE_SERVICE_OK)
soft_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
soft_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
soft_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
soft_service_critical_alerts++;
}
else {
if(temp_event->entry_type == AE_SERVICE_OK)
hard_service_ok_alerts++;
else if(temp_event->entry_type == AE_SERVICE_WARNING)
hard_service_warning_alerts++;
else if(temp_event->entry_type == AE_SERVICE_UNKNOWN)
hard_service_unknown_alerts++;
else if(temp_event->entry_type == AE_SERVICE_CRITICAL)
hard_service_critical_alerts++;
}
}
printf("
\n");
printf("
\n");
printf("\n");
printf("Service '%s' on Host '%s' | \n", svc->description, svc->host_name);
printf("\n");
if(alert_types & AE_SERVICE_ALERT) {
printf("\n");
printf(" Service Alerts \n");
printf("\n");
printf(" \n");
printf("State | Soft Alerts | Hard Alerts | Total Alerts | \n");
printf("OK | %d | %d | %d | \n", soft_service_ok_alerts, hard_service_ok_alerts, soft_service_ok_alerts + hard_service_ok_alerts);
printf("WARNING | %d | %d | %d | \n", soft_service_warning_alerts, hard_service_warning_alerts, soft_service_warning_alerts + hard_service_warning_alerts);
printf("UNKNOWN | %d | %d | %d | \n", soft_service_unknown_alerts, hard_service_unknown_alerts, soft_service_unknown_alerts + hard_service_unknown_alerts);
printf("CRITICAL | %d | %d | %d | \n", soft_service_critical_alerts, hard_service_critical_alerts, soft_service_critical_alerts + hard_service_critical_alerts);
printf("All States | %d | %d | %d | \n", soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts, hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts, soft_service_ok_alerts + soft_service_warning_alerts + soft_service_unknown_alerts + soft_service_critical_alerts + hard_service_ok_alerts + hard_service_warning_alerts + hard_service_unknown_alerts + hard_service_critical_alerts);
printf(" \n");
printf(" \n");
printf(" | \n");
}
printf(" \n");
printf(" \n");
printf(" |
\n");
return;
}
/* find a specific alert producer */
alert_producer *find_producer(int type, char *hname, char *sdesc) {
alert_producer *temp_producer;
for(temp_producer = producer_list; temp_producer != NULL; temp_producer = temp_producer->next) {
if(temp_producer->producer_type != type)
continue;
if(hname != NULL && strcmp(hname, temp_producer->host_name))
continue;
if(sdesc != NULL && strcmp(sdesc, temp_producer->service_description))
continue;
return temp_producer;
}
return NULL;
}
/* adds a new producer to the list in memory */
alert_producer *add_producer(int producer_type, char *host_name, char *service_description) {
alert_producer *new_producer = NULL;
/* allocate memory for the new entry */
new_producer = (alert_producer *)malloc(sizeof(alert_producer));
if(new_producer == NULL)
return NULL;
/* allocate memory for the host name */
if(host_name != NULL) {
new_producer->host_name = (char *)malloc(strlen(host_name) + 1);
if(new_producer->host_name != NULL)
strcpy(new_producer->host_name, host_name);
}
else
new_producer->host_name = NULL;
/* allocate memory for the service description */
if(service_description != NULL) {
new_producer->service_description = (char *)malloc(strlen(service_description) + 1);
if(new_producer->service_description != NULL)
strcpy(new_producer->service_description, service_description);
}
else
new_producer->service_description = NULL;
new_producer->producer_type = producer_type;
new_producer->total_alerts = 0;
/* add the new entry to the list in memory, sorted by time */
new_producer->next = producer_list;
producer_list = new_producer;
return new_producer;
}
void free_producer_list(void) {
alert_producer *this_producer = NULL;
alert_producer *next_producer = NULL;
for(this_producer = producer_list; this_producer != NULL;) {
next_producer = this_producer->next;
if(this_producer->host_name != NULL)
free(this_producer->host_name);
if(this_producer->service_description != NULL)
free(this_producer->service_description);
free(this_producer);
this_producer = next_producer;
}
producer_list = NULL;
return;
}
/* displays top alerts */
void display_top_alerts(void) {
archived_event *temp_event = NULL;
alert_producer *temp_producer = NULL;
alert_producer *next_producer = NULL;
alert_producer *last_producer = NULL;
alert_producer *new_producer = NULL;
alert_producer *temp_list = NULL;
int producer_type = AE_HOST_PRODUCER;
int current_item = 0;
int odd = 0;
char *bgclass = "";
/* process all events */
for(temp_event = event_list; temp_event != NULL; temp_event = temp_event->next) {
producer_type = (temp_event->event_type == AE_HOST_ALERT) ? AE_HOST_PRODUCER : AE_SERVICE_PRODUCER;
/* see if we already have a record for the producer */
temp_producer = find_producer(producer_type, temp_event->host_name, temp_event->service_description);
/* if not, add a record */
if(temp_producer == NULL)
temp_producer = add_producer(producer_type, temp_event->host_name, temp_event->service_description);
/* producer record could not be added */
if(temp_producer == NULL)
continue;
/* update stats for producer */
temp_producer->total_alerts++;
}
/* sort the producer list by total alerts (descending) */
total_items = 0;
temp_list = NULL;
for(new_producer = producer_list; new_producer != NULL;) {
next_producer = new_producer->next;
last_producer = temp_list;
for(temp_producer = temp_list; temp_producer != NULL; temp_producer = temp_producer->next) {
if(new_producer->total_alerts >= temp_producer->total_alerts) {
new_producer->next = temp_producer;
if(temp_producer == temp_list)
temp_list = new_producer;
else
last_producer->next = new_producer;
break;
}
else
last_producer = temp_producer;
}
if(temp_list == NULL) {
new_producer->next = NULL;
temp_list = new_producer;
}
else if(temp_producer == NULL) {
new_producer->next = NULL;
last_producer->next = new_producer;
}
new_producer = next_producer;
total_items++;
}
producer_list = temp_list;
printf("
\n");
if(item_limit <= 0 || total_items <= item_limit || total_items == 0)
printf("
Displaying all %d matching alert producers\n", total_items);
else
printf("
Displaying top %d of %d total matching alert producers\n", item_limit, total_items);
printf("
\n");
printf("
\n");
printf("Rank | Producer Type | Host | Service | Total Alerts |
\n");
/* display top producers */
for(temp_producer = producer_list; temp_producer != NULL; temp_producer = temp_producer->next) {
if(current_item >= item_limit && item_limit > 0)
break;
current_item++;
if(odd) {
odd = 0;
bgclass = "Odd";
}
else {
odd = 1;
bgclass = "Even";
}
printf("", bgclass);
printf("#%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");
}
printf("
\n");
printf("
\n");
return;
}