标签:style blog io color ar os for sp div
#!/bin/bash PROGNAME=`basename $0` VERSION="Version 1.0," AUTHOR="Phoenix" # include config DIR=$(/usr/bin/dirname $0) . $DIR/utils.sh print_version() { echo "$VERSION $AUTHOR" } print_help() { print_version $PROGNAME $VERSION echo "" echo "$PROGNAME is a Nagios plugin to monitor a specific dir whether has more than optional warning/critical thresholds file numbers" echo "" echo "$PROGNAME -d/--dir [-t/--type] [-w/--warning] [-c/--critical]" echo "" echo "Options:" echo " --dir|-d)" echo " Defines the dir which to be dectected." echo " --warning|-w)" echo " Sets a warning thresholds" echo " --critical|-c)" echo " Sets a critical thresholds" echo " --type|-t)" echo " Detection type: default type is f" echo " b block (buffered) special" echo " c character (unbuffered) special" echo " d directory" echo " p named pipe (FIFO)" echo " f regular file" echo " l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic" echo " link is broken. If you want to search for symbolic links when -L is in effect, use -xtype." echo " s socket" echo " D door (Solaris)" echo $STATE_UNKNOWN } type="f" while test -n "$1"; do case "$1" in --help|-h) print_help exit $STATE_UNKNOWN ;; --version|-v) print_version $PROGNAME $VERSION exit $STATE_UNKNOWN ;; --dir|-d) dir=$2 shift ;; --type|-t) type=$2 shift ;; --warning|-w) warn=$2 shift ;; --critical|-c) crit=$2 shift ;; *) echo "Unknown argument: $1" print_help exit $STATE_UNKNOWN ;; esac shift done if [[ "m$dir" == "m" ]]; then echo "Error: Arg -d/--dir needed!" exit $STATE_UNKNOWN fi val_wcdiff() { if [ ${warn} -gt ${crit} ] then wcdiff=1 fi } if [ -n "$warn" -a -n "$crit" ] then val_wcdiff if [ "$wcdiff" = 1 ] then echo "Please adjust your warning/critical thresholds. The warning must be lower than the critical!" exit $STATE_UNKNOWN fi fi if [ -d $dir ]; then filenum=$(find $dir -maxdepth 1 -type $type | wc -l) else echo "Error: Dir $dir not exist!" exit $STATE_UNKNOWN fi output="Dir: $dir, FileNum: $filenum" perfdata="filenum=$filenum;$warn;$crit" if [ -n "$warn" -a -n "$crit" ] then gtwarn=$(echo "$filenum > $warn" | bc) gtcrit=$(echo "$filenum > $crit" | bc) if [[ $gtwarn -eq 1 && $gtcrit -eq 0 ]] then echo "WARNING - ${output} | ${perfdata}" exit $STATE_WARNING elif [[ $gtcrit -eq 1 ]] then echo "CRITICAL - ${output} | ${perfdata}" exit $STATE_CRITICAL else echo "OK - ${output} | ${perfdata}" exit $STATE_OK fi else echo "OK - ${output} | ${perfdata}" exit $STATE_OK fi
标签:style blog io color ar os for sp div
原文地址:http://www.cnblogs.com/cornell/p/4071886.html