Skip to content

Commit

Permalink
Stop updating rule status on enable/disable
Browse files Browse the repository at this point in the history
  • Loading branch information
banderror committed Dec 1, 2021
1 parent 79079a7 commit b594dd4
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 23 deletions.
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 };
};

0 comments on commit b594dd4

Please sign in to comment.