Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
d86a9a2
WIP
patrykkopycinski Jul 3, 2020
e3d625f
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 3, 2020
76c422c
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 3, 2020
5adc6c3
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 5, 2020
47ae246
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 6, 2020
ad2d17c
WIP
patrykkopycinski Jul 6, 2020
14669c0
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 6, 2020
b2bfd9c
WIP
patrykkopycinski Jul 6, 2020
50b0f2b
WIP
patrykkopycinski Jul 6, 2020
3a8b07d
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 6, 2020
92ce479
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 6, 2020
1a8ce00
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 7, 2020
365d771
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 7, 2020
71f2cc6
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 7, 2020
1adb152
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 7, 2020
d21cd06
type
patrykkopycinski Jul 7, 2020
6870ac9
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 8, 2020
f6ffe56
WIP
patrykkopycinski Jul 8, 2020
e1a65ff
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 8, 2020
d6d9e8e
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 9, 2020
dafaa65
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 9, 2020
f16aa1c
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 9, 2020
0e0f954
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 9, 2020
f1a9071
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 9, 2020
6a6d724
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 10, 2020
3aa0796
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 10, 2020
1dbf863
WIP
patrykkopycinski Jul 11, 2020
82538f0
WIP
patrykkopycinski Jul 11, 2020
39a7ffa
WIP
patrykkopycinski Jul 11, 2020
4974834
WIP
patrykkopycinski Jul 11, 2020
38942cd
WIP
patrykkopycinski Jul 11, 2020
fea58df
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 11, 2020
e92e003
WIP
patrykkopycinski Jul 11, 2020
feeae46
test
patrykkopycinski Jul 11, 2020
fe19fa1
WIP
patrykkopycinski Jul 12, 2020
ed681d6
WIP
patrykkopycinski Jul 12, 2020
7972327
types
patrykkopycinski Jul 12, 2020
81c1adc
cleanup
patrykkopycinski Jul 12, 2020
35d5bc3
WIP
patrykkopycinski Jul 12, 2020
b422977
types
patrykkopycinski Jul 12, 2020
fc125b5
fix input
patrykkopycinski Jul 13, 2020
b7eec88
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 13, 2020
d0bfd94
constant results
patrykkopycinski Jul 13, 2020
011171a
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 13, 2020
94d24e1
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 13, 2020
8e4c5ef
Fix layout
patrykkopycinski Jul 13, 2020
4a45d82
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 13, 2020
d57926a
Fix form state
patrykkopycinski Jul 13, 2020
186aaad
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 13, 2020
df98cf9
Fix sendAlertToTimelineAction
patrykkopycinski Jul 13, 2020
9a67b4d
Fix react warnings
patrykkopycinski Jul 13, 2020
7588578
Add support for nonEcsData in sendAlertToTimelineAction
patrykkopycinski Jul 13, 2020
69fbcf5
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 14, 2020
8dbe7ab
PR comments
patrykkopycinski Jul 14, 2020
51780f9
Fix i18n
patrykkopycinski Jul 14, 2020
96d4007
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 14, 2020
7679e32
i18n
patrykkopycinski Jul 14, 2020
2cd6442
Merge branch 'master' into feat/treshold-rule-type
elasticmachine Jul 14, 2020
2d54b30
Merge branch 'master' of github.com:elastic/kibana into feat/treshold…
patrykkopycinski Jul 14, 2020
1b2662b
Fix mapping
patrykkopycinski Jul 14, 2020
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 @@ -275,7 +275,12 @@ export type To = t.TypeOf<typeof to>;
export const toOrUndefined = t.union([to, t.undefined]);
export type ToOrUndefined = t.TypeOf<typeof toOrUndefined>;

export const type = t.keyof({ machine_learning: null, query: null, saved_query: null });
export const type = t.keyof({
machine_learning: null,
query: null,
saved_query: null,
threshold: null,
});
export type Type = t.TypeOf<typeof type>;

export const typeOrUndefined = t.union([type, t.undefined]);
Expand Down Expand Up @@ -369,6 +374,17 @@ export type Threat = t.TypeOf<typeof threat>;
export const threatOrUndefined = t.union([threat, t.undefined]);
export type ThreatOrUndefined = t.TypeOf<typeof threatOrUndefined>;

