MQTT Integration
Last updated
Last updated
(c) 2011 - 2024 ilert GmbH
MQTT is a lightweight, publish-subscribe, machine-to-machine network protocol for message queue/message queuing service. It is designed for connections with remote locations that have devices with resource constraints or limited network bandwidth, such as in the Internet of Things. While ilert doesn't directly support an MQTT broker to accept the publishing of messages, it supports integrations specifically meant to connect MQTT topics to ilert events and provides the ilagent tool to connect your MQTT brokers to ilert without actually writing the code yourself.
Go to Alert sources -> Alert sources and click on Create new alert source.
Search for MQTT in the search field, click on the MQTT tile, and click Next.
Give your alert source a name, optionally assign teams, and click Next.
Select an escalation policy by creating a new one or assigning an existing one.
Select your Alert grouping preference and click Continue setup. You may click Do not group alerts for now and change it later.
The next page shows additional settings, such as customer alert templates or notification priority. Click on Finish setup for now.
On the final page, an API key and/or webhook URL will be generated, which you will need later in this guide.
Foreword: you are free to use any MQTT client to subscribe to your topics and wire them into an API call to POST api.ilert.com/api/v1/mqtt/{your-key-here}
(the endpoint accepts the payload of our generic event API. See also this eventing guide).
However, if you don't wish to write your own software to wire subscriber and POST request, you may use our swiss-army-knife tool ilagent which supports an MQTT mode where it subscribes to a specific MQTT topic to deliver events or heartbeats to ilert; it automatically buffers the messages in a local database to support retries as well. It is open source and can be found on GitHub.
While you may compile the binary locally, we also support an official Docker image ilert/ilagent which can be used to get started quickly.
Note: your messages need to be in the format of the ilert event API schema; at least: {apiKey, eventType, summary}
You can always check docker run ilert/ilagent --help
for a full list of arguments. e.g. username and password for the MQTT broker.
If you don't want to provide the apiKey in every message, you can overwrite it with the --event_key 'il1api123...'
argument.
Note: your messages need to be JSON.
The ilagent also supports basic event key overwrites so that you can map any message top-level keys into an event payload.
The top sample code will subscribe to ALL MQTT topics and filter every message for message.type == 'ALERT'
it will then map the field message.state: SET => ALERT, ACK => ACCEPT and CLR => RESOLVE
to the event.eventType
additionally message.mCode
will be used as event.alertKey
and message.comment as event.summary
.
With these flexible arguments, you may quickly prototype or start your alert management without the need to write and deploy a custom mapper.
If you are using this subscriber bridge for critical scenarios, make sure to read the section on MQTT at least once delivery guarantee in the ilagent readme.
In case your broker is running in docker as well, you cannot simply use localhost to connect; you will need to link your broker to your ilagent container with --link broker-container-name:broker-container-name
then provide -m broker-container-name
so that your ilagent actually connects to your broker.