aboutsummaryrefslogtreecommitdiff
path: root/check_snmp_if
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-06-15 19:56:34 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-06-15 19:56:34 +0200
commita8933b27422f75c7a34459c7e19acf233bd0858f (patch)
tree0cbd05c984ffde81a35e2f43c410407468fb237a /check_snmp_if
parentd56055580c298fe2b6c4d9c0490ee08929810c01 (diff)
downloadmonitoring_custom-a8933b27422f75c7a34459c7e19acf233bd0858f.tar.gz
check_snmp_if: add perfdata
Diffstat (limited to 'check_snmp_if')
-rwxr-xr-xcheck_snmp_if36
1 files changed, 34 insertions, 2 deletions
diff --git a/check_snmp_if b/check_snmp_if
index 5872367..279f397 100755
--- a/check_snmp_if
+++ b/check_snmp_if
@@ -1,5 +1,8 @@
#!/bin/bash
+# https://ixnfo.com/en/snmp-oid-and-mib-for-interfaces.html
+# https://oidref.com/1.3.6.1.2.1.2.2.1
+
RESULTS=(OK WARNING CRITICAL UNKNOWN)
perror() {
@@ -16,10 +19,33 @@ fail() {
result() {
local RET=$1
shift
- echo "SNMP IF ${RESULTS[$RET]}: $@"
+ echo -n "SNMP IF ${RESULTS[$RET]}: $@"
+ perfdata
exit $RET
}
+walk() {
+ snmpwalk -c "$COMMUNITY" -v 2c "$HOSTNAME" "1.3.6.1.2.1.2.2.1.$1.$INTERFACE"
+ return $?
+}
+
+extract_val() {
+ sed -n 's/.*=\(.*\)/\1/p' | sed -n 's/.*:\s*\(.*\)/\1/p'
+}
+
+perfdata() {
+ [ $GENPERFDATA -eq 0 ] && return
+
+ echo -n "| "
+ echo -n "in=$INOCTETS "
+ echo -n "out=$OUTOCTETS "
+ echo -n "in_err=$INERRORS "
+ echo -n "out_err=$OUTERRORS "
+ echo
+}
+
+GENPERFDATA=0
+
while getopts ":H:c:i:" opt; do
case $opt in
H)
@@ -45,7 +71,13 @@ RET=$?
[ $RET -ne 0 ] && result 3 "snmpwalk failed with code $RET: $SNMPWALK_RESULT"
[ -z "$SNMPWALK_RESULT" ] && result 2 "No matching entry found."
-IFS='=' LINE=($SNMPWALK_RESULT)
+GENPERFDATA=1
+
+INOCTETS=$(walk 10 | extract_val)
+OUTOCTETS=$(walk 16 | extract_val)
+
+INERRORS=$(walk 14 | extract_val)
+OUTERRORS=$(walk 20 | extract_val)
sed -n 's/.*=\(.*\)/\1/p' <<< "$SNMPWALK_RESULT" | grep "up\|1" > /dev/null && result 0 "Interface $INTERFACE is up."