Email alerting

Time to complete: 17 min.

Overview

Welcome to the fifth tutorial in the Kaa getting started guide! We assume that you have successfully connected your first device to Kaa, collected data from a device, and sent alerts with Open Distro so make sure to review those tutorials before proceeding here.

From this tutorial, you will learn how to configure a webhook destination for Open Distro that will be triggered to send an email when a certain telemetry value from the endpoint exceeds a defined threshold.

We will use Kaa SMTP server.

Open Distro integration

We assume that you have successfully completed Open Distro Alerting tutorial and remember the theory but let’s recap what is Open Distro. Open Distro is an open-source distribution of Elasticsearch with advanced security, alerting, SQL support, automated index management, deep performance analysis, and more. Kaa forwards all telemetry data from your endpoints into Elasticsearch index attached to your tenant.

Playbook

Create a device action

The first you need to do - is to create a device action.

Go to the “Device actions” dashboard and choose your application.

Device actions

Here you can create the webhooks that perform some actions when triggered.
You can add these webhooks as triggers in Open Distro - and the action you choose will be executed as soon as the condition specified in Open Distro is met.

Click the “Add action” button.

Add action

Here you can choose an automation type.
In our case, it is an email-notification.
Specify the required parameters of the automation type you have chosen.

Webhook link

In order to test that the webhook works and emails are sent, you can call the provided webhook directly, for example, using Postman, cURL, or any other HTTP client you like.

Webhook test

Create webhook destination

We assume that you have already created a CO2 monitor and trigger during completing the previous Open Distro Alerting tutorial so that your monitor looks next:

WHEN max()
OF dataSample.co2
OVER all documents
FOR THE LAST 1 minute(s)
WHERE dataSample.co2 is greater than 1000

and trigger is IS ABOVE 1,000.

If you don’t have the above monitor and trigger, go to the Open Distro Alerting and create them. It won’t take much time. Meantime, we will wait for you here ;)


To create a webhook destination, go to Alerting, Destination, and click Add destination button.

Add destination button

Enter “Email destination” into the Name field. Select Custom webhook for the Type field. Go to the device actions page and copy the link to the webhook, you created earlier. Paste the link in the Webhook URL placeholder.

Setup destination

Click Create.

Go to Monitors, click on your monitor (it was named CO2 level monitor in the previous tutorial), find the CO2 level trigger, select it and click Edit. Scroll to the bottom and click and click Add action.

Enter “Email action” for the Action name field. Select just created Email destination for the destination field.

Click Send test message to test the integration.

Send test message button

The mail must arrive at the email address, you’ve specified in the device action.

Test mail

Report high CO2 level

Let’s report that CO2 equals 1200 and see what happens.

Simulate a high CO2 level by invoking the next cURL. Don’t forget to replace <app-version-name> and <endpoint-token> with your application version name and the endpoint token respectively.

curl --location --request POST 'https://connect.cloud.kaaiot.com:443/kp1/<app-version-name>/dcx/<endpoint-token>/json' \
--data-raw '{
  "co2": 1200
}'

Within a minute you should receive an alerting mail.

View alerts history

To view alert history, go to the alerting dashboard.

Alerts history

Learn more

Feedback

This tutorial is based on Kaa 1.5. If you, our reader from the future, spot some major discrepancies with your current version of the Kaa platform, or if anything does not work for you, please give us a shout and we will help!

And if the tutorial served you well, we’d still love to hear your feedback, so join the community!