boolean fire = false;
// get the alert definition in preparation for lots of processing on it
AlertDefinition alertDefinition = entityManager.find(AlertDefinition.class, alertDefinitionId);
AlertDampening alertDampening = alertDefinition.getAlertDampening();
AlertDampening.Category category = alertDampening.getCategory();
if (log.isDebugEnabled()) {
log.debug("Alert condition processing for " + alertDefinition);
log.debug("Dampening rules are: " + alertDampening);
}
if (category == AlertDampening.Category.NONE) {
if ((eventType == AlertDampeningEvent.Type.POSITIVE)
|| (eventType == AlertDampeningEvent.Type.POSITIVE_AGAIN)) {
/*
* technically we should always fire for the NONE category, but since this method has other
* consequences we'll call it and pass 1 as the second argument
*/
fire = this.shouldFireConsecutiveCountAlert(alertDefinitionId, 1);
}
} else if (category == AlertDampening.Category.CONSECUTIVE_COUNT) {
/*
* we don't care if the condition set becomes untrue, we need a number of events to be true in a row; a
* false event effectively resets that counter, so we need not perform a check in that instance
*/
if ((eventType == AlertDampeningEvent.Type.POSITIVE)
|| (eventType == AlertDampeningEvent.Type.POSITIVE_AGAIN)) {
int count = alertDampening.getValue();
fire = this.shouldFireConsecutiveCountAlert(alertDefinitionId, count);
}
} else if (category == AlertDampening.Category.PARTIAL_COUNT) {
if ((eventType == AlertDampeningEvent.Type.POSITIVE)
|| (eventType == AlertDampeningEvent.Type.POSITIVE_AGAIN)) {
int count = alertDampening.getValue();
int period = alertDampening.getPeriod();
fire = this.shouldFirePartialCountAlert(alertDefinitionId, count, period);
}
} else if (category == AlertDampening.Category.DURATION_COUNT) {
/*
* we don't care if the condition set becomes untrue, the count is all about how many times it was known
* to be positive (or positive again) during the collection period
*/
if ((eventType == AlertDampeningEvent.Type.POSITIVE)
|| (eventType == AlertDampeningEvent.Type.POSITIVE_AGAIN)) {
int count = alertDampening.getValue();
long period = alertDampening.getPeriod() * alertDampening.getPeriodUnits().getNumberOfSeconds();
// check whether "value" number of positive events have occurred within the last "period" seconds
fire = this.shouldFireDurationCountAlert(alertDefinitionId, count, period);
}
} else {
log.info("Category " + alertDampening.getCategory()
+ " is not supported for alert dampening processing");
}
/*
* If the dampening rules say we can fire, then create a new alert, and find the unmatched alert condition