Unterschiede zwischen den Revisionen 1 und 2
Revision 1 vom 2019-01-01 21:53:20
Größe: 2996
Autor: phil
Kommentar: init
Revision 2 vom 2019-01-01 22:38:11
Größe: 8239
Autor: phil
Kommentar: XMPP-Benachrichtigungen
Gelöschter Text ist auf diese Art markiert. Hinzugefügter Text ist auf diese Art markiert.
Zeile 45: Zeile 45:

== Benachrichtigungen per XMPP ==
Standardmäßig ist Icinga 2 zum Versand von Benachrichtigungen per E-Mail konfiguriert. Der Versand von XMPP-Nachrichten ist im folgenden Beispiel im Wesentlichen eine Kopie der Mail-Konfiguration, ergänzt um die Angaben zum XMPP-Server und den zu nutzenden Accounts.
 * Zuerst legen wir ein Template an - {{{/etc/icinga2/conf.d/templates.conf}}}:{{{
template Notification "xmpp-host-notification" {
  command = "xmpp-host-notification"
  states = [ Up, Down ]
  types = [ Problem, Acknowledgement, Recovery, Custom,
            FlappingStart, FlappingEnd,
            DowntimeStart, DowntimeEnd, DowntimeRemoved ]
  period = "24x7"
}

template Notification "xmpp-service-notification" {
  command = "xmpp-service-notification"
  states = [ OK, Warning, Critical, Unknown ]
  types = [ Problem, Acknowledgement, Recovery, Custom,
            FlappingStart, FlappingEnd,
            DowntimeStart, DowntimeEnd, DowntimeRemoved ]
  period = "24x7"
}
}}}
 * Anschließend wird das ''NotificationCommand'' für Host- und Service-Nachrichten unter {{{/etc/icinga2/conf.d/commands.conf}}} definiert:{{{
object NotificationCommand "xmpp-host-notification" {
  command = [ SysconfDir + "/icinga2/scripts/xmpp-host-notification.sh" ]
  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    HOSTALIAS = "$host.display_name$"
    HOSTADDRESS = "$address$"
    HOSTSTATE = "$host.state$"
    LONGDATETIME = "$icinga.long_date_time$"
    HOSTOUTPUT = "$host.output$"
    NOTIFICATIONAUTHORNAME = "$notification.author$"
    NOTIFICATIONCOMMENT = "$notification.comment$"
    HOSTDISPLAYNAME = "$host.display_name$"
    XMPP_SENDER = XMPP_Sender
    XMPP_HOST = XMPP_Host
    XMPP_PASSWORD = XMPP_Password
    USERXMPPID = "$user.vars.xmppid$"
  }
}

object NotificationCommand "xmpp-service-notification" {
  command = [ SysconfDir + "/icinga2/scripts/xmpp-service-notification.sh" ]

  env = {
    NOTIFICATIONTYPE = "$notification.type$"
    SERVICEDESC = "$service.name$"
    HOSTALIAS = "$host.display_name$"
    HOSTADDRESS = "$address$"
    SERVICESTATE = "$service.state$"
    LONGDATETIME = "$icinga.long_date_time$"
    SERVICEOUTPUT = "$service.output$"
    NOTIFICATIONAUTHORNAME = "$notification.author$"
    NOTIFICATIONCOMMENT = "$notification.comment$"
    HOSTDISPLAYNAME = "$host.display_name$"
    SERVICEDISPLAYNAME = "$service.display_name$"
    XMPP_SENDER = XMPP_Sender
    XMPP_HOST = XMPP_Host
    XMPP_PASSWORD = XMPP_Password
    USERXMPPID = "$user.vars.xmppid$"
  }
}
}}}
 * Die Zugangsdaten für den XMPP-Account, über den die Nachrichten verschickt werden, werden zentral in der {{{/etc/icinga2/constants.conf}}} festgelegt:{{{
const XMPP_Sender = "monitor"
const XMPP_Host = "jabber.example.org"
const XMPP_Password = "Yw7bfKiHZbKcyrs3dxC"}}}
 * Die User-Konfiguration wird um die Variable ''xmppid'' ergänzt, die zur Angabe des jeweiligen XMPP-Accounts dient - {{{/etc/icinga2/conf.d/users.conf}}}:{{{
object User "Admin" {
  import "generic-user"
  email = "admin@example.org"
  vars.xmppid = "admin@jabber.example.org"
  groups = [ "admins" ]
}
}}}
 * Alle Hosts, für die XMPP-Nachrichten verschickt werden sollen, erhalten eine Variable, die später ausgewertet werden kann - {{{/etc/icinga2/conf.d/hosts.conf}}}:{{{
object Host NodeName {
  import "generic-host"
  address = "127.0.0.1"
  ...
  vars.notification["xmpp"] = {
    groups = [ "admins" ]
  }
}
}}}
 * Nun werden die Notification-Regeln erstellt - {{{/etc/icinga2/conf.d/notifications.conf}}}:{{{
apply Notification "xmpp-host" to Host {
  import "xmpp-host-notification"
  user_groups = host.vars.notification.xmpp.groups
  assign where host.vars.notification.xmpp
}

apply Notification "xmpp-service" to Service {
  import "xmpp-service-notification"
  user_groups = host.vars.notification.xmpp.groups
  assign where host.vars.notification.xmpp
}
}}}
 * Abschließend werden die Skripte zum eigentlichen Versand der Nachrichten angelegt - {{{/etc/icinga2/scripts/xmpp-host-notification.sh}}}:{{{
#!/usr/bin/env bash
template=$(cat <<TEMPLATE
***** Icinga *****

Notification Type: $NOTIFICATIONTYPE

Host: $HOSTALIAS
Address: $HOSTADDRESS
State: $HOSTSTATE

Date/Time: $LONGDATETIME

Additional Info: $HOSTOUTPUT

Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
TEMPLATE
)

/usr/bin/printf "%b" "$template" | /usr/bin/sendxmpp --file=/dev/null --ssl \
                "--username=$XMPP_SENDER" "--password=$XMPP_PASSWORD" "--jserver=$XMPP_HOST" "$USERXMPPID"
}}}
 * Für die Service-Nachrichten - {{{/etc/icinga2/scripts/xmpp-service-notification.sh}}}:{{{
#!/usr/bin/env bash
template=$(cat <<TEMPLATE
***** Icinga *****

Notification Type: $NOTIFICATIONTYPE

Service: $SERVICEDESC
Host: $HOSTALIAS
Address: $HOSTADDRESS
State: $SERVICESTATE

Date/Time: $LONGDATETIME

Additional Info: $SERVICEOUTPUT

Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
TEMPLATE
)

/usr/bin/printf "%b" "$template" | /usr/bin/sendxmpp --file=/dev/null --ssl \
                "--username=$XMPP_SENDER" "--password=$XMPP_PASSWORD" "--jserver=$XMPP_HOST" "$USERXMPPID"}}}

