# How to make a new custom global variable?

**URL:** <https://discuss.elastic.co/t/how-to-make-a-new-custom-global-variable/75163>\
**Category:** Kibana\
**Created:** [February 15, 2017, 9:00am UTC](https://discuss.elastic.co/t/how-to-make-a-new-custom-global-variable/75163 "2017-02-15T09:00:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![valereds](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@valereds](https://discuss.elastic.co/u/valereds)\
**Post date:** [February 15, 2017, 9:00am UTC](https://discuss.elastic.co/t/how-to-make-a-new-custom-global-variable/75163/1 "2017-02-15T09:00:50Z")

</div>

Hi all,  
I need to make a custom global variable (to write inside the kibana.yml) and maybe access to its value from the 'config' service inside my controllers.  
Can anyone explain me how kibana deals with settings variable?  
Thank you so much in advance!

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [February 15, 2017, 6:55pm UTC](https://discuss.elastic.co/t/how-to-make-a-new-custom-global-variable/75163/2 "2017-02-15T18:55:09Z")

</div>

I'm assuming that when you say "inside my controllers" that you're talking about inside a Kibana plugin you're developing. In that case, adding variable that will live inside `kibana.yml` is pretty easy.

In your plugin configuration, you set up something like this (just the important bits here):

```auto
return new kibana.Plugin({
  id: 'myplugin',

  //optionally override the setting prefix
  // configPrefix: 'custom.myplugin', 
  
  config: function (Joi) {
    return Joi.object({
      enabled: Joi.boolean().default(true),
      firstsetting: Joi.string(),
      deepsetting: Joi.object({
        propone: Joi.string().default('some value'),
        proptwo: Joi.number().integer().default(100),
        propthree: Joi.string(),
      }).default(),
    });
  },
  
  // ...
});

```

The `config` parameter is the important part here. It uses [Joi](https://github.com/hapijs/joi), which is passed in as the first parameter. Any settings you define in here will be prefixed with the name of your app by default, but you can override that using `configPrefix` (note that it doesn't have to use a `.` in its name, but it can).

So, say you wanted to set `firstsetting` and override the default of `deepsetting.propone`, you would add something like this to your `kibana.yml`.

```auto
myplugin.firstsetting: 'hello'
myplugin.deepsetting.propone: 'another string'

```

The values of these settings in the yml file are validated with Joi, and if they are wrong, Kibana will not start. The resulting value after resolving it with the yml file is now available using the `config` service on the `server` object. As an example, you could use this value in an `init` function like so:

```auto
return new kibana.Plugin({
  id: 'myplugin',

  // ...
  
  init: function (server) {
    const config = server.config();
    const propone = config.get('myplugin.deepsetting.propone'); // another string
    const proptwo = config.get('myplugin.deepsetting.proptwo'); // 100
  }

  // ...
});

```

---

<div class="post-metadata">

**Author:** ![valereds](https://avatars.discourse-cdn.com/v4/letter/v/f19dbf/32.png) [@valereds](https://discuss.elastic.co/u/valereds)\
**Post date:** [February 15, 2017, 8:39pm UTC](https://discuss.elastic.co/t/how-to-make-a-new-custom-global-variable/75163/3 "2017-02-15T20:39:53Z")

</div>

Hi Joe, perfect explanation. Thank you so much!!! Now it's all clear! 👍

---

<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:** [March 15, 2017, 8:39pm UTC](https://discuss.elastic.co/t/how-to-make-a-new-custom-global-variable/75163/4 "2017-03-15T20:39:54Z")

</div>

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