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

[7.x] [SIEM][Detection Engine] critical blocker, fixes ordering issue that causes rules to not run the first time (#56230) #56256

Merged
merged 1 commit into from
Jan 29, 2020
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { defaults, pickBy, isEmpty } from 'lodash/fp';
import { PartialAlert } from '../../../../../alerting/server/types';
import { readRules } from './read_rules';
import { UpdateRuleParams, IRuleSavedAttributesSavedObjectAttributes } from './types';
import { addTags } from './add_tags';
Expand Down Expand Up @@ -108,7 +109,7 @@ export const updateRules = async ({
type,
references,
version,
}: UpdateRuleParams) => {
}: UpdateRuleParams): Promise<PartialAlert | null> => {
const rule = await readRules({ alertsClient, ruleId, id });
if (rule == null) {
return null;
Expand Down Expand Up @@ -170,6 +171,18 @@ export const updateRules = async ({
}
);

const update = await alertsClient.update({
id: rule.id,
data: {
tags: addTags(tags ?? rule.tags, rule.params.ruleId, immutable ?? rule.params.immutable),
name: calculateName({ updatedName: name, originalName: rule.name }),
schedule: {
interval: calculateInterval(interval, rule.schedule.interval),
},
actions: rule.actions,
params: nextParams,
},
});
if (rule.enabled && enabled === false) {
await alertsClient.disable({ id: rule.id });
} else if (!rule.enabled && enabled === true) {
Expand All @@ -195,16 +208,10 @@ export const updateRules = async ({
} else {
// enabled is null or undefined and we do not touch the rule
}
return alertsClient.update({
id: rule.id,
data: {
tags: addTags(tags ?? rule.tags, rule.params.ruleId, immutable ?? rule.params.immutable),
name: calculateName({ updatedName: name, originalName: rule.name }),
schedule: {
interval: calculateInterval(interval, rule.schedule.interval),
},
actions: rule.actions,
params: nextParams,
},
});

if (enabled != null) {
return { ...update, enabled };
} else {
return update;
}
};