Skip to content

Commit

Permalink
HWKALERTS-161 Filter alerts by resolved and ack timestamps (#206)
Browse files Browse the repository at this point in the history
* HWKALERTS-161 Filter alerts by resolved and ack timestamps

* HWKALERTS-161 Feedback: more semantic on criteria and small fixes
  • Loading branch information
lucasponce authored and jshaughn committed Sep 19, 2016
1 parent b2474ed commit 268e855
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public enum Status {
private String resolvedBy;

@JsonInclude(Include.NON_EMPTY)
private List<Note> notes;
private List<Note> notes = new ArrayList<>();;

@JsonInclude(Include.NON_EMPTY)
private List<LifeCycle> lifecycle = new ArrayList<>();

@JsonInclude(Include.NON_EMPTY)
@Thin
Expand All @@ -85,6 +88,7 @@ public Alert(String tenantId, Trigger trigger, Dampening dampening, List<Set<Con
this.status = Status.OPEN;
this.severity = trigger.getSeverity();
this.eventType = EventType.ALERT.name();
addLifecycle(this.status, "system", this.ctime);
}

@JsonIgnore
Expand Down Expand Up @@ -158,9 +162,6 @@ public void setResolvedEvalSets(List<Set<ConditionEval>> resolvedEvalSets) {
}

public List<Note> getNotes() {
if (null == notes) {
this.notes = new ArrayList<>();
}
return notes;
}

Expand All @@ -181,6 +182,29 @@ public void addNote(String user, String text) {
getNotes().add(new Note(user, text));
}

public List<LifeCycle> getLifecycle() {
return lifecycle;
}

public void setLifecycle(List<LifeCycle> lifecycle) {
this.lifecycle = lifecycle;
}

public void addLifecycle(Status status, String user, long stime) {
if (status == null || user == null) {
throw new IllegalArgumentException("Lifecycle must have non-null state and user");
}
getLifecycle().add(new LifeCycle(status, user, stime));
}

@JsonIgnore
public LifeCycle getCurrentLifecycle() {
if (getLifecycle().isEmpty()) {
return null;
}
return getLifecycle().get(getLifecycle().size() - 1);
}

@Override
public String toString() {
return "Alert [alertId=" + id + ", status=" + status + ", ackTime=" + ackTime
Expand Down Expand Up @@ -271,4 +295,79 @@ public String toString() {
'}';
}
}

public static class LifeCycle {
@JsonInclude(Include.NON_EMPTY)
private Status status;

@JsonInclude(Include.NON_EMPTY)
private String user;

@JsonInclude(Include.NON_EMPTY)
private long stime;

public LifeCycle() {
// for json assembly
}

public LifeCycle(Status status, String user, long stime) {
this.status = status;
this.user = user;
this.stime = stime;
}

public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
}

public Status getStatus() {
return status;
}

public void setStatus(Status status) {
this.status = status;
}

public long getStime() {
return stime;
}

public void setStime(long stime) {
this.stime = stime;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

LifeCycle lifeCycle = (LifeCycle) o;

if (stime != lifeCycle.stime) return false;
if (user != null ? !user.equals(lifeCycle.user) : lifeCycle.user != null) return false;
return status == lifeCycle.status;

}

@Override
public int hashCode() {
int result = user != null ? user.hashCode() : 0;
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (int) (stime ^ (stime >>> 32));
return result;
}

@Override
public String toString() {
return "LifeCycle{" +
"user='" + user + '\'' +
", status=" + status +
", stime=" + stime +
'}';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* Copyright 2015-2016 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");
Expand Down Expand Up @@ -31,6 +31,10 @@
public class AlertsCriteria {
Long startTime = null;
Long endTime = null;
Long startResolvedTime = null;
Long endResolvedTime = null;
Long startAckTime = null;
Long endAckTime = null;
String alertId = null;
Collection<String> alertIds = null;
Alert.Status status = null;
Expand Down Expand Up @@ -68,6 +72,59 @@ public void setEndTime(Long endTime) {
this.endTime = endTime;
}

public Long getStartResolvedTime() {
return startResolvedTime;
}

/**
* @param startResolvedTime fetched Alerts must have at least one resolvedTime in the lifecycle greater than or
* equal to startResolvedTime.
* Alerts lifecycle might involve several transitions between ACKNOWLEDGE and RESOLVE
* states.
*/
public void setStartResolvedTime(Long startResolvedTime) {
this.startResolvedTime = startResolvedTime;
}

public Long getEndResolvedTime() {
return endResolvedTime;
}

/**
* @param endResolvedTime fetched Alerts must have at least one resolvedTime in the lifecycle less than or equal to
* endResolvedTime.
* Alerts lifecycle might involve several transitions between ACKNOWLEDGE and RESOLVE states.
*/
public void setEndResolvedTime(Long endResolvedTime) {
this.endResolvedTime = endResolvedTime;
}

public Long getStartAckTime() {
return startAckTime;
}

/**
* @param startAckTime fetched Alerts must have at least one ackTime in the lifecycle greater than or equal to
* startAckTime.
* Alerts lifecycle might involve several transitions between ACKNOWLEDGE and RESOLVE states.
*/
public void setStartAckTime(Long startAckTime) {
this.startAckTime = startAckTime;
}

public Long getEndAckTime() {
return endAckTime;
}

/**
* @param endAckTime fetched Alerts must have at least one ackTime in the lifecycle less than or equal to
* endAckTime.
* Alerts lifecycle might involve several transitions between ACKNOWLEDGE and RESOLVE states.
*/
public void setEndAckTime(Long endAckTime) {
this.endAckTime = endAckTime;
}

public String getAlertId() {
return alertId;
}
Expand Down Expand Up @@ -193,20 +250,32 @@ public boolean hasTriggerIdCriteria() {
|| (null != triggerIds && !triggerIds.isEmpty());
}

public boolean hasResolvedTimeCriteria() {
return (null != startResolvedTime || null != endResolvedTime);
}

public boolean hasAckTimeCriteria() {
return (null != startAckTime || null != endAckTime);
}

public boolean hasCriteria() {
return hasAlertIdCriteria()
|| hasStatusCriteria()
|| hasSeverityCriteria()
|| hasTagCriteria()
|| hasCTimeCriteria()
|| hasTriggerIdCriteria();
|| hasTriggerIdCriteria()
|| hasResolvedTimeCriteria()
|| hasAckTimeCriteria();
}

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

0 comments on commit 268e855

Please sign in to comment.