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

Prepare alerts and actions for feature controls #52956

Merged
merged 7 commits into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/alerting/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"alertTypeId": {
"type": "keyword"
},
"consumer": {
"type": "keyword"
},
"interval": {
"type": "keyword"
},
Expand Down
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/alerting/server/alerts_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function getMockData(overwrites: Record<string, any> = {}) {
name: 'abc',
tags: ['foo'],
alertTypeId: '123',
consumer: 'bar',
interval: '10s',
throttle: null,
params: {
Expand Down Expand Up @@ -182,6 +183,7 @@ describe('create()', () => {
"alertTypeId": "123",
"apiKey": undefined,
"apiKeyOwner": undefined,
"consumer": "bar",
"createdBy": "elastic",
"enabled": true,
"interval": "10s",
Expand Down Expand Up @@ -787,6 +789,7 @@ describe('create()', () => {
},
],
alertTypeId: '123',
consumer: 'bar',
name: 'abc',
params: { bar: true },
apiKey: Buffer.from('123:abc').toString('base64'),
Expand Down
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/alerting/server/routes/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ server.route(createAlertRoute);

const mockedAlert = {
alertTypeId: '1',
consumer: 'bar',
name: 'abc',
interval: '10s',
tags: ['foo'],
Expand Down Expand Up @@ -64,6 +65,7 @@ test('creates an alert with proper parameters', async () => {
},
],
"alertTypeId": "1",
"consumer": "bar",
"id": "123",
"interval": "10s",
"name": "abc",
Expand All @@ -90,6 +92,7 @@ test('creates an alert with proper parameters', async () => {
},
],
"alertTypeId": "1",
"consumer": "bar",
"enabled": true,
"interval": "10s",
"name": "abc",
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/alerting/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface ScheduleRequest extends Hapi.Request {
name: string;
tags: string[];
alertTypeId: string;
consumer: string;
interval: string;
actions: Array<{
group: string;
Expand Down Expand Up @@ -42,6 +43,7 @@ export const createAlertRoute = {
.items(Joi.string())
.default([]),
alertTypeId: Joi.string().required(),
consumer: Joi.string().required(),
throttle: getDurationSchema().default(null),
interval: getDurationSchema().required(),
params: Joi.object().required(),
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/alerting/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface Alert {
name: string;
tags: string[];
alertTypeId: string;
consumer: string;
interval: string;
actions: AlertAction[];
params: Record<string, any>;
Expand All @@ -83,6 +84,7 @@ export interface RawAlert extends SavedObjectAttributes {
name: string;
tags: string[];
alertTypeId: string;
consumer: string;
interval: string;
actions: RawAlertAction[];
params: SavedObjectAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const getResult = (): RuleAlertType => ({
name: 'Detect Root/Admin Users',
tags: [`${INTERNAL_RULE_ID_KEY}:rule-1`],
alertTypeId: 'siem.signals',
consumer: 'siem',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! 👍

params: {
description: 'Detecting root and admin users',
ruleId: 'rule-1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SIGNALS_ID } from '../../../../common/constants';
import { APP_ID, SIGNALS_ID } from '../../../../common/constants';
import { RuleParams } from './types';
import { addRuleIdToTags } from './add_rule_id_to_tags';

Expand Down Expand Up @@ -40,6 +40,7 @@ export const createRules = async ({
name,
tags: addRuleIdToTags(tags, ruleId),
alertTypeId: SIGNALS_ID,
consumer: APP_ID,
params: {
description,
ruleId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class AlertUtils {
throttle: '1m',
tags: [],
alertTypeId: 'test.always-firing',
consumer: 'bar',
params: {
index: ES_TEST_INDEX_NAME,
reference,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function getTestAlertData(overwrites = {}) {
name: 'abc',
tags: ['foo'],
alertTypeId: 'test.noop',
consumer: 'bar',
interval: '1m',
throttle: '1m',
actions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
break;
case 'space_1_all at space1':
case 'superuser at space1':
expect(response.statusCode).to.eql(200);
// Wait until alerts scheduled actions 3 times before disabling the alert and waiting for tasks to finish
await esTestIndexTool.waitForDocs('alert:test.always-firing', reference, 3);
await alertUtils.disable(response.body.id);
Expand Down Expand Up @@ -582,6 +583,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
break;
case 'space_1_all at space1':
case 'superuser at space1':
expect(response.statusCode).to.eql(200);
// Actions should execute twice before widning things down
await esTestIndexTool.waitForDocs('action:test.index-record', reference, 2);
await alertUtils.disable(response.body.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
],
enabled: true,
alertTypeId: 'test.noop',
consumer: 'bar',
params: {},
createdBy: user.username,
interval: '1m',
Expand Down Expand Up @@ -201,10 +202,10 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
statusCode: 400,
error: 'Bad Request',
message:
'child "name" fails because ["name" is required]. child "alertTypeId" fails because ["alertTypeId" is required]. child "interval" fails because ["interval" is required]. child "params" fails because ["params" is required]. child "actions" fails because ["actions" is required]',
'child "name" fails because ["name" is required]. child "alertTypeId" fails because ["alertTypeId" is required]. child "consumer" fails because ["consumer" is required]. child "interval" fails because ["interval" is required]. child "params" fails because ["params" is required]. child "actions" fails because ["actions" is required]',
validation: {
source: 'payload',
keys: ['name', 'alertTypeId', 'interval', 'params', 'actions'],
keys: ['name', 'alertTypeId', 'consumer', 'interval', 'params', 'actions'],
},
});
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function createFindTests({ getService }: FtrProviderContext) {
name: 'abc',
tags: ['foo'],
alertTypeId: 'test.noop',
consumer: 'bar',
interval: '1m',
enabled: true,
actions: [],
Expand Down Expand Up @@ -138,6 +139,7 @@ export default function createFindTests({ getService }: FtrProviderContext) {
name: 'abc',
tags: ['foo'],
alertTypeId: 'test.noop',
consumer: 'bar',
interval: '1m',
enabled: false,
actions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
name: 'abc',
tags: ['foo'],
alertTypeId: 'test.noop',
consumer: 'bar',
interval: '1m',
enabled: true,
actions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
...updatedData,
id: createdAlert.id,
alertTypeId: 'test.noop',
consumer: 'bar',
createdBy: 'elastic',
enabled: true,
updatedBy: user.username,
Expand Down Expand Up @@ -274,7 +275,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
.put(`${getUrlPrefix(space.id)}/api/alert/1`)
.set('kbn-xsrf', 'foo')
.auth(user.username, user.password)
.send(getTestAlertData({ interval: '10x', enabled: undefined }));
.send(getTestAlertData({ interval: '10x', enabled: undefined, consumer: undefined }));

switch (scenario.id) {
case 'no_kibana_privileges at space1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
],
enabled: true,
alertTypeId: 'test.noop',
consumer: 'bar',
params: {},
createdBy: null,
interval: '1m',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function createFindTests({ getService }: FtrProviderContext) {
name: 'abc',
tags: ['foo'],
alertTypeId: 'test.noop',
consumer: 'bar',
interval: '1m',
enabled: true,
actions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
name: 'abc',
tags: ['foo'],
alertTypeId: 'test.noop',
consumer: 'bar',
interval: '1m',
enabled: true,
actions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
id: createdAlert.id,
tags: ['bar'],
alertTypeId: 'test.noop',
consumer: 'bar',
createdBy: null,
enabled: true,
updatedBy: null,
Expand Down