ホスト名/IPを指定せずにサブネット内のすべてのホストをicingaモニタリングに追加する

ホスト名/IPを指定せずにサブネット内のすべてのホストをicingaモニタリングに追加する

プロビジョニング システムで、ドメイン test.domain.local に新しいホスト ( ) を設定する予定です。またclient44.test.domain.local、 などの正規表現を使用して、これらすべてのホストを自動的に監視したい Icinga サーバーがあります*.test.domain.local

すべてのクライアントはnagios-nrpe-server(バージョン 2.13-3) パッケージを取得します。このパッケージは、icinga-server がクライアントからデータを取得できるように構成されており、動作することが確認されています。

今のところは、SSH、ping への応答など、すべてのノードが持つことがわかっているサービス/項目を監視します。

私は見てきましたこのリンクしかし、ホスト、ホストグループ、サービス クラス間の関係がよくわかりません。

Icinga サーバーとすべてのクライアントは両方とも Debian を実行します。

答え1

私は fredmu と協力してこの問題に取り組んできましたが、Tim Brigham の回答にヒントを得て実用的な解決策を思いつきました。

デフォルトのgeneric-host定義を使用すると、テンプレートに基づいてホスト構成ファイルを自動的に生成するスクリプトを使用してこの問題を解決できます。オプションで、これらのファイルを定期的に生成する cronjob として実行することもできます。

生成ホストcfg.sh

#!/usr/bin/env bash

icinga_root="/etc/icinga/objects"
subnet="10.0.0.*"
template="template_icinga.cfg"
alias_file="alias.txt"

# navigate to the Icinga configuration directory
cd $icinga_root

# create first server alias if doesn't exist
if [ ! -e $alias_file ]; then
    echo "1" > $alias_file
fi

# iterate through subnet, store "hostname:ip" in associative array
declare -A address

for host in $(nmap -sP $subnet | awk -F '[ ()]' '/for [a-z]+/ {print $5 ":" $7}'); do
    address[$(echo $host | cut -d: -f1)]=$(echo $host | cut -d: -f2)
done

# iterate through hosts, create files if not exist based off template
for host in ${!address[@]}; do
    host_file=${host}_icinga.cfg

    if [ ! -e $host_file ]; then
        # fetch new server alias
        alias=$(cat $alias_file)

        # create the next server alias
        expr $alias + 1 > $alias_file

        # create hostname_icinga.cfg if doesn't exist, based off template
        cp $template $host_file

        # replace contents of new template; hostname, alias and ip
        sed -i -r \
            -e "s/tmp-hostname/$host/" \
            -e "s/tmp-alias/Server$alias/" \
            -e "s/tmp-address/${address[$host]}/" $host_file
    fi

done

テンプレート_icinga.cfg

define host{
        use                     generic-host
        host_name               tmp-hostname
        alias                   tmp-alias
        address                 tmp-address
        }

結果として、次のようなファイルが作成されます。

define host{
        use                     generic-host
        host_name               monitor.company.local
        alias                   Server1
        address                 10.0.0.1
        }

答え2

これに対処する方法はたくさんあります。

以前、単一の icinga チェックとして実行される bash スクリプトを作成しました。スクリプトはサブドメイン内のすべてのホストをチェックし、障害が見つかったかどうか、または見つかった障害の数に基づいて状態を返します。

最近、私は Puppet のカスタム ファクトのファンになりました。よく書かれたテンプレートと組み合わせると、for ループを使用して多数のノードにチェックを簡単に追加できます。

関連情報