Official Iptables Monitoring script tuning in Nagios

Source: Internet
Author: User

There is a script available on Nagios's official website to monitor the status of Iptables, but the official script is not directly available and needs to be modified in order to be used, as is the case here, because Nagios's command mechanism is run with Nagios users, Therefore, the official web-based script is not available before the adjustment is not normal use, the official website provides the Iptables monitoring script is simple, is the use of iptables instructions to count the real-time input on the number of bars, if the number of 1 is less than 0 alarm. However, the normal user is not able to use the iptables command, if you do not make adjustments in Nagios will appear nrpe:unable to read output error, so you need to adjust in the system, You need to add a sudo-free sudo permission to Nagios using the iptables command:

[Email protected] ~]# Visudo ... A little ... nagios all= (All) nopasswd:/sbin/iptables ... Slightly...

It is important to note here that before deploying Nagios, it is important to note that the user who created Nagios is a non-logged-on useradd-s parameter, so adding sudo permissions does not have a security risk, and finally the official script can be modified:

#!/bin/bash#you must add nagios permission to iptables in / etc  / sudoersstate_ok=0state_warning=1state_criticalll=2state_unknown=3chains=$ (sudo iptables  -nvL | grep  ' Chain '  | awk  ' { print $2 } ') For chain  in  $CHAINS  ; do    if [  "$CHAIN"  !=  ' FORWARD '  ] && [  "$CHAIN"  !=  ' OUTPUT '  ] && [ $ (expr  substr  $CHAIN  1 4)  !=  "Log_"  ] ; then         cnt=$ (expr $ (sudo iptables -s  $CHAIN  | wc -l)   '-'  1 '         if [  $CNT  -eq 0 ] ;  then            output= "${OUTPUT}ERROR  $CHAIN   $CNT  rules! "             echo  $OUTPUT              exit  $STATE _criticall         else            output= "${OUTPUT}OK   $CHAIN   $CNT  rules "            echo   $OUTPUT             exit  $STATE _ok         fi    fidone


This article from "Technical essay" blog, declined reprint!

Official Iptables Monitoring script tuning in Nagios

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.