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:
-
Node.JS v10.19 or later
-
An editor of your choice, such as VS Code or Webstorm
Steps
-
Create and initialize the project by running the following command:
mkdir example-web-service-group && cd $_ npm init --yes
-
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" } }
-
Add the
web-service-interface
package by running the following command:npm install @sirensolutions/web-service-interface
-
Open the
package.json
file to ensure that the@sirensolutions/web-service-interface
package is underdependencies
. -
Create an
index.js
file by running the following command:touch index.js
-
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 theoutputConfiguration
.5 This export and function call is how you hook the Web service to Siren Investigate. -
It’s ready to go! Copy or move the
example-service-group
folder into the Siren Investigateplugins
folder by running the following command:cp -r . /path/to/investigate/plugins
-
Start Elasticsearch and Siren Investigate by running the following commands:
cd path/to/elasticsearch ./bin/elasticseach
cd path/to/investigate ./bin/investigate
-
To start using the service, copy and paste
localhost:5606
into your browser.