Top/Nagios/NSCA

NSCAはてなブックマーク

Nagios Service Check Acceptor.
大規模ネットワークでの負荷分散や ファイアーウォール越えのためにあります。


DMS(Distributing Monitoring Server, 分散監視サーバー)
CMS(Central Monitoring Server, 中央監視サーバー)

CMS←DMS⇔監視対象
↑
DMS⇔監視対象


処理の流れは以下ような感じです。

DMSCMS
サービスチェック終了→ocspコマンド実行→send_nscaが送信→nscaが受信→外部コマンドファイルに書き出す→Nagiosが外部コマンドファイルを読む


以下

DMS172.16.0.1
CMS192.168.0.1

と仮定。


ダウンロード

インストール

まず、両者に共通して必要な暗号化ライブラリを入れます。
ダウンロード

インストール

tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make install

共有ライブラリを検索するパスを設定

vi /etc/ld.so.conf
/usr/local/lib
ldconfig

DMS*1へのインストール

Nagiosの設定

vi /usr/local/nagios/etc/nagios.cfg
enable_notifications=0
obsess_over_services=1
ocsp_command=submit_check_result
enable_notifications通知の有無
obsess_over_servicesサービスに付きまとうか(笑)
ocsp_commandocspコマンド

インストール

tar zxvf nsca-2.4.tar.gz
cd nsca-2.4
./configure
make all
cp src/send_nsca /usr/local/nagios/bin/
cp send_nsca.cfg /usr/local/nagios/etc/
chown nagios:nagios /usr/local/nagios/etc/send_nsca.cfg

send_nscaの設定

vi /usr/local/nagios/etc/send_nsca.cfg
passwd=任意
encryption_method=任意
passwdパスワード
encryption_method暗号化方法

ocspコマンドを定義する。

vi /usr/local/nagios/etc/checkcommands.cfg
define command{
        command_name        submit_check_result
        command_line        /usr/local/nagios/libexec/submit_check_result $HOSTNAME$ '$SERVICEDESC$' $SERVICESTATE$ '$OUTPUT$'
        }
vi /usr/local/nagios/libexec/submit_check_result
#!/bin/sh
# Arguments:
#  $1 = host_name (Short name of host that the service is
#       associated with)
#  $2 = svc_description (Description of the service)
#  $3 = state_string (A string representing the status of
#       the given service - "OK", "WARNING", "CRITICAL"
#       or "UNKNOWN")
#  $4 = plugin_output (A text string that should be used
#       as the plugin output for the service checks)
#
# Convert the state string to the corresponding return code
return_code=-1
case "$3" in
    OK)
        return_code=0
        ;;
        WARNING)
            return_code=1
        ;;
        CRITICAL)
            return_code=2
        ;;
        UNKNOWN)
            return_code=-1
        ;;
esac
# pipe the service check info into the send_nsca program, which
# in turn transmits the data to the nsca daemon on the central
# monitoring server
/bin/echo -e "$1\t$2\t$return_code\t$4\n" | /usr/local/nagios/bin/send_nsca -H 192.168.0.1 -c /usr/local/nagios/etc/send_nsca.cfg
chmod a+x /usr/local/nagios/libexec/submit_check_result 

CMS*2へのインストール

Nagiosの設定
accept_passive_service_checks=1になっているか確認。

vi /usr/local/nagios/etc/nagios.cfg
check_external_commands=1
check_external_commands外部コマンドをチェックするか

各ホストの設定をCMS側でもする。adressは不要。

vi /usr/local/nagios/etc/hosts.cfg

ホストに対するサービスの項目にactive_checks_enabled 0を追加。
一般設定がDMS用とCMSが直接監視する用とに分けてあれば、
分散監視用一般設定に書いてもOKでした!

vi /usr/local/nagios/etc/services.cfg
        active_checks_enabled           0
active_checks_enabledアクティブチェックが有効か無効か
  • もし、CMSが直接監視するホストを持たなければ、上記の代わりに
    vi /usr/local/nagios/etc/nagios.cfg
    execute_service_checks=0
    execute_service_checks起動した時にサービスチェックを実行するかどうか

記録ディレクトリの準備

mkdir /usr/local/nagios/var/rw

インストール

tar zxvf nsca-2.4.tar.gz
cd nsca-2.4
./configure
make all
cp src/nsca /usr/local/nagios/bin/
cp nsca.cfg /usr/local/nagios/etc/
chown nagios:nagios /usr/local/nagios/etc/nsca.cfg

nscaの設定

vi /usr/local/nagios/etc/nsca.cfg
aggregate_writes=1
append_to_file=1
passwd=任意
decryption_method=任意
aggregate_writesまとめて送られてきたデータをそのまま書き込む
append_to_file外部コマンドファイルに書き込む
passwdパスワード
decryption_method暗号化方法

サービスポート一覧に登録

vi +534 /etc/services
nsca            5667/tcp                        # NSCA

xinetdに登録

vi /etc/xinetd.d/nsca
# default: on
# description: NSCA
service nsca
{
        flags           = REUSE
        socket_type     = stream
        wait            = no
        user            = nagios
        group           = nagios
        server          = /usr/local/nagios/bin/nsca
        server_args     = -c /usr/local/nagios/etc/nsca.cfg --inetd
        log_on_failure  += USERID
        disable         = no
        only_from       = 172.16.0.1
}
/etc/rc.d/init.d/xinetd restart
tail /var/log/messages




tail /var/log/messages

libwrap refused connection to nsca from 

というエラーが出るときは、hosts.denyをチェック。

nsca:      ALL  EXCEPT 172.16.0.1

などとする。

ポート

TCP 5667

参考

Amazon

*1 Distributing Monitoring Server, 分散監視サーバー
*2 Central Monitoring Server, 中央監視サーバー
差分 一覧