Skip to content

Commit

Permalink
[SIEM] [Detection Engine] Timestamps for rules (#56197) (#56225)
Browse files Browse the repository at this point in the history
* utilize createdAt and updatedAt from the alerting saved object

* revert accidental change to test rule

* updatedAt is not a part of savedObject attributes passed back from alerting, it's at the top level
  • Loading branch information
dhurley14 authored Jan 28, 2020
1 parent 8fdb64d commit f9d72bb
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ export const getResult = (): RuleAlertType => ({
alertTypeId: 'siem.signals',
consumer: 'siem',
params: {
createdAt: '2019-12-13T16:40:33.400Z',
updatedAt: '2019-12-13T16:40:33.400Z',
description: 'Detecting root and admin users',
ruleId: 'rule-1',
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const createCreateRulesBulkRoute = (server: ServerFacade): Hapi.ServerRou
const rules = await Promise.all(
request.payload.map(async payloadRule => {
const {
created_at: createdAt,
description,
enabled,
false_positives: falsePositives,
Expand All @@ -72,7 +71,6 @@ export const createCreateRulesBulkRoute = (server: ServerFacade): Hapi.ServerRou
threat,
to,
type,
updated_at: updatedAt,
references,
timeline_id: timelineId,
timeline_title: timelineTitle,
Expand Down Expand Up @@ -103,7 +101,6 @@ export const createCreateRulesBulkRoute = (server: ServerFacade): Hapi.ServerRou
const createdRule = await createRules({
alertsClient,
actionsClient,
createdAt,
description,
enabled,
falsePositives,
Expand All @@ -128,7 +125,6 @@ export const createCreateRulesBulkRoute = (server: ServerFacade): Hapi.ServerRou
to,
type,
threat,
updatedAt,
references,
version,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const createCreateRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
},
async handler(request: RulesRequest, headers) {
const {
created_at: createdAt,
description,
enabled,
false_positives: falsePositives,
Expand All @@ -58,7 +57,6 @@ export const createCreateRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
threat,
to,
type,
updated_at: updatedAt,
references,
} = request.payload;
const alertsClient = isFunction(request.getAlertsClient) ? request.getAlertsClient() : null;
Expand Down Expand Up @@ -90,7 +88,6 @@ export const createCreateRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
const createdRule = await createRules({
alertsClient,
actionsClient,
createdAt,
description,
enabled,
falsePositives,
Expand All @@ -115,7 +112,6 @@ export const createCreateRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
to,
type,
threat,
updatedAt,
references,
version: 1,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export const createImportRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
const createdRule = await createRules({
alertsClient,
actionsClient,
createdAt: new Date().toISOString(),
description,
enabled,
falsePositives,
Expand All @@ -154,7 +153,6 @@ export const createImportRulesRoute = (server: ServerFacade): Hapi.ServerRoute =
to,
type,
threat,
updatedAt: new Date().toISOString(),
references,
version,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export const transformAlertToRule = (
ruleStatus?: SavedObject<IRuleSavedAttributesSavedObjectAttributes>
): Partial<OutputRuleAlertRest> => {
return pickBy<OutputRuleAlertRest>((value: unknown) => value != null, {
created_at: alert.params.createdAt,
updated_at: alert.params.updatedAt,
created_at: alert.createdAt.toISOString(),
updated_at: alert.updatedAt.toISOString(),
created_by: alert.createdBy,
description: alert.params.description,
enabled: alert.enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const createRules = ({
alertTypeId: SIGNALS_ID,
consumer: APP_ID,
params: {
createdAt: new Date().toISOString(),
description,
ruleId,
index,
Expand All @@ -66,7 +65,6 @@ export const createRules = ({
threat,
to,
type,
updatedAt: new Date().toISOString(),
references,
version,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export const installPrepackagedRules = (
threat,
references,
version,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
}),
];
}, []);
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export const updateRules = async ({
threat,
to,
type,
updatedAt: new Date().toISOString(),
references,
version: calculatedVersion,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export const sampleRuleAlertParams = (
meta: undefined,
threat: undefined,
version: 1,
updatedAt: '2019-12-17T15:04:25.343Z',
createdAt: '2019-12-17T15:04:37.105Z',
});

export const sampleDocNoSortId = (someUuid: string = sampleIdGuid): SignalSourceHit => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ describe('buildBulkBody', () => {
ruleParams: sampleParams,
id: sampleRuleGuid,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -103,6 +105,8 @@ describe('buildBulkBody', () => {
ruleParams: sampleParams,
id: sampleRuleGuid,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -189,6 +193,8 @@ describe('buildBulkBody', () => {
ruleParams: sampleParams,
id: sampleRuleGuid,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -272,6 +278,8 @@ describe('buildBulkBody', () => {
ruleParams: sampleParams,
id: sampleRuleGuid,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ interface BuildBulkBodyParams {
ruleParams: RuleTypeParams;
id: string;
name: string;
createdAt: string;
createdBy: string;
updatedAt: string;
updatedBy: string;
interval: string;
enabled: boolean;
Expand All @@ -28,7 +30,9 @@ export const buildBulkBody = ({
ruleParams,
id,
name,
createdAt,
createdBy,
updatedAt,
updatedBy,
interval,
enabled,
Expand All @@ -39,7 +43,9 @@ export const buildBulkBody = ({
id,
name,
enabled,
createdAt,
createdBy,
updatedAt,
updatedBy,
interval,
tags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ describe('buildRule', () => {
name: 'some-name',
id: sampleRuleGuid,
enabled: false,
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: 'some interval',
Expand Down Expand Up @@ -85,6 +87,8 @@ describe('buildRule', () => {
name: 'some-name',
id: sampleRuleGuid,
enabled: true,
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: 'some interval',
Expand Down Expand Up @@ -128,6 +132,8 @@ describe('buildRule', () => {
name: 'some-name',
id: sampleRuleGuid,
enabled: true,
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: 'some interval',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ interface BuildRuleParams {
name: string;
id: string;
enabled: boolean;
createdAt: string;
createdBy: string;
updatedAt: string;
updatedBy: string;
interval: string;
tags: string[];
Expand All @@ -23,7 +25,9 @@ export const buildRule = ({
name,
id,
enabled,
createdAt,
createdBy,
updatedAt,
updatedBy,
interval,
tags,
Expand Down Expand Up @@ -58,7 +62,7 @@ export const buildRule = ({
updated_by: updatedBy,
threat: ruleParams.threat,
version: ruleParams.version,
created_at: ruleParams.createdAt,
updated_at: ruleParams.updatedAt,
created_at: createdAt,
updated_at: updatedAt,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -93,6 +95,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand All @@ -117,6 +121,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -148,6 +154,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -179,6 +187,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -212,6 +222,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -245,6 +257,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down Expand Up @@ -280,6 +294,8 @@ describe('searchAfterAndBulkCreate', () => {
id: sampleRuleGuid,
signalsIndex: DEFAULT_SIGNALS_INDEX,
name: 'rule-name',
createdAt: '2020-01-28T15:58:34.810Z',
updatedAt: '2020-01-28T15:59:14.004Z',
createdBy: 'elastic',
updatedBy: 'elastic',
interval: '5m',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ interface SearchAfterAndBulkCreateParams {
id: string;
signalsIndex: string;
name: string;
createdAt: string;
createdBy: string;
updatedBy: string;
updatedAt: string;
interval: string;
enabled: boolean;
pageSize: number;
Expand All @@ -38,8 +40,10 @@ export const searchAfterAndBulkCreate = async ({
signalsIndex,
filter,
name,
createdAt,
createdBy,
updatedBy,
updatedAt,
interval,
enabled,
pageSize,
Expand All @@ -58,7 +62,9 @@ export const searchAfterAndBulkCreate = async ({
id,
signalsIndex,
name,
createdAt,
createdBy,
updatedAt,
updatedBy,
interval,
enabled,
Expand Down Expand Up @@ -118,7 +124,9 @@ export const searchAfterAndBulkCreate = async ({
id,
signalsIndex,
name,
createdAt,
createdBy,
updatedAt,
updatedBy,
interval,
enabled,
Expand Down
Loading

0 comments on commit f9d72bb

Please sign in to comment.