-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Cases] Include rule registry client for updating alert statuses #108588
Changes from 7 commits
59da630
c8b7028
d9bf686
44768f1
26f1f9e
ed6c6c8
2f585da
f71d00e
83a3663
72379b7
c4a86fc
a4c9aff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
"features", | ||
"kibanaReact", | ||
"kibanaUtils", | ||
"ruleRegistry", | ||
"triggersActionsUi" | ||
], | ||
"server":true, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,19 +12,11 @@ export const get = async ( | |
{ alertsInfo }: AlertGet, | ||
clientArgs: CasesClientArgs | ||
): Promise<CasesClientGetAlertsResponse> => { | ||
const { alertsService, scopedClusterClient, logger } = clientArgs; | ||
const { alertsService, logger } = clientArgs; | ||
if (alertsInfo.length === 0) { | ||
return []; | ||
} | ||
|
||
const alerts = await alertsService.getAlerts({ alertsInfo, scopedClusterClient, logger }); | ||
if (!alerts) { | ||
return []; | ||
} | ||
|
||
return alerts.docs.map((alert) => ({ | ||
id: alert._id, | ||
index: alert._index, | ||
...alert._source, | ||
})); | ||
const alerts = await alertsService.getAlerts({ alertsInfo, logger }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice clean up here but are we sure we are not breaking other people stuff by making this change |
||
return alerts ?? []; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,7 @@ | |
|
||
import { CaseStatuses } from '../../../common/api'; | ||
import { AlertInfo } from '../../common'; | ||
|
||
interface Alert { | ||
id: string; | ||
index: string; | ||
destination?: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We weren't referencing these fields. We're using a lodash |
||
ip: string; | ||
}; | ||
source?: { | ||
ip: string; | ||
}; | ||
} | ||
import { Alert } from '../../services/alerts/types'; | ||
|
||
export type CasesClientGetAlertsResponse = Alert[]; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
*/ | ||
|
||
import Boom from '@hapi/boom'; | ||
import { SavedObjectsFindResponse, SavedObject } from 'kibana/server'; | ||
import { SavedObjectsFindResponse, SavedObject, Logger } from 'kibana/server'; | ||
|
||
import { | ||
ActionConnector, | ||
|
@@ -22,26 +22,16 @@ import { | |
import { buildCaseUserActionItem } from '../../services/user_actions/helpers'; | ||
|
||
import { createIncident, getCommentContextFromAttributes } from './utils'; | ||
import { createCaseError, flattenCaseSavedObject, getAlertInfoFromComments } from '../../common'; | ||
import { | ||
AlertInfo, | ||
createCaseError, | ||
flattenCaseSavedObject, | ||
getAlertInfoFromComments, | ||
} from '../../common'; | ||
import { CasesClient, CasesClientArgs, CasesClientInternal } from '..'; | ||
import { Operations } from '../../authorization'; | ||
import { casesConnectors } from '../../connectors'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just moved this below the caller of it. |
||
/** | ||
* Returns true if the case should be closed based on the configuration settings and whether the case | ||
* is a collection. Collections are not closable because we aren't allowing their status to be changed. | ||
* In the future we could allow push to close all the sub cases of a collection but that's not currently supported. | ||
*/ | ||
function shouldCloseByPush( | ||
configureSettings: SavedObjectsFindResponse<CasesConfigureAttributes>, | ||
caseInfo: SavedObject<CaseAttributes> | ||
): boolean { | ||
return ( | ||
configureSettings.total > 0 && | ||
configureSettings.saved_objects[0].attributes.closure_type === 'close-by-pushing' && | ||
caseInfo.attributes.type !== CaseType.collection | ||
); | ||
} | ||
import { CasesClientGetAlertsResponse } from '../alerts/types'; | ||
|
||
/** | ||
* Parameters for pushing a case to an external system | ||
|
@@ -106,9 +96,7 @@ export const push = async ( | |
|
||
const alertsInfo = getAlertInfoFromComments(theCase?.comments); | ||
|
||
const alerts = await casesClientInternal.alerts.get({ | ||
alertsInfo, | ||
}); | ||
const alerts = await getAlertsCatchErrors({ casesClientInternal, alertsInfo, logger }); | ||
|
||
const getMappingsResponse = await casesClientInternal.configuration.getMappings({ | ||
connector: theCase.connector, | ||
|
@@ -278,3 +266,38 @@ export const push = async ( | |
throw createCaseError({ message: `Failed to push case: ${error}`, error, logger }); | ||
} | ||
}; | ||
|
||
async function getAlertsCatchErrors({ | ||
casesClientInternal, | ||
alertsInfo, | ||
logger, | ||
}: { | ||
casesClientInternal: CasesClientInternal; | ||
alertsInfo: AlertInfo[]; | ||
logger: Logger; | ||
}): Promise<CasesClientGetAlertsResponse> { | ||
try { | ||
return await casesClientInternal.alerts.get({ | ||
alertsInfo, | ||
}); | ||
} catch (error) { | ||
logger.error(`Failed to retrieve alerts during push: ${error}`); | ||
return []; | ||
} | ||
} | ||
|
||
/** | ||
* Returns true if the case should be closed based on the configuration settings and whether the case | ||
* is a collection. Collections are not closable because we aren't allowing their status to be changed. | ||
* In the future we could allow push to close all the sub cases of a collection but that's not currently supported. | ||
*/ | ||
function shouldCloseByPush( | ||
configureSettings: SavedObjectsFindResponse<CasesConfigureAttributes>, | ||
caseInfo: SavedObject<CaseAttributes> | ||
): boolean { | ||
return ( | ||
configureSettings.total > 0 && | ||
configureSettings.saved_objects[0].attributes.closure_type === 'close-by-pushing' && | ||
caseInfo.attributes.type !== CaseType.collection | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We depend on the rule registry to interact with the alerts now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruleRegistry
should be optional. Cases should still work without rule registry enabled.