Skip to content

Commit 411b0da

Browse files
committed
Normalize threshold field on routes that use legacy style schema definitions
1 parent 8b7c0f7 commit 411b0da

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

x-pack/plugins/security_solution/common/detection_engine/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
EntriesArray,
1313
ExceptionListItemSchema,
1414
} from '../shared_imports';
15-
import { Type, JobStatus } from './schemas/common/schemas';
15+
import { Type, JobStatus, Threshold, ThresholdNormalized } from './schemas/common/schemas';
1616

1717
export const hasLargeValueItem = (
1818
exceptionItems: Array<ExceptionListItemSchema | CreateExceptionListItemSchema>
@@ -55,5 +55,12 @@ export const normalizeThresholdField = (
5555
: [thresholdField!];
5656
};
5757

58+
export const normalizeThresholdObject = (threshold: Threshold): ThresholdNormalized => {
59+
return {
60+
...threshold,
61+
field: normalizeThresholdField(threshold.field),
62+
};
63+
};
64+
5865
export const getRuleStatusText = (value: JobStatus | null | undefined): JobStatus | null =>
5966
value === 'partial failure' ? 'warning' : value != null ? value : null;

x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* 2.0.
66
*/
77

8+
import { normalizeThresholdObject } from '../../../../common/detection_engine/utils';
89
import { transformRuleToAlertAction } from '../../../../common/detection_engine/transform_actions';
910
import { SanitizedAlert } from '../../../../../alerting/common';
1011
import { SERVER_APP_ID, SIGNALS_ID } from '../../../../common/constants';
@@ -97,7 +98,7 @@ export const createRules = async ({
9798
severity,
9899
severityMapping,
99100
threat,
100-
threshold,
101+
threshold: threshold ? normalizeThresholdObject(threshold) : undefined,
101102
/**
102103
* TODO: Fix typing inconsistancy between `RuleTypeParams` and `CreateRulesOptions`
103104
*/

x-pack/plugins/security_solution/server/lib/detection_engine/rules/patch_rules.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { addTags } from './add_tags';
1414
import { calculateVersion, calculateName, calculateInterval, removeUndefined } from './utils';
1515
import { ruleStatusSavedObjectsClientFactory } from '../signals/rule_status_saved_objects_client';
1616
import { internalRuleUpdate, RuleParams } from '../schemas/rule_schemas';
17+
import { normalizeThresholdObject } from '../../../../common/detection_engine/utils';
1718

1819
class PatchError extends Error {
1920
public readonly statusCode: number;
@@ -150,7 +151,7 @@ export const patchRules = async ({
150151
severity,
151152
severityMapping,
152153
threat,
153-
threshold,
154+
threshold: threshold ? normalizeThresholdObject(threshold) : undefined,
154155
threatFilters,
155156
threatIndex,
156157
threatQuery,

x-pack/plugins/security_solution/server/lib/detection_engine/schemas/rule_converters.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import uuid from 'uuid';
99
import { SavedObject } from 'kibana/server';
10-
import { normalizeThresholdField } from '../../../../common/detection_engine/utils';
10+
import { normalizeThresholdObject } from '../../../../common/detection_engine/utils';
1111
import {
1212
InternalRuleCreate,
1313
RuleParams,
@@ -96,10 +96,7 @@ export const typeSpecificSnakeToCamel = (params: CreateTypeSpecific): TypeSpecif
9696
query: params.query,
9797
filters: params.filters,
9898
savedId: params.saved_id,
99-
threshold: {
100-
...params.threshold,
101-
field: normalizeThresholdField(params.threshold.field),
102-
},
99+
threshold: normalizeThresholdObject(params.threshold),
103100
};
104101
}
105102
case 'machine_learning': {

0 commit comments

Comments
 (0)