#!/bin/bash # # check_swap_sl.sh # # Program: Used swap check plugin for Nagios # License : GPL # Copyright (c) 2004 Timo Dotzauer (tdotzauer@online.de) # # check_swap_sl.sh Version 1.0 2004/08/18 # # Description : # # This plugin is for check the TotalSwap, CachedSwap and FreeSwap # # Usage: # check_swap_sl -w | --warning -c | --critical # check_swap_sl -h | --help for detailed help # check_swap_sl -v | --version for version information # # Example: # # check_swap_sl -w 131072 -c 225280 # This will set warning status if the swap used 128 MB or more and will set cirtical # status if the swap used 220 MB or more. # # BUGS : Nothing - at this time ;-) export st=`cat /proc/meminfo |grep SwapTotal` export sf=`cat /proc/meminfo |grep SwapFree` export sc=`cat /proc/meminfo |grep SwapCached` export sc1=`echo $sc |awk '{print $2}'` export sf1=`echo $sf |awk '{print $2}'` export st1=`echo $st |awk '{print $2}'` if [ -z "$1" ] ; then echo "Usage:" echo "check_swap_sl -w | --warning -c | --critical " echo "check_swap_sl -h | --help for detailed help" echo "check_swap_sl -v | --version for version information" exit 3 fi case "$1" in -h|--help) echo "This plugin will check the used swap space." echo "" echo "Required Arguments:" echo " -w, --warning INTEGER" echo " Exit with WARNING status if less than INTEGER (kbyte) of swap space are free" echo " -c, --critical INTEGER" echo " Exit with CRITICAL status if less than INTEGER (kbyte) of swap space are free" echo " -h, --help" echo " Print detailed help screen" echo " -v, --version INTEGER.INTEGER or INTERGER:INTEGER:INTEGER" echo " Print version information" echo "Warning: Threshold must be INTEGER (kbyte)" echo "" echo "Usage:" echo "check_swap_sl -w | --warning -c | --critical " echo "check_swap_sl -h | --help for detailed help" echo "check_swap_sl -v | --version for version information" ;; -v|--version) echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute, " echo "copies of the plugins under the terms of the GNU General Public License. " echo "This Version was only tested under SuSE Linux." ;; -w|--warning) if [ "$1" = "-w" ] | [ "$1" = "--warning" ] & [ -z "$2" ] ; then echo "Warning: Threshold must be INTEGER (kbyte)" echo "" echo "Usage:" echo "check_swap_sl -w | --warning -c | --critical " echo "check_swap_sl -h | --help for detailed help" echo "check_swap_sl -v | --version for version information" exit 3 fi ;; -c|--critical) if [ "$3" = "-c" ] | [ "$3" = "--critical" ] & [ -z "$4" ] ; then echo "Warning: Threshold must be INTEGER (kbyte)" echo "" echo "Usage:" echo "check_swap_sl -w | --warning -c | --critical " echo "check_swap_sl -h | --help for detailed help" echo "check_swap_sl -v | --version for version information" exit 3 fi ;; *) if [ "$1"x != "x" ] ; then echo "Unknown argument. Usage check_swap_sl -h for detailed information." exit 3 fi ;; esac if [ "$2" = "-c" ] ; then echo "Unknown warning value: $2." exit 3 fi if [ -z $4 ] ; then echo "Unknown critical value: $4." exit 3 fi if [ "$st1" -le "$2" ] ; then echo "ERROR: Warning value can not higher than Total Swap." exit 3 fi if [ "$st1" -le "$4" ] ; then echo "ERROR: Critical value can not higher than Total Swap." exit 3 fi if [ $sc1 -ge $2 ] ; then echo "SWAP WARNING: Total: $st1 Cached: $sc1 Free: $sf1 " exit 2 fi if [ -z $4 ] ; then echo "Unknown critical value: $4." exit 3 fi if [ $2 -ge $4 ] ; then echo "ERROR: Warning value can not lower or equal than critical value" exit 3 fi if [ $sc1 -ge $2 ] ; then echo "SWAP CRITICAL: Total: $st1 Cached: $sc1 Free: $sf1 " exit 2 fi echo "SWAP OK: Total: $st1 Cached: $sc1 Free: $sf1 " exit 0