Skip to content

Commit

Permalink
Addressed some comments about alert_id enrichment
Browse files Browse the repository at this point in the history
  • Loading branch information
donaherc committed Mar 1, 2022
1 parent c1bf6ea commit 3ba3958
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ interface SearchResultSource {
_source: SignalSource;
}

type CreatedSignalId = string;
type AlertId = string;

type SearchResultWithSource = SearchResultSource & SearchResultWithEventId;

export function selectEvents(
Expand Down Expand Up @@ -52,11 +55,15 @@ export function sendAlertTelemetryEvents(
return;
}
// Create map of ancenstor_id -> alert_id
let signalIdMap = new Map<string, string>();
createdEvents.map(function (obj: SignalSource) {
signalIdMap = signalIdMap.set(String(obj['kibana.alert.original_event.id']), String(obj._id));
return null;
});
const signalIdMap = createdEvents.reduce((signalMap, obj) => {
const ancestorId = String(obj['kibana.alert.original_event.id']);
const alertId = String(obj._id);
if (ancestorId !== null && ancestorId !== undefined) {
const newsignalMap = signalIdMap.set(ancestorId, alertId);
}

return newsignalMap;
}, new Map<CreatedSignalId, AlertId>());

const sources = selectEvents(filteredEvents, signalIdMap);

Expand Down

0 comments on commit 3ba3958

Please sign in to comment.