2017-02-13 3 views
0

Ich versuche mein erstes Nagios-Plugin zu schreiben, um die Status der WLAN-Controller-APs zu überprüfen. Das Ziel war, eine Art „universelle“ Plugin zu machen, aber ich erhalte eine Fehlermeldung:Neuer Nagios BASH-Plugin-Ausgabefehler: "Solch eine Instanz ist derzeit an dieser OID vorhanden: Ganzzahl-Ausdruck erwartet"

.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 

Hier ist mein Code:

#!/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) 

Und hier ist der Eingang und die gewünschte Ausgabe. Ich bin mir nicht sicher, ob die Ausgabe für Nagios/Icinga2 richtig ist.

./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 | 

Edit: Hier ist der Satz -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 
+1

Sie haben eine große Zeichenfolge, die Sie an einen numerischen Test übergeben. Das funktioniert nicht. –

+1

BTW, du hast eine Menge Quotebugs. Führen Sie Ihren Code durch http://shellcheck.net/ und beheben Sie, was es findet. –

+1

BTW, erwarten Sie, dass 'ap_op_status_oid_length =" $ ap_op_status_oid_length + 1 "' eine mathematische Operation ist? Es ist nicht. Vielleicht möchten Sie 'ap_op_status_oid_length = $ ((ap_op_status_oid_length + 1))' 'oder' ((++ ap_op_status_oid_length)) '- Letzteres ist ein Bashism, wobei ersteres POSIX-konform ist. –

Antwort

1

ap_stat enthält nicht-numerischen Inhalte. Ihr Code übergibt ihn an einen Testoperator, der die Analyse als numerisch erfordert.

Verwenden Sie set -x, um die Ausführung Ihres Skripts zu verfolgen; Dadurch wird diese Situation leichter zu diagnostizieren.

+0

ap_stat gibt einfach eine 1 – cflinspach

+1

eindeutig nicht in der Situation, wo Sie diesen Fehler erhalten. Erneut, sammle 'set -x' logs (wie durch Ausführen von' PS4 = ': $ LINENO +' bash -x yenscript'). –

+1

@red_eagle, ... Ich nehme an, dass 'snmpwalk' einen Fehler zurückgibt. Sie lesen das erste Wort dieses Fehlers in "oid_index", das zweite Wort in "equal", das dritte Wort in "integer", und der Rest davon endet in "ap_stat". –

Verwandte Themen