#!/bin/sh
# written by Steve Murphy, with inspiration from Dmitry Vayntrub's check_uptime.sh
#
# The plugin shows the number of open files by asterisk
# and allows you to set warn/crit values in case asterisk
# 'leaks' open file descriptors.
#
#######################################################################
VERSION="asterisk_limit_fds v1.00"

usage()
{
cat << EOF
usage: $0

This script checks how many open files that asterisk owns, and  if there are more than 750,
it restarts asterisk. Meant to be run as root from crontab

EOF
}

while getopts v OPTION
do
     case $OPTION in
	?)
	   usage
	   exit $STATE_UNKNOWN
	   ;;
     esac
done

LSOF_REPORT=`/usr/lib/nagios/plugins/my_lsof | wc -l`
if [ $LSOF_REPORT -gt 700 ] ; then
	rasterisk -x "core restart now"
	echo "asterisk restarted!"
	exit $STATE_OK
fi

