这个文件主要是根据kibana api 定义该插件类型,本次demo 定义插件类型为app.修改内容如下:
const api =require('./server/routes');
export default function (kibana) {
return new kibana.Plugin({
require: ['elasticsearch'],
uiExports: {
// Register the app component of our plugin to uiExports
app: {
// The title of the app (will be shown to the user)
title: 'Indices',
// An description of the application.
description: 'An awesome Kibana plugin',
// The require reference to the JavaScript file for this app
main: 'plugins/elasticsearch_status/app',
// The require reference to the icon of the app
icon: 'plugins/elasticsearch_status/icon.svg'
}
},
// The init method will be executed when the Kibana server starts and loads
// this plugin. It is used to set up everything that you need.
init(server, options) {
// Just call the api module that we imported above (the server/routes.js file)
// and pass the server to it, so it can register several API interfaces at the server.
api(server);
}
});
};
export default function (server) {
const call = server.plugins.elasticsearch.getCluster('admin').callWithRequest;
server.route({
path: '/api/elasticsearch_status/indices',
method: 'GET',
handler(req, reply) {
call(req, 'cluster.state').then(function (response) {
// Return just the names of all indices to the client.
reply(
Object.keys(response.metadata.indices)
);
});
}
});
// Add a route to retrieve the status of an index by its name
server.route({
path: '/api/elasticsearch_status/index/{name}',
method: 'GET',
handler(req, reply) {
call(req, 'cluster.state', {
metric: 'metadata',
index: req.params.name
}).then(function (response) {
reply(response.metadata.indices[req.params.name]);
});
}
});
};