首页 > 代码库 > 123

123

#!/bin/bashPROGNAME=`basename $0`VERSION="Version 1.0,"AUTHOR="Phoenix"# include configDIR=$(/usr/bin/dirname $0). $DIR/utils.shprint_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    shiftdoneif [[ "m$dir" == "m" ]]; then    echo "Error: Arg -d/--dir needed!"    exit $STATE_UNKNOWNfival_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    fifiif [ -d $dir ]; then    filenum=$(find $dir -maxdepth 1 -type $type | wc -l)else    echo "Error: Dir $dir not exist!"    exit $STATE_UNKNOWNfioutput="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    fielse    echo "OK - ${output} | ${perfdata}"    exit $STATE_OKfi

123