新的Nagios BASH插件输出错误:“此OID当前存在此类实例:预期为整数表达式" [英] New Nagios BASH plugin output error: "Such Instance currently exists at this OID: integer expression expected"

查看:114
本文介绍了新的Nagios BASH插件输出错误:“此OID当前存在此类实例:预期为整数表达式"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to write my first Nagios plugin to check the statuses on WLAN Controllers APs. The goal was to make a kind of "universal" plugin but I'm getting an error:

.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$2}')
        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.

And here's the input and desired output. I'm not sure about if the output is right for Nagios/Icinga2 though.

./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$2}'
::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包含非数字内容.您的代码会将其传递给测试操作员,该操作员需要将其解析为数字.

ap_stat contains non-numeric contents. Your code is passing it to a test operator that requires it to parse as numeric.

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

Use set -x to trace your script's execution; this will make this kind of situation easier to diagnose.

这篇关于新的Nagios BASH插件输出错误:“此OID当前存在此类实例:预期为整数表达式"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