]> git.pld-linux.org Git - packages/cacti-template-snmp_tcp_connection_status.git/blob - cacti-template-snmp_tcp_connection_status.sh
- add time_close
[packages/cacti-template-snmp_tcp_connection_status.git] / cacti-template-snmp_tcp_connection_status.sh
1 #!/bin/sh
2 #
3 # get number of tcp connection
4 # jbrooks@oddelement.com
5 #
6 # modified to use awk and added timeout param by Elan Ruusamäe <glen@pld-linux.org>
7
8 hostname=$1
9 snmp_community=${2:-public}
10 timeout=${3:-10}
11 retry=5
12
13 if [ -z "$hostname" ]; then
14         echo >&2 "Usage: $0 HOSTNAME [SNMP_COMMUNITY] [TIMEOUT]"
15         exit 1
16 fi
17
18 snmpnetstat -v 2c -r "$retry" -c "$snmp_community" -t "$timeout" -Can -Cp tcp "$hostname" | awk '
19         $1 == "tcp" {
20                 ss[$4]++;
21         }
22
23         END {
24                 # socket states from net-snmp-5.4.2.1/apps/snmpnetstat/inet.c
25                 split("CLOSED LISTEN SYNSENT SYNRECEIVED ESTABLISHED FINWAIT1 FINWAIT2 CLOSEWAIT LASTACK CLOSING TIMEWAIT", t, " ");
26                 # create mapping (duh, why there are different data names used?)
27                 # XXX TIMECLOSE missing
28                 split("time_close listen syn_sent syn_recv established fin_wait1 fin_wait2 closewait lastack closing time_wait", m, " ");
29                 for (i in t) {
30                         s = t[i];
31                         k = m[i];
32                         printf("%s:%d ", k, ss[s]);
33                 }
34 }'
This page took 0.262176 seconds and 3 git commands to generate.