Skip to content

Commit

Permalink
[Beats Management] Install Beats index template on plugin init (#19072)
Browse files Browse the repository at this point in the history
* Install Beats index template on plugin init

* Adding missing files
  • Loading branch information
ycombinator authored and mattapperson committed Aug 27, 2018
1 parent 46135cd commit 40719d7
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 1 deletion.
4 changes: 3 additions & 1 deletion x-pack/plugins/beats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Original file line number Diff line number Diff line change
@@ -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);
};
7 changes: 7 additions & 0 deletions x-pack/plugins/beats/server/lib/client/index.js
Original file line number Diff line number Diff line change
@@ -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';
84 changes: 84 additions & 0 deletions x-pack/plugins/beats/server/lib/index_template/beats_template.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
}
7 changes: 7 additions & 0 deletions x-pack/plugins/beats/server/lib/index_template/index.js
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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
});
}

0 comments on commit 40719d7

Please sign in to comment.