忘れるので書いておこう。
今回は遠隔サーバ(監視するサーバ)の設定です。
※Nagios 本体は tar から コンパイルして /usr/local/nagios にインストール済み。サーバ単体で localhost の監視を出来るのを確認する。
Nagios Addons から NSCA をダウンロード。
解凍
tar zxvf nsca-2.7.2.tar.gz
cd nsca-2.7.2
コンパイル
./configure
make all
インストール
cp src/send_nsca /usr/local/nagios/bin/
chown nagios.nagios /usr/local/nagios/bin/send_nsca
chmod 755 $_
cp sample-config/send_nsca.cfg /usr/local/nagios/etc/
chown nagios.nagios /usr/local/nagios/etc/send_nsca.cfg
chmod 640 $_
nagios 設定
# vi /usr/local/nagios/etc/nagios.cfg
enable_notifications=0
# このサーバからの警告発信を無効にする。
obsess_over_services=1
# 各サービスのチェック後コマンドを実行するオプション。使うコマンドは『ocsp_command』で設定。
ocsp_command=submit_check_result
# 実行するコマンド。『submit_check_result』 というコマンドを『/usr/local/nagios/etc/objects/commands.cfg』 に記載する。
vi /usr/local/nagios/etc/send_nsca.cfg
監視する側と設定を合わせる。
password=heoeoeoeoeojsasldfaas
encryption_method=3
『submit_check_result』 を作成する。
vi /usr/local/nagios/libexec/submit_check_result
#!/bin/sh
# NSCA サーバの IP アドレスを指定。
central_server="192.168.1.1"
# 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
;;
[0-2])
return_code=$3
;;
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
/usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_code" "$4" | /usr/local/nagios/bin/send_nsca $central_server -c /usr/local/nagios/etc/send_nsca.cfg
# chmod +x /usr/local/nagios/libexec/submit_check_result
『/usr/local/nagios/etc/objects/commands.cfg』に ocsp_command コマンド追加。
###############
# for nsca client
define command{
command_name submit_check_result
command_line /usr/local/nagios/libexec/submit_check_result $HOSTNAME$ ‘$SERVICEDESC$’ $SERVICESTATEID$ ‘$SERVICEOUTPUT$’
}
###############
引っかかったところ。
mcrypt-devel インストールしてないのでエラー。
→こんなエラー
[root@chiba_sv src]# /usr/local/nagios/bin/send_nsca -H example.com -c /usr/local/nagios/etc/send_nsca.cfg Invalid encryption method (3) in config file '/usr/local/nagios/etc/send_nsca.cfg' - Line 64 Client was not compiled with mcrypt library, so encryption is unavailable. Error: Config file '/usr/local/nagios/etc/send_nsca.cfg' contained errors...
php5-apache2 インストールしてない。( Vine 5.0 )
→ 左のメニューがリンク切れ、表示が変。
ホスト名 localhost から変更しなかったので、監視元サーバに認識されない。
→『/usr/local/nagios/etc/objects/localhost.cfg』のhost_name を監視元サーバと合わせないと、識別されないのでいつまでたっても監視元サーバに認識されない。
参考にさせていただいたサイト。(ありがとうございます!)
雑記録 – Nagios NSCAによる遠隔サーバの内部リソース監視
