forked from opensearch-project/security-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alerts in Correlations Part 2 (opensearch-project#1062)
* notification for alerting in correlation * correlation alerts mapping change * working code Signed-off-by: Riya Saxena <[email protected]> * alertsInCorrelation without notifciations Signed-off-by: Riya Saxena <[email protected]> * alertsInCorrelation without notifciations Signed-off-by: Riya Saxena <[email protected]> * alertsInCorrelation without notifciations Signed-off-by: Riya Saxena <[email protected]> * alerts in correlations notification service added Signed-off-by: Riya Saxena <[email protected]> * addressing the comments Signed-off-by: Riya Saxena <[email protected]> * addressing the comments Signed-off-by: Riya Saxena <[email protected]> * getCorrelationAlerts API changes Signed-off-by: Riya Saxena <[email protected]> * APIs added for Alerts in Correlations Signed-off-by: Riya Saxena <[email protected]> * update alerts with an errorMessage when correlationRule is deleted Signed-off-by: Riya Saxena <[email protected]> * address the design changes discussed Signed-off-by: Riya Saxena <[email protected]> * address the design changes discussed Signed-off-by: Riya Saxena <[email protected]> * fixed tests Signed-off-by: Riya Saxena <[email protected]> * minor fixes due to merge Signed-off-by: Riya Saxena <[email protected]> * alerts API changes Signed-off-by: Riya Saxena <[email protected]> * klint fixes Signed-off-by: Riya Saxena <[email protected]> * license headers added Signed-off-by: Riya Saxena <[email protected]> * fixed format violations Signed-off-by: Riya Saxena <[email protected]> --------- Signed-off-by: Riya <[email protected]> Signed-off-by: Riya Saxena <[email protected]>
- Loading branch information
1 parent
62e4453
commit a74f509
Showing
19 changed files
with
970 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/org/opensearch/securityanalytics/action/AckCorrelationAlertsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
/** | ||
* Acknowledge Correlation Alert Action | ||
*/ | ||
public class AckCorrelationAlertsAction extends ActionType<AckCorrelationAlertsResponse> { | ||
public static final String NAME = "cluster:admin/opensearch/securityanalytics/correlationAlerts/ack"; | ||
public static final AckCorrelationAlertsAction INSTANCE = new AckCorrelationAlertsAction(); | ||
|
||
public AckCorrelationAlertsAction() { | ||
super(NAME, AckCorrelationAlertsResponse::new); | ||
} | ||
} | ||
|
56 changes: 56 additions & 0 deletions
56
src/main/java/org/opensearch/securityanalytics/action/AckCorrelationAlertsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.action.ValidateActions; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class AckCorrelationAlertsRequest extends ActionRequest { | ||
private final List<String> correlationAlertIds; | ||
|
||
public AckCorrelationAlertsRequest(List<String> correlationAlertIds) { | ||
this.correlationAlertIds = correlationAlertIds; | ||
} | ||
|
||
public AckCorrelationAlertsRequest(StreamInput in) throws IOException { | ||
correlationAlertIds = Collections.unmodifiableList(in.readStringList()); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if(correlationAlertIds == null || correlationAlertIds.isEmpty()) { | ||
validationException = ValidateActions.addValidationError("alert ids list cannot be empty", validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeStringCollection(this.correlationAlertIds); | ||
} | ||
|
||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
return builder.startObject() | ||
.field("correlation_alert_ids", correlationAlertIds) | ||
.endObject(); | ||
} | ||
|
||
public static AckAlertsRequest readFrom(StreamInput sin) throws IOException { | ||
return new AckAlertsRequest(sin); | ||
} | ||
|
||
public List<String> getCorrelationAlertIds() { | ||
return correlationAlertIds; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/opensearch/securityanalytics/action/AckCorrelationAlertsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.commons.alerting.model.CorrelationAlert; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class AckCorrelationAlertsResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private final List<CorrelationAlert> acknowledged; | ||
private final List<CorrelationAlert> failed; | ||
|
||
public AckCorrelationAlertsResponse(List<CorrelationAlert> acknowledged, List<CorrelationAlert> failed) { | ||
this.acknowledged = acknowledged; | ||
this.failed = failed; | ||
} | ||
|
||
public AckCorrelationAlertsResponse(StreamInput sin) throws IOException { | ||
this( | ||
Collections.unmodifiableList(sin.readList(CorrelationAlert::new)), | ||
Collections.unmodifiableList(sin.readList(CorrelationAlert::new)) | ||
); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput streamOutput) throws IOException { | ||
streamOutput.writeList(this.acknowledged); | ||
streamOutput.writeList(this.failed); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject() | ||
.field("acknowledged",this.acknowledged) | ||
.field("failed",this.failed); | ||
return builder.endObject(); | ||
} | ||
|
||
public List<CorrelationAlert> getAcknowledged() { | ||
return acknowledged; | ||
} | ||
|
||
public List<CorrelationAlert> getFailed() { | ||
return failed; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/opensearch/securityanalytics/action/GetCorrelationAlertsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionType; | ||
|
||
public class GetCorrelationAlertsAction extends ActionType<GetCorrelationAlertsResponse> { | ||
|
||
public static final GetCorrelationAlertsAction INSTANCE = new GetCorrelationAlertsAction(); | ||
public static final String NAME = "cluster:admin/opensearch/securityanalytics/correlationAlerts/get"; | ||
|
||
public GetCorrelationAlertsAction() { | ||
super(NAME, GetCorrelationAlertsResponse::new); | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
src/main/java/org/opensearch/securityanalytics/action/GetCorrelationAlertsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionRequestValidationException; | ||
import org.opensearch.commons.alerting.model.Table; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import java.util.Locale; | ||
|
||
import static org.opensearch.action.ValidateActions.addValidationError; | ||
|
||
public class GetCorrelationAlertsRequest extends ActionRequest { | ||
private String correlationRuleId; | ||
private String correlationRuleName; | ||
private Table table; | ||
private String severityLevel; | ||
private String alertState; | ||
|
||
private Instant startTime; | ||
|
||
private Instant endTime; | ||
|
||
public static final String CORRELATION_RULE_ID = "correlation_rule_id"; | ||
|
||
public GetCorrelationAlertsRequest( | ||
String correlationRuleId, | ||
String correlationRuleName, | ||
Table table, | ||
String severityLevel, | ||
String alertState, | ||
Instant startTime, | ||
Instant endTime | ||
) { | ||
super(); | ||
this.correlationRuleId = correlationRuleId; | ||
this.correlationRuleName = correlationRuleName; | ||
this.table = table; | ||
this.severityLevel = severityLevel; | ||
this.alertState = alertState; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
public GetCorrelationAlertsRequest(StreamInput sin) throws IOException { | ||
this( | ||
sin.readOptionalString(), | ||
sin.readOptionalString(), | ||
Table.readFrom(sin), | ||
sin.readString(), | ||
sin.readString(), | ||
sin.readOptionalInstant(), | ||
sin.readOptionalInstant() | ||
); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
ActionRequestValidationException validationException = null; | ||
if ((correlationRuleId != null && correlationRuleId.isEmpty())) { | ||
validationException = addValidationError(String.format(Locale.getDefault(), | ||
"Correlation ruleId is empty or not valid", CORRELATION_RULE_ID), | ||
validationException); | ||
} | ||
return validationException; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalString(correlationRuleId); | ||
out.writeOptionalString(correlationRuleName); | ||
table.writeTo(out); | ||
out.writeString(severityLevel); | ||
out.writeString(alertState); | ||
out.writeOptionalInstant(startTime); | ||
out.writeOptionalInstant(endTime); | ||
} | ||
|
||
public String getCorrelationRuleId() { | ||
return correlationRuleId; | ||
} | ||
|
||
public Table getTable() { | ||
return table; | ||
} | ||
|
||
public String getSeverityLevel() { | ||
return severityLevel; | ||
} | ||
|
||
public String getAlertState() { | ||
return alertState; | ||
} | ||
|
||
public String getCorrelationRuleName() { | ||
return correlationRuleName; | ||
} | ||
|
||
public Instant getStartTime() { | ||
return startTime; | ||
} | ||
|
||
public Instant getEndTime() { | ||
return endTime; | ||
} | ||
} | ||
|
54 changes: 54 additions & 0 deletions
54
src/main/java/org/opensearch/securityanalytics/action/GetCorrelationAlertsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.action; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.commons.alerting.model.CorrelationAlert; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.core.common.io.stream.StreamInput; | ||
import org.opensearch.core.common.io.stream.StreamOutput; | ||
import org.opensearch.core.xcontent.ToXContentObject; | ||
import org.opensearch.core.xcontent.XContentBuilder; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class GetCorrelationAlertsResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private static final Logger log = LogManager.getLogger(GetCorrelationAlertsResponse.class); | ||
private static final String CORRELATION_ALERTS_FIELD = "correlationAlerts"; | ||
private static final String TOTAL_ALERTS_FIELD = "total_alerts"; | ||
|
||
private List<CorrelationAlert> alerts; | ||
private Integer totalAlerts; | ||
|
||
public GetCorrelationAlertsResponse(List<CorrelationAlert> alerts, Integer totalAlerts) { | ||
super(); | ||
this.alerts = alerts; | ||
this.totalAlerts = totalAlerts; | ||
} | ||
|
||
public GetCorrelationAlertsResponse(StreamInput sin) throws IOException { | ||
this( | ||
Collections.unmodifiableList(sin.readList(CorrelationAlert::new)), | ||
sin.readInt() | ||
); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeCollection(this.alerts); | ||
out.writeInt(this.totalAlerts); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject() | ||
.field(CORRELATION_ALERTS_FIELD, this.alerts) | ||
.field(TOTAL_ALERTS_FIELD, this.totalAlerts); | ||
return builder.endObject(); | ||
} | ||
} |
Oops, something went wrong.