9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Nagiosでiptablesの状態監視をする。

Last updated at Posted at 2015-01-29

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
         }

設定完了するとこんな感じに、
iptables監視.png

ちなみにzabbixなら標準で監視できるそうだ。
http://sfujiwara.hatenablog.com/entry/20120913/1347508926

9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?