Select Page

Icinga 2 Notifications manuell testen

by | Sep 16, 2016 | Icinga

Bei jeder Installation von Icinga 2 sollte das Notificationsystem getestet werden.
Je nach Installation werden verschiedene Gruppen eingerichtet, die abhängig vom Service beachrichtigt werden sollen. Solche Testbenachrichtigungen können in der Oberfläche von Icinga Web 2 erzeugt und losgeschickt werden. Aber dazu muss der jeweilige Host oder Service rausgesucht werden. Diese Aufgabe kann auch eleganter über die REST-API von Icinga 2 angestoßen werden.
Ein kleines Skript und schon gehts von der Kommandozeile:

#!/bin/bash
#
unset ftp_proxy
unset http_proxy
unset https_proxy
apiuser="myuser"
apipasswd="mypasswd"
server="localhost"
while getopts h:s: opt
do
  case "$opt" in
    h) host=$OPTARG ;;
    s) service=$OPTARG ;;
    h) Usage
       exit 1 ;;
    ?) echo "ERROR: invalid option" >&2
       exit 1 ;;
  esac
done
shift $((OPTIND - 1))
if [ -n "${service}" ] ; then
  # Bitte in eine Zeile zusammenfassen
  curl -k -s -u "${apiuser}:${apipasswd}" -H 'Accept: application/json'
  -X POST 'https://'${server}':5665/v1/actions/send-custom-notification'
  -d '{ "type": "Service", "service" : "'${host}"!"${service}'", "author": "icingaadmin",
  "comment": "This is a testmessage", "force": true }' | python -m json.tool
  exit
fi
if [ -n "${host}" ] ; then
  # Bitte in eine Zeile zusammenfassen
  curl -k -s -u "${apiuser}:${apipasswd}" -H 'Accept: application/json'
  -X POST 'https://'${server}':5665/v1/actions/send-custom-notification'
  -d '{ "type": "Host", "host" : "'${host}'", "author": "icingaadmin",
  "comment": "This is a testmessage", "force": true }' | python -m json.tool
  exit
fi
root@icinga-node1:$ ./send_icinga2_message -h srv04 -s ping4
{
    "results": [
        {
            "code": 200.0,
            "status": "Successfully sent custom notification for object 'srv04!ping4'."
        }
    ]
}

In Icinga Web 2 sieht das ganze dann so aus 🙂 Wenn ihr mehr über Icinga 2 wissen möchtet, kommt einfach auf uns zu.
bildschirmfoto_2016-09-16_16-27-16bildschirmfoto_2016-09-16_16-28-28
Die Notification-Scripts für die in den Screenshots gezeigten Notifications basieren auf den Blogpost “Icinga 2 + Director + Notifications = <3” von Marianne Spiller.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

More posts on the topic Icinga