2 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
5 PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
21 echo "Usage: $PROGNAME -C CHAIN -t TABLE"
22 echo "Usage: $PROGNAME --help"
23 echo "Usage: $PROGNAME --version"
27 print_revision $PROGNAME $VERSION
31 echo "This plugin tests if iptables has needed amount of rules loaded"
35 echo " Chain to list. Default: $chain"
37 echo " Table to list. Default: $table"
39 echo " Install sudo rules"
41 echo " Enable verbose run"
43 echo " Print this help screen"
45 echo " Print version and license information"
53 new=/etc/sudoers.$$.new
55 cat /etc/sudoers > $new
58 # Lines matching CHECK_IPTABLES added by $0 $ARGS on $(date)
59 User_Alias CHECK_IPTABLES=nagios
60 CHECK_IPTABLES ALL=(root) NOPASSWD: $list_iptables
63 if visudo -c -f $new; then
64 mv -f $new /etc/sudoers
72 # if running as root, skip sudo
73 [ "$(id -u)" != 0 ] || sudo=
75 $sudo $list_iptables | grep -Fc /
78 while [ $# -gt 0 ]; do
91 print_revision $PROGNAME $VERSION
96 print_revision $PROGNAME $VERSION
125 echo >&2 "Unknown argument: $1"
135 list_iptables="$iptables -n -t $table -L $chain"
137 if [ "$setup_sudo" = 1 ]; then
141 count=$(list_iptables)
142 if [ "$count" -lt "$critical" ]; then
145 elif [ "$count" -lt "$warning" ]; then
153 echo "$state: $count iptables rules in $chain chain of $table table"