Contact us: contact@deburen.uk

Using Prosody's mod_push_msg to send Grafana alerts to an XMPP chat room

Grafana doesn't have native xmpp alerting support, this describes how to configure it to use a Prosody module to send alerts to an XMPP chat room.

Introduction

Daniel Gultsch published an article on sending Jabber / XMPP Messages via HTTP. I have often wanted Grafana to be able to send alerts into our XMPP infrastructure so I thought I would try setting it up and seeing if Grafana is flexible enough to be able to send alerts to a Multi User Chatroom (MUC). TL;DR: it is.

Assumptions

Prosody set up

It is worth noting at this stage that I had to change my authentication source as the method that I was using (mod_auth_imap) doesn't support HTTP Basic authentication. I am now using mod_auth_dovecot instead. This is out of scope of this guide.

You need a user set up for Grafana to post to the MUC from (I'm using grafana@<domain name>).

First you need to add the mod_post_msg and mod_muc_bot modules to your Prosody installation, here are my Bastillefile additions:

CMD prosodyctl install --server=https://modules.prosody.im/rocks/ mod_post_msg
CMD prosodyctl install --server=https://modules.prosody.im/rocks/ mod_muc_bot

Next, enable the mod_post_msg in prosody.cfg.lua:

    modules_enabled = {
        [...]
        "post_msg"; -- allows sending XMPP <message> stanzas via a simple HTTP API.
        [...]
    }

Now add the following to your VirtualHost configuration, changing <domain name> to whatever the domain name is for your VirtualHost:

VirtualHost "<domain name>"
    [...]
    modules_enabled = { "muc_mam", "muc_bot" }
    known_bots = { "grafana@<domain name>" }
    bots_get_messages = false
    ignore_bot_errors = true

Now restart Prosody and, if necessary, set up the MUC that you want to send alerts to and make sure the user that you intend to send alerts as is able to log in, and is part of the MUC.

Grafana

Go to Alerting -> Notification configuration and either edit an existing Contact Point, or create a new one.

When adding a Contact Point Integration, choose Webhook and set the URL to https://<domain name>:5281/msg/.

Expand the Optional webhook settings and set them as follows:

Now run a test, and you should find the message is successfully delivered into the chat room.