aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2020-12-11 21:23:46 +0100
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2020-12-11 21:23:46 +0100
commit7edbc6d8a3d4080595c9dc5b289478e0e989f471 (patch)
tree0dfe30aed26b28559e3c55f8d6556e377c3a60c4
parenteb6f3dd5cc1d652f6fa9f5e1a51283964796b263 (diff)
downloadmonitoring_custom-7edbc6d8a3d4080595c9dc5b289478e0e989f471.tar.gz
check_snmp_if
-rwxr-xr-xcheck_snmp_if52
1 files changed, 52 insertions, 0 deletions
diff --git a/check_snmp_if b/check_snmp_if
new file mode 100755
index 0000000..fcc85ae
--- /dev/null
+++ b/check_snmp_if
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+RESULTS=(OK WARNING CRITICAL UNKNOWN)
+
+perror() {
+ echo "$@"
+} >&2
+
+fail() {
+ local RET=$1
+ shift
+ perror "$@"
+ exit $RET
+}
+
+result() {
+ local RET=$1
+ shift
+ echo "SNMP IF ${RESULTS[$RET]}: $@"
+ exit $RET
+}
+
+while getopts ":H:c:i:" opt; do
+ case $opt in
+ H)
+ HOSTNAME="$OPTARG"
+ ;;
+ c)
+ COMMUNITY="$OPTARG"
+ ;;
+ i)
+ INTERFACE="$OPTARG"
+ ;;
+ :)
+ fail 3 "$OPTARG requires Argument."
+ ;;
+ *)
+ fail 3 "Invalid option $OPTARG"
+ esac
+done
+
+SNMPWALK_RESULT=$(snmpwalk -c "$COMMUNITY" -v 2c "$HOSTNAME" ifOperStatus.$INTERFACE; exit $?)
+RET=$?
+
+[ $RET -ne 0 ] && result 3 "snmwalk failed with code $RET: $SNMPWALK_RESULT"
+[ -z "$SNMPWALK_RESULT" ] && result 2 "No matching entry found."
+
+IFS='=' LINE=($SNMPWALK_RESULT)
+
+sed -n 's/.*=\(.*\)/\1/p' <<< "$SNMPWALK_RESULT" | grep "up" && result 0 "Interface $INTERFACE is up."
+
+result 2 "Interface $INTERFACE is not up: $SNMPWALK_RESULT"