Kibana 7.6.1: Getting values from kibana.yml

Hello. At 7.4.2 kibana i was able to get hosts config value from clusterClient:

const hosts = server.plugins.elasticsearch.getCluster('data').clusterClient.config.hosts

But now at 7.6+ it's seems imposibble because https://github.com/elastic/kibana/pull/53824.

I also tried some solutions from here Unknown key 'elasticsearch.hosts' for Kibana plugin config. But it didn't work for me.

Is there any possible solutions to get values from kibana.yml?

You can gain access to kibana.yml variables with server.config().get(). Then in your plugin registration, you can pass any kibana.yml variables to the client with injectDefaultVars.

For example

1 Like

It is not working:

injectDefaultVars(server) {
  const config = server.config();
  return {
    testHosts: config.get('elasticsearch.hosts'),
  };
},
server   error  [08:07:09.992]  Error: Unknown config key: elasticsearch.hosts
  at Config.get (/home/asf/kibana_source/kibana/src/legacy/server/config/config.js:147:15)
  at fn (/home/asf/kibana_source/kibana/plugins/vms-reporter-kibana-plugin/index.js:27:29)
  ...

You will need to register your new kibana.yml configuration options in joi schema

Yes. But error raise when web page loads for the first time (in my case getting http://localhost:5603/dev/), not when getting a value from config object.

      ...
      injectDefaultVars(server) {
        const config = server.config();
        return {
          testHosts: config.get('elasticsearch.hosts'),
        };
      },
    },

    config(Joi) {
      return Joi.object({
        enabled: Joi.boolean().default(true),
        testHosts: Joi.string().default('no hosts')
      }).default();
    },

Error when running yarn start:

server    log   [12:18:44.826] [info][listening] Server running at http://localhost:5603/dev
server    log   [12:18:49.865] [info][server][Kibana][http] http server running at http://localhost:5603/dev
server   error  [12:18:51.014]  Error: Unknown config key: elasticsearch.hosts
    at Config.get (/home/asf/kibana_source/kibana/src/legacy/server/config/config.js:147:15)
    at fn (/home/asf/kibana_source/kibana/plugins/vms-reporter-kibana-plugin/index.js:27:29)
    at reduce (/home/asf/kibana_source/kibana/src/core/server/legacy/legacy_internals.ts:50:25)
    at Array.reduce (<anonymous>)
    at LegacyInternals.defaultVars (/home/asf/kibana_source/kibana/src/core/server/legacy/legacy_internals.ts:48:66)
    at LegacyInternals.getVars (/home/asf/kibana_source/kibana/src/core/server/legacy/legacy_internals.ts:89:22)
    at renderApp (/home/asf/kibana_source/kibana/src/legacy/ui/ui_render/ui_render_mixin.js:192:31)
    at internals.Toolkit.renderAppWithDefaultConfig (/home/asf/kibana_source/kibana/src/legacy/ui/ui_render/ui_render_mixin.js:210:12)
    at handler (/home/asf/kibana_source/kibana/plugins/opendistro_security/lib/auth/types/basicauth/routes.js:85:26)
    at module.exports.internals.Manager.execute (/home/asf/kibana_source/kibana/node_modules/hapi/lib/toolkit.js:35:106)
    at Object.internals.handler (/home/asf/kibana_source/kibana/node_modules/hapi/lib/handler.js:50:48)
    at exports.execute (/home/asf/kibana_source/kibana/node_modules/hapi/lib/handler.js:35:36)
    at module.exports.internals.Core.constructor.Request._lifecycle (/home/asf/kibana_source/kibana/node_modules/hapi/lib/request.js:263:62)

That is interesting. It looks like you can not grab kibana.yml configurations from another plugin.

If you take a look at sense plugin, dev tools, then you can see where it grabs elasticsearchUrl contains elasticsearch.hosts.

ReferenceError: first is not defined

It seems like it's not working on 7.6.1. Btw i looked at 7.6.1 source code of console plugin (https://github.com/elastic/kibana/blob/v7.6.1/src/legacy/core_plugins/console/index.ts). Here is too much hack code. So I'm thinking about reading and parsing kibana.yml myself.

Also i see that there is a "newPlatform" for plugins. Found some plugins at https://github.com/elastic/kibana/tree/v7.6.1/src/plugins. But I didn't find any public documentation for developing plugins on the "newPlatform". Are any available? Also kbn-plugin-generator still generates "legacy" plugins in v7.6.1 branch (did not checked v7.6.2).

Thanks for helping

upd. I found migration guide: https://github.com/elastic/kibana/blob/master/src/core/MIGRATION.md

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.