nagios3をubuntuにインストールしてみた(その2)

Nagios 3.0.6の設定ファイルは、/etc/nagios3 以下にある。
/etc/nagios3/conf.d/ ディレクトリ内にあるファイルが
contact, contact_group
service, service_group
host, host_group
timeperiod
などを定義している。
このあたりの関係を理解するのに実は土曜日までかかった(^^;)

  • 【command定義例】

指定したホストに対してHTTPリクエストを行い結果をチェックする
(-p ポート番号 -H ホスト名[又はIPアドレス] -u URL[デフォルトは/] -w ワーニング応答秒数 -c クリティカル応答秒数 -s 応答コンテンツに含まれる文字列[応答結果のエラー判定のため])
command_name が他定義ファイルから指定される名前
(xxxx_name というのが一意に定義される名前となる。重複してはいけない)
command_line が実際に発行されるコマンド

define command{
command_name check_httpcvnet
command_line $USER1$/check_http -p 8088 -H $HOSTADDRESS$ -u $ARG1$ -w $ARG2$ -c $ARG3$ -s $ARG4$
}

  • 【contact定義例】

障害発生時の通知先がcontactで、複数のcontactをまとめたグループを定義してるのがcontact_group
contact_name が定義名
alias がメモ的なもの
email が実際の通知先
contact_groupは必ずしも定義する必要はないが、複数に通知する場合はあったほうがいい。

define contact{
contact_name cvnet-alert1
alias Alert mail1
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email xxxxxx@xxxxx.co.jp
}

define contactgroup{
contactgroup_name cvnet-group
alias CV.net Alert members
members cvnet-alert1, cvnet-alert2
}

  • 【host定義例】

実際にチェックするのはserviceで定義するが、あるホスト(IP)に対してserviceを定義するという形なので必須。
host_name が定義名
alias がメモ的なもの
address が実際のホスト(or IPアドレス)
check_command がホストをチェックするためのコマンド
host_group は定義する必要無いが、NagiosのWeb画面で見るときにちょっと便利になる

define host{
host_name saas-server
alias CV.net saas server
address xxxx.xxxxxx.co.jp
check_command check-host-alive
max_check_attempts 10
notification_interval 0
notification_period 24x7
notification_options d,u,r
}

define hostgroup{
hostgroup_name Cvnet
alias CV.net servers
members saas-server, ap01-server
}

  • 【service定義例】

実際にチェックしたいURLを定義する
service_description が定義名
host_name はそのサービスを提供しているホスト
display_name がWeb画面などで表示される名前
servicegroups は定義する必要ないが、NagiosのWeb画面で見るときにちょっと便利になる
normal_check_interval がチェック間隔の秒数
contact_groups か contacts に通知先(複数ある場合は,で区切る)
check_command にチェックしたいURLなどを指定(command定義の内容に合わせる)
!で区切った文字列が$ARG1$、$ARG2$、... となる。特殊記号が入る場合には'を使う

define service{
host_name ap01-server
service_description ap01-user13
display_name ap01-Server user13-test
servicegroups ap01
check_period 24x7
max_check_attempts 1
normal_check_interval 30
retry_check_interval 1
contact_groups cvnet-group
notification_interval 0
notification_period 24x7
notification_options w,u,c,r
check_command check_httpcvnet!'/cv.net_user13/xxxx/login.aspx?xxx1=0&xxx2=xxxx&xxx3=xxx&xx4=xxx'!1!3!"OK"
}

define servicegroup{
servicegroup_name ap01
alias ap01 server (for development section)
}


という形で定義していく。標準で入っている定義ファイルは上の定義が各ファイルに別れているが、
同じファイル上にあったほうがわかりやすいので新規で /etc/nagios3/conf.d/ ディレクトリに
ファイルを作り定義すると良い。

また、notify-service-by-email とnotify-host-by-email の定義は /etc/nagios3/commnads.cfg にアルので、変更したい場合には書き換えるか、内容をコピーして定義名を変えて使う。
日本語(EUCコード)も可能らしい。(未確認)