Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
tracker feature 306 regarding escalations
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenp authored and Michael Friedrich committed May 25, 2010
1 parent befc3c0 commit 8c7d6c6
Show file tree
Hide file tree
Showing 11 changed files with 415 additions and 27 deletions.
9 changes: 9 additions & 0 deletions base/checks.c
Expand Up @@ -1291,6 +1291,9 @@ int handle_async_service_check_result(service *temp_service, check_result *queue
temp_service->last_notification=(time_t)0;
temp_service->next_notification=(time_t)0;
temp_service->current_notification_number=0;
temp_service->current_warning_notification_number=0;
temp_service->current_critical_notification_number=0;
temp_service->current_unknown_notification_number=0;
temp_service->problem_has_been_acknowledged=FALSE;
temp_service->acknowledgement_type=ACKNOWLEDGEMENT_NONE;
temp_service->notified_on_unknown=FALSE;
Expand Down Expand Up @@ -1520,6 +1523,12 @@ int handle_async_service_check_result(service *temp_service, check_result *queue
check_for_host_flapping(temp_host,TRUE,FALSE,TRUE);
flapping_check_done=TRUE;

if (hard_state_change==TRUE){
temp_service->current_warning_notification_number=0;
temp_service->current_critical_notification_number=0;
temp_service->current_unknown_notification_number=0;
}

/* (re)send notifications out about this service problem if the host is up (and was at last check also) and the dependencies were okay... */
service_notification(temp_service,NOTIFICATION_NORMAL,NULL,NULL,NOTIFICATION_OPTION_NONE);

Expand Down
172 changes: 158 additions & 14 deletions base/notifications.c
Expand Up @@ -98,10 +98,23 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
/* should the notification number be increased? */
if(type==NOTIFICATION_NORMAL || (options & NOTIFICATION_OPTION_INCREMENT)){
svc->current_notification_number++;
/* also increment the warning/critical/unknown state counter */
if (svc->current_state == STATE_WARNING) {
svc->current_warning_notification_number++;
}
if (svc->current_state == STATE_CRITICAL) {
svc->current_critical_notification_number++;
}
if (svc->current_state == STATE_UNKNOWN) {
svc->current_unknown_notification_number++;
}
increment_notification_number=TRUE;
}

log_debug_info(DEBUGL_NOTIFICATIONS,1,"Current notification number: %d (%s)\n",svc->current_notification_number,(increment_notification_number==TRUE)?"incremented":"unchanged");
log_debug_info(DEBUGL_NOTIFICATIONS,1,"Current warning notification number: %d (%s)\n",svc->current_warning_notification_number,(increment_notification_number==TRUE)?"incremented":"unchanged");
log_debug_info(DEBUGL_NOTIFICATIONS,1,"Current critical notification number: %d (%s)\n",svc->current_critical_notification_number,(increment_notification_number==TRUE)?"incremented":"unchanged");
log_debug_info(DEBUGL_NOTIFICATIONS,1,"Current unknown notification number: %d (%s)\n",svc->current_unknown_notification_number,(increment_notification_number==TRUE)?"incremented":"unchanged");

/* save and increase the current notification id */
svc->current_notification_id=next_notification_id;
Expand Down Expand Up @@ -256,6 +269,15 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat

/* adjust current notification number */
svc->current_notification_number--;
if (svc->current_state == STATE_WARNING) {
svc->current_warning_notification_number--;
}
if (svc->current_state == STATE_CRITICAL) {
svc->current_critical_notification_number--;
}
if (svc->current_state == STATE_UNKNOWN) {
svc->current_unknown_notification_number--;
}

log_debug_info(DEBUGL_NOTIFICATIONS,0,"No contacts were notified. Next possible notification time: %s",ctime(&svc->next_notification));
}
Expand All @@ -269,8 +291,18 @@ int service_notification(service *svc, int type, char *not_author, char *not_dat
else{

/* readjust current notification number, since one didn't go out */
if(increment_notification_number==TRUE)
if(increment_notification_number==TRUE) {
svc->current_notification_number--;
if (svc->current_state == STATE_WARNING) {
svc->current_warning_notification_number--;
}
if (svc->current_state == STATE_CRITICAL) {
svc->current_critical_notification_number--;
}
if (svc->current_state == STATE_UNKNOWN) {
svc->current_unknown_notification_number--;
}
}

log_debug_info(DEBUGL_NOTIFICATIONS,0,"No contacts were found for notification purposes. No notification was sent out.\n");
}
Expand Down Expand Up @@ -793,6 +825,10 @@ int notify_contact_of_service(contact *cntct, service *svc, int type, char *not_
/* checks to see if a service escalation entry is a match for the current service notification */
int is_valid_escalation_for_service_notification(service *svc, serviceescalation *se, int options){
int notification_number=0;
int warning_notification_number=0;
int critical_notification_number=0;
int unknown_notification_number=0;
int widematch=1;
time_t current_time=0L;
service *temp_service=NULL;

Expand All @@ -802,10 +838,14 @@ int is_valid_escalation_for_service_notification(service *svc, serviceescalation
time(&current_time);

/* if this is a recovery, really we check for who got notified about a previous problem */
if(svc->current_state==STATE_OK)
if(svc->current_state==STATE_OK)
notification_number=svc->current_notification_number-1;
else
notification_number=svc->current_notification_number;
/* These will not be incremented in the case of a recovery, so use the current values regardless of the state */
warning_notification_number=svc->current_warning_notification_number;
critical_notification_number=svc->current_critical_notification_number;
unknown_notification_number=svc->current_unknown_notification_number;

/* this entry if it is not for this service */
temp_service=se->service_ptr;
Expand All @@ -817,13 +857,59 @@ int is_valid_escalation_for_service_notification(service *svc, serviceescalation
if(options & NOTIFICATION_OPTION_BROADCAST)
return TRUE;

/* skip this escalation if it happens later */
if(se->first_notification > notification_number)
return FALSE;
/* skip this escalation if it happens later
* Only skip if none of the notifications numbers match */

if(se->first_notification == -2 || se->first_notification > notification_number)
widematch=0;

if (!widematch){
switch (svc->current_state){
case STATE_WARNING:{
if (se->first_warning_notification == -2 || se->first_warning_notification > warning_notification_number)
return FALSE;
break;
}
case STATE_CRITICAL:{
if (se->first_critical_notification == -2 || se->first_critical_notification > critical_notification_number)
return FALSE;
break;
}
case STATE_UNKNOWN:{
if (se->first_unknown_notification == -2 || se->first_unknown_notification > unknown_notification_number)
return FALSE;
break;
}
}
}

/* skip this escalation if it has already passed */
if(se->last_notification!=0 && se->last_notification < notification_number)
return FALSE;
/* skip this escalation if it has already passed
* only skip if none of the notifications numbers match */

widematch=1;
if(se->last_notification == -2 || se->last_notification!=0 && se->last_notification < notification_number)
widematch=0;


if (!widematch){
switch (svc->current_state){
case STATE_WARNING:{
if (se->last_warning_notification == -2 || ((se->last_warning_notification!=0) && (se->last_warning_notification < warning_notification_number)))
return FALSE;
break;
}
case STATE_CRITICAL:{
if (se->last_critical_notification == -2 || ((se->last_critical_notification!=0) && (se->last_critical_notification < critical_notification_number)))
return FALSE;
break;
}
case STATE_UNKNOWN:{
if (se->last_unknown_notification == -2 || ((se->last_unknown_notification!=0) && (se->last_unknown_notification < unknown_notification_number)))
return FALSE;
break;
}
}
}

/* skip this escalation if it has a timeperiod and the current time isn't valid */
if(se->escalation_period!=NULL && check_time_against_period(current_time,se->escalation_period_ptr)==ERROR)
Expand Down Expand Up @@ -1076,6 +1162,13 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
/* should the notification number be increased? */
if(type==NOTIFICATION_NORMAL || (options & NOTIFICATION_OPTION_INCREMENT)){
hst->current_notification_number++;
/* also increment down/unreachable state counter */
if (hst->current_state == HOST_DOWN) {
hst->current_down_notification_number++;
}
if (hst->current_state == HOST_UNREACHABLE) {
hst->current_unreachable_notification_number++;
}
increment_notification_number=TRUE;
}

Expand Down Expand Up @@ -1231,6 +1324,12 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int

/* adjust current notification number */
hst->current_notification_number--;
if (hst->current_state == HOST_DOWN) {
hst->current_down_notification_number--;
}
if (hst->current_state == HOST_UNREACHABLE) {
hst->current_unreachable_notification_number--;
}

log_debug_info(DEBUGL_NOTIFICATIONS,0,"No contacts were notified. Next possible notification time: %s",ctime(&hst->next_host_notification));
}
Expand All @@ -1243,8 +1342,15 @@ int host_notification(host *hst, int type, char *not_author, char *not_data, int
else{

/* adjust notification number, since no notification actually went out */
if(increment_notification_number==TRUE)
if(increment_notification_number==TRUE) {
hst->current_notification_number--;
if (hst->current_state == HOST_DOWN) {
hst->current_down_notification_number--;
}
if (hst->current_state == HOST_UNREACHABLE) {
hst->current_unreachable_notification_number--;
}
}

log_debug_info(DEBUGL_NOTIFICATIONS,0,"No contacts were found for notification purposes. No notification was sent out.\n");
}
Expand Down Expand Up @@ -1730,7 +1836,10 @@ int notify_contact_of_host(contact *cntct, host *hst, int type, char *not_author
/* checks to see if a host escalation entry is a match for the current host notification */
int is_valid_escalation_for_host_notification(host *hst, hostescalation *he, int options){
int notification_number=0;
int down_notification_number=0;
int unreachable_notification_number=0;
time_t current_time=0L;
int widematch=1;
host *temp_host=NULL;

log_debug_info(DEBUGL_FUNCTIONS,0,"is_valid_escalation_for_host_notification()\n");
Expand All @@ -1743,6 +1852,10 @@ int is_valid_escalation_for_host_notification(host *hst, hostescalation *he, int
notification_number=hst->current_notification_number-1;
else
notification_number=hst->current_notification_number;
/* these are not incremented in the case of recovery, so don't need special handling */
down_notification_number=hst->current_down_notification_number;
unreachable_notification_number=hst->current_unreachable_notification_number;


/* find the host this escalation entry is associated with */
temp_host=he->host_ptr;
Expand All @@ -1755,12 +1868,43 @@ int is_valid_escalation_for_host_notification(host *hst, hostescalation *he, int
return TRUE;

/* skip this escalation if it happens later */
if(he->first_notification > notification_number)
return FALSE;
if(he->first_notification == -2 || he->first_notification > notification_number)
widematch=0;

if (!widematch){
switch (hst->current_state){
case HOST_DOWN:{
if (he->first_down_notification == -2 || he->first_down_notification > down_notification_number)
return FALSE;
break;
}
case HOST_UNREACHABLE:{
if (he->first_unreachable_notification == -2 || he->first_unreachable_notification > unreachable_notification_number)
return FALSE;
break;
}
}
}

/* skip this escalation if it has already passed */
if(he->last_notification!=0 && he->last_notification < notification_number)
return FALSE;
/* skip this escalation if it has already passed. only skip if none match */
widematch=1;
if(he->last_notification == -2 || he->last_notification!=0 && he->last_notification < notification_number)
widematch=0;

if (!widematch){
switch (hst->current_state){
case HOST_DOWN:{
if (he->last_down_notification == -2 || he->last_down_notification!=0 && he->last_down_notification < down_notification_number)
return FALSE;
break;
}
case HOST_UNREACHABLE:{
if (he->last_unreachable_notification == -2 || he->last_unreachable_notification && he->last_unreachable_notification < unreachable_notification_number)
return FALSE;
break;
}
}
}

/* skip this escalation if it has a timeperiod and the current time isn't valid */
if(he->escalation_period!=NULL && check_time_against_period(current_time,he->escalation_period_ptr)==ERROR)
Expand Down
5 changes: 4 additions & 1 deletion base/sehandlers.c
Expand Up @@ -747,8 +747,11 @@ int handle_host_state(host *hst){
check_pending_flex_host_downtime(hst);

/* notify contacts about the recovery or problem if its a "hard" state */
if(hst->state_type==HARD_STATE)
if(hst->state_type==HARD_STATE){
hst->current_down_notification_number=0;
hst->current_unreachable_notification_number=0;
host_notification(hst,NOTIFICATION_NORMAL,NULL,NULL,NOTIFICATION_OPTION_NONE);
}

/* handle the host state change */
handle_host_event(hst);
Expand Down
29 changes: 25 additions & 4 deletions cgi/config.c
Expand Up @@ -1872,13 +1872,26 @@ void display_serviceescalations(void){
printf("&nbsp;");
printf("</TD>\n");

printf("<TD CLASS='%s'>%d</TD>",bg_class,temp_se->first_notification);
printf("<TD CLASS='%s'>%d, %d, %d, %d</TD>",bg_class,temp_se->first_notification,temp_se->first_warning_notification,temp_se->first_critical_notification, temp_se->first_unknown_notification);

printf("<TD CLASS='%s'>",bg_class);

if(temp_se->last_notification==0)
printf("Infinity, ");
else
printf("%d, ",temp_se->last_notification);
if(temp_se->last_warning_notification==0)
printf("Infinity, ");
else
printf("%d, ",temp_se->last_warning_notification);
if(temp_se->last_critical_notification==0)
printf("Infinity");
else
printf("%d",temp_se->last_notification);
printf("%d",temp_se->last_critical_notification);
if(temp_se->last_unknown_notification==0)
printf("Infinity");
else
printf("%d", temp_se->last_unknown_notification);
printf("</TD>\n");

get_interval_time_string(temp_se->notification_interval,time_string,sizeof(time_string));
Expand Down Expand Up @@ -2081,13 +2094,21 @@ void display_hostescalations(void){
printf("&nbsp;");
printf("</TD>\n");

printf("<TD CLASS='%s'>%d</TD>",bg_class,temp_he->first_notification);
printf("<TD CLASS='%s'>%d, %d, %d</TD>",bg_class,temp_he->first_notification,temp_he->first_down_notification,temp_he->first_unreachable_notification);

printf("<TD CLASS='%s'>",bg_class);
if(temp_he->last_notification==0)
printf("Infinity, ");
else
printf("%d, ",temp_he->last_notification);
if(temp_he->last_down_notification==0)
printf("Infinity, ");
else
printf("%d, ",temp_he->last_down_notification);
if(temp_he->last_unreachable_notification==0)
printf("Infinity");
else
printf("%d",temp_he->last_notification);
printf("%d",temp_he->last_unreachable_notification);
printf("</TD>\n");

get_interval_time_string(temp_he->notification_interval,time_string,sizeof(time_string));
Expand Down

0 comments on commit 8c7d6c6

Please sign in to comment.