#!/bin/bash
# Tony Whitmore
# Status:	Developmental
# Version:	0.0.2
# Homepage:	The latest version of this script can be found at http://darcs.tonywhitmore.co.uk/
# License:	You may freely use, modify and redistribute this script as long as you allow others to do the same.
#		This script is provided without warranty or even fitness for purpose. Use at own risk.
# Description:	Returns the system uptime of a Linux host in a format usable by Nagios / Opsview.
#		Uses /proc/swaps as a source of information.
#		A warning is returned when the number of active swap partitions is less than or equal to variable $1
#		A critical state is returned when the number of active swap partitions is less than or equal to variable $2
#		If no warning/critical parameters are supplied then the script just returns the number of swap 
#		partitions and exits with status "OK".
#		This script assumes the following additional programs are in the user's path: 
#		grep
#
# Example:    	check_swap_active 0 0 (returns a warning when no swap active)

ACTIVE_SWAP=`grep -cv ^Filename /proc/swaps`

if [ $ACTIVE_SWAP -le $2 ]; then
	EXIT=2
elif [ $ACTIVE_SWAP -le $1 ]; then
	EXIT=1
else
	EXIT=0
fi

OUTPUT="Number of active swap partitions: $ACTIVE_SWAP | active_swap=$ACTIVE_SWAP";
echo $OUTPUT
exit $EXIT