export const threshold = t.exact(
t.type({
field: t.string,
value: PositiveIntegerGreaterThanZero,
})
);
export type Threshold = t.TypeOf<typeof threshold>;

export const thresholdOrUndefined = t.union([threshold, t.undefined]);
export type ThresholdOrUndefined = t.TypeOf<typeof thresholdOrUndefined>;

export const created_at = IsoDateString;
export const updated_at = IsoDateString;
export const updated_by = t.string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
To,
type,
Threat,
threshold,
ThrottleOrNull,
note,
References,
Expand Down Expand Up @@ -111,6 +112,7 @@ export const addPrepackagedRulesSchema = t.intersection([
tags: DefaultStringArray, // defaults to empty string array if not set during decode
to: DefaultToString, // defaults to "now" if not set during decode
threat: DefaultThreatArray, // defaults to empty array if not set during decode
threshold, // defaults to "undefined" if not set during decode
throttle: DefaultThrottleNull, // defaults to "null" if not set during decode
timestamp_override, // defaults to "undefined" if not set during decode
references: DefaultStringArray, // defaults to empty array of strings if not set during decode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AddPrepackagedRulesSchema } from './add_prepackaged_rules_schema';
import { addPrepackagedRuleValidateTypeDependents } from './add_prepackaged_rules_type_dependents';
import { getAddPrepackagedRulesSchemaMock } from './add_prepackaged_rules_schema.mock';

describe('create_rules_type_dependents', () => {
describe('add_prepackaged_rules_type_dependents', () => {
test('saved_id is required when type is saved_query and will not validate without out', () => {
const schema: AddPrepackagedRulesSchema = {
...getAddPrepackagedRulesSchemaMock(),
Expand Down Expand Up @@ -68,4 +68,26 @@ describe('create_rules_type_dependents', () => {
const errors = addPrepackagedRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "timeline_title" exists, "timeline_id" must also exist']);
});

test('threshold is required when type is threshold and validates with it', () => {
const schema: AddPrepackagedRulesSchema = {
...getAddPrepackagedRulesSchemaMock(),
type: 'threshold',
};
const errors = addPrepackagedRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "type" is "threshold", "threshold" is required']);
});

test('threshold.value is required and has to be bigger than 0 when type is threshold and validates with it', () => {
const schema: AddPrepackagedRulesSchema = {
...getAddPrepackagedRulesSchemaMock(),
type: 'threshold',
threshold: {
field: '',
value: -1,
},
};
const errors = addPrepackagedRuleValidateTypeDependents(schema);
expect(errors).toEqual(['"threshold.value" has to be bigger than 0']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ export const validateTimelineTitle = (rule: AddPrepackagedRulesSchema): string[]
return [];
};

export const validateThreshold = (rule: AddPrepackagedRulesSchema): string[] => {
if (rule.type === 'threshold') {
if (!rule.threshold) {
return ['when "type" is "threshold", "threshold" is required'];
} else if (rule.threshold.value <= 0) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally you can use the io-ts type to verify the value is in bound -- either:
threshold.is(rule.threshold) (as imported from detection_engine/schemas/common/schemas.ts)
-or-
PositiveIntegerGreaterThanZero.is(rule.threshold.value)

return ['"threshold.value" has to be bigger than 0'];
} else {
return [];
}
}
return [];
};

export const addPrepackagedRuleValidateTypeDependents = (
schema: AddPrepackagedRulesSchema
): string[] => {
Expand All @@ -103,5 +116,6 @@ export const addPrepackagedRuleValidateTypeDependents = (
...validateMachineLearningJobId(schema),
...validateTimelineId(schema),
...validateTimelineTitle(schema),
...validateThreshold(schema),
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
To,
type,
Threat,
threshold,
ThrottleOrNull,
note,
Version,
Expand Down Expand Up @@ -106,6 +107,7 @@ export const createRulesSchema = t.intersection([
tags: DefaultStringArray, // defaults to empty string array if not set during decode
to: DefaultToString, // defaults to "now" if not set during decode
threat: DefaultThreatArray, // defaults to empty array if not set during decode
threshold, // defaults to "undefined" if not set during decode
throttle: DefaultThrottleNull, // defaults to "null" if not set during decode
timestamp_override, // defaults to "undefined" if not set during decode
references: DefaultStringArray, // defaults to empty array of strings if not set during decode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,26 @@ describe('create_rules_type_dependents', () => {
const errors = createRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "timeline_title" exists, "timeline_id" must also exist']);
});

test('threshold is required when type is threshold and validates with it', () => {
const schema: CreateRulesSchema = {
...getCreateRulesSchemaMock(),
type: 'threshold',
};
const errors = createRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "type" is "threshold", "threshold" is required']);
});

test('threshold.value is required and has to be bigger than 0 when type is threshold and validates with it', () => {
const schema: CreateRulesSchema = {
...getCreateRulesSchemaMock(),
type: 'threshold',
threshold: {
field: '',
value: -1,
},
};
const errors = createRuleValidateTypeDependents(schema);
expect(errors).toEqual(['"threshold.value" has to be bigger than 0']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ export const validateTimelineTitle = (rule: CreateRulesSchema): string[] => {
return [];
};

export const validateThreshold = (rule: CreateRulesSchema): string[] => {
if (rule.type === 'threshold') {
if (!rule.threshold) {
return ['when "type" is "threshold", "threshold" is required'];
} else if (rule.threshold.value <= 0) {
return ['"threshold.value" has to be bigger than 0'];
} else {
return [];
}
}
return [];
};

export const createRuleValidateTypeDependents = (schema: CreateRulesSchema): string[] => {
return [
...validateAnomalyThreshold(schema),
Expand All @@ -101,5 +114,6 @@ export const createRuleValidateTypeDependents = (schema: CreateRulesSchema): str
...validateMachineLearningJobId(schema),
...validateTimelineId(schema),
...validateTimelineTitle(schema),
...validateThreshold(schema),
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
To,
type,
Threat,
threshold,
ThrottleOrNull,
note,
Version,
Expand Down Expand Up @@ -125,6 +126,7 @@ export const importRulesSchema = t.intersection([
tags: DefaultStringArray, // defaults to empty string array if not set during decode
to: DefaultToString, // defaults to "now" if not set during decode
threat: DefaultThreatArray, // defaults to empty array if not set during decode
threshold, // defaults to "undefined" if not set during decode
throttle: DefaultThrottleNull, // defaults to "null" if not set during decode
timestamp_override, // defaults to "undefined" if not set during decode
references: DefaultStringArray, // defaults to empty array of strings if not set during decode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,26 @@ describe('import_rules_type_dependents', () => {
const errors = importRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "timeline_title" exists, "timeline_id" must also exist']);
});

test('threshold is required when type is threshold and validates with it', () => {
const schema: ImportRulesSchema = {
...getImportRulesSchemaMock(),
type: 'threshold',
};
const errors = importRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "type" is "threshold", "threshold" is required']);
});

test('threshold.value is required and has to be bigger than 0 when type is threshold and validates with it', () => {
const schema: ImportRulesSchema = {
...getImportRulesSchemaMock(),
type: 'threshold',
threshold: {
field: '',
value: -1,
},
};
const errors = importRuleValidateTypeDependents(schema);
expect(errors).toEqual(['"threshold.value" has to be bigger than 0']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ export const validateTimelineTitle = (rule: ImportRulesSchema): string[] => {
return [];
};

export const validateThreshold = (rule: ImportRulesSchema): string[] => {
if (rule.type === 'threshold') {
if (!rule.threshold) {
return ['when "type" is "threshold", "threshold" is required'];
} else if (rule.threshold.value <= 0) {
return ['"threshold.value" has to be bigger than 0'];
} else {
return [];
}
}
return [];
};

export const importRuleValidateTypeDependents = (schema: ImportRulesSchema): string[] => {
return [
...validateAnomalyThreshold(schema),
Expand All @@ -101,5 +114,6 @@ export const importRuleValidateTypeDependents = (schema: ImportRulesSchema): str
...validateMachineLearningJobId(schema),
...validateTimelineId(schema),
...validateTimelineTitle(schema),
...validateThreshold(schema),
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
enabled,
tags,
threat,
threshold,
throttle,
references,
to,
Expand Down Expand Up @@ -89,6 +90,7 @@ export const patchRulesSchema = t.exact(
tags,
to,
threat,
threshold,
throttle,
timestamp_override,
references,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,26 @@ describe('patch_rules_type_dependents', () => {
const errors = patchRuleValidateTypeDependents(schema);
expect(errors).toEqual(['either "id" or "rule_id" must be set']);
});

test('threshold is required when type is threshold and validates with it', () => {
const schema: PatchRulesSchema = {
...getPatchRulesSchemaMock(),
type: 'threshold',
};
const errors = patchRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "type" is "threshold", "threshold" is required']);
});

test('threshold.value is required and has to be bigger than 0 when type is threshold and validates with it', () => {
const schema: PatchRulesSchema = {
...getPatchRulesSchemaMock(),
type: 'threshold',
threshold: {
field: '',
value: -1,
},
};
const errors = patchRuleValidateTypeDependents(schema);
expect(errors).toEqual(['"threshold.value" has to be bigger than 0']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,26 @@ export const validateId = (rule: PatchRulesSchema): string[] => {
}
};

export const validateThreshold = (rule: PatchRulesSchema): string[] => {
if (rule.type === 'threshold') {
if (!rule.threshold) {
return ['when "type" is "threshold", "threshold" is required'];
} else if (rule.threshold.value <= 0) {
return ['"threshold.value" has to be bigger than 0'];
} else {
return [];
}
}
return [];
};

export const patchRuleValidateTypeDependents = (schema: PatchRulesSchema): string[] => {
return [
...validateId(schema),
...validateQuery(schema),
...validateLanguage(schema),
...validateTimelineId(schema),
...validateTimelineTitle(schema),
...validateThreshold(schema),
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
To,
type,
Threat,
threshold,
ThrottleOrNull,
note,
version,
Expand Down Expand Up @@ -114,6 +115,7 @@ export const updateRulesSchema = t.intersection([
tags: DefaultStringArray, // defaults to empty string array if not set during decode
to: DefaultToString, // defaults to "now" if not set during decode
threat: DefaultThreatArray, // defaults to empty array if not set during decode
threshold, // defaults to "undefined" if not set during decode
throttle: DefaultThrottleNull, // defaults to "null" if not set during decode
timestamp_override, // defaults to "undefined" if not set during decode
references: DefaultStringArray, // defaults to empty array of strings if not set during decode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,26 @@ describe('update_rules_type_dependents', () => {
const errors = updateRuleValidateTypeDependents(schema);
expect(errors).toEqual(['either "id" or "rule_id" must be set']);
});

test('threshold is required when type is threshold and validates with it', () => {
const schema: UpdateRulesSchema = {
...getUpdateRulesSchemaMock(),
type: 'threshold',
};
const errors = updateRuleValidateTypeDependents(schema);
expect(errors).toEqual(['when "type" is "threshold", "threshold" is required']);
});

test('threshold.value is required and has to be bigger than 0 when type is threshold and validates with it', () => {
const schema: UpdateRulesSchema = {
...getUpdateRulesSchemaMock(),
type: 'threshold',
threshold: {
field: '',
value: -1,
},
};
const errors = updateRuleValidateTypeDependents(schema);
expect(errors).toEqual(['"threshold.value" has to be bigger than 0']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ export const validateId = (rule: UpdateRulesSchema): string[] => {
}
};

export const validateThreshold = (rule: UpdateRulesSchema): string[] => {
if (rule.type === 'threshold') {
if (!rule.threshold) {
return ['when "type" is "threshold", "threshold" is required'];
} else if (rule.threshold.value <= 0) {
return ['"threshold.value" has to be bigger than 0'];
} else {
return [];
}
}
return [];
};

export const updateRuleValidateTypeDependents = (schema: UpdateRulesSchema): string[] => {
return [
...validateId(schema),
Expand All @@ -112,5 +125,6 @@ export const updateRuleValidateTypeDependents = (schema: UpdateRulesSchema): str
...validateMachineLearningJobId(schema),
...validateTimelineId(schema),
...validateTimelineTitle(schema),
...validateThreshold(schema),
];
};
Loading