Skip to content

Commit

Permalink
Merge pull request #420 from PagerDuty/cef_details_email
Browse files Browse the repository at this point in the history
  • Loading branch information
gsreynolds authored Mar 26, 2024
2 parents 38846b0 + 5d84e08 commit 2c1f9a9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
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

0 comments on commit 2c1f9a9

Please sign in to comment.