Skip to content

Commit

Permalink
simplify event schema
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed Dec 2, 2019
1 parent 6f1048e commit 2bc6fee
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 212 deletions.
9 changes: 7 additions & 2 deletions x-pack/legacy/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ export class ActionExecutor {
action: EVENT_LOG_ACTIONS.execute,
},
kibana: {
space_id: namespace,
saved_objects: [`action:${actionId}`],
namespace,
saved_objects: [
{
type: 'action',
id: actionId,
},
],
},
};

Expand Down
48 changes: 35 additions & 13 deletions x-pack/plugins/event_log/generated/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"ignore_above": 1024,
"type": "keyword"
}
}
},
"dynamic": "strict"
},
"event": {
"properties": {
Expand All @@ -39,31 +40,52 @@
"end": {
"type": "date"
}
}
},
"dynamic": "strict"
},
"user": {
"properties": {
"name": {
"ignore_above": 1024,
"type": "keyword"
}
}
},
"dynamic": "strict"
},
"kibana": {
"properties": {
"saved_objects": {
"ignore_above": 1024,
"type": "keyword"
},
"server_uuid": {
"ignore_above": 1024,
"type": "keyword"
"type": "keyword",
"ignore_above": 1024
},
"space_id": {
"ignore_above": 1024,
"type": "keyword"
"namespace": {
"type": "keyword",
"ignore_above": 1024
},
"saved_objects": {
"properties": {
"store": {
"type": "keyword",
"ignore_above": 1024
},
"id": {
"type": "keyword",
"ignore_above": 1024
},
"name": {
"type": "keyword",
"ignore_above": 1024
},
"type": {
"type": "keyword",
"ignore_above": 1024
}
},
"type": "nested",
"dynamic": "strict"
}
}
},
"dynamic": "strict"
}
}
}
61 changes: 28 additions & 33 deletions x-pack/plugins/event_log/generated/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,22 @@
// provides TypeScript and config-schema interfaces for ECS for use with
// the event log

import { schema } from '@kbn/config-schema';
import { schema, TypeOf } from '@kbn/config-schema';

export const ECS_VERSION_GENERATED = '1.2.0';
type DeepWriteable<T> = { -readonly [P in keyof T]: DeepWriteable<T[P]> };
type DeepPartial<T> = {
[P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : DeepPartial<T[P]>;
};

// a typescript interface describing the schema
export interface IEventGenerated {
'@timestamp'?: string | string[];
tags?: string | string[];
message?: string | string[];
ecs?: {
version?: string | string[];
};
event?: {
action?: string | string[];
provider?: string | string[];
start?: string | string[];
duration?: number | number[];
end?: string | string[];
};
user?: {
name?: string | string[];
};
kibana?: {
saved_objects?: string | string[];
server_uuid?: string | string[];
space_id?: string | string[];
};
}
export const ECS_VERSION = '1.2.0';

// types and config-schema describing the es structures
export type IEvent = DeepPartial<DeepWriteable<TypeOf<typeof EventSchema>>>;

// a config-schema describing the schema
export const EventSchemaGenerated = schema.maybe(
export const EventSchema = schema.maybe(
schema.object({
'@timestamp': ecsDate(),
tags: ecsString(),
tags: ecsStringMulti(),
message: ecsString(),
ecs: schema.maybe(
schema.object({
Expand All @@ -67,20 +49,33 @@ export const EventSchemaGenerated = schema.maybe(
),
kibana: schema.maybe(
schema.object({
saved_objects: ecsString(),
server_uuid: ecsString(),
space_id: ecsString(),
namespace: ecsString(),
saved_objects: schema.maybe(
schema.arrayOf(
schema.object({
store: ecsString(),
id: ecsString(),
name: ecsString(),
type: ecsString(),
})
)
),
})
),
})
);

function ecsStringMulti() {
return schema.maybe(schema.arrayOf(schema.string()));
}

function ecsString() {
return schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())]));
return schema.maybe(schema.string());
}

function ecsNumber() {
return schema.maybe(schema.oneOf([schema.number(), schema.arrayOf(schema.number())]));
return schema.maybe(schema.number());
}

function ecsDate() {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/event_log/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "event_log",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["x-pack", "event_log"],
"configPath": ["xpack", "event_log"],
"server": true,
"ui": false
}
Loading

0 comments on commit 2bc6fee

Please sign in to comment.