#!/bin/sh

critical () {
	echo 'UNKNOWN - unable to retrieve active session count'
	exit 3
}

hostname=$1
warn=$2
crit=$3

tot=`/usr/bin/snmpget  -t 30 -r 5 -Ov -OQ -v 1 -c TLimsIs $hostname:161 1.3.6.1.4.1.1991.1.1.4.1.1.0 2>/dev/null`

if [ $? != 0 ]
then
	critical
fi

free=`/usr/bin/snmpget  -t 30 -r 5 -Ov -OQ -v 1 -c TLimsIs $hostname:161 1.3.6.1.4.1.1991.1.1.4.1.13.0 2>/dev/null`

if [ $? != 0 ]
then
	critical
fi

active=`expr $tot - $free`

if [ "$active" -gt "$warn" ]
then
	echo ACTIVE CONNECTIONS: WARNING - $active '|'active=$active
	exit 1
fi

if [ "$active" -gt "$crit" ]
then
	echo ACTIVE CONNECTIONS: CRITICAL - $active '|'active=$active
	exit 2
fi

echo ACTIVE CONNECTIONS: OK - $active '|'active=$active

exit 0

