Rename alertTypeParams to params (#51255) (#51611)

This commit is contained in:
Mike Côté 2019-11-25 13:30:40 -05:00 committed by GitHub
parent 0e446eaf2d
commit b82a724b9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 275 additions and 275 deletions

View file

@ -202,7 +202,7 @@ Payload:
|tags|A list of keywords to reference and search in the future.|string[]|
|alertTypeId|The id value of the alert type you want to call when the alert is scheduled to execute.|string|
|interval|The interval in seconds, minutes, hours or days the alert should execute. Example: `10s`, `5m`, `1h`, `1d`.|string|
|alertTypeParams|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|params|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|actions|Array of the following:<br> - `group` (string): We support grouping actions in the scenario of escalations or different types of alert instances. If you don't need this, feel free to use `default` as a value.<br>- `id` (string): The id of the action saved object to execute.<br>- `params` (object): The map to the `params` the action type will receive. In order to help apply context to strings, we handle them as mustache templates and pass in a default set of context. (see templating actions).|array|
#### `DELETE /api/alert/{id}`: Delete alert
@ -246,7 +246,7 @@ Payload:
|interval|The interval in seconds, minutes, hours or days the alert should execute. Example: `10s`, `5m`, `1h`, `1d`.|string|
|name|A name to reference and search in the future.|string|
|tags|A list of keywords to reference and search in the future.|string[]|
|alertTypeParams|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|params|The parameters to pass in to the alert type executor `params` value. This will also validate against the alert type params validator if defined.|object|
|actions|Array of the following:<br> - `group` (string): We support grouping actions in the scenario of escalations or different types of alert instances. If you don't need this, feel free to use `default` as a value.<br>- `id` (string): The id of the action saved object to execute.<br>- `params` (object): There map to the `params` the action type will receive. In order to help apply context to strings, we handle them as mustache templates and pass in a default set of context. (see templating actions).|array|
#### `POST /api/alert/{id}/_enable`: Enable an alert

View file

@ -31,7 +31,7 @@
}
}
},
"alertTypeParams": {
"params": {
"enabled": false,
"type": "object"
},

View file

@ -48,7 +48,7 @@ function getMockData(overwrites: Record<string, any> = {}) {
alertTypeId: '123',
interval: '10s',
throttle: null,
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -80,7 +80,7 @@ describe('create()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -130,25 +130,25 @@ describe('create()', () => {
});
const result = await alertsClient.create({ data });
expect(result).toMatchInlineSnapshot(`
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"alertTypeParams": Object {
"bar": true,
},
"id": "1",
"interval": "10s",
"scheduledTaskId": "task-123",
}
`);
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"id": "1",
"interval": "10s",
"params": Object {
"bar": true,
},
"scheduledTaskId": "task-123",
}
`);
expect(savedObjectsClient.create).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.create.mock.calls[0]).toHaveLength(3);
expect(savedObjectsClient.create.mock.calls[0][0]).toEqual('alert');
@ -164,9 +164,6 @@ describe('create()', () => {
},
],
"alertTypeId": "123",
"alertTypeParams": Object {
"bar": true,
},
"apiKey": undefined,
"apiKeyOwner": undefined,
"createdBy": "elastic",
@ -175,6 +172,9 @@ describe('create()', () => {
"muteAll": false,
"mutedInstanceIds": Array [],
"name": "abc",
"params": Object {
"bar": true,
},
"tags": Array [
"foo",
],
@ -240,7 +240,7 @@ describe('create()', () => {
enabled: false,
alertTypeId: '123',
interval: 10000,
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -263,30 +263,30 @@ describe('create()', () => {
});
const result = await alertsClient.create({ data });
expect(result).toMatchInlineSnapshot(`
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"alertTypeParams": Object {
"bar": true,
},
"enabled": false,
"id": "1",
"interval": 10000,
}
`);
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"enabled": false,
"id": "1",
"interval": 10000,
"params": Object {
"bar": true,
},
}
`);
expect(savedObjectsClient.create).toHaveBeenCalledTimes(1);
expect(taskManager.schedule).toHaveBeenCalledTimes(0);
});
test('should validate alertTypeParams', async () => {
test('should validate params', async () => {
const alertsClient = new AlertsClient(alertsClientParams);
const data = getMockData();
alertTypeRegistry.get.mockReturnValueOnce({
@ -302,7 +302,7 @@ describe('create()', () => {
async executor() {},
});
await expect(alertsClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
`"alertTypeParams invalid: [param1]: expected value of type [string] but got [undefined]"`
`"params invalid: [param1]: expected value of type [string] but got [undefined]"`
);
});
@ -337,7 +337,7 @@ describe('create()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -387,7 +387,7 @@ describe('create()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -448,7 +448,7 @@ describe('create()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -511,7 +511,7 @@ describe('create()', () => {
],
alertTypeId: '123',
name: 'abc',
alertTypeParams: { bar: true },
params: { bar: true },
apiKey: Buffer.from('123:abc').toString('base64'),
apiKeyOwner: 'elastic',
createdBy: 'elastic',
@ -923,7 +923,7 @@ describe('get()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -946,24 +946,24 @@ describe('get()', () => {
});
const result = await alertsClient.get({ id: '1' });
expect(result).toMatchInlineSnapshot(`
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"alertTypeParams": Object {
"bar": true,
},
"id": "1",
"interval": "10s",
}
`);
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"id": "1",
"interval": "10s",
"params": Object {
"bar": true,
},
}
`);
expect(savedObjectsClient.get).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
@ -981,7 +981,7 @@ describe('get()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -1016,7 +1016,7 @@ describe('find()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -1041,31 +1041,31 @@ describe('find()', () => {
});
const result = await alertsClient.find();
expect(result).toMatchInlineSnapshot(`
Object {
"data": Array [
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"alertTypeParams": Object {
"bar": true,
},
"id": "1",
"interval": "10s",
},
],
"page": 1,
"perPage": 10,
"total": 1,
}
`);
Object {
"data": Array [
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeId": "123",
"id": "1",
"interval": "10s",
"params": Object {
"bar": true,
},
},
],
"page": 1,
"perPage": 10,
"total": 1,
}
`);
expect(savedObjectsClient.find).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.find.mock.calls[0]).toMatchInlineSnapshot(`
Array [
@ -1086,7 +1086,7 @@ describe('delete()', () => {
attributes: {
alertTypeId: '123',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
scheduledTaskId: 'task-123',
@ -1155,7 +1155,7 @@ describe('update()', () => {
attributes: {
enabled: true,
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -1183,7 +1183,7 @@ describe('update()', () => {
interval: '10s',
name: 'abc',
tags: ['foo'],
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -1198,25 +1198,25 @@ describe('update()', () => {
},
});
expect(result).toMatchInlineSnapshot(`
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeParams": Object {
"bar": true,
},
"enabled": true,
"id": "1",
"interval": "10s",
"scheduledTaskId": "task-123",
}
`);
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"enabled": true,
"id": "1",
"interval": "10s",
"params": Object {
"bar": true,
},
"scheduledTaskId": "task-123",
}
`);
expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update.mock.calls[0]).toHaveLength(4);
expect(savedObjectsClient.update.mock.calls[0][0]).toEqual('alert');
@ -1233,14 +1233,14 @@ describe('update()', () => {
},
],
"alertTypeId": "123",
"alertTypeParams": Object {
"bar": true,
},
"apiKey": null,
"apiKeyOwner": null,
"enabled": true,
"interval": "10s",
"name": "abc",
"params": Object {
"bar": true,
},
"scheduledTaskId": "task-123",
"tags": Array [
"foo",
@ -1291,7 +1291,7 @@ describe('update()', () => {
attributes: {
enabled: true,
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -1320,7 +1320,7 @@ describe('update()', () => {
interval: '10s',
name: 'abc',
tags: ['foo'],
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -1335,26 +1335,26 @@ describe('update()', () => {
},
});
expect(result).toMatchInlineSnapshot(`
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"alertTypeParams": Object {
"bar": true,
},
"apiKey": "MTIzOmFiYw==",
"enabled": true,
"id": "1",
"interval": "10s",
"scheduledTaskId": "task-123",
}
`);
Object {
"actions": Array [
Object {
"group": "default",
"id": "1",
"params": Object {
"foo": true,
},
},
],
"apiKey": "MTIzOmFiYw==",
"enabled": true,
"id": "1",
"interval": "10s",
"params": Object {
"bar": true,
},
"scheduledTaskId": "task-123",
}
`);
expect(savedObjectsClient.update).toHaveBeenCalledTimes(1);
expect(savedObjectsClient.update.mock.calls[0]).toHaveLength(4);
expect(savedObjectsClient.update.mock.calls[0][0]).toEqual('alert');
@ -1371,14 +1371,14 @@ describe('update()', () => {
},
],
"alertTypeId": "123",
"alertTypeParams": Object {
"bar": true,
},
"apiKey": "MTIzOmFiYw==",
"apiKeyOwner": "elastic",
"enabled": true,
"interval": "10s",
"name": "abc",
"params": Object {
"bar": true,
},
"scheduledTaskId": "task-123",
"tags": Array [
"foo",
@ -1400,7 +1400,7 @@ describe('update()', () => {
`);
});
it('should validate alertTypeParams', async () => {
it('should validate params', async () => {
const alertsClient = new AlertsClient(alertsClientParams);
alertTypeRegistry.get.mockReturnValueOnce({
id: '123',
@ -1428,7 +1428,7 @@ describe('update()', () => {
interval: '10s',
name: 'abc',
tags: ['foo'],
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -1443,7 +1443,7 @@ describe('update()', () => {
},
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"alertTypeParams invalid: [param1]: expected value of type [string] but got [undefined]"`
`"params invalid: [param1]: expected value of type [string] but got [undefined]"`
);
});
});

View file

@ -77,7 +77,7 @@ interface UpdateOptions {
tags: string[];
interval: string;
actions: AlertAction[];
alertTypeParams: Record<string, any>;
params: Record<string, any>;
};
}
@ -111,7 +111,7 @@ export class AlertsClient {
public async create({ data, options }: CreateOptions) {
// Throws an error if alert type isn't registered
const alertType = this.alertTypeRegistry.get(data.alertTypeId);
const validatedAlertTypeParams = validateAlertTypeParams(alertType, data.alertTypeParams);
const validatedAlertTypeParams = validateAlertTypeParams(alertType, data.params);
const apiKey = await this.createAPIKey();
const username = await this.getUserName();
@ -125,7 +125,7 @@ export class AlertsClient {
apiKey: apiKey.created
? Buffer.from(`${apiKey.result.id}:${apiKey.result.api_key}`).toString('base64')
: undefined,
alertTypeParams: validatedAlertTypeParams,
params: validatedAlertTypeParams,
muteAll: false,
mutedInstanceIds: [],
});
@ -199,7 +199,7 @@ export class AlertsClient {
const apiKey = await this.createAPIKey();
// Validate
const validatedAlertTypeParams = validateAlertTypeParams(alertType, data.alertTypeParams);
const validatedAlertTypeParams = validateAlertTypeParams(alertType, data.params);
this.validateActions(alertType, data.actions);
const { actions, references } = this.extractReferences(data.actions);
@ -210,7 +210,7 @@ export class AlertsClient {
{
...attributes,
...data,
alertTypeParams: validatedAlertTypeParams,
params: validatedAlertTypeParams,
actions,
updatedBy: username,
apiKeyOwner: apiKey.created ? username : null,

View file

@ -76,7 +76,7 @@ const mockedAlertTypeSavedObject = {
alertTypeId: '123',
interval: '10s',
mutedInstanceIds: [],
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -253,7 +253,7 @@ test('validates params before executing the alert type', async () => {
references: [],
});
await expect(taskRunner.run()).rejects.toThrowErrorMatchingInlineSnapshot(
`"alertTypeParams invalid: [param1]: expected value of type [string] but got [undefined]"`
`"params invalid: [param1]: expected value of type [string] but got [undefined]"`
);
});

View file

@ -94,12 +94,12 @@ export class TaskRunnerFactory {
const services = getServices(fakeRequest);
// Ensure API key is still valid and user has access
const {
attributes: { alertTypeParams, actions, interval, throttle, muteAll, mutedInstanceIds },
attributes: { params, actions, interval, throttle, muteAll, mutedInstanceIds },
references,
} = await services.savedObjectsClient.get<RawAlert>('alert', alertId);
// Validate
const validatedAlertTypeParams = validateAlertTypeParams(alertType, alertTypeParams);
const validatedAlertTypeParams = validateAlertTypeParams(alertType, params);
// Inject ids into actions
const actionsWithIds = actions.map(action => {

View file

@ -61,6 +61,6 @@ test('should validate and throw error when params is invalid', () => {
{}
)
).toThrowErrorMatchingInlineSnapshot(
`"alertTypeParams invalid: [param1]: expected value of type [string] but got [undefined]"`
`"params invalid: [param1]: expected value of type [string] but got [undefined]"`
);
});

View file

@ -19,6 +19,6 @@ export function validateAlertTypeParams<T extends Record<string, any>>(
try {
return validator.validate(params);
} catch (err) {
throw Boom.badRequest(`alertTypeParams invalid: ${err.message}`);
throw Boom.badRequest(`params invalid: ${err.message}`);
}
}

View file

@ -15,7 +15,7 @@ const mockedAlert = {
name: 'abc',
interval: '10s',
tags: ['foo'],
alertTypeParams: {
params: {
bar: true,
},
actions: [
@ -57,12 +57,12 @@ test('creates an alert with proper parameters', async () => {
},
],
"alertTypeId": "1",
"alertTypeParams": Object {
"bar": true,
},
"id": "123",
"interval": "10s",
"name": "abc",
"params": Object {
"bar": true,
},
"tags": Array [
"foo",
],
@ -83,12 +83,12 @@ test('creates an alert with proper parameters', async () => {
},
],
"alertTypeId": "1",
"alertTypeParams": Object {
"bar": true,
},
"enabled": true,
"interval": "10s",
"name": "abc",
"params": Object {
"bar": true,
},
"tags": Array [
"foo",
],
@ -112,12 +112,12 @@ test('creates an alert with proper parameters', async () => {
},
],
"alertTypeId": "1",
"alertTypeParams": Object {
"bar": true,
},
"enabled": true,
"interval": "10s",
"name": "abc",
"params": Object {
"bar": true,
},
"tags": Array [
"foo",
],

View file

@ -17,7 +17,7 @@ interface ScheduleRequest extends Hapi.Request {
alertTypeId: string;
interval: string;
actions: AlertAction[];
alertTypeParams: Record<string, any>;
params: Record<string, any>;
throttle: string | null;
};
}
@ -41,7 +41,7 @@ export const createAlertRoute = {
alertTypeId: Joi.string().required(),
throttle: getDurationSchema().default(null),
interval: getDurationSchema().required(),
alertTypeParams: Joi.object().required(),
params: Joi.object().required(),
actions: Joi.array()
.items(
Joi.object().keys({

View file

@ -14,7 +14,7 @@ const mockedAlert = {
id: '1',
alertTypeId: '1',
interval: '10s',
alertTypeParams: {
params: {
bar: true,
},
actions: [

View file

@ -17,7 +17,7 @@ const mockedResponse = {
alertTypeId: '1',
tags: ['foo'],
interval: '12s',
alertTypeParams: {
params: {
otherField: false,
},
actions: [
@ -40,7 +40,7 @@ test('calls the update function with proper parameters', async () => {
name: 'abc',
tags: ['bar'],
interval: '12s',
alertTypeParams: {
params: {
otherField: false,
},
actions: [
@ -74,11 +74,11 @@ test('calls the update function with proper parameters', async () => {
},
},
],
"alertTypeParams": Object {
"otherField": false,
},
"interval": "12s",
"name": "abc",
"params": Object {
"otherField": false,
},
"tags": Array [
"bar",
],

View file

@ -19,7 +19,7 @@ interface UpdateRequest extends Hapi.Request {
tags: string[];
interval: string;
actions: AlertAction[];
alertTypeParams: Record<string, any>;
params: Record<string, any>;
throttle: string | null;
};
}
@ -43,7 +43,7 @@ export const updateAlertRoute = {
.items(Joi.string())
.required(),
interval: getDurationSchema().required(),
alertTypeParams: Joi.object().required(),
params: Joi.object().required(),
actions: Joi.array()
.items(
Joi.object().keys({

View file

@ -65,7 +65,7 @@ export interface Alert {
alertTypeId: string;
interval: string;
actions: AlertAction[];
alertTypeParams: Record<string, any>;
params: Record<string, any>;
scheduledTaskId?: string;
createdBy: string | null;
updatedBy: string | null;
@ -83,7 +83,7 @@ export interface RawAlert extends SavedObjectAttributes {
alertTypeId: string;
interval: string;
actions: RawAlertAction[];
alertTypeParams: SavedObjectAttributes;
params: SavedObjectAttributes;
scheduledTaskId?: string;
createdBy: string | null;
updatedBy: string | null;

View file

@ -40,7 +40,7 @@ export const createSignals = async ({
name,
tags: [],
alertTypeId: SIGNALS_ID,
alertTypeParams: {
params: {
description,
ruleId,
index,

View file

@ -129,11 +129,11 @@ describe('read_signals', () => {
test('should return a single value of rule-1 with multiple values', async () => {
const result1 = getResult();
result1.id = '4baa53f8-96da-44ee-ad58-41bccb7f9f3d';
result1.alertTypeParams.ruleId = 'rule-1';
result1.params.ruleId = 'rule-1';
const result2 = getResult();
result2.id = '5baa53f8-96da-44ee-ad58-41bccb7f9f3d';
result2.alertTypeParams.ruleId = 'rule-2';
result2.params.ruleId = 'rule-2';
const alertsClient = alertsClientMock.create();
alertsClient.get.mockResolvedValue(getResult());
@ -150,11 +150,11 @@ describe('read_signals', () => {
test('should return a single value of rule-2 with multiple values', async () => {
const result1 = getResult();
result1.id = '4baa53f8-96da-44ee-ad58-41bccb7f9f3d';
result1.alertTypeParams.ruleId = 'rule-1';
result1.params.ruleId = 'rule-1';
const result2 = getResult();
result2.id = '5baa53f8-96da-44ee-ad58-41bccb7f9f3d';
result2.alertTypeParams.ruleId = 'rule-2';
result2.params.ruleId = 'rule-2';
const alertsClient = alertsClientMock.create();
alertsClient.get.mockResolvedValue(getResult());
@ -171,11 +171,11 @@ describe('read_signals', () => {
test('should return null for a made up value with multiple values', async () => {
const result1 = getResult();
result1.id = '4baa53f8-96da-44ee-ad58-41bccb7f9f3d';
result1.alertTypeParams.ruleId = 'rule-1';
result1.params.ruleId = 'rule-1';
const result2 = getResult();
result2.id = '5baa53f8-96da-44ee-ad58-41bccb7f9f3d';
result2.alertTypeParams.ruleId = 'rule-2';
result2.params.ruleId = 'rule-2';
const alertsClient = alertsClientMock.create();
alertsClient.get.mockResolvedValue(getResult());
@ -194,8 +194,8 @@ describe('read_signals', () => {
test('returns null if the objects are not of a signal rule type', () => {
const signal = findSignalInArrayByRuleId(
[
{ alertTypeId: 'made up 1', alertTypeParams: { ruleId: '123' } },
{ alertTypeId: 'made up 2', alertTypeParams: { ruleId: '456' } },
{ alertTypeId: 'made up 1', params: { ruleId: '123' } },
{ alertTypeId: 'made up 2', params: { ruleId: '456' } },
],
'123'
);
@ -205,30 +205,30 @@ describe('read_signals', () => {
test('returns correct type if the objects are of a signal rule type', () => {
const signal = findSignalInArrayByRuleId(
[
{ alertTypeId: SIGNALS_ID, alertTypeParams: { ruleId: '123' } },
{ alertTypeId: 'made up 2', alertTypeParams: { ruleId: '456' } },
{ alertTypeId: SIGNALS_ID, params: { ruleId: '123' } },
{ alertTypeId: 'made up 2', params: { ruleId: '456' } },
],
'123'
);
expect(signal).toEqual({ alertTypeId: 'siem.signals', alertTypeParams: { ruleId: '123' } });
expect(signal).toEqual({ alertTypeId: 'siem.signals', params: { ruleId: '123' } });
});
test('returns second correct type if the objects are of a signal rule type', () => {
const signal = findSignalInArrayByRuleId(
[
{ alertTypeId: SIGNALS_ID, alertTypeParams: { ruleId: '123' } },
{ alertTypeId: SIGNALS_ID, alertTypeParams: { ruleId: '456' } },
{ alertTypeId: SIGNALS_ID, params: { ruleId: '123' } },
{ alertTypeId: SIGNALS_ID, params: { ruleId: '456' } },
],
'456'
);
expect(signal).toEqual({ alertTypeId: 'siem.signals', alertTypeParams: { ruleId: '456' } });
expect(signal).toEqual({ alertTypeId: 'siem.signals', params: { ruleId: '456' } });
});
test('returns null with correct types but data does not exist', () => {
const signal = findSignalInArrayByRuleId(
[
{ alertTypeId: SIGNALS_ID, alertTypeParams: { ruleId: '123' } },
{ alertTypeId: SIGNALS_ID, alertTypeParams: { ruleId: '456' } },
{ alertTypeId: SIGNALS_ID, params: { ruleId: '123' } },
{ alertTypeId: SIGNALS_ID, params: { ruleId: '456' } },
],
'892'
);

View file

@ -14,7 +14,7 @@ export const findSignalInArrayByRuleId = (
if (isAlertTypeArray(objects)) {
const signals: SignalAlertType[] = objects;
const signal: SignalAlertType[] = signals.filter(datum => {
return datum.alertTypeParams.ruleId === ruleId;
return datum.params.ruleId === ruleId;
});
if (signal.length !== 0) {
return signal[0];

View file

@ -137,7 +137,7 @@ export type AlertTypeParams = Omit<SignalAlertParams, 'name' | 'enabled' | 'inte
export type SignalAlertType = Alert & {
id: string;
alertTypeParams: AlertTypeParams;
params: AlertTypeParams;
};
export interface SignalsRequest extends RequestFacade {

View file

@ -78,11 +78,11 @@ export const updateSignal = async ({
// where it is trying to return AlertAction[] or RawAlertAction[]
const actions = (signal.actions as AlertAction[] | undefined) || [];
const alertTypeParams = signal.alertTypeParams || {};
const params = signal.params || {};
const nextAlertTypeParams = defaults(
const nextParams = defaults(
{
...alertTypeParams,
...params,
},
{
description,
@ -120,7 +120,7 @@ export const updateSignal = async ({
name: calculateName({ updatedName: name, originalName: signal.name }),
interval: calculateInterval(interval, signal.interval),
actions,
alertTypeParams: nextAlertTypeParams,
params: nextParams,
},
});
};

View file

@ -118,7 +118,7 @@ export const getResult = (): SignalAlertType => ({
name: 'Detect Root/Admin Users',
tags: [],
alertTypeId: 'siem.signals',
alertTypeParams: {
params: {
description: 'Detecting root and admin users',
ruleId: 'rule-1',
index: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],

View file

@ -75,7 +75,7 @@ describe('utils', () => {
test('should omit query if query is null', () => {
const fullSignal = getResult();
fullSignal.alertTypeParams.query = null;
fullSignal.params.query = null;
const signal = transformAlertToSignal(fullSignal);
expect(signal).toEqual({
created_by: 'elastic',
@ -105,7 +105,7 @@ describe('utils', () => {
test('should omit query if query is undefined', () => {
const fullSignal = getResult();
fullSignal.alertTypeParams.query = undefined;
fullSignal.params.query = undefined;
const signal = transformAlertToSignal(fullSignal);
expect(signal).toEqual({
created_by: 'elastic',
@ -135,8 +135,8 @@ describe('utils', () => {
test('should omit a mix of undefined, null, and missing fields', () => {
const fullSignal = getResult();
fullSignal.alertTypeParams.query = undefined;
fullSignal.alertTypeParams.language = null;
fullSignal.params.query = undefined;
fullSignal.params.language = null;
const { from, enabled, ...omitData } = transformAlertToSignal(fullSignal);
expect(omitData).toEqual({
created_by: 'elastic',
@ -194,7 +194,7 @@ describe('utils', () => {
test('should return immutable is equal to false', () => {
const fullSignal = getResult();
fullSignal.alertTypeParams.immutable = false;
fullSignal.params.immutable = false;
const signalWithEnabledFalse = transformAlertToSignal(fullSignal);
expect(signalWithEnabledFalse).toEqual({
created_by: 'elastic',

View file

@ -29,32 +29,32 @@ export const getIdError = ({
export const transformAlertToSignal = (signal: SignalAlertType): Partial<OutputSignalAlertRest> => {
return pickBy<OutputSignalAlertRest>((value: unknown) => value != null, {
created_by: signal.createdBy,
description: signal.alertTypeParams.description,
description: signal.params.description,
enabled: signal.enabled,
false_positives: signal.alertTypeParams.falsePositives,
filter: signal.alertTypeParams.filter,
filters: signal.alertTypeParams.filters,
from: signal.alertTypeParams.from,
false_positives: signal.params.falsePositives,
filter: signal.params.filter,
filters: signal.params.filters,
from: signal.params.from,
id: signal.id,
immutable: signal.alertTypeParams.immutable,
index: signal.alertTypeParams.index,
immutable: signal.params.immutable,
index: signal.params.index,
interval: signal.interval,
rule_id: signal.alertTypeParams.ruleId,
language: signal.alertTypeParams.language,
output_index: signal.alertTypeParams.outputIndex,
max_signals: signal.alertTypeParams.maxSignals,
risk_score: signal.alertTypeParams.riskScore,
rule_id: signal.params.ruleId,
language: signal.params.language,
output_index: signal.params.outputIndex,
max_signals: signal.params.maxSignals,
risk_score: signal.params.riskScore,
name: signal.name,
query: signal.alertTypeParams.query,
references: signal.alertTypeParams.references,
saved_id: signal.alertTypeParams.savedId,
meta: signal.alertTypeParams.meta,
severity: signal.alertTypeParams.severity,
size: signal.alertTypeParams.size,
query: signal.params.query,
references: signal.params.references,
saved_id: signal.params.savedId,
meta: signal.params.meta,
severity: signal.params.severity,
size: signal.params.size,
updated_by: signal.updatedBy,
tags: signal.alertTypeParams.tags,
to: signal.alertTypeParams.to,
type: signal.alertTypeParams.type,
tags: signal.params.tags,
to: signal.params.to,
type: signal.params.type,
});
};

View file

@ -183,7 +183,7 @@ export class AlertUtils {
throttle: '1m',
tags: [],
alertTypeId: 'test.always-firing',
alertTypeParams: {
params: {
index: ES_TEST_INDEX_NAME,
reference,
},

View file

@ -13,7 +13,7 @@ export function getTestAlertData(overwrites = {}) {
interval: '1m',
throttle: '1m',
actions: [],
alertTypeParams: {},
params: {},
...overwrites,
};
}

View file

@ -166,7 +166,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
.send(
getTestAlertData({
alertTypeId: 'test.always-firing',
alertTypeParams: {
params: {
index: ES_TEST_INDEX_NAME,
reference: 'create-test-2',
},
@ -258,7 +258,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
.send(
getTestAlertData({
alertTypeId: 'test.authorization',
alertTypeParams: {
params: {
callClusterAuthorizationIndex: authorizationIndex,
savedObjectsClientType: 'dashboard',
savedObjectsClientId: '1',
@ -356,7 +356,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
.send(
getTestAlertData({
alertTypeId: 'test.always-firing',
alertTypeParams: {
params: {
index: ES_TEST_INDEX_NAME,
reference,
},
@ -491,7 +491,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
reference,
overwrites: {
interval: '1s',
alertTypeParams: {
params: {
index: ES_TEST_INDEX_NAME,
reference,
groupsToScheduleActionsInSeries: ['default', 'other'],
@ -560,7 +560,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
reference,
overwrites: {
interval: '1s',
alertTypeParams: {
params: {
index: ES_TEST_INDEX_NAME,
reference,
groupsToScheduleActionsInSeries: ['default', null, 'default'],

View file

@ -59,7 +59,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
actions: [],
enabled: true,
alertTypeId: 'test.noop',
alertTypeParams: {},
params: {},
createdBy: user.username,
interval: '1m',
scheduledTaskId: response.body.scheduledTaskId,
@ -173,10 +173,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 "alertTypeParams" fails because ["alertTypeParams" is required]. child "actions" fails because ["actions" is required]',
'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]',
validation: {
source: 'payload',
keys: ['name', 'alertTypeId', 'interval', 'alertTypeParams', 'actions'],
keys: ['name', 'alertTypeId', 'interval', 'params', 'actions'],
},
});
break;
@ -185,7 +185,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
}
});
it(`should handle create alert request appropriately when alertTypeParams isn't valid`, async () => {
it(`should handle create alert request appropriately when params isn't valid`, async () => {
const response = await supertestWithoutAuth
.post(`${getUrlPrefix(space.id)}/api/alert`)
.set('kbn-xsrf', 'foo')
@ -214,7 +214,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
statusCode: 400,
error: 'Bad Request',
message:
'alertTypeParams invalid: [param1]: expected value of type [string] but got [undefined]',
'params invalid: [param1]: expected value of type [string] but got [undefined]',
});
break;
default:

View file

@ -62,7 +62,7 @@ export default function createFindTests({ getService }: FtrProviderContext) {
interval: '1m',
enabled: true,
actions: [],
alertTypeParams: {},
params: {},
createdBy: 'elastic',
scheduledTaskId: match.scheduledTaskId,
throttle: '1m',
@ -119,7 +119,7 @@ export default function createFindTests({ getService }: FtrProviderContext) {
interval: '1m',
enabled: true,
actions: [],
alertTypeParams: {},
params: {},
createdBy: 'elastic',
scheduledTaskId: match.scheduledTaskId,
throttle: '1m',

View file

@ -56,7 +56,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
interval: '1m',
enabled: true,
actions: [],
alertTypeParams: {},
params: {},
createdBy: 'elastic',
scheduledTaskId: response.body.scheduledTaskId,
throttle: '1m',

View file

@ -33,7 +33,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
const updatedData = {
name: 'bcd',
tags: ['bar'],
alertTypeParams: {
params: {
foo: true,
},
interval: '12s',
@ -93,7 +93,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
.send({
name: 'bcd',
tags: ['bar'],
alertTypeParams: {
params: {
foo: true,
},
interval: '12s',
@ -142,7 +142,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
tags: ['bar'],
throttle: '1m',
alertTypeId: '1',
alertTypeParams: {
params: {
foo: true,
},
interval: '12s',
@ -203,10 +203,10 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
statusCode: 400,
error: 'Bad Request',
message:
'child "throttle" fails because ["throttle" is required]. child "name" fails because ["name" is required]. child "tags" fails because ["tags" is required]. child "interval" fails because ["interval" is required]. child "alertTypeParams" fails because ["alertTypeParams" is required]. child "actions" fails because ["actions" is required]',
'child "throttle" fails because ["throttle" is required]. child "name" fails because ["name" is required]. child "tags" fails because ["tags" 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: ['throttle', 'name', 'tags', 'interval', 'alertTypeParams', 'actions'],
keys: ['throttle', 'name', 'tags', 'interval', 'params', 'actions'],
},
});
break;
@ -222,7 +222,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
.send(
getTestAlertData({
alertTypeId: 'test.validation',
alertTypeParams: {
params: {
param1: 'test',
},
})
@ -239,7 +239,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
tags: ['bar'],
interval: '1m',
throttle: '1m',
alertTypeParams: {},
params: {},
actions: [],
});
@ -261,7 +261,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
statusCode: 400,
error: 'Bad Request',
message:
'alertTypeParams invalid: [param1]: expected value of type [string] but got [undefined]',
'params invalid: [param1]: expected value of type [string] but got [undefined]',
});
break;
default:

View file

@ -125,7 +125,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
getTestAlertData({
interval: '1m',
alertTypeId: 'test.always-firing',
alertTypeParams: {
params: {
index: ES_TEST_INDEX_NAME,
reference: 'create-test-2',
},
@ -193,7 +193,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
.send(
getTestAlertData({
alertTypeId: 'test.authorization',
alertTypeParams: {
params: {
callClusterAuthorizationIndex: authorizationIndex,
savedObjectsClientType: 'dashboard',
savedObjectsClientId: '1',
@ -238,7 +238,7 @@ export default function alertTests({ getService }: FtrProviderContext) {
.send(
getTestAlertData({
alertTypeId: 'test.always-firing',
alertTypeParams: {
params: {
index: ES_TEST_INDEX_NAME,
reference,
},

View file

@ -41,7 +41,7 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
actions: [],
enabled: true,
alertTypeId: 'test.noop',
alertTypeParams: {},
params: {},
createdBy: null,
interval: '1m',
scheduledTaskId: response.body.scheduledTaskId,

View file

@ -45,7 +45,7 @@ export default function createFindTests({ getService }: FtrProviderContext) {
interval: '1m',
enabled: true,
actions: [],
alertTypeParams: {},
params: {},
createdBy: null,
scheduledTaskId: match.scheduledTaskId,
updatedBy: null,

View file

@ -39,7 +39,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
interval: '1m',
enabled: true,
actions: [],
alertTypeParams: {},
params: {},
createdBy: null,
scheduledTaskId: response.body.scheduledTaskId,
updatedBy: null,

View file

@ -28,7 +28,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
const updatedData = {
name: 'bcd',
tags: ['bar'],
alertTypeParams: {
params: {
foo: true,
},
interval: '12s',
@ -68,7 +68,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
.send({
name: 'bcd',
tags: ['foo'],
alertTypeParams: {
params: {
foo: true,
},
interval: '12s',

View file

@ -99,7 +99,7 @@
"alertTypeId": {
"type": "keyword"
},
"alertTypeParams": {
"params": {
"enabled": false,
"type": "object"
},
@ -1068,4 +1068,4 @@
}
}
}
}
}

View file

@ -100,7 +100,7 @@
"alertTypeId": {
"type": "keyword"
},
"alertTypeParams": {
"params": {
"enabled": false,
"type": "object"
},
@ -1291,4 +1291,4 @@
}
}
}
}
}

View file

@ -100,7 +100,7 @@
"alertTypeId": {
"type": "keyword"
},
"alertTypeParams": {
"params": {
"enabled": false,
"type": "object"
},
@ -1300,4 +1300,4 @@
}
}
}
}
}

View file

@ -133,7 +133,7 @@
"alertTypeId": {
"type": "keyword"
},
"alertTypeParams": {
"params": {
"enabled": false,
"type": "object"
},

View file

@ -84,7 +84,7 @@
"alertTypeId": {
"type": "keyword"
},
"alertTypeParams": {
"params": {
"enabled": false,
"type": "object"
},
@ -1091,4 +1091,4 @@
}
}
}
}
}