ICINGA2 + Check WMI Plus でWindowsホストの監視(3)

今回は、ひととおり監視の設定が出来るようになったIcingaでメール通知の設定をします。

メール送信には mailx パッケージが必要なので、あらかじめインストールしておきます。

sudo yum -y install mailx


  1. ユーザーの作成
    メールの送信先となるユーザーを作成します。

    1. ユーザーテンプレートの作成
      まず、ユーザーテンプレートを作成する必要があります。
      Icinga Directorから、Users / Contacts を選択します。

    2. User templates を選択して、下記のようにユーザーテンプレートを作成します。

    3. ユーザーの作成

      再度 Users / Contacts を選択して、ユーザーを作成します。この中で、先ほど作成したユーザーテンプレートを指定します。


  2. Notification templateの作成

    次に、Notification templateを作成します。
    Icinga Directorから、Notification - Notification templates を選択して、Host template, Service template をそれぞれ作成します。

    必要に応じ、State and transition state filterを設定することで、通知する内容をフィルタすることが出来ます。

  3. Notificationの作成

    最後に、Notificationを作成します。
    Icinga Directorから、Notification - Notification templates を選択して、下記のように作成します。
    ここで、先ほど作成したNotification Templateを指定します。


以上をDeployすることで、通知が有効になります。

デフォルトでは、サーバがMXレコードを引きメールを送信しようとします。
SMTPサーバを指定したい場合は、スクリプトを修正する必要があります。

  • /etc/icinga2/scripts/mail-service-notification.sh
  • /etc/icinga2/scripts/mail-host-notification.sh

#!/usr/bin/env bash
#
# Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/)
# Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license

PROG="`basename $0`"
ICINGA2HOST="`hostname`"
MAILBIN="mail"

このMAILBINの内容に、SMTPサーバの指定を追加してしまいます。
MAILBIN="mail -S smtp=[smtpserver] "