Make variable configurable for plugin and reference in code

using kibana 5.5.1. The aim is to make a variable through kibana.yml whose edits can be implemented without deleting and re-compiling the optimization folder. Below is the index.js

export default function (kibana) {
return new kibana.Plugin({
id:'my_team_plugin',
uiExports: {
docViews: ['plugins/my_team_plugin/team_plugin']

	},
	config: function (Joi) {
		return Joi.object({
			enabled: Joi.boolean().default(true),
			tx: Joi.string(),});
			},
	});

}

Using this it seems to recognize this line in kibana.yml
my_team_plugin.tx: xxxxxxxxxxx

after the Joi has been configured how can I call the variable in js files so that edits made to the config can be implemented without re-optimization? require('./../index.js') causes an error.

No need to include index.js to access configurations. On the server, configurations are available on the server object. For example, in the APM application, configurations are accessed on the server via server.config()

To access configurations on the client, you must first put them into injectDefaultVars. Then, in the UI code you can access the variables via chrome.getInjected

Thanks for the tip, though I tried following your advice and ended up with this and it is giving me errors

export default function (kibana) {
return new kibana.Plugin({
id: 'my_team_plugin',
uiExports: {
docViews: ['plugins/my_team_plugin/team_plugin']

   injectDefaultVars(server) { 
     const config = server.config(); 
     return { 
       tx: config.get('my_team_plugin.tx'), 
     }; 
   }, 
 }, 


 config(Joi) { 
   return Joi.object({ 
     enabled: Joi.boolean().default(true), 
     tx: Joi.string(), 

   }).default(); 
 }, 

});
}
if not in index.js where do I put it? That is where it is in the apm example you referenced.

Looks like your index.js file is not quit right. You do not have a comma after docViews. What version of kibana are you using? What is the error message?

export default function (kibana) { 
   return new kibana.Plugin({ 
     id: 'my_team_plugin', 

     uiExports: { 
       docViews: ['plugins/my_team_plugin/team_plugin'],
       injectDefaultVars(server) { 
         const config = server.config(); 
         return { 
           tx: config.get('my_team_plugin.tx'), 
         }; 
       }, 
     }, 

     config(Joi) { 
       return Joi.object({ 
         enabled: Joi.boolean().default(true), 
         tc: Joi.string(), 
       }).default(); 
     }, 
   }); 
}
1 Like

log [fatal] ValidationError: child "my_team_plugin" fails because ["tx" is not allowed].

Kibana 5.5.1

looks like the cause of the error was that the joi string and the config.get variable were differe (which was a typo. now corrected). But chrome injector likely wont work with my environment. is there another way to load it as a variable in a way that will allow edits to take place without re-optimizing?

Why would chrome injector not work in your environment?

It worked. Thanks a ton for your help. you da man

This was indeed a great post buddy, would love to come back and see more such post in near future.

With Regards,
Protar,
Tutuapp | ShowBox Download | Kodi

great post.thanks for sharing this post
tutuapp

This is a great thread where i got more information. I am bookmarking this website so that i can regularly visit this and got more and more knowledge from this official site.

It works for me Thanks a ton for your help. Visit showbox download to get official showbox apk and stream unlimited movies and videos.

Sounds good its works Thank You SO much best radar detector russia

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