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.
APIs added for Alerts in Correlations
Signed-off-by: Riya Saxena <[email protected]>
- Loading branch information
1 parent
42f2b46
commit 462604d
Showing
13 changed files
with
504 additions
and
145 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/CorrelationAckAlertsAction.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 Alert Action | ||
*/ | ||
public class CorrelationAckAlertsAction extends ActionType<CorrelationAckAlertsResponse> { | ||
public static final String NAME = "cluster:admin/opensearch/securityanalytics/correlationAlerts/ack"; | ||
public static final CorrelationAckAlertsAction INSTANCE = new CorrelationAckAlertsAction(); | ||
|
||
public CorrelationAckAlertsAction() { | ||
super(NAME, CorrelationAckAlertsResponse::new); | ||
} | ||
} | ||
|
52 changes: 52 additions & 0 deletions
52
src/main/java/org/opensearch/securityanalytics/action/CorrelationAckAlertsRequest.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,52 @@ | ||
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 CorrelationAckAlertsRequest extends ActionRequest { | ||
private final List<String> correlationAlertIds; | ||
|
||
public CorrelationAckAlertsRequest(List<String> correlationAlertIds) { | ||
this.correlationAlertIds = correlationAlertIds; | ||
} | ||
|
||
public CorrelationAckAlertsRequest(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; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/org/opensearch/securityanalytics/action/CorrelationAckAlertsResponse.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,52 @@ | ||
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 CorrelationAckAlertsResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private final List<CorrelationAlert> acknowledged; | ||
private final List<CorrelationAlert> failed; | ||
|
||
public CorrelationAckAlertsResponse(List<CorrelationAlert> acknowledged, List<CorrelationAlert> failed) { | ||
this.acknowledged = acknowledged; | ||
this.failed = failed; | ||
} | ||
|
||
public CorrelationAckAlertsResponse(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; | ||
} | ||
} |
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
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
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
Oops, something went wrong.