Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tcpstats.sh, which contained typos and wrong regexes... #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions bin/tcpstats.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#!/bin/sh

# Date: 22/08/2016
# Author: Long Chen
# Date: 2021-11-11
# Authors: Long Chen, Daniel Scharon
# Description: A script to send TCP stats to zabbix server by using zabbix sender
# Requires: Zabbix Sender

Expand All @@ -23,24 +23,24 @@ s["time-wait"]=0} \
# Get TCP stats by using netstat command
get_TCP_conn_stats(){
netstat -st |sed -n '/Tcp:/,+10p' | grep -v "Tcp:" | sed 's/^ //g' | awk '{a[NR]=$0" "$1} END {host="-"; for (i in a) {\
sub (/^.* active connections openings /, "tcp.conn.active.opens", a[i]); \
sub (/^.* active connection openings /, "tcp.conn.active.opens", a[i]); \
sub (/^.* passive connection openings /, "tcp.conn.passive.opens", a[i]); \
sub (/^.* failed connection attempts /, "tcp.conn.failed.attempts", a[i]); \
sub (/^.* resets sent /, "tcp.conn.resets.sent", a[i]); \
sub (/^.* connection resets received /, "tcp.conn.resets.recv", a[i]); \
sub (/^.* connections established /, "tcp.conn.estab", a[i]); \
sub (/^.* segments received /, "tcp.seg.recv", a[i]); \
sub (/^.* segments send out /, "tcp.seg.send", a[i]); \
sub (/^.* segments retransmited /, "tcp.seg.retrans", a[i]); \
sub (/^.* bad segments received. /, "tcp.seg.bad", a[i]); \
sub (/^[[:digit:]]* segments received /, "tcp.seg.recv", a[i]); \
sub (/^.* segments sent out /, "tcp.seg.send", a[i]); \
sub (/^.* segments retransmitted /, "tcp.seg.retrans", a[i]); \
sub (/^.* bad segments received /, "tcp.seg.bad", a[i]); \
print host, a[i]}}'
}

# Send the results to zabbix server by using zabbix sender
result=$((get_TCP_socket_states; get_TCP_conn_stats) | /usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -i - 2>&1)
result=$( (get_TCP_socket_states; get_TCP_conn_stats) | /usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -i - 2>&1)
response=$(echo "$result" | awk -F ';' '$1 ~ /^info/ && match($1,/[0-9].*$/) {sum+=substr($1,RSTART,RLENGTH)} END {print sum}')
if [ -n "$response" ]; then
echo "$response"
else
echo "$result"
fi
fi