Created
August 15, 2014 05:25
-
-
Save alexcreek/ecfdf17875ad7170d743 to your computer and use it in GitHub Desktop.
nagios plugin to monitor TCP/UDP connections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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