Skip to content

Commit

Permalink
[HKWALERTS-53] Add severity to Triggers and Alerts
Browse files Browse the repository at this point in the history
Adds RTGov-style severities to Trigger definitions: User can set one of
Low, Medium (default), High, Critical.  Alerts generated by the Trigger
inherit the assigned severity.  Alert fetch offers severity filtering.
Trigger severity can be updated, but alert severity is immutable.

TODO (if needed): Alert severity filter support in RDB impl.
  • Loading branch information
jshaughn committed May 29, 2015
1 parent b2e7783 commit fe6cee6
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hawkular.alerts.api.model;

/**
* Severity set for a {@link org.hawkular.alerts.api.model.trigger.Trigger} and assigned to an
* {@link org.hawkular.alerts.api.model.condition.Alert} it generates.
*
* @author jay shaughnessy
* @author lucac ponce
*/
public enum Severity {
LOW, MEDIUM, HIGH, CRITICAL
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.List;
import java.util.Set;

import org.hawkular.alerts.api.model.Severity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

Expand Down Expand Up @@ -50,6 +52,9 @@ public enum Status {
@JsonInclude(Include.NON_EMPTY)
private List<Set<ConditionEval>> evalSets;

@JsonInclude
private Severity severity;

@JsonInclude
private Status status;

Expand Down Expand Up @@ -78,9 +83,10 @@ public Alert() {
// for json assembly
}

public Alert(String tenantId, String triggerId, List<Set<ConditionEval>> evalSets) {
public Alert(String tenantId, String triggerId, Severity severity, List<Set<ConditionEval>> evalSets) {
this.tenantId = tenantId;
this.triggerId = triggerId;
this.severity = (null == severity) ? Severity.MEDIUM : severity;
this.evalSets = evalSets;
this.ctime = System.currentTimeMillis();
this.status = Status.OPEN;
Expand Down Expand Up @@ -128,6 +134,14 @@ public void setTriggerId(String triggerId) {
this.triggerId = triggerId;
}

public Severity getSeverity() {
return severity;
}

public void setSeverity(Severity severity) {
this.severity = severity;
}

public Status getStatus() {
return status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Map;
import java.util.Set;

import org.hawkular.alerts.api.model.Severity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

Expand Down Expand Up @@ -51,6 +53,9 @@ public enum Match {
@JsonInclude
private boolean autoResolveAlerts;

@JsonInclude
private Severity severity;

/** A map with key based on actionPlugin and value a set of action's ids */
@JsonInclude(Include.NON_EMPTY)
private Map<String, Set<String>> actions;
Expand All @@ -67,6 +72,7 @@ public TriggerTemplate(String name) {
this.autoDisable = false;
this.autoResolve = false;
this.autoResolveAlerts = true;
this.severity = Severity.MEDIUM;
this.firingMatch = Match.ALL;
this.autoResolveMatch = Match.ALL;
this.actions = new HashMap<>();
Expand Down Expand Up @@ -115,6 +121,14 @@ public void setAutoResolveAlerts(boolean autoResolveAlerts) {
this.autoResolveAlerts = autoResolveAlerts;
}

public Severity getSeverity() {
return severity;
}

public void setSeverity(Severity severity) {
this.severity = severity;
}

public Match getFiringMatch() {
return firingMatch;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Collection;

import org.hawkular.alerts.api.model.Severity;
import org.hawkular.alerts.api.model.condition.Alert;
import org.hawkular.alerts.api.model.trigger.Tag;

Expand All @@ -34,6 +35,8 @@ public class AlertsCriteria {
Collection<String> alertIds = null;
Alert.Status status = null;
Collection<Alert.Status> statusSet = null;
Severity severity = null;
Collection<Severity> severities = null;
String triggerId = null;
Collection<String> triggerIds = null;
Tag tag = null;
Expand Down Expand Up @@ -141,22 +144,41 @@ public void setTags(Collection<Tag> tags) {
this.tags = tags;
}

public Severity getSeverity() {
return severity;
}

public void setSeverity(Severity severity) {
this.severity = severity;
}

public Collection<Severity> getSeverities() {
return severities;
}

public void setSeverities(Collection<Severity> severities) {
this.severities = severities;
}

public boolean hasCriteria() {
return null != startTime || //
null != endTime || //
null != triggerId || //
(null != triggerIds && !triggerIds.isEmpty()) || //
null != tag || //
(null != tags && !tags.isEmpty()) ||
null != status ||
(null != statusSet && !statusSet.isEmpty());
return null != startTime //
|| null != endTime
|| null != status
|| null != severity
|| null != triggerId
|| null != tag
|| (null != statusSet && !statusSet.isEmpty())
|| (null != severities && !severities.isEmpty())
|| (null != triggerIds && !triggerIds.isEmpty())
|| (null != tags && !tags.isEmpty());
}

@Override
public String toString() {
return "AlertsCriteria [startTime=" + startTime + ", endTime=" + endTime + ", triggerId=" + triggerId
+ ", triggerIds=" + triggerIds + ", tag=" + tag + ", tags=" + tags + ", status=" + status + ", " +
"statusSet=" + statusSet + "]";
return "AlertsCriteria [startTime=" + startTime + ", endTime=" + endTime + ", alertId=" + alertId
+ ", alertIds=" + alertIds + ", status=" + status + ", statusSet=" + statusSet + ", severity="
+ severity + ", severities=" + severities + ", triggerId=" + triggerId + ", triggerIds=" + triggerIds
+ ", tag=" + tag + ", tags=" + tags + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.exc.InvalidFormatException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hawkular.alerts.api.model.Severity;
import org.hawkular.alerts.api.model.action.Action;
import org.hawkular.alerts.api.model.condition.Alert;
import org.hawkular.alerts.api.model.condition.AvailabilityCondition;
Expand All @@ -52,6 +52,7 @@
import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;

/**
* Validation of JSON serialization/deserialization
Expand Down Expand Up @@ -93,7 +94,7 @@ public void jsonActionTest() throws Exception {

@Test
public void jsonAlertTest() throws Exception {
Alert alert = new Alert(TEST_TENANT, "trigger-test", null);
Alert alert = new Alert(TEST_TENANT, "trigger-test", Severity.MEDIUM, null);

String output = objectMapper.writeValueAsString(alert);

Expand Down Expand Up @@ -734,7 +735,8 @@ public void jsonTriggerTest() throws Exception {
"\"enabled\":true," +
"\"autoDisable\":true," +
"\"autoResolve\":true," +
"\"autoResolveAlerts\":true}";
"\"autoResolveAlerts\":true," +
"\"severity\":\"HIGH\"}";
Trigger trigger = objectMapper.readValue(str, Trigger.class);

assertTrue(trigger.getName().equals("test-name"));
Expand All @@ -748,6 +750,7 @@ public void jsonTriggerTest() throws Exception {
assertTrue(trigger.isAutoDisable());
assertTrue(trigger.isAutoResolve());
assertTrue(trigger.isAutoResolveAlerts());
assertTrue(trigger.getSeverity() == Severity.HIGH);

String output = objectMapper.writeValueAsString(trigger);

Expand Down

0 comments on commit fe6cee6

Please sign in to comment.