Diese Seite beschreibt die Installation und Ersteinrichtung der Monitoring-Software Icinga 2 und der Weboberfläche Icinga Web 2 und Debian Stretch.

Installation

  • Neben den eigentlichen Icinga-Paketen werden noch die Monitoring Plugins benötigt, welche die regelmäßigen Prüfungen ausführen:

    apt install icinga2 monitoring-plugins
  • Nach der Installation findest du eine Beispielkonfiguration zur Überwachung des eigenen Hosts unter /etc/icinga2/conf.d

  • Mit Hilfe von Icinga Web 2 kannst du die Ergebnisse der Prüfungen übersichtlich im Browser betrachten und Icinga darüber auch steuern
  • Für die Kommunikation zwischen Icinga 2 und der Weboberfläche wird der Icinga Data Output, kurz IDO, genutzt. Icinga 2 schreibt die durch die Prüfungen ermittelten Werte in eine Datenbank, die von der Weboberfläche ausgelesen wird. Nachfolgend wird die Installation mit einer MariaDB-Datenbank beschrieben:

    apt install icinga2-ido-mysql mariadb-server

Ersteinrichtung

  • Zuerst muss das IDO-Feature aktiviert und Icinga neu initialisiert werden:

    icinga2 feature list
    icinga2 feature enable ido-mysql
    systemctl reload icinga2
  • Icinga 2 besitzt eine API, die es ermöglicht, Icinga 2 über die Weboberfläche zu steuern. Die API wird mit Hilfe des Wizards eingerichtet:

    icinga2 api setup
  • Nun sollte ein API-Account mit eingeschränkten Rechten einrichtet werden, der von der Weboberfläche genutzt wird. Diese wird in der Datei /etc/icinga2/confd/api-users.conf definiert. Da dieser API-Account keinen Vollzugriff benötigt, werden seine Zugriffsrechte beschränkt:

    object ApiUser "icingaweb2" {
      password = "Ultr4!Sich3r3s:P4ssw0rt"
      permissions = [
        "status/query",
        "actions/*",
        "objects/modify/*",
        "objects/query/*"
      ]
    }
  • Nun kann Icinga Web 2 installiert werden:

    apt install icingaweb2 icingacli php-curl
  • Für PHP benötigt Icinga Web 2 eine gesetzte Zeitzone. Diese kann in der entsprechenden php.ini, bspw. unter /etc/php/7.0/apache2/php.ini angegeben werden:

    date.timezone = Europe/Berlin
  • Nach dem Aufruf der Weboberfläche unter /icingaweb2 kann der Einrichtungsassistent gestartet werden. Dieser verlangt die Authentifizierung mittels eines Tokens. Dies wird auf der Kommandezeile erzeugt:

    icingai setup token create;
  • Nun müssen im Einrichtungsassistenten einige Angaben gemacht werden. Unter Database Ressource werden die Informationen zur Account-Datenbank angegeben. Diese muss vor dem nächsten Schritt noch manuell angelegt werden, bspw:

    CREATE  DATABASE icingaweb2;
    
    GRANT ALL ON icingaweb2.* TO 'incgaweb2'@'localhost' IDENTIFIED BY 'N0ch-3in_Ultr4!Sich3r3s:P4ssw0rt';
  • Beim Schritt Command Transport werden die Daten zum kürzlich angelegten API-Account eingetragen.

