Back-End Node.js Server
Kibanalytics uses Node.js with Express to collect and process data from the client side KBS tracker library. To increase security, it includes a customizable payload schema verification that can be enabled or disabled with EXPRESS_VALIDATE_JSON_SCHEMA enviroment variable.
Also, it's possible to add custom data / processing steps with the plugin system.
Payload Schema Validation
The validator uses AJV library and JSON Schema to check the payload from the client side KBS tracker library. It can be enabled by setting the EXPRESS_VALIDATE_JSON_SCHEMA to "1". It's recomended to enable the payload verification as KBS accepts custom payloads, and a malicious user can send large payloads continuously to overload the Kibanalytics server and database.
By default, Kibanalytics includes two schemas: "collect" and "click".
Collect Schema
This schema will validate the default payload for the events generated by the KBS tracker library. If you're using custom server side properties, you have to edit "serverSide" property to fit your needs.
const serverSide = {
type: 'object',
properties: {
foo: { type: 'string' }
},
required: [],
additionalProperties: false
}
Click Schema
This schema will validate the default payload for click events generated by the KBS tracker library. If you're using custom server side properties, you have to edit "serverSide" property to fit your needs.
Custom Schemas
Any custom event payload can be validated with the schemas defined inside "/src/schemas/events" folder. The filename will correspond to the event type it will validate, for exemple, for a custom event named "add-new-user", you have to create a new file called "add-new-user.schema.js" and export a valid AJV JSON Schema object.
Use "/src/schemas/events/custom.schema.js" as base for your custom events payload schema.
TIP
The schemas defined under "/src/schemas/events" folder will validate only the payload property. Other standard properties will be validated with "/src/schemas/endpoints/collect.schema.js".
Plugins
Kibanalytics have a simple plugin system to process / change / add data to the final output to be saved to the database and showed on Kibana.
The system works by setting a shared data context that each plugin have access and permission to manipulate.
For new plugins, just create a new file under the "plugins" folder like "your-plugin.plugin.js" with the follow function signature and exports the function:
function myPlugin(req) {
/*
req object from Express middleware
Shared context can be acessed on req.data property
*/
req.data.myPlugin = {
foo: 'bar'
};
}
TIP
Plugins defined under "/src/plugins" folder will be loaded automatically. If you want take control over the plugin load order, just edit "/src/plugins/index.js" and manually add each plugin to the "plugins" array variable with the desired execution order based on array index.
Out of the box, Kibanalytics includes several plugins to enrich the collected data from events. For further details, please check the implementation code for each plugin.