Deploying Kibana with Pre-Installed Plugins

Kibana is an open source project. Modifying and developing over it is therfore a natural thing to do. Organizations might want to do it to fit their various specific needs. Although, a developer could dive right in the src/ directory and fiddle with the code immediately, a more proper way of customizing Kibana is through a plugin. In this short article, I will get you up to speed on why and how to deploy your kibana instance, with a Pre-Installed plugins.

Deployment

While developing a Kibana plugin, your code will be located in Kibana’s plugin/ directory.  But when it comes to deployment, plugins in plugin/ directory will be ignored. To finally deploy your plugin, there are two ways.

/bin/kibana-plugin install (Official Way)

The recommended way was to run the following in your build script:

bin/kibana-plugin install file:///some/local/path/my-plugin.zip -d path/to/directory

Modify build tasks (My Way)

I like better when a software is more self-contained, keeping build scripts as small as possible.

In tasks/build/index.js, you will find the list of tasks that are executed during a build process.

tasks/build/index.js

import { flatten } from 'lodash';
module.exports = function (grunt) {
  grunt.registerTask('build', 'Build packages', function () {
    grunt.task.run(flatten([
      'clean:build',
      'clean:target',
      '_build:downloadNodeBuilds',
      '_build:extractNodeBuilds',
      'copy:devSource',
      'clean:devSourceForTestbed',
      'babel:build',
      '_build:plugins',
      '_build:data',
      '_build:verifyTranslations',
      '_build:packageJson',
      '_build:readme',
      '_build:babelCache',
      '_build:installNpmDeps',
      '_build:notice',
      '_build:removePkgJsonDeps',
      'clean:testsFromModules',
      'run:optimizeBuild',
      'stop:optimizeBuild',
      '_build:versionedLinks',
      '_build:osShellScripts',
      grunt.option('skip-archives') ? [] : ['_build:archives'],
      grunt.option('skip-os-packages') ? [] : [
        '_build:pleaseRun',
        '_build:osPackages',
      ],
      '_build:shasums'
    ]));
  });
};

Before we can add our own build task, we must first create it. In the same directory (tasks/build/), create your custom build javascript file. Say foo.js:

tasks/build/foo.js

export default (grunt) => {

  grunt.registerTask('_build:forSonar', 'Install organization specific plugins', function () {
    // This makes the foo plugin installed by default.
    grunt.file.copy('plugins/foo', 'build/kibana/plugins/foo');  // change foo to the name of your plugin.
  });
}

To add our custom build task to tasks/build/index.js, add _build:foo right after _build:plugins, like this:

New tasks/build/index.js

import { flatten } from 'lodash';
module.exports = function (grunt) {
  grunt.registerTask('build', 'Build packages', function () {
    grunt.task.run(flatten([
      'clean:build',
      'clean:target',
      '_build:downloadNodeBuilds',
      '_build:extractNodeBuilds',
      'copy:devSource',
      'clean:devSourceForTestbed',
      'babel:build',
      '_build:plugins',
      '_build:foo',  // Custom build task.
      '_build:data',
      '_build:verifyTranslations',
      '_build:packageJson',
      '_build:readme',
      '_build:babelCache',
      '_build:installNpmDeps',
      '_build:notice',
      '_build:removePkgJsonDeps',
      'clean:testsFromModules',
      'run:optimizeBuild',
      'stop:optimizeBuild',
      '_build:versionedLinks',
      '_build:osShellScripts',
      grunt.option('skip-archives') ? [] : ['_build:archives'],
      grunt.option('skip-os-packages') ? [] : [
        '_build:pleaseRun',
        '_build:osPackages',
      ],
      '_build:shasums'
    ]));
  });
};

_build:plugins just creates a plugin directory in the build directory. Something we needed before running our build task.

That’s it. Hope you found this useful.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.