以前設定した時のメモ:nagios3を入れてみた - Qiita
環境
- nagios-nrpe-server(監視される側): グローバルIP: 22.22.22.22
- nagios(監視する側): 192.168.5.5 グローバルIP: 33.33.33.33
監視される側にて実施
インストール
apt-get install -y nagios-nrpe-server nagios-nrpe-plugin
nagios-plugins
- /usr/lib/nagios/plugins/check_http/ 以下に
check_http
などが入る。- 後ほど出てくる
$USER1$
は上記PATH
- 後ほど出てくる
/etc/nagios/nrpe.cfgで定義されているcommand[xxxxx]を確認。
/etc/nagios/nrpe.cfg
-command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
+command[check_rootdir]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
nagios-nrpe-serverを起動
/etc/init.d/nagios-nrpe-server start
nagios-nrpe-serverが5666portで待ち受ける。
以下コマンドで情報を取得できることを確認。
/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
- 監視する側からの接続許可設定
/etc/nagios/nrpe.cfg
allowed_hosts=127.0.0.1,33.33.33.33
nagios-nrpe-serverを起動
/etc/init.d/nagios-nrpe-server restart
監視する側にて実施
nagios-nrpe-server(22.22.22.22)へ接続確認
以下コマンドで情報を取得できることを確認。
/usr/lib/nagios/plugins/check_nrpe -H 22.22.22.22 -c check_rootdir
nagios設定開始
nagios.cfgのcfg_dir=で指定されているディレクトリ内であれあば、どのファイルに記述してもよい。
ここでは cfg_dir=/etc/nagios3/servers/ とし、
- /etc/nagios3/servers/command.cfg
- /etc/nagios3/servers/hosts.cfg
- /etc/nagios3/servers/services.cfg
に記述するものとする。
command.cfg
define command{
command_name check_nrpe_2
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
hosts.cfg
define host{
use generic-host
host_name nrpe-server
address 22.22.22.22
contact_groups contact_all
}
services.cfg
define service{
use generic-service
host_name nrpe-server
service_description check_rootdir
check_command check_nrpe_2!check_rootdir
}
- check_command行の
check_rootdir
がcheck_nrpe_2
の$ARG1$
に入る。
動作確認
syntax check
sudo nagios3 -v /etc/nagios3/nagios.cfg
sudo /etc/init.d/nagios3 restart
web画面確認
にアクセスし、画面が見れることを確認。
監視される側に定義追加
/etc/nagios/nrpe.cfg
command[check_pop]=/usr/lib/nagios/plugins/check_pop -H localhost
command[check_spop]=/usr/lib/nagios/plugins/check_spop -H localhost
command[check_smtp]=/usr/lib/nagios/plugins/check_smtp -H localhost
command[check_smtp_587]=/usr/lib/nagios/plugins/check_smtp -H localhost -p 587
command[check_dns]=/usr/lib/nagios/plugins/check_dns -H google.co.jp
管理する側にcheck_commandを追加
間違い例
以下のように書くと一番下のcheck_dnsのみ有効になる。
define service{
use generic-service
host_name nrpe-server
service_description check_all
check_command check_nrpe_2!check_users
check_command check_nrpe_2!check_load
check_command check_nrpe_2!check_rootdir
check_command check_nrpe_2!check_zombie_procs
check_command check_nrpe_2!check_total_procs
check_command check_nrpe_2!check_pop
check_command check_nrpe_2!check_spop
check_command check_nrpe_2!check_smtp
check_command check_nrpe_2!check_smtp_587
check_command check_nrpe_2!check_dns
}
独自サービス定義
check_http_mod
azurewebsites.netの例
define host{
use custom-host
host_name hoge.azurewebsites.net
address 11.22.33.44
check_command return-ok
}
define command{
command_name check_http_hoge
command_line $USER1$/check_http -H $HOSTADDRESS$ -u $ARG1$
}
define service{
use generic-service
service_description http_hoge.azurewebsites.net
host_name hoge.azurewebsites.net
check_command check_http_hoge!hoge.azurewebsites.net/js/a.js
}