Beginners' tutorial: Developing Web service drivers

This is a quick-start guide to getting your first Web service drivers up and running.

Prerequisites

Before you begin, download and install the following tools:

Steps

  1. Create and initialize the project by running the following command:

    mkdir example-web-service-group && cd $_
    npm init --yes
  2. Add Kibana to the package.json file. Ensure that the file contains the following parameters:

    {
      "name": "example-web-service-group",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "",
      "license": "ISC",
      "kibana": {
        "version": "5.6.10"
      }
    }
  3. Add the web-service-interface package by running the following command:

    npm install @sirensolutions/web-service-interface
  4. Open the package.json file to ensure that the @sirensolutions/web-service-interface package is under dependencies.

  5. Create an index.js file by running the following command:

    touch index.js
  6. Copy the following code into the index.js file:

    import { registerServices, ServiceDefinition } from '@sirensolutions/web-service-interface';
    
    class StringReverser extends ServiceDefinition { (1)
    
      name = 'stringreverser';
      inputSchema = { (2)
          message: {
            type: 'text',
            required: true // This defaults to false if you do not set it.
          }
        };
      outputConfiguration = { reversed_message: 'text' }; (3)
    
      invoke(inputs) { (4)
        // Reverse my input
        const reversed_input = inputs.message.split('').reverse().join();
        return [{
            reversed_message: reversed_input
          }];
      }
    }
    
    export default registerServices('example-web-service-group', [StringReverser]); (5)
    1 Extends the class, so that it complies with the Web service interface.
    2 Specifies the inputs that this Web service accepts and whether or not they are mandatory parameters.
    3 Defines the structure and types of the output fields, which are used to create the Elasticsearch field mapping.
    4 The function that is called when your Web service is invoked. It receives the parameters that are defined in inputSchema and must return an object that has the same structure as the outputConfiguration.
    5 This export and function call is how you hook the Web service to Siren Investigate.
  7. It’s ready to go! Copy or move the example-service-group folder into the Siren Investigate plugins folder by running the following command:

    cp -r . /path/to/investigate/plugins
  8. Start Elasticsearch and Siren Investigate by running the following commands:

    cd path/to/elasticsearch
    ./bin/elasticseach
    cd path/to/investigate
    ./bin/investigate
  9. To start using the service, copy and paste localhost:5606 into your browser.