packages: cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp...

glen glen at pld-linux.org
Fri Oct 23 16:00:50 CEST 2009


Author: glen                         Date: Fri Oct 23 14:00:50 2009 GMT
Module: packages                      Tag: HEAD
---- Log message:
- support using simple snmpget

---- Files affected:
packages/cacti-template-snmp_tcp_connection_status:
   cacti-template-snmp_tcp_connection_status.sh (1.4 -> 1.5) 

---- Diffs:

================================================================
Index: packages/cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp_connection_status.sh
diff -u packages/cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp_connection_status.sh:1.4 packages/cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp_connection_status.sh:1.5
--- packages/cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp_connection_status.sh:1.4	Thu Feb 19 18:57:16 2009
+++ packages/cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp_connection_status.sh	Fri Oct 23 16:00:45 2009
@@ -1,26 +1,59 @@
 #!/bin/sh
 #
-# get number of tcp connection
-# jbrooks at oddelement.com
+# get number of tcp connections
+# original code and xml templates by: <jbrooks at oddelement.com>
+# history:
+# http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp_connection_status.sh
 #
-# modified to use awk and added timeout param by Elan Ruusamäe <glen at pld-linux.org>
+# Modified to use snmpd server side summary script Elan Ruusamäe <glen at pld-linux.org>
+
+PROGRAM=${0##*/}
+
+# parse command line args
+t=$(getopt -o o: -n "$PROGRAM" -- "$@")
+[ $? != 0 ] && exit $?
+eval set -- "$t"
+
+while :; do
+	case "$1" in
+	-o)
+		snmpget=$2
+		shift
+	;;
+	--)
+		shift
+		break
+	;;
+	*)
+		echo 2>&1 "$PROGRAM: Internal error: [$1] not recognized!"
+		exit 1
+	;;
+	esac
+	shift
+done
 
 hostname=$1
 snmp_community=${2:-public}
 timeout=${3:-10}
 retry=5
 
-if [ -z "$hostname" ]; then
+if [ -z "$hostname" -o "$hostname" = "hostcommunity" ]; then # WTF
 	echo >&2 "Usage: $0 HOSTNAME [SNMP_COMMUNITY] [TIMEOUT]"
 	exit 1
 fi
 
+if [ "$snmpget" ]; then
+	local out
+	out=$(snmpget -v2c -On -c "$snmp_community" -t "$timeout" "$hostname" "$snmpget") || exit $?
+   	echo ${out#.*STRING: }
+	exit 0
+fi
+
 snmpnetstat -v 2c -r "$retry" -c "$snmp_community" -t "$timeout" -Can -Cp tcp "$hostname" | awk '
 	$1 == "tcp" {
 		ss[$4]++;
 	}
 
-	END {
 		# socket states from net-snmp-5.4.2.1/apps/snmpnetstat/inet.c
 		split("CLOSED LISTEN SYNSENT SYNRECEIVED ESTABLISHED FINWAIT1 FINWAIT2 CLOSEWAIT LASTACK CLOSING TIMEWAIT", t, " ");
 		# create mapping (duh, why there are different data names used?)
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/cacti-template-snmp_tcp_connection_status/cacti-template-snmp_tcp_connection_status.sh?r1=1.4&r2=1.5&f=u



More information about the pld-cvs-commit mailing list