Select Page

Back to the Future: Icinga2 notifications via XMPP

by | Sep 14, 2020 | NETWAYS

The commonly used method of notifying users in Icinga2 is (similar to other systems) sending an email. For more urgent and mobile notifications SMS, voice calls and a few other options are possible.

The grow and spreading of chat services made the ussage of such a service the obvious next step (or at least a great gadget). There are scripts for Slack, Rocket Chat, Matrix, Telegram, naturally IRC and, from hearsay, Iridium. As one might have deducted from the head line, the topic here is one more service, namely XMPP/Jabber (Jabber is the deprecated name of the protocol).

XMPP is a free standard (as in freedom, not only as in “free beer”), extensible and there are several implementations for server and client. Although it is not well known, the scope of application is huge. A small example are the chat services of several big tech companies which were simply based on XMPP at the beginning (and also mostly based on free software). Of course, as they grew, this environment was converted to a “walled garden”. The communication follows a procedure similar to email, a client (meaning the device of a user) connects to a server and hands over a message. This message will then be transfered to the target server (if necessary), which will deliver it to a user’s device. Comparably to email, XMPP is intented as a federated system; everybody can (in principle) operate a server and communicate with everybody else.
Accordingly an user is identified by a JID, consisting of a local part (user name) and a domain part in the form of user@domain.tld.

There are three reasons for notifications via XMPP:

  1. In general a second channel for notifications is useful, because the first one might fail. If the mail setup breaks down, nobody gets notified about it (or anything else anymore).
  2. XMPP is a very flexible and powerful protocol and a user can be notified in a short time span and on a wide range of devices (if the device is online or supports a PUSH-like behaviour). Additionaly an XMPP infrastructure of the necessary size can be operated without the need for external dependencies.
  3. The author of this article is a XMPP fan and wants to advertise XMPP a bit. Especially as an alternative to proprietary services of companies with questionable intent.

On the question of the implementation, there are several samples available, for example this article, which appeared in this blog. After six years an update seems appropriate though. Two details  are especially relevant here:

  1. The migration from Python2 to Python3.
  2. The XMPP library used there is deprecated.

For those reasons this variant was developed, but the usage of enviroment variables for the handover of sensible data (login credentials) is not (yet) supported, if one uses the Director for configuring this script. Addiotionaly the sleekxmpp library is deprecated. These and a few other change are implemented in this version, which is the reason and topic of this article.

If one wants to receive XMPP notifications from Icinga2, the ability to send XMPP messages in general is needed, meaning at least an account on a server, for example or Alternatively the infra structure could be self operated, for example with an instance of ejabberd. As for dependencies of the script itself, Python3 with standard libraries and the slixmpp library is needed. The script has to copied to a fitting directory (possible /etc/icinga2/scripts) and the configuration from the icinga2_configdirectory has to be integrated in the icinga2 configuration. Especially the path of the script and the details of the sending and the receiving xmpp account have to replaced.

An example for this in action looks like this in conversations:

The whole thing is rather minimalistic at this point and helpful ideas, critic or proposals are welcome.

Finally there isn’t anything left, but to hope, that this might be helpful for someone. If this is the case, it would be really nice to hear about it 🙂

Lorenz Kästle
Lorenz Kästle

Lorenz hat seinen Bachelor der Informatik an der FAU gemacht und sich zuletzt mit Betriebssystemen dort beschäftigt. In seiner Freizeit beschäftigt er sich ein wenig mit XMPP und der Programmiersprache Erlang.
More posts on the topicNETWAYS

Monthly Snap April 2021

April was the month of easter eggs, and was, as always, the month where spring, summer and winter shook hands. Despite that several colleagues took a few days off around easter, we have a good and varied selection of blogs for you:   Stackconf   Katja made...

Let’s meet again – OSMC 2021

Good news! We’re happy to announce that the Open Source Monitoring Conference will take place this year again. Based on a survey with a resulting majority of two thirds of former OSMC attendees we are excited to organize our event again and can't wait to welcome you...

May the force be with you

Der erste Star Wars Film (Star Wars: Episode IV – Eine neue Hoffnung) kam bereits 1977 in den Kinos. Aber seit wann ist der 04.05. der sogenannte „Star Wars Tag“? Seit dem 04.05.1979 wird der 04. Mai jährlich als „Star Wars Tag“ gefeiert. Aber warum ist das so? Der...


Tue 18

Icinga 2 Fundamentals Training | Online

May 18 @ 09:00 - May 21 @ 17:00
Jun 15

stackconf online

June 15 - June 17
Jun 22

Ansible Fundamentals Training | Online

June 22 @ 09:00 - June 24 @ 17:00
Jun 22

Kubernetes Quick Start | Online

June 22 @ 09:00 - 17:00
Jun 25

Ansible AWX (Tower) Training | Online

June 25 @ 09:00 - 17:00