Monitoring Traefik 2 with Icinga

Checking if a specific website or web application is alive and well is a classic task of monitoring software. I monitor personal web services with good old Icinga2. Last year I wrote a small Python script that runs on a Icinga2 master or satellite node that queries the Traefik API to automate the generation of Icinga2 rules. For me this was a nice and useful exercise to learn how to use REST APIs together with Python for system administration. In the process of upgrading Traefik 1.7 to 2.0 I also had to modify this script.

So without further ado lets jump right in. The way my script works:

It fetches the exposed Traefik Routers with their coresponding hostnames and services and creates Icinga2 apply rules that use the HTTP check. The script is designed to run as a nightly cronjob so that new services that should be monitored are added automatically.


  • A working Traefik v2.x reverse proxy with it's API exposed
  • Icinga2 monitoring server

Before proceeding please make shure you can access Traefik's API. For example in this way:

curl -s --user admin:passw0rd http://example.lan:8080/api/http/routers | jq
    "entryPoints": [
    "middlewares": [


Run all this steps on a Icinga 2 master or satellite node.

Download script and install script

git clone
sudo -u nagios mkdir /etc/icinga2/cronjobs
chmod +x traefik_icinga_check/
sudo cp traefik_icinga_check/  /etc/icinga2/cronjobs/
sudo chown nagios:nagios /etc/icinga2/cronjobs/

Set up parameters via .env

$ sudo -u nagios touch /etc/icinga2/cronjobs/.env

Open and insert parameters /etc/icinga2/cronjobs/.env (same as Traefik dashboard)


Test the script manually by printing to STDOUT

$ sudo -u nagios /etc/icinga2/cronjobs/
apply Service " https apache-apache" {
                import "generic-service"
                check_command = "http"
                vars.http_address = ""
                vars.http_vhost = ""

                vars.http_ssl = "1"
                vars.http_sni = "true"

                vars.notification["mail"] = {
                    groups = [ "icingaadmins" ]

Configure the Host that runs Traefik

Edit your Traefik host and add the array, so that it matches the rules set in

object Host "Reverse Proxy" {
  import "generic-host"
  address = ""
  vars.os = "Linux" = ["traefik"]

Create cronjob for nagios user

sudo -u nagios crontab -e

Edit and insert nightly cronjob. Something like that should suffice.

# Daily at 2am: Generate Icinga checks from Traefik API and restart Icinga2 service
0 2 * * * /etc/icinga2/cronjobs/ > /etc/icinga2/zones.d/YOUR-ZONE/traefik_services.conf && systemctl restart icinga2 >/dev/null 2>&1

Note: Of course you need to print the output of to a directory that is either inside your zone or in conf.d

The end result should look like this:

Screenshot of Icinga2 with Traefik Service

I am looking forward to any feedback or even pull-requests for the small script.

Source for the graphics used in the header: Background vector created by vectorpouch -