#!/bin/sh # # ## Plugin for Nagios to monitor the user quota # ## Written by Muthukumar Krithivasan # # # ## You are free to use this script under the terms of the Gnu Public License. # ## I make no guarantee as to whether this will harm anything, much less work # ## - use at your own risk. # # # Usage: ./check_quota # # ## Description: # # This plugin users repquota command to get the quota values # From the repqut output see the quota state as to what ( ++ , +- , -- ) and identifies the Exit Stats for nagios # # ## Output: # # The plugin prints "ok" or either "warning" or "critical" # # Exit Codes # 0 OK # 1 Warning # 2 Critical # 3 Unknown Invalid command line arguments or could not determine used space PROGNAME=`basename $0` VERSION="0.1" AUTHOR="(c) 2007 Muthukumar SK" # Exit codes STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 print_version() { echo "$PROGNAME $VERSION $AUTHOR" } print_usage() { echo "Usage: $PROGNAME [-h|-V]"; echo "" echo " -h, --help"; echo " print the help message and exit" echo " -V, --version"; echo " print version and exit" } print_help() { print_version echo "" echo "Plugin for Nagios to check user quota" echo "" print_usage echo "" } # Grab the command line arguments exitstatus=$STATE_WARNING #default while test -n "$1"; do case "$1" in --help) print_help exit $STATE_OK ;; -h) print_help exit $STATE_OK ;; --version) print_version exit $STATE_OK ;; -V) print_version exit $STATE_OK ;; *) echo "Unknown argument: $1" print_usage exit $STATE_UNKNOWN ;; esac shift done OKUSERS="" WARNUSER="" CRITUSER="" PREVUSER="" for x in `repquota -a -s` do if [ "$x" == "+-" ] then WARNUSER=$WARNUSER:$PREVUSER fi if [ "$x" == "++" ] then CRITUSER=$CRITUSER:$PREVUSER fi if [ "$x" == "--" ] then OKUSERS=$OKUSERS:$PREVUSER fi PREVUSER=$x done if [ $CRITUSER ]; then mesg="CRITICAL -" exitstatus=$STATE_CRITICAL elif [ $WARNUSER ]; then mesg="WARNING -" exitstatus=$STATE_WARNING else mesg="OK" exitstatus=$STATE_OK fi msgs="CRITUSER : $CRITUSER \nWARNUSER : $WARNUSER \nOKUSERS : $OKUSERS" echo -e "$mesg $msgs" exit $exitstatus # vim: autoindent number ts=4