iptablesの自動起動が有効化されていなかったせいで、先日サーバをリブートした後から、iptablesが起動していなかったorz
再発防止として、iptablesが起動しているかどうかの監視をNagiosで行うようにした。
反省と自戒の念を込めてメモしておく。
iptablesはpsで引っかからないので、check_procsが使えず少し手間取った。
調べてみると、
http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-rg-ja-4/s1-proc-directories.html に
ip_tables_names使用中のiptablesの種類を一覧表示します。
このファイルは、iptablesがシステム上でアクティブで、
次のような値を1つ以上含んでいる場合にのみ存在します: filter、mangle、又はnat。
とあったので、これをもとに下記のような監視スクリプトを書いて監視することにした。
# cat check_iptables.sh
# !/bin/sh
grep filter /proc/net/ip_tables_names > /dev/null 2>&1
RC=$?
if [ $RC -eq 0 ]; then
ST="running"
EX="0"
else
ST="stopped"
EX="2"
fi
echo "iptables is $ST"
exit $EX
あとは、nrpe.cfgに
command[check_iptables]=/home/nagios/script/check_iptables.sh
という形で仕込んで、
Nagiosサーバ側で監視設定を仕込んであげて完了。
define service {
host_name <監視ホスト名>
service_description IPTABLES-STAT
check_command check_nrpe!check_iptables
max_check_attempts 3
normal_check_interval 5
retry_check_interval 5
register 1
notification_options u,r,c
}
ちなみにzabbixなら標準で監視できるそうだ。
http://sfujiwara.hatenablog.com/entry/20120913/1347508926
