#
# $Id$
#
# control tool for maintaining Kamailio
#
#===================================================================

##### ----------------------------------------------- #####
### FIFO specific variables and functions
#

##### ----------------------------------------------- #####
### load CTL base
#
if [ -f "$MYLIBDIR/kamctl.ctlbase" ]; then
	. "$MYLIBDIR/kamctl.ctlbase"
else
	mwarn "Cannot load CTL core functions '$MYLIBDIR/kamctl.ctlbase' ..."
	# exit -1
fi

#
##### ----------------------------------------------- #####
### parameters
#

#
##### ----------------------------------------------- #####
### functions
#
usage_ser_mi() {
	echo
	mecho " -- command 'kamcmd_mi'"
	echo
cat <<EOF
 kamcmd_mi ............................. send mi command through kamcmd
EOF
}
USAGE_FUNCTIONS="$USAGE_FUNCTIONS usage_ser_mi"


ser_mi_cmd()
{
	mdbg "entering ser_mi_cmd $*"
	
	if [ "$#" -lt 1 ]; then
		merr "kamcmd_mi must take at least command name as parameter"
		exit 1
	fi

	
	$SERCMD mi "$@"
}

CTLCMD=ser_mi_cmd

ser_mi_monitor() {
	trap "rm $path;  clear; echo monitor ^C-ed; exit 1" 2
	attempt=0
	if [ "$2" = "" ]; then
	    loops=-1;
	else
	    loops=$2;
	fi
	clear
	while [ $loops -ne $attempt ] ; do
		attempt=`$EXPR $attempt + 1`
		#clear
		tput clear
		
		# print_stats $name $path $attempt
		mecho "[cycle #: $attempt; if constant make sure server lives]"

		$SERCMD mi version
		$SERCMD mi uptime
		mecho "Transaction Statistics"
		$SERCMD mi get_statistics UAS_transactions UAC_transactions inuse_transactions

		mecho "Stateless Server Statistics: "
		$SERCMD mi get_statistics sent_replies sent_err_replies received_ACKs

		mecho "UsrLoc Stats: "
		$SERCMD mi get_statistics usrloc
		if [ $loops -ne $attempt ] ; then
			sleep $WATCH_PERIOD
		fi
	done
	exit 0
}

KAMAILIO_MONITOR=ser_mi_monitor



