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

Fetch Custom Details added to alerts from both email and event based alerts #420

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
6 changes: 5 additions & 1 deletion src/config/column-generator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,11 @@ export const customAlertColumnForSavedColumn = (savedColumn) => {
return null;
}
const accessor = (incident) => {
const path = `alerts[*].body.cef_details.${accessorPath}`;
// custom details are in both body.cef_details.details and body.details for events
// but only body.details is guaranteed to exist, and won't be null
// body.cef_details.details can be null if the alert is from an email
// const path = `alerts[*].body.cef_details.${accessorPath}`;
const path = `alerts[*].body.${accessorPath}`;
let result = null;
try {
result = JSONPath({
Expand Down
21 changes: 13 additions & 8 deletions src/mocks/incidents.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ const generateMockAlert = () => {
const message = faker.commerce.productDescription();
const uuid = faker.string.uuid();
const link = faker.internet.url();
const customDetails = {
quote,
'some obsecure field': uuid,
link,
object_details: {
key1: 'value1',
},
};
return {
type: 'alert',
id: alertId,
Expand All @@ -30,18 +38,15 @@ const generateMockAlert = () => {
created_at: createdAt,
body: {
contexts: [],
// custom details are in both body.cef_details.details and body.details for events
// but only body.details is guaranteed to exist, and won't be null
// body.cef_details.details can be null if the alert is from an email
details: customDetails,
cef_details: {
contexts: [],
dedup_key: alertId,
description: title,
details: {
quote,
'some obsecure field': uuid,
link,
object_details: {
key1: 'value1',
},
},
details: customDetails,
event_class: jobType,
message,
mutations: [
Expand Down
12 changes: 9 additions & 3 deletions src/redux/incidents/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,10 @@ export function* filterIncidentsImpl() {
// Handle case when '[*]' accessors are used
const strippedAccessor = col.accessorPath.replace(/([[*\]])/g, '.');
return (
`alerts.body.cef_details.${strippedAccessor}`
// custom details are in both body.cef_details.details and body.details for events
// but only body.details is guaranteed to exist, and won't be null
// body.cef_details.details can be null if the alert is from an email
`alerts.body.${strippedAccessor}`
.split('.')
// Handle case when special character is wrapped in quotation marks
.map((a) => (a.includes("'") ? a.replaceAll("'", '') : a))
Expand All @@ -523,8 +526,11 @@ export function* filterIncidentsImpl() {
const incidentAlertsForSearch = incidentAlerts[incident.id] instanceof Array ? incidentAlerts[incident.id] : [];
const incidentAlertsForSearchWithFlattedCustomDetails = incidentAlertsForSearch.map(
(alert) => {
const flattedCustomDetails = alert.body?.cef_details
? Object.values(flattenObject(alert.body.cef_details)).join(' ')
// custom details are in both body.cef_details.details and body.details for events
// but only body.details is guaranteed to exist, and won't be null
// body.cef_details.details can be null if the alert is from an email
const flattedCustomDetails = alert.body?.details
? Object.values(flattenObject(alert.body.details)).join(' ')
: '';
return {
...alert,
Expand Down
2 changes: 1 addition & 1 deletion src/redux/incidents/sagas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Sagas: Incidents', () => {
it('filterIncidents: Search by Alert Custom Detail Field', () => {
const mockIncident = mockIncidents[0];
const customField = 'some obsecure field';
const customFieldValue = mockIncident.alerts[0].body.cef_details.details[customField];
const customFieldValue = mockIncident.alerts[0].body.details[customField];
const expectedIncidentResult = [mockIncident];
return expectSaga(filterIncidents)
.withReducer(incidents)
Expand Down
Loading