首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >新Nagios BASH插件输出错误:“此OID: integer表达式中当前存在这样的实例”

新Nagios BASH插件输出错误:“此OID: integer表达式中当前存在这样的实例”
EN

Stack Overflow用户
提问于 2017-02-13 16:22:59
回答 1查看 374关注 0票数 0

我正在尝试编写我的第一个Nagios插件来检查WLAN控制器AP上的状态。我们的目标是制作一种“通用”插件,但我遇到了一个错误:

代码语言:javascript
运行
复制
.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

这是我的密码:

代码语言:javascript
运行
复制
#!/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 2。

代码语言:javascript
运行
复制
./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

代码语言:javascript
运行
复制
: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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-13 16:34:37

ap_stat包含非数字内容.您的代码将它传递给一个测试操作符,该操作符要求将其解析为数字。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42208795

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档