403Webshell
Server IP : 172.64.80.1  /  Your IP : 216.73.216.175
Web Server : LiteSpeed
System : Linux srv13.swhc.ca 4.18.0-553.126.2.lve.el8.x86_64 #1 SMP Thu May 28 14:12:30 UTC 2026 x86_64
User : hongluck ( 2522)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib64/nagios/plugins/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib64/nagios/plugins/check_disk_inodes
#!/bin/bash
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

PROGNAME=`basename $0`
VERSION="version 0.93"
AUTHOR="by Radu MARINESCU [email protected]"
#############################
# Program paths. If left empty the script tries to find the programs
# in the PATH. Fill in the correct paths only if needed.
#############################
#usually /bin/awk or /usr/bin/awk
AWK=""
#usually /bin/grep or /usr/bin/grep
GREP=""
#usually /bin/df
DF=""
#############################

if [ ${#AWK} == 0 ] #the variable AWK is not defined; trying to find awk in the PATH
then
	AWK=`which awk 2>&1`
	AWK_EXISTS=$?
	if [ "$AWK_EXISTS" != 0 ] || [ ${#AWK} == 0 ] #awk is not in the PATH or the variable AWK is empty
	then
		echo "Error! Can't find awk."
		exit 3
	fi	
fi

if [ ${#GREP} == 0 ] #the variable GREP is not defined; trying to find grep in the PATH
then
	GREP=`which grep 2>&1`
	GREP_EXISTS=$?
	if [ "$GREP_EXISTS" != 0 ] || [ ${#GREP} == 0 ] #grep is not in the PATH or the variable GREP is empty
	then
		echo "Error! Can't find grep."
		exit 3
	fi	
fi

if [ ${#DF} == 0 ] #the variable DF is not defined; trying to find df in the PATH
then
	DF=`which df 2>&1`
	DF_EXISTS=$?
	if [ "$DF_EXISTS" != 0 ] || [ ${#DF} == 0 ] #df is not in the PATH or the variable DF is empty
	then
		echo "Error! Can't find df."
		exit 3
	fi	
fi


#############################
# Functions
#############################

print_version() {
    echo "$VERSION $AUTHOR"
}


print_help() {
print_version $PROGNAME $VERSION
echo ""
echo "$PROGNAME is a Nagios plugin that you can yse to check the number"
echo "of used inodes on a disk. It processes the output of \"df\" command"
echo "It runs on UNIX, Linux and BSD platforms and reports the following"
echo "performance data:"
echo "- total disk inodes"
echo "- currently used inodes"
echo "- currently used inodes in percents (%)"
echo " "
echo "$PROGNAME [-v] [-h] [-w UsedInodesWarning] [-c UsedInodesCritical] [-p Partition]"
echo " "
echo "Options:"
echo "  --version|-v)"
echo "    prints the program version"
echo "  --help|-h)"
echo "    prints this help information"
echo "  -w)"
echo "    warning threshold (in percents without % sign) for used inodes"
echo "  -c)"
echo "    critical threshold (in percents without % sign) for used inodes"
echo "  -p)"
echo "    disk partition to check"
echo " "
exit 3
}


# float number comparison
function fcomp() {
    $AWK -v n1=$1 -v n2=$2 'BEGIN{ if (n1<=n2) exit 0; exit 1}'
}

#############################


if [ $# -lt 1 ]; then
    print_help
    exit 3
fi

while test -n "$1"; do
    case "$1" in
        --help|-h)
            print_help
            exit 3
            ;;
        --version|-v)
            print_version $PROGNAME $VERSION
            exit 3
            ;;
        -w)
            WarnInodes=$2
            shift
            ;;
        -c)
            CritInodes=$2
            shift
            ;;
        -p)
            Partition=$2
            shift
            ;;
        *)
            echo "Unknown argument: $1"
            print_help
            exit 3
            ;;
    esac
    shift
done

if [ ${#Partition} == 0 ]
	then
		echo "Error! You must specify a partition to check! Example: /var or / or /home"
		exit 3
fi

if fcomp $WarnInodes 0
then
    WarnInodes=0
fi
if fcomp 100 $WarnInodes
then
    WarnInodes=100
fi

if fcomp $CritInodes 0
then
    CritInodes=0
fi
if fcomp 100 $CritInodes
then
    CritInodes=100
fi

if fcomp $CritInodes $WarnInodes
then
    WarnInodes=$CritInodes
fi


USEDTXT=`$DF -Pi $Partition 2>&1`
if [ $? != 0 ]
then
	echo "Error! Disk partition $Partition can't be checked. Does it exist?"
	exit 3
fi

InodesTxt=`echo "$USEDTXT" | $GREP "${Partition}\$"`
InodesTotal=`echo "$InodesTxt" | $AWK '{print $2}'`
InodesUsed=`echo "$InodesTxt" | $AWK '{print $3}'`
InodesFree=`echo "$InodesTxt" | $AWK '{print $4}'`
InodesUsedProc=`echo "$InodesTxt" | $AWK '{printf "%.1f", $3*100/$2}'`
InodesFreeProc=`echo "$InodesTxt" | $AWK '{printf "%.1f", $4*100/$2}'`

WarnInodesAbs=`echo "$WarnInodes $InodesTotal" | $AWK '{printf "%d", $2*$1/100}'`
CritInodesAbs=`echo "$CritInodes $InodesTotal" | $AWK '{printf "%d", $2*$1/100}'`

PerfData="'used inodes'=${InodesUsed};${WarnInodesAbs};${CritInodesAbs};0;${InodesTotal} 'used inodes (pct.)'=${InodesUsedProc}%;${WarnInodes};${CritInodes};0;100"

if fcomp $InodesUsedProc $WarnInodes
then
    echo "OK; $Partition: total inodes ${InodesTotal}, used ${InodesUsed} (${InodesUsedProc}%), free ${InodesFree} (${InodesFreeProc}%) | $PerfData"
    exit 0
fi

if fcomp $WarnInodes $InodesUsedProc && fcomp $InodesUsedProc $CritInodes
then
    echo "Warning; $Partition: total inodes ${InodesTotal}, used ${InodesUsed} (${InodesUsedProc}%>${WarnInodes}%), free ${InodesFree} (${InodesFreeProc}%) | $PerfData"
    exit 1
fi

if fcomp $CritInodes $InodesUsedProc
then
    echo "CRITICAL; $Partition: total inodes ${InodesTotal}, used ${InodesUsed} (${InodesUsedProc}%>${CritInodes}%), free ${InodesFree} (${InodesFreeProc}%) | $PerfData"
    exit 2
fi

#otherwise ... UNKNOWN
echo "UNKNOWN; $Partition: total inodes ${InodesTotal}, used ${InodesUsed} (${InodesUsedProc}%), free ${InodesFree} (${InodesFreeProc}%) | $PerfData"
exit 3

Youez - 2016 - github.com/yon3zu
LinuXploit