Benachrichtigungen per XMPP

Standardmäßig ist Icinga 2 zum Versand von Benachrichtigungen per E-Mail konfiguriert. Der Versand von XMPP-Nachrichten ist im folgenden Beispiel im Wesentlichen eine Kopie der Mail-Konfiguration, ergänzt um die Angaben zum XMPP-Server und den zu nutzenden Accounts.

  • Zuerst legen wir ein Template an - /etc/icinga2/conf.d/templates.conf:

    template Notification "xmpp-host-notification" {
      command = "xmpp-host-notification"
      states = [ Up, Down ]
      types = [ Problem, Acknowledgement, Recovery, Custom,
                FlappingStart, FlappingEnd,
                DowntimeStart, DowntimeEnd, DowntimeRemoved ]
      period = "24x7"
    }
    
    template Notification "xmpp-service-notification" {
      command = "xmpp-service-notification"
      states = [ OK, Warning, Critical, Unknown ]
      types = [ Problem, Acknowledgement, Recovery, Custom,
                FlappingStart, FlappingEnd,
                DowntimeStart, DowntimeEnd, DowntimeRemoved ]
      period = "24x7"
    }
  • Anschließend wird das NotificationCommand für Host- und Service-Nachrichten unter /etc/icinga2/conf.d/commands.conf definiert:

    object NotificationCommand "xmpp-host-notification" {
      command = [ SysconfDir + "/icinga2/scripts/xmpp-host-notification.sh" ]
      env = {
        NOTIFICATIONTYPE = "$notification.type$"
        HOSTALIAS = "$host.display_name$"
        HOSTADDRESS = "$address$"
        HOSTSTATE = "$host.state$"
        LONGDATETIME = "$icinga.long_date_time$"
        HOSTOUTPUT = "$host.output$"
        NOTIFICATIONAUTHORNAME = "$notification.author$"
        NOTIFICATIONCOMMENT = "$notification.comment$"
        HOSTDISPLAYNAME = "$host.display_name$"
        XMPP_SENDER = XMPP_Sender
        XMPP_HOST = XMPP_Host
        XMPP_PASSWORD = XMPP_Password
        USERXMPPID = "$user.vars.xmppid$"
      }
    }
    
    object NotificationCommand "xmpp-service-notification" {
      command = [ SysconfDir + "/icinga2/scripts/xmpp-service-notification.sh" ]
    
      env = {
        NOTIFICATIONTYPE = "$notification.type$"
        SERVICEDESC = "$service.name$"
        HOSTALIAS = "$host.display_name$"
        HOSTADDRESS = "$address$"
        SERVICESTATE = "$service.state$"
        LONGDATETIME = "$icinga.long_date_time$"
        SERVICEOUTPUT = "$service.output$"
        NOTIFICATIONAUTHORNAME = "$notification.author$"
        NOTIFICATIONCOMMENT = "$notification.comment$"
        HOSTDISPLAYNAME = "$host.display_name$"
        SERVICEDISPLAYNAME = "$service.display_name$"
        XMPP_SENDER = XMPP_Sender
        XMPP_HOST = XMPP_Host
        XMPP_PASSWORD = XMPP_Password
        USERXMPPID = "$user.vars.xmppid$"
      }
    }
  • Die Zugangsdaten für den XMPP-Account, über den die Nachrichten verschickt werden, werden zentral in der /etc/icinga2/constants.conf festgelegt:

    const XMPP_Sender = "monitor"
    const XMPP_Host = "jabber.example.org"
    const XMPP_Password = "Yw7bfKiHZbKcyrs3dxC"
  • Die User-Konfiguration wird um die Variable xmppid ergänzt, die zur Angabe des jeweiligen XMPP-Accounts dient - /etc/icinga2/conf.d/users.conf:

    object User "Admin" {
      import "generic-user"
      email = "admin@example.org"
      vars.xmppid = "admin@jabber.example.org"
      groups = [ "admins" ]
    }
  • Alle Hosts, für die XMPP-Nachrichten verschickt werden sollen, erhalten eine Variable, die später ausgewertet werden kann - /etc/icinga2/conf.d/hosts.conf:

    object Host NodeName {
      import "generic-host"
      address = "127.0.0.1"
      ...
      vars.notification["xmpp"] = {
        groups = [ "admins" ]
      }
    }
  • Nun werden die Notification-Regeln erstellt - /etc/icinga2/conf.d/notifications.conf:

    apply Notification "xmpp-host" to Host {
      import "xmpp-host-notification"
      user_groups = host.vars.notification.xmpp.groups
      assign where host.vars.notification.xmpp
    }
    
    apply Notification "xmpp-service" to Service {
      import "xmpp-service-notification"
      user_groups = host.vars.notification.xmpp.groups
      assign where host.vars.notification.xmpp
    }
  • Abschließend werden die Skripte zum eigentlichen Versand der Nachrichten angelegt - /etc/icinga2/scripts/xmpp-host-notification.sh:

    template=$(cat <<TEMPLATE
    ***** Icinga  *****
    
    Notification Type: $NOTIFICATIONTYPE
    
    Host: $HOSTALIAS
    Address: $HOSTADDRESS
    State: $HOSTSTATE
    
    Date/Time: $LONGDATETIME
    
    Additional Info: $HOSTOUTPUT
    
    Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
    TEMPLATE
    )
    
    /usr/bin/printf "%b" "$template" | /usr/bin/sendxmpp --file=/dev/null --ssl \
                    "--username=$XMPP_SENDER" "--password=$XMPP_PASSWORD" "--jserver=$XMPP_HOST" "$USERXMPPID"
  • Für die Service-Nachrichten - /etc/icinga2/scripts/xmpp-service-notification.sh:

    template=$(cat <<TEMPLATE
    ***** Icinga  *****
    
    Notification Type: $NOTIFICATIONTYPE
    
    Service: $SERVICEDESC
    Host: $HOSTALIAS
    Address: $HOSTADDRESS
    State: $SERVICESTATE
    
    Date/Time: $LONGDATETIME
    
    Additional Info: $SERVICEOUTPUT
    
    Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
    TEMPLATE
    )
    
    /usr/bin/printf "%b" "$template" | /usr/bin/sendxmpp --file=/dev/null --ssl \
                    "--username=$XMPP_SENDER" "--password=$XMPP_PASSWORD" "--jserver=$XMPP_HOST" "$USERXMPPID"

Icinga 2 unter Debian installieren (zuletzt geändert am 2021-05-26 14:33:09 durch anonym)


Creative Commons Lizenzvertrag
This page is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.