Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Includes findingIds as parameter for filtering alerts #1357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class RestGetAlertsAction : BaseRestHandler() {
val severityLevel = request.param("severityLevel", "ALL")
val alertState = request.param("alertState", "ALL")
val monitorId: String? = request.param("monitorId")
val findingIdsParam: String? = request.param("findingIds")
val findingIds: List<String> = findingIdsParam?.split(",")?.map { it.trim() } ?: listOf()
val workflowId: String? = request.param("workflowIds")
val workflowIds = mutableListOf<String>()
if (workflowId.isNullOrEmpty() == false) {
Expand All @@ -73,7 +75,7 @@ class RestGetAlertsAction : BaseRestHandler() {
searchString
)

val getAlertsRequest = GetAlertsRequest(table, severityLevel, alertState, monitorId, null, workflowIds = workflowIds)
val getAlertsRequest = GetAlertsRequest(table, findingIds = findingIds, severityLevel, alertState, monitorId, null, workflowIds = workflowIds)
return RestChannelConsumer {
channel ->
client.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, getAlertsRequest, RestToXContentListener(channel))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ class TransportGetAlertsAction @Inject constructor(
queryBuilder.filter(QueryBuilders.termsQuery("monitor_id", getAlertsRequest.monitorIds))
addWorkflowIdNullOrEmptyCheck(getAlertsRequest, queryBuilder)
}
if (getAlertsRequest.findingIds.isNullOrEmpty() == false) {
queryBuilder.filter(QueryBuilders.termQuery("finding_id", getAlertsRequest.findingIds))
addWorkflowIdNullOrEmptyCheck(getAlertsRequest, queryBuilder)
} else if (getAlertsRequest.findingIds.isNullOrEmpty() == false) {
queryBuilder.filter(QueryBuilders.termsQuery("finding_id", getAlertsRequest.findingIds))
addWorkflowIdNullOrEmptyCheck(getAlertsRequest, queryBuilder)
}
if (
getAlertsRequest.workflowIds.isNullOrEmpty() == false &&
!(getAlertsRequest.workflowIds!!.size == 1 && getAlertsRequest.workflowIds!![0] == "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 0)
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", id, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", id, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 0)
try {
client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, "wrong_alert_index"))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, "wrong_alert_index"))
.get()
fail()
} catch (e: Exception) {
Expand Down Expand Up @@ -162,12 +162,12 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
assertEquals("Alert saved for test monitor", 1, alerts.size)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, customAlertsIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, customAlertsIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", id, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", id, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -299,7 +299,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -342,7 +342,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
var table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.isEmpty())
Expand All @@ -355,7 +355,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
table = Table("asc", "id", null, 1, 0, "")
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.isEmpty())
Expand Down Expand Up @@ -429,7 +429,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -541,7 +541,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -601,7 +601,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -641,7 +641,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
var table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand All @@ -659,7 +659,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
table = Table("asc", "id", null, 10, 0, "")
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -691,7 +691,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
var table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand All @@ -705,7 +705,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
table = Table("asc", "id", null, 10, 0, "")
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -748,7 +748,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
var table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", id, customAlertIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", id, customAlertIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertEquals(1, getAlertsResponse.alerts.size)
Expand All @@ -764,14 +764,14 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
// Verify that alert is moved to history index
table = Table("asc", "id", null, 10, 0, "")
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", id, customAlertIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", id, customAlertIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertEquals(0, getAlertsResponse.alerts.size)

table = Table("asc", "id", null, 10, 0, "")
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", id, customAlertHistoryIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", id, customAlertHistoryIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertEquals(1, getAlertsResponse.alerts.size)
Expand Down Expand Up @@ -832,7 +832,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
}
var table = Table("asc", "id", null, 1000, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", monitorId, customAlertIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", monitorId, customAlertIndex))
.get()

Assert.assertTrue(getAlertsResponse != null)
Expand All @@ -850,14 +850,14 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
// Verify that alert is moved to history index
table = Table("asc", "id", null, 1000, 0, "")
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", monitorId, customAlertIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", monitorId, customAlertIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertEquals(0, getAlertsResponse.alerts.size)

