Skip to content

Instantly share code, notes, and snippets.

@alexcreek
Created August 15, 2014 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexcreek/ecfdf17875ad7170d743 to your computer and use it in GitHub Desktop.
Save alexcreek/ecfdf17875ad7170d743 to your computer and use it in GitHub Desktop.
nagios plugin to monitor TCP/UDP connections
#!/bin/bash
if [[ $# -ne 2 ]]; then
echo "WARN and CRIT thresholds not defined"
exit 3
fi
warn="$1"
crit="$2"
tcp=$(ss -tan | tail -n +3 | egrep -c -v "UNCONN|LISTEN")
udp=$(ss -anu | tail -n +3 | egrep -c -v "UNCONN|LISTEN")
total=$(($tcp + $udp))
if [[ $total -lt $warn ]]; then
echo "OK TCP $tcp UDP $udp"
exit 0
fi
if [[ $total -ge $warn && $total -lt $crit ]]; then
echo "WARN TCP $tcp UDP $udp"
exit 1
fi
if [[ $total -ge $crit ]]; then
echo "CRIT TCP $tcp UDP $udp"
exit 2
fi
echo "UNKNOWN STATUS"
exit 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment