Seite wählen

Icinga 2 Notifications manuell testen

von | 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 Kommentare

Trackbacks/Pingbacks

  1. Monthly Snap September >Starface, Elasticsearch, OSBConf, Icinga 2 Notifications, RSpec Colleagues › NETWAYS Blog - […] demonstrated manual tests of Icinga 2 Notifications and Daniela, Pamela and Markus Waldmüller reviewed the OSBConf […]

Einen Kommentar abschicken

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Mehr Beiträge zum Thema Icinga