#!/bin/bash

# Return codes:

STATE_OK=0

STATE_WARNING=1

STATE_CRITICAL=2

STATE_UNKNOWN=3

# Arguments:

WARNLEVEL=$1

CRITLEVEL=$2

#get number of established connections
 
connections=$(su - root -c "netstat -anp | grep -c EST")
#echo $connections
if [ $connections -lt $WARNLEVEL ]; then

echo "OK, $connections established connections"

exitstatus=$STATE_OK

exit $exitstatus
fi

if [ $connections -gt $CRITLEVEL ]; then

echo "CRITICAL, $connections established connections"

exitstatus=$STATE_CRITICAL

exit $exitstatus
fi

if [ $connections -gt $WARNLEVEL ]; then

echo "warning, $connections established connections"

exitstatus=$STATE_WARNING

exit $exitstatus
fi