New Nagios BASH plugin output error: "Such Instance currently exists at this OID: integer expression expected"

New Nagios BASH plugin output error: "Such Instance currently exists at this OID: integer expression expected"

我正在尝试编写我的第一个 Nagios 插件来检查 WLAN 控制器 AP 上的状态。目标是制作一种 "universal" 插件,但出现错误:

.1.3.6.1.4.1.14179.2.2.1.1.3.0.: Unknown Object Identifier ()

/usr/lib/nagios/plugins/check_wlc_ap_state.sh: line 50: [: Such Instance currently exists at this OID: integer expression expected
/usr/lib/nagios/plugins/check_wlc_ap_state.sh: line 53: [: Such Instance currently exists at this OID: integer expression expected
/usr/lib/nagios/plugins/check_wlc_ap_state.sh: line 56: [: Such Instance currently exists at this OID: integer expression expected
UNKOWN-  = Such Instance currently exists at this OID

这是我的代码:

#!/bin/bash

while getopts "H:C:O:N:I:w:c:h" option; do
        case "$option" in
                H )     host_address=$OPTARG;;
                C )     host_community=$OPTARG;;
                O )     ap_op_status_oid=$OPTARG;;
                N )     ap_hostname_oid=$OPTARG;;
                w )     warn_thresh=$OPTARG;;
                c )     crit_thresh=$OPTARG;;
                h )     show_help="yes";;

        esac
done

# Help Menu
help_menu="Plugin to check AP operational status.
Example:
Check AP Status on Cisco CS5508
./check_wlc_ap_state.sh -H [Controller IP] -C [Controller Community] -O .1.3.6.1.4.1.14179.2.2.1.1.6.0 -N .1.3.6.1.4.1.14179.2.2.1.1.3.0 -w 2 -c 3

Required Arguments:
-H      WLAN Controller Address
-C      WLAN Controller RO Community String
-O      OID to AP Operation Status
-N      OID to AP Hostname
-c      Critical Threshold
-w      Warning Threshold

Optional Arguments:
-h      Display help 
"

if [ "$show_help" = "yes" -o $# -lt 1 ]; then
  echo "$help_menu"
  exit 0
fi

# Change the .1. to iso. and get the length + 1 to get rid of the trailing .
ap_op_status_oid=${ap_op_status_oid:2}
ap_op_status_oid="iso$ap_op_status_oid"
ap_op_status_oid_length=${#ap_op_status_oid}
ap_op_status_oid_length="$ap_op_status_oid_length+1"

#Get info
while read -r oid_index equal integer ap_stat;
do
        ap_index="${oid_index:$ap_op_status_oid_length}"
        ap_hostname=$(snmpget -c $host_community $host_address -v 1 $ap_hostname_oid.$ap_index | awk -F '"' '{print}')
        if [ "$ap_stat" -lt "$warn_thresh" ]; then
                echo -n "OK- $ap_hostname = $ap_stat | "
                exit 0;
        elif [ "$ap_stat" -eq "$warn_thresh" ]; then
                echo -n "WARNING- $ap_hostname = $ap_stat | "
                exit 1;
        elif [ "$ap_stat" -ge "$crit_thresh" ]; then
                echo -n "CRITICAL- $ap_hostname = $ap_stat | "
                exit 2;
        else
                echo -n "UNKOWN- $ap_hostname = $ap_stat | "
                exit 3;
        fi

done < <(snmpwalk -c $host_community -v 2c $host_address $ap_op_status_oid)

这是输入和期望的输出。不过,我不确定输出是否适合 Nagios/Icinga2。

./check_wlc_ap_state.sh -H 10.77.208.12 -C r350urc31 -O .1.3.6.1.4.1.14179.2.2.1.1.6.0 -N .1.3.6.1.4.1.14179.2.2.1.1.3.0 -w 2 -c 3

OK- AP-1 = 1 | OK- AP-2 = 1 | OK- AP-3 = 1 | OK- AP-4 = 1 | OK- AP-5 = 1 | OK- AP-6 = 1 | OK- AP-7 = 1 | OK- AP-8 = 1 |

编辑:这是设置 -x

:40+ap_op_status_oid=.3.6.1.4.1.14179.2.2.1.1.6.0
:41+ap_op_status_oid=iso.3.6.1.4.1.14179.2.2.1.1.6.0
:42+ap_op_status_oid_length=31
:43+ap_op_status_oid_length=32
:46+read -r oid_index equal integer ap_stat
::69+snmpwalk -c public -v 2c 10.77.208.12 iso.3.6.1.4.1.14179.2.2.1.1.6.0
:48+oid_index=iso.3.6.1.4.1.14179.2.2.1.1.6.0.129.196.3.1.112
:49+equal==
:50+integer=INTEGER:
:51+ap_stat=1
:52+ap_index=129.196.3.1.112
::53+awk -F '"' '{print}'
::53+snmpget -c public 10.77.208.12 -v 1 .1.3.6.1.4.1.14179.2.2.1.1.3.0.129.196.3.1.112
:53+ap_hostname=AP-01
:55+'[' 1 -lt 2 ']'
:56+echo -n 'OK- AP-01 = 1 | '
OK- AP-01 = 1 | :57+exit 0

ap_stat 包含 non-numeric 内容。您的代码将其传递给要求将其解析为数字的测试运算符。

使用set -x 来跟踪脚本的执行;这将使这种情况更容易诊断。