diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2021-09-30 23:32:45 +0200 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2021-09-30 23:32:45 +0200 |
commit | 536bd24438799a15686415b054f57676b053702d (patch) | |
tree | ac5b93d2a342166c3d2d11a867934ec725b7273e /check_snmp_if | |
parent | cf666ed055e1e76c5acf0d323d87438bfb8342d6 (diff) | |
download | monitoring_custom-536bd24438799a15686415b054f57676b053702d.tar.gz |
move
Diffstat (limited to 'check_snmp_if')
-rwxr-xr-x | check_snmp_if | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/check_snmp_if b/check_snmp_if deleted file mode 100755 index 5d56ae3..0000000 --- a/check_snmp_if +++ /dev/null @@ -1,114 +0,0 @@ -#!/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 -# https://bestmonitoringtools.com/mibdb/mibdb_search.php?mib=IF-MIB - -RESULTS=(OK WARNING CRITICAL UNKNOWN) - -readonly MIB_IFOPERSTATUS="1.3.6.1.2.1.2.2.1.8" -readonly MIB_ALIAS="1.3.6.1.2.1.31.1.1.1.18" -readonly MIB_NAME="1.3.6.1.2.1.31.1.1.1.1" -readonly MIB_IN="1.3.6.1.2.1.31.1.1.1.6" -readonly MIB_OUT="1.3.6.1.2.1.31.1.1.1.10" -readonly MIB_ERR_IN="1.3.6.1.2.1.2.2.1.14" -readonly MIB_ERR_OUT="1.3.6.1.2.1.2.2.1.20" - -perror() { - echo "$@" -} >&2 - -fail() { - local RET=$1 - shift - perror "$@" - exit $RET -} - -result() { - local RET=$1 - shift - echo -n "SNMP IF ${RESULTS[$RET]}: $@" - perfdata - exit $RET -} - -walk() { - snmpwalk $AUTH "$HOSTNAME" "$1" - return $? -} - -extract_val() { - sed -n 's/.*=\(.*\)/\1/p' | sed -n 's/.*:\s*\(.*\)/\1/p' | tr -d "\"'" -} - -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:u:p:" opt; do - case $opt in - H) - HOSTNAME="$OPTARG" - ;; - c) - COMMUNITY="$OPTARG" - ;; - i) - INTERFACE="$OPTARG" - ;; - u) - SNMP_USER="$OPTARG" - ;; - p) - SNMP_PW="$OPTARG" - ;; - :) - fail 3 "$OPTARG requires Argument." - ;; - *) - fail 3 "Invalid option $OPTARG" - esac -done - -AUTH="" -if [ -n "$COMMUNITY" ]; then - AUTH="-c $COMMUNITY -v 2c" -elif [ -n "$SNMP_USER" ] && [ -n "$SNMP_PW" ]; then - AUTH="-v 3 -u $SNMP_USER -A $SNMP_PW -l authNoPriv" -else - result 3 "No or insufficient authentication info provided" -fi - -SNMPWALK_RESULT=$(walk "$MIB_IFOPERSTATUS.$INTERFACE"; exit $?) -RET=$? - -[ $RET -ne 0 ] && result 3 "snmpwalk failed with code $RET: $SNMPWALK_RESULT" -[ -z "$SNMPWALK_RESULT" ] && result 2 "No matching entry found." - -GENPERFDATA=1 - -NAME=$(walk "$MIB_NAME.$INTERFACE" | extract_val) -ALIAS=$(walk "$MIB_ALIAS.$INTERFACE" | extract_val) - -COMPLETE_NAME="$NAME" -if [ -n "$ALIAS" ]; then COMPLETE_NAME+=" ($ALIAS)"; fi - -INOCTETS=$(walk "$MIB_IN.$INTERFACE" | extract_val) -OUTOCTETS=$(walk "$MIB_OUT.$INTERFACE" | extract_val) - -INERRORS=$(walk "$MIB_ERR_IN.$INTERFACE" | extract_val) -OUTERRORS=$(walk "$MIB_ERR_OUT.$INTERFACE" | extract_val) - -extract_val <<< "$SNMPWALK_RESULT" | grep "up\|1" > /dev/null && result 0 "$COMPLETE_NAME is up." - -result 2 "$COMPLETE_NAME $INTERFACE is not up: $SNMPWALK_RESULT" |