table = Table("asc", "id", null, 1000, 0, "")
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", monitorId, customAlertHistoryIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", monitorId, customAlertHistoryIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertEquals(11, getAlertsResponse.alerts.size)
Expand Down Expand Up @@ -929,7 +929,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
searchAlerts(id)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -1433,12 +1433,12 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
assertEquals("Alert saved for test monitor", 1, customAlertsIndexAlerts.size)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, customAlertsIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, customAlertsIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", monitorId, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", monitorId, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -1675,12 +1675,12 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
assertEquals("Alert saved for test monitor", 1, alerts.size)
val table = Table("asc", "id", null, 1, 0, "")
var getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", null, customAlertsIndex))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", null, customAlertsIndex))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
getAlertsResponse = client()
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, "ALL", "ALL", id, null))
.execute(AlertingActions.GET_ALERTS_ACTION_TYPE, GetAlertsRequest(table, null, "ALL", "ALL", id, null))
.get()
Assert.assertTrue(getAlertsResponse != null)
Assert.assertTrue(getAlertsResponse.alerts.size == 1)
Expand Down Expand Up @@ -1883,7 +1883,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
var getAlertsResponse = client()
.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(table, "ALL", "ALL", null, null)
GetAlertsRequest(table, null, "ALL", "ALL", null, null)
)
.get()

Expand All @@ -1893,7 +1893,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
var alertsResponseForRequestWithoutCustomIndex = client()
.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(table, "ALL", "ALL", null, null, monitorIds = listOf(id, id1, "1", "2"))
GetAlertsRequest(table, null, "ALL", "ALL", null, null, monitorIds = listOf(id, id1, "1", "2"))
)
.get()
Assert.assertTrue(alertsResponseForRequestWithoutCustomIndex != null)
Expand All @@ -1902,7 +1902,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
var getAlertsByAlertIds = client()
.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(table, "ALL", "ALL", null, null, alertIds = alertIds)
GetAlertsRequest(table, null, "ALL", "ALL", null, null, alertIds = alertIds)
)
.get()
Assert.assertTrue(getAlertsByAlertIds != null)
Expand All @@ -1911,7 +1911,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
var getAlertsByWrongAlertIds = client()
.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(table, "ALL", "ALL", null, null, alertIds = listOf("1", "2"))
GetAlertsRequest(table, null, "ALL", "ALL", null, null, alertIds = listOf("1", "2"))
)
.get()

Expand Down Expand Up @@ -2596,7 +2596,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(
table, "ALL", "ALL", monitorId, customAlertsIndex,
table, null, "ALL", "ALL", monitorId, customAlertsIndex,
workflowIds = listOf(workflowId)
)
)
Expand Down Expand Up @@ -3818,15 +3818,15 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
var getAlertsResponse = client()
.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(table, "ALL", "ALL", null, alertsIndex)
GetAlertsRequest(table, null, "ALL", "ALL", null, alertsIndex)
)
.get()
assertTrue(getAlertsResponse != null)
assertTrue(getAlertsResponse.alerts.size == alertSize)
getAlertsResponse = client()
.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(table, "ALL", "ALL", monitorId, null, workflowIds = listOf(workflowId))
GetAlertsRequest(table, null, "ALL", "ALL", monitorId, null, workflowIds = listOf(workflowId))
)
.get()
assertTrue(getAlertsResponse != null)
Expand Down Expand Up @@ -4197,6 +4197,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(
table = table,
findingIds = null,
severityLevel = "ALL",
alertState = "ALL",
monitorId = null,
Expand Down Expand Up @@ -4254,6 +4255,7 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
AlertingActions.GET_ALERTS_ACTION_TYPE,
GetAlertsRequest(
table = table,
findingIds = null,
severityLevel = "ALL",
alertState = "AUDIT",
monitorId = monitorResponse.id,
Expand Down