温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nagios 实时监控 iptables 状态

发布时间:2020-08-04 08:18:07 来源:网络 阅读:683 作者:lichaoshan 栏目:移动开发

    实时监控Iptables,防止人为关闭后,忘了开启,或者监控规则是否有增删。

在客户端(被监控端):

# cd /usr/local/nagios/etc

# vim nrpe.cfg 增加如下内容:

command[check_iptables]=/usr/local/nagios/libexec/check_iptables.sh

# cd /usr/local/nagios/libexec

# touch check_iptables.sh

# chmod 755 check_iptables.sh

# chown nagios:nagios check_iptables.sh

# vim check_iptables.sh ;增加如下内容:

---------------------------------

#!/bin/bash
local_iptables_md5="975fe1cb63de080b470a1073bebb0f56"  //首先获取iptables 开启状态下的MD5值
check_iptables_md5=`sudo /sbin/iptables -n -t filter -L|md5sum|awk '{print $1}'`
if [ $local_iptables_md5 == $check_iptables_md5 ]; then
        echo "OK - Iptables is OK"
        exit 0
else
        echo "CRITICAL - Iptables is CRITICAL"
        exit 2
fi

---------------------------------

脚本说明:先获取iptables的值,然后对比现在的值,如果一样,说明iptables状态正常,否则报异常;


# visudo  增加如下内容:

nagios ALL= NOPASSWD: /sbin/iptables -n -t filter -L

注:脚本调用了iptables命令,iptables默认只允许root调用,所有需要修改sudo。以上语句,表示只允许nagios用户不用密码使用该条命令。


在服务端(监控端):

在监控配置文件里新增如下内容:

define service {
        use                  web-service
        host_name             ip address
        service_description   iptables_status
        check_command           check_nrpe!check_iptables
        }

最后检测配置并重启nagios。


可能遇到的问题:

Status Information:

CRITICAL - Iptables are CRITICAL The Table filter and Chain has 0 rules configured

解决办法:

# visudo

找到 “Defaults    requiretty”字样,然后更改为:

Defaults:nagios    !requiretty

保存退出,即可!



向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI