Skip to content

Commit

Permalink
Adding actionTypeId
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Jun 2, 2021
1 parent 31c439f commit f99ecd0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class ActionExecutor {
event: { action: EVENT_LOG_ACTIONS.execute },
kibana: {
alerting: {
action_type_id: actionTypeId,
primary_saved_object: {
id: actionId,
type: 'action',
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/event_log/generated/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@
"type": "keyword",
"ignore_above": 1024
},
"action_type_id": {
"type": "keyword",
"ignore_above": 1024
},
"instance_id": {
"type": "keyword",
"ignore_above": 1024
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/event_log/generated/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const EventSchema = schema.maybe(
schema.object({
action_group_id: ecsString(),
action_subgroup: ecsString(),
action_type_id: ecsString(),
instance_id: ecsString(),
primary_saved_object: schema.maybe(
schema.object({
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/event_log/scripts/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ exports.EcsCustomPropertyMappings = {
type: 'keyword',
ignore_above: 1024,
},
action_type_id: {
type: 'keyword',
ignore_above: 1024,
},
instance_id: {
type: 'keyword',
ignore_above: 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function ({ getService }: FtrProviderContext) {
spaceId: space.id,
connectorId: createdAction.id,
outcome: 'success',
actionTypeId: 'test.index-record',
message: `action executed: test.index-record:${createdAction.id}: My action`,
});
break;
Expand Down Expand Up @@ -502,13 +503,14 @@ export default function ({ getService }: FtrProviderContext) {
interface ValidateEventLogParams {
spaceId: string;
connectorId: string;
actionTypeId: string;
outcome: string;
message: string;
errorMessage?: string;
}

async function validateEventLog(params: ValidateEventLogParams): Promise<void> {
const { spaceId, connectorId, outcome, message, errorMessage } = params;
const { spaceId, connectorId, actionTypeId, outcome, message, errorMessage } = params;

const events: IValidatedEvent[] = await retry.try(async () => {
return await getEventLog({
Expand Down Expand Up @@ -544,6 +546,7 @@ export default function ({ getService }: FtrProviderContext) {

expect(event?.event?.outcome).to.equal(outcome);

expect(event?.kibana?.alerting?.action_type_id).to.equal(actionTypeId);
expect(event?.kibana?.alerting?.primary_saved_object).to.eql({
type: 'action',
id: connectorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default function ({ getService }: FtrProviderContext) {
await validateEventLog({
spaceId: Spaces.space1.id,
actionId: createdAction.id,
actionTypeId: 'test.index-record',
outcome: 'success',
message: `action executed: test.index-record:${createdAction.id}: My action`,
});
Expand Down Expand Up @@ -138,6 +139,7 @@ export default function ({ getService }: FtrProviderContext) {
await validateEventLog({
spaceId: Spaces.space1.id,
actionId: createdAction.id,
actionTypeId: 'test.failing',
outcome: 'failure',
message: `action execution failure: test.failing:${createdAction.id}: failing action`,
errorMessage: `an error occurred while running the action executor: expected failure for .kibana-alerting-test-data actions-failure-1:space1`,
Expand Down Expand Up @@ -330,13 +332,14 @@ export default function ({ getService }: FtrProviderContext) {
interface ValidateEventLogParams {
spaceId: string;
actionId: string;
actionTypeId: string;
outcome: string;
message: string;
errorMessage?: string;
}

async function validateEventLog(params: ValidateEventLogParams): Promise<void> {
const { spaceId, actionId, outcome, message, errorMessage } = params;
const { spaceId, actionId, actionTypeId, outcome, message, errorMessage } = params;

const events: IValidatedEvent[] = await retry.try(async () => {
return await getEventLog({
Expand Down Expand Up @@ -371,6 +374,13 @@ export default function ({ getService }: FtrProviderContext) {

expect(event?.event?.outcome).to.equal(outcome);

expect(event?.kibana?.alerting?.action_type_id).to.equal(actionTypeId);
expect(event?.kibana?.alerting?.primary_saved_object).to.eql({
type: 'action',
id: actionId,
namespace: 'space1',
});

expect(event?.kibana?.saved_objects).to.eql([
{
rel: 'primary',
Expand Down

0 comments on commit f99ecd0

Please sign in to comment.