1

I am working on a custom plugin to Kibana (7.5.2). The plugin is of type 'app'. I would like to be able to pass parameters to this plugin in order to pre-load some data from Elasticsearch. I.e., I need to provide users with some specific URLs containing parameters that will be used by the plugin to show only a relevant portion of data.

My problem is that I was not able to find sufficient documentation on this and I do not know what the correct approach should be. I will try to summarize what I know/have done so far:

  1. I have read the official resources on plugin development

  2. I am aware of the fact that _g and _a URL parameters are used to pass state in Kibana applications. However, a) I am not sure if this is the correct approach in my case and b) I also failed to find any information on how my plugin should access the data from these parameters.

  3. I checked the sources of other known plugins, but again, failed to find any clues.

  4. I am able to inject some configuration values using injectUiAppVars in the init method of my plugin (index.js) and retrieve these values in my app (main.js):

    index.js:


export default function (kibana) {
 return new kibana.Plugin({
   require: ['elasticsearch'],
   name: ...,
   uiExports: {
     ...
   },

   ...

   init(server, options) { // eslint-disable-line no-unused-vars
     server.injectUiAppVars('logviewer', async () => {
       var kibana_vars = await server.getInjectedUiAppVars('kibana');
       var aggregated_vars = { ...kibana_vars, ...{ mycustomparameter: "some value" } }
       return aggregated_vars
     });

   ...
   }
 });
}

main.js

   import chrome from 'ui/chrome';
   . . . 
   const mycustomparameter = chrome.getInjected('mycustomparameter');

Providing that I manage to obtain parameters from URL, this would allow me to pass them to my app (via mycustomparameter), but again, I am not sure if this approach is correct.

  1. I tried to get some help via the Elastic forum, but did not receive any answer yet.

My questions 1. Is there any source of information on this particular topic? I am aware of the fact that the plugin API changes frequently, hence I do not expect to find an extensive documentation. Maybe a good example?

  1. Am I completely off course with the way I am trying to achieve it?

Thanks for reading this, any help would be much appreciated!

milank
  • 11
  • 1
  • Your method for retrieving the injected variables using `chrome` is very useful. An [example](https://discuss.elastic.co/t/reading-config-env-variable-inside-kibana-plugin/167643/5) at the Elastic forum was more complicated. – nplatis Oct 31 '20 at 19:45

0 Answers0