diff --git a/x-pack/plugins/beats/index.js b/x-pack/plugins/beats/index.js index 8319485db1749..8839a30fc5a2e 100644 --- a/x-pack/plugins/beats/index.js +++ b/x-pack/plugins/beats/index.js @@ -4,13 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ +import { installIndexTemplate } from './server/lib/index_template'; import { PLUGIN } from './common/constants'; export function beats(kibana) { return new kibana.Plugin({ id: PLUGIN.ID, require: ['kibana', 'elasticsearch', 'xpack_main'], - init: function () { + init: async function (server) { + await installIndexTemplate(server); } }); } diff --git a/x-pack/plugins/beats/server/lib/client/call_with_internal_user_factory.js b/x-pack/plugins/beats/server/lib/client/call_with_internal_user_factory.js new file mode 100644 index 0000000000000..8b5dbed773430 --- /dev/null +++ b/x-pack/plugins/beats/server/lib/client/call_with_internal_user_factory.js @@ -0,0 +1,16 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { once } from 'lodash'; + +const callWithInternalUser = once((server) => { + const { callWithInternalUser } = server.plugins.elasticsearch.getCluster('admin'); + return callWithInternalUser; +}); + +export const callWithInternalUserFactory = (server) => { + return callWithInternalUser(server); +}; diff --git a/x-pack/plugins/beats/server/lib/client/index.js b/x-pack/plugins/beats/server/lib/client/index.js new file mode 100644 index 0000000000000..a56a50e2864a5 --- /dev/null +++ b/x-pack/plugins/beats/server/lib/client/index.js @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { callWithInternalUserFactory } from './call_with_internal_user_factory'; diff --git a/x-pack/plugins/beats/server/lib/index_template/beats_template.json b/x-pack/plugins/beats/server/lib/index_template/beats_template.json new file mode 100644 index 0000000000000..6ef57b9c549ed --- /dev/null +++ b/x-pack/plugins/beats/server/lib/index_template/beats_template.json @@ -0,0 +1,84 @@ +{ + "index_patterns": [ + ".management-beats" + ], + "version": 65000, + "settings": { + "index": { + "number_of_shards": 1, + "auto_expand_replicas": "0-1", + "codec": "best_compression" + } + }, + "mappings": { + "_doc": { + "dynamic": "strict", + "properties": { + "type": { + "type": "keyword" + }, + "enrollment_token": { + "properties": { + "token": { + "type": "keyword" + }, + "expires_on": { + "type": "date" + } + } + }, + "configuration_block": { + "properties": { + "tag": { + "type": "keyword" + }, + "type": { + "type": "keyword" + }, + "block_yml": { + "type": "text" + } + } + }, + "beat": { + "properties": { + "id": { + "type": "keyword" + }, + "enrollment_token": { + "type": "keyword" + }, + "access_token": { + "type": "keyword" + }, + "verified_on": { + "type": "date" + }, + "type": { + "type": "keyword" + }, + "host_ip": { + "type": "keyword" + }, + "host_name": { + "type": "keyword" + }, + "ephemeral_id": { + "type": "keyword" + }, + "local_configuration_yml": { + "type": "text" + }, + "central_configuration_yml": { + "type": "text" + }, + "metadata": { + "dynamic": "true", + "type": "object" + } + } + } + } + } + } +} diff --git a/x-pack/plugins/beats/server/lib/index_template/index.js b/x-pack/plugins/beats/server/lib/index_template/index.js new file mode 100644 index 0000000000000..04128e46ff0ea --- /dev/null +++ b/x-pack/plugins/beats/server/lib/index_template/index.js @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { installIndexTemplate } from './install_index_template'; diff --git a/x-pack/plugins/beats/server/lib/index_template/install_index_template.js b/x-pack/plugins/beats/server/lib/index_template/install_index_template.js new file mode 100644 index 0000000000000..01b080903ccac --- /dev/null +++ b/x-pack/plugins/beats/server/lib/index_template/install_index_template.js @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import beatsIndexTemplate from './beats_template'; +import { callWithInternalUserFactory } from '../client'; + +const TEMPLATE_NAME = 'beats-template'; + +export function installIndexTemplate(server) { + const callWithInternalUser = callWithInternalUserFactory(server); + return callWithInternalUser('indices.putTemplate', { + name: TEMPLATE_NAME, + body: beatsIndexTemplate + }); +}