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

[Security Solution][Detections] Fix 409 conflict error happening when user enables a rule #120088

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ export const performBulkActionRoute = (
await enableRule({
rule,
rulesClient,
ruleStatusClient,
spaceId: context.securitySolution.getSpaceId(),
});
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,19 @@

import { SanitizedAlert } from '../../../../../alerting/common';
import { RulesClient } from '../../../../../alerting/server';
import { RuleExecutionStatus } from '../../../../common/detection_engine/schemas/common/schemas';
import { IRuleExecutionLogClient } from '../rule_execution_log/types';
import { RuleParams } from '../schemas/rule_schemas';

interface EnableRuleArgs {
rule: SanitizedAlert<RuleParams>;
rulesClient: RulesClient;
ruleStatusClient: IRuleExecutionLogClient;
spaceId: string;
}

/**
* Enables the rule and updates its status to 'going to run'
*
* @param rule - rule to enable
* @param rulesClient - Alerts client
* @param ruleStatusClient - ExecLog client
*/
export const enableRule = async ({
rule,
rulesClient,
ruleStatusClient,
spaceId,
}: EnableRuleArgs) => {
export const enableRule = async ({ rule, rulesClient }: EnableRuleArgs) => {
await rulesClient.enable({ id: rule.id });

await ruleStatusClient.logStatusChange({
ruleId: rule.id,
ruleName: rule.name,
ruleType: rule.alertTypeId,
spaceId,
newStatus: RuleExecutionStatus['going to run'],
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const patchRules = async ({
if (rule.enabled && enabled === false) {
await rulesClient.disable({ id: rule.id });
} else if (!rule.enabled && enabled === true) {
await enableRule({ rule, rulesClient, ruleStatusClient, spaceId });
await enableRule({ rule, rulesClient });
} else {
// enabled is null or undefined and we do not touch the rule
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const updateRules = async ({
if (existingRule.enabled && enabled === false) {
await rulesClient.disable({ id: existingRule.id });
} else if (!existingRule.enabled && enabled === true) {
await enableRule({ rule: existingRule, rulesClient, ruleStatusClient, spaceId });
await enableRule({ rule: existingRule, rulesClient });
}
return { ...update, enabled };
};