# Kibana plugin - read configuration from kibana.yml

**URL:** <https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260>\
**Category:** Kibana\
**Created:** [March 2, 2018, 1:42pm UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260 "2018-03-02T13:42:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![milkamar](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@milkamar](https://discuss.elastic.co/u/milkamar)\
**Post date:** [March 2, 2018, 1:42pm UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260/1 "2018-03-02T13:42:55Z")

</div>

Hello,  
I code own plugin for kibana, but am unable to read plugin-related configuration from kibana.yml

kibana.yml - custom attributes part

> # cleanup tool
> 
> # kibanaVersion format: [major].[minor]
> 
> cleanup\_tool.kibanaVersion: 4.6  
> cleanup\_tool.enabled: true  
> cleanup\_tool.debug: true
> 
> # auditlog settings
> 
> cleanup\_tool.auditlogRecordsPerPage: 20  
> cleanup\_tool.auditlogDefaultSortField: timestamp  
> cleanup\_tool.auditlogDefaultSortDirection: desc
> 
> # scrollTime used in Scroll API on searching for documents for bulk processing
> 
> cleanup\_tool.scrollTime: 3m
> 
> # settings for scheduler connection to ES - prevents all Kibana features from using high priviledges needed for scheduler
> 
> cleanup\_tool.schedulerESHost: 10.88.13.204  
> cleanup\_tool.schedulerESPort: 9200  
> cleanup\_tool.schedulerESUser: superClean  
> cleanup\_tool.schedulerESPassword: password  
> cleanup\_tool.schedulerESRequestTimeout: 30000  
> cleanup\_tool.schedulerESPingTimeout: 3000  
> cleanup\_tool.schedulerESKeepAlive: true
> 
> # ms to wait before recall ES on failure
> 
> cleanup\_tool.checkESTimeout: 30000

index.js (config(Joi) part)

> config(Joi) {  
> const { array, boolean, number, object, string } = Joi;
> 
> ```
> return Joi.object({
> kibanaVersion: Joi.string().default('4.6'),
> enabled: Joi.boolean().default(true),
> debug: Joi.boolean().default(true),
> auditlogRecordsPerPage: Joi.number().integer().default(20),
> auditlogDefaultSortField: Joi.string().default('timestamp'),
> auditlogDefaultSortDirection: Joi.string().default('desc'),
> scrollTime: Joi.string().default('3m'),
> schedulerESHost: Joi.string().default('127.0.0.1'),
> schedulerESPort: Joi.number().integer().default(9200),
> schedulerESUser: Joi.string().default('elastic'),
> schedulerESPassword: Joi.string().default('changeme'),
> schedulerESRequestTimeout: Joi.number().integer().default(30000),
> schedulerESPingTimeout: Joi.number().integer().default(3000),
> schedulerESKeepAlive: Joi.boolean().default(true),
> checkESTimeout: Joi.number().default(30000)
> }).default();
> }
> 
> ```

I believe, configuration is read from here, when plugin starts ?

index.js (injectVars part)

> injectVars: function(server, options) {  
> const config = server.config();  
> return {  
> kbnIndex: config.get('kibana.index'), // unused  
> elasticsearchUrl: config.get('elasticsearch.url'), // new  
> enabled: options.enabled,  
> debug: options.debug,  
> auditlogRecordsPerPage: options.auditlogRecordsPerPage,  
> auditlogDefaultSortField: options.auditlogDefaultSortField,  
> auditlogDefaultSortDirection: options.auditlogDefaultSortDirection,  
> scrollTime: options.scrollTime,  
> schedulerESHost: options.schedulerESHost,  
> schedulerESPort: options.schedulerESPort,  
> schedulerESUser: options.schedulerESUser,  
> schedulerESPassword: options.schedulerESPassword,  
> schedulerESRequestTimeout: options.schedulerESRequestTimeout,  
> schedulerESPingTimeout: options.schedulerESPingTimeout,  
> schedulerESKeepAlive: options.schedulerESKeepAlive  
> };  
> }¨

But when I later access

> options.schedulerESUser

, it has default value 'elastic' rather than what I have specified in kibana.yml.

Does anybody know how to solve this ?  
Thanks in advance.

P.S. - note that I am completely new to kibana plugin development.

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [March 3, 2018, 7:53pm UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260/2 "2018-03-03T19:53:37Z")

</div>

Assuming you are talking about reading a config value from the server side, you can use the `server.config` service.

```auto
  server.route({
    method: 'GET',
    path: '/api/myplugin/v1/coolstuff',
    async handler: (req, reply) => {

      const config = req.server.config();
      const schedulerESUser = config.get('myplugin.stuff.schedulerESUser');
      const usefulData = await helperModule(schedulerESUser);

      reply(usefulData);
    }
  });

```

---

<div class="post-metadata">

**Author:** ![milkamar](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@milkamar](https://discuss.elastic.co/u/milkamar)\
**Post date:** [March 7, 2018, 11:58am UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260/3 "2018-03-07T11:58:27Z")

</div>

Hey, thanks for reply, it was helpful for me to get oriented in plugin's code,  
but mistake was actually in field

> name  
> in package.json.

This has to be set to the same value, as the configuration prefix in kibana.yml.

---

<div class="post-metadata">

**Author:** ![milkamar](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@milkamar](https://discuss.elastic.co/u/milkamar)\
**Post date:** [March 7, 2018, 12:40pm UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260/4 "2018-03-07T12:40:00Z")

</div>

One more question though.

I read about callWithRequest and found out that "normal usage" is to forward "req" from client request.

I need to ping elasticsearch at the start up of my plugin, to test if it is available;  
but not with callWithInternalUser, because it has no rights to certain operations plugin requires. I need to use custom user defined in by fields in kibana.yml.

Is it possible to create "req" object manually ?  
Is it possible to modify authentication of incoming request ?

I tried following:

> const reqAuthorizationString = options.schedulerESUser + ':' + options.schedulerESPassword;  
> const reqAllIn = { 'headers': { 'authorization': { 'credentials': reqAuthorizationString } } };  
> callWithRequest(reqAllIn, 'ping', {}).then(function (response) { //some code here }  
> but this throws 401 with following message:

> Authentication Exception :: {"path":"/","query":{},"statusCode":401,"response":"","wwwAuthenticateDirective":"Basic realm=\"security\" charset=\"UTF-8\""}"}

Is it possible to manually create "req" parameter ?

---

<div class="post-metadata">

**Author:** ![tsullivan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tsullivan/32/31077_2.png) [@tsullivan](https://discuss.elastic.co/u/tsullivan)\
**Post date:** [March 7, 2018, 5:28pm UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260/5 "2018-03-07T17:28:24Z")

</div>

> [@milkamar](#):
>
> I need to ping elasticsearch at the start up of my plugin, to test if it is available;

There's a relatively standard way to do this. In your plugin's init method:

```auto
init(plugin, server) {
  const esPlugin = server.plugins.elasticsearch;
  plugin.status.yellow('Waiting for Elasticsearch');

  esPlugin.status.once('green', () => {
    // kibana has a solid connection to elasticsearch, now initialize my plugin
    // more init code ...
    plugin.status.green('Plugin ready'));
  });
}

```

> [@milkamar](#):
>
> Is it possible to create "req" object manually ?
> 
> Is it possible to modify authentication of incoming request ?

Yes, these things are possible, but I would avoid them if you can for now.

Shay announced the opening of X-Pack at the Elasticon Keynote recently, and once the code is open, it'll be easier to find references on how to do these kinds of things.

---

<div class="post-metadata">

**Author:** ![milkamar](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@milkamar](https://discuss.elastic.co/u/milkamar)\
**Post date:** [March 8, 2018, 7:51am UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260/6 "2018-03-08T07:51:03Z")

</div>

Hey,  
thanks very much, I managed to make it work somehow ! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 5, 2018, 7:51am UTC](https://discuss.elastic.co/t/kibana-plugin-read-configuration-from-kibana-yml/122260/7 "2018-04-05T07:51:37Z")

</div>

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