[OpenSIPS-Users] snmp workaround

Richard Revels rrevels at bandwidth.com
Mon Aug 25 15:37:54 CEST 2008


I'm having a bit of a problem with snmpstats not spitting out the  
opensipsSIPStatusCodesTable.  I don't think the problem is my  
configuration but sooner or later it will get fixed no matter where it  
is.

Meanwhile I've set up a workaround that could be useful even when this  
problem is gone using the pass command in snmp.  Pass can use whatever  
means you want to spew out the values (perl, bash, c, visual basic)  
and I chose bash 'cause it was quick and easy.  I expect some people  
will look at the bash script and have questions but I'm not going to  
try and anticipate what they might be.  If you have a question,  
respond back to the list and I'll do what I can to answer.

In the snmpd.conf file add the line:

pass .1.3.6.1.4.1.2021.255 /foouser/bin/foo.sh

foo.sh uses the fifo to grab the stat(s) being looked for at the  
moment.  The listing for foo.sh is at the bottom of this post.  After  
these two things are in place snmpwalk will output something like the  
following:

[root at zenguest1 ~]# snmpwalk -v 1 -c public localhost . 
1.3.6.1.4.1.2021.255
UCD-SNMP-MIB::ucdavis.255.4 = STRING: "so long and thanks for all the  
fish"
UCD-SNMP-MIB::ucdavis.255.4.1 = STRING: "opensips stats"
UCD-SNMP-MIB::ucdavis.255.4.2.1 = Gauge32: 239000
UCD-SNMP-MIB::ucdavis.255.4.2.2 = Gauge32: 245027
UCD-SNMP-MIB::ucdavis.255.4.2.3 = Gauge32: 68335
UCD-SNMP-MIB::ucdavis.255.4.2.4 = Gauge32: 18216
UCD-SNMP-MIB::ucdavis.255.4.2.5 = Gauge32: 8
UCD-SNMP-MIB::ucdavis.255.4.2.6 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.2.7 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.2.8 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.2.9 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.2.10 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.2.11 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.3.1 = Gauge32: 72500
UCD-SNMP-MIB::ucdavis.255.4.3.2 = Gauge32: 17
UCD-SNMP-MIB::ucdavis.255.4.3.3 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.4.1 = Gauge32: 177381
UCD-SNMP-MIB::ucdavis.255.4.6.1 = Gauge32: 2461
UCD-SNMP-MIB::ucdavis.255.4.6.3 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.6.4 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.6.6 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.6.7 = Gauge32: 8
UCD-SNMP-MIB::ucdavis.255.4.6.8 = Gauge32: 3
UCD-SNMP-MIB::ucdavis.255.4.6.9 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.6.10 = Gauge32: 7
UCD-SNMP-MIB::ucdavis.255.4.6.11 = Gauge32: 7
UCD-SNMP-MIB::ucdavis.255.4.7.1 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.7.3 = Gauge32: 0
UCD-SNMP-MIB::ucdavis.255.4.8.1 = Gauge32: 1187
UCD-SNMP-MIB::ucdavis.255.4.11.1 = Gauge32: 71293
UCD-SNMP-MIB::ucdavis.255.4.11.2 = Gauge32: 72603

Here is the listing for foo.sh:


#!/bin/bash
IFS="
"
#anchor OID is .1.3.6.1.4.1.2021.255
anchor=".1.3.6.1.4.1.2021.255";
#anchor.4.2.x core stats
#anchor.4.3.x - 1xx messages
#anchor.4.4.x - 2xx messages
#anchor.4.5.x - 3xx messages
#anchor.4.6.x - 4xx messages
#...
#anchor.4.11.x - 9xx messages

get_list()
{
	y=0;
	for x in `/usr/local/openser/sbin/openserctl fifo get_statistics  
${1}:`;do
		value[$y]=`echo $x | cut -f 2 -d =`;
		#echo ${value[$y]};
		y=$y+1;
	done
}

get_value()
{
	if [ "$arg2" = "$anchor" ]; then exit 0; fi;
	echo -e "$arg2";
	if [ "$arg2" = "$anchor.4.1" ]; then echo -e "string\nopensips stats 
\n"; exit 0; fi;
	if [ "$arg2" = "$anchor.4.2.1" ]; then get_list core; echo -e "gauge\n 
${value[0]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.2" ]; then get_list core; echo -e "gauge\n 
${value[1]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.3" ]; then get_list core; echo -e "gauge\n 
${value[2]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.4" ]; then get_list core; echo -e "gauge\n 
${value[3]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.5" ]; then get_list core; echo -e "gauge\n 
${value[4]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.6" ]; then get_list core; echo -e "gauge\n 
${value[5]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.7" ]; then get_list core; echo -e "gauge\n 
${value[6]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.8" ]; then get_list core; echo -e "gauge\n 
${value[7]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.9" ]; then get_list core; echo -e "gauge\n 
${value[8]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.10" ]; then get_list core; echo -e "gauge 
\n${value[9]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.2.11" ]; then get_list core; echo -e "gauge 
\n${value[10]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.3.1" ]; then get_list snmpstats; echo -e  
"gauge\n${value[1]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.3.2" ]; then get_list snmpstats; echo -e  
"gauge\n${value[3]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.3.3" ]; then get_list snmpstats; echo -e  
"gauge\n${value[9]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.4.1" ]; then get_list snmpstats; echo -e  
"gauge\n${value[11]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.1" ]; then get_list snmpstats; echo -e  
"gauge\n${value[27]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.3" ]; then get_list snmpstats; echo -e  
"gauge\n${value[31]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.4" ]; then get_list snmpstats; echo -e  
"gauge\n${value[33]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.6" ]; then get_list snmpstats; echo -e  
"gauge\n${value[37]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.7" ]; then get_list snmpstats; echo -e  
"gauge\n${value[39]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.8" ]; then get_list snmpstats; echo -e  
"gauge\n${value[41]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.9" ]; then get_list snmpstats; echo -e  
"gauge\n${value[59]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.10" ]; then get_list snmpstats; echo -e  
"gauge\n${value[71]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.6.11" ]; then get_list snmpstats; echo -e  
"gauge\n${value[75]}\n"; exit 0;fi;
         if [ "$arg2" = "$anchor.4.7.1" ]; then get_list snmpstats;  
echo -e "gauge\n${value[83]}\n"; exit 0;fi;
         if [ "$arg2" = "$anchor.4.7.3" ]; then get_list snmpstats;  
echo -e "gauge\n${value[89]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.8.1" ]; then get_list snmpstats; echo -e  
"gauge\n${value[99]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.11.1" ]; then get_list script; echo -e  
"gauge\n${value[0]}\n"; exit 0;fi;
	if [ "$arg2" = "$anchor.4.11.2" ]; then get_list script; echo -e  
"gauge\n${value[1]}\n"; exit 0;fi;
	echo -e "string\nso long and thanks for all the fish\n"; exit 0;
}

get_next()
{
	case $arg2 in
		$anchor )
			arg2="$anchor.4" ;;
		$anchor.4 )
			arg2="$anchor.4.1" ;;    #Process file name
                 $anchor.4.1 )
                         arg2="$anchor.4.2.1" ;;  #core rcv_requests
                 $anchor.4.2.1 )
                         arg2="$anchor.4.2.2" ;;  #core rcv_replies
                 $anchor.4.2.2 )
                         arg2="$anchor.4.2.3" ;;  #core forwarded  
requests
                 $anchor.4.2.3 )
                         arg2="$anchor.4.2.4" ;;
                 $anchor.4.2.4 )
                         arg2="$anchor.4.2.5" ;;
                 $anchor.4.2.5 )
                         arg2="$anchor.4.2.6" ;;
                 $anchor.4.2.6 )
                         arg2="$anchor.4.2.7" ;;
                 $anchor.4.2.7 )
                         arg2="$anchor.4.2.8" ;;
                 $anchor.4.2.8 )
                         arg2="$anchor.4.2.9" ;;
                 $anchor.4.2.9 )
                         arg2="$anchor.4.2.10" ;;
                 $anchor.4.2.10 )
                         arg2="$anchor.4.2.11" ;;
                 $anchor.4.2.11 )
                         arg2="$anchor.4.3.1" ;;  #snmpstat 100 out
                 $anchor.4.3.1 )
                         arg2="$anchor.4.3.2" ;;  #snmpstat 180 out
                 $anchor.4.3.2 )
                         arg2="$anchor.4.3.3" ;;  #snmpstat 183 out
                 $anchor.4.3.3 )
                         arg2="$anchor.4.4.1" ;;  #snmpstat 200 out
                 $anchor.4.4.1 )
                         arg2="$anchor.4.6.1" ;;  #snmpstat 401 out
                 $anchor.4.6.1 )
                         arg2="$anchor.4.6.3" ;;  #snmpstat 403 out
                 $anchor.4.6.3 )
                         arg2="$anchor.4.6.4" ;;  #snmpstat 404 out
                 $anchor.4.6.4 )
                         arg2="$anchor.4.6.6" ;;  #snmpstat 406 out
                 $anchor.4.6.6 )
                         arg2="$anchor.4.6.7" ;;  #snmpstat 407 out
                 $anchor.4.6.7 )
                         arg2="$anchor.4.6.8" ;;  #snmpstat 408 out
                 $anchor.4.6.8 )
                         arg2="$anchor.4.6.9" ;;  #snmpstat 480 out
                 $anchor.4.6.9 )
                         arg2="$anchor.4.6.10" ;;  #snmpstat 486 out
                 $anchor.4.6.10 )
                         arg2="$anchor.4.6.11" ;;  #snmpstat 488 out
                 $anchor.4.6.11 )
                         arg2="$anchor.4.7.1" ;;  #snmpstat 500 out
                 $anchor.4.7.1 )
                         arg2="$anchor.4.7.3" ;;  #snmpstat 503 out
                 $anchor.4.7.3 )
                         arg2="$anchor.4.8.1" ;;  #snmpstat 603 out
                 $anchor.4.8.1 )
                         arg2="$anchor.4.11.1" ;;  #script invite200
                 $anchor.4.11.1 )
                         arg2="$anchor.4.11.2" ;;  #script initial  
invite
		* )
			exit 0;
	esac
}

arg1=$1;
arg2=$2;
value=( 0 );

# -s gets passed in when snmp wants to write.  no can do.
if [ $arg1 = -s ]; then
	echo "not-writable";
	exit;
fi
if [ $arg1 = -n ]; then
	get_next;
	get_value;
	exit;
fi
if [ $arg1 = -g ]; then
	get_value;
	exit;
fi










More information about the Users mailing list