Webhooks (Kafka)

Setup Webhooks to receive notifications and alerts and store them in Kafka topic.

This page describes how to setup a webhook channel to send alert events into a Kafka topic via the Lenses API.

Set up

1. Create a topic (alerts-topic in examples) for alert events. We will setup the webhook channel to call back into the Lenses API to insert alert events into this topic. Remember to set the desired types for the topic’s key and value within Lenses, so that it knows the format to insert the data.```

2. Create a Group with at least Insert Data permission (Data Namespaces permissions) for that topic and kafka connection.

Permissions

3. Create a Service account, assigning it to the previously created group, and save the Service Account Token for the next step.

Add connection

1. Visit Admin → Connections and click New connection

Lenses.io Connection

2. Select Webhook

Webhook Connection

3. Provide a name and configuration

Host should be Lenses host, same goes for Port. Enable Use HTTPS if Lenses uses SSL.

In Credentials paste Service Account Token.

Add channel

Next add one or multiple target Webhook channels.

1. Visit Admin → Channels and click Webhook

Webhook channel

2. Setup the configuration options

Permissions

.. note:: From Lenses 4.3 /api/jdbc/insert/prepared/$topicName is deprecated and will be removed in 5.0. Please use api/v1/kafka/topics/$topicName/data

HTTP method - POST.

Request path - /api/v1/kafka/topics/alerts-topic/data (assuming alerts-topic is the name of the topic created in Set up Point 1 - if not replace with correct name).

HTTP Headers - X-Kafka-Lenses-Token: {{CREDS[0]}} ({{CREDS[0]}} will be parsed to Service Account Token from connection’s Credentials).

Body payload

Body payload has to have format accepted by Lenses API:

[
  {
    "key": ... ,
    "value": ""
  }
]

The key and value fields represent topic’s key and value. The format of those fields corresponds to the type that was defined upon topic creation (STRING, JSON, AVRO, etc.).

Body payload example For topic with STRING key and JSON value:

[
  {
    "key": "{{ID}}",
    "value": {
      "level": "{{LEVEL}}",
      "category": "{{CATEGORY}}",
      "instance": "{{INSTANCE}}",
      "summary": "{{SUMMARY}}",
      "timestamp": "{{TIMESTAMP}}",
      "id": "{{ID}}"
    }
  }
]

Additional info

About webhooks in general - contains description of Template variables.