Nagios の設定をしよう、そうしよう。
Linuxに乗せるアプリって、やたら設定が面倒で分かりにくかったりする。CUI なんだから我慢しろって話ですが。ApacheとかSambaとか、設定のやりづらさが敷居を高くしてる気がする。
で、Nagios の設定は、/usr/local/nagios/etc/ 以下のサンプルファイルをコピーして、必要なところを書き換える形で行う。いらないところは、鬼のように削除。サンプル残ってるから、コメントアウトなんかしてあげない。(ここはポリシーの問題です)
■nagios.cfg (以下の行をコメントアウトにしてやった)
#cfg_file=/usr/local/nagios/etc/dependencies.cfg #cfg_file=/usr/local/nagios/etc/escalations.cfg
■hosts.cfg (監視ホストの設定)
# 'hoge' host definition
define host{
use generic-host
host_name hoge
alias hoge
address 192.168.0.10
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24x7
notification_options d,u,r
}
■hostgroups.cfg (監視ホストのグループ分け)
define hostgroup {
hostgroup_name HogeNet
alias HogeNet
contact_groups nagios
members hoge
}
■contacts.cfg (障害メールの送信先)
# 'nagios' contact definition
define contact{
contact_name nagios
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email,notify-by-epager
host_notification_commands host-notify-by-email,host-notify-by-epager
email hoge@deftrash.com
pager hoge@deftrash.com
}
■contactgroup.cfg (管理者のグループ分け)
# 'nagios' contact definition
define contact{
define contactgroup{
contactgroup_name nagios
alias Nagios Admin
members nagios
}
■services.cfg (監視サービスの設定) ※抜粋
# Service definition
define service{
use generic-service
host_name hoge
service_description FTP
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 10
retry_check_interval 1
contact_groups nagios
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
check_command check_ftp
}
services.cfg とか hosts.cfg の冒頭にある定義はシステムが使うようなんで、イジらない。まあ、他を寄せ付けないモード全開なので大丈夫だと思うけど。とりあえず、2つ目以降をうまいこと書き換えるべし。
上記以外のものについては、サンプルをコピーしてそのまま使うことにした。escalations.cfg と dependencies.cfg は使用しないので、コピーすらしなかった。基本的に、いらないことはしない。そこらへん、大人ですから。
すべての設定が終わったら、妥当性チェックを行う。Warning や Error が出たら、修正をする。
# /usr/local/nagios/bin/nagios -v /usr/loval/nagios/etc/nagios.cfg
services.cfg の書き間違いや項目不備でエラーが出ることが多いかと。ちなみに、うちは nagios.cfg でcheckcommands.cfg の行を間違って削除していて、エラー出まくって焦った。だから、余計なことはしちゃいけないんです。ということで、似たようなエラーが大量に出たら、nagios.cfg を怪しんだ方が良いでしょう。
