2016-11-30 41 views
1

我實施了nscaNagios爲分佈式監控的目的,似乎一切工作,除了一個奇怪的,我似乎無法找到任何答案。

發送和接收被動檢查,但輸出顯示第4個變量始終未初始化,因此顯示爲$OUTPUT$。看起來好像檢查顯示了非中央服務器上的正確信息,但是當它被髮送時,它似乎沒有正確插入。

commands.cfg

define command{ 
     command_name submit_check_result 
     command_line  /usr/share/nagios3/plugins/eventhandlers/submit_check_result $HOSTNAME$ '$SERVICEDESC$' $SERVICESTATE$ '$OUTPUT$' 
     } 

submit_check_result

#!/bin/sh 
return_code=-1 

    case "$3" in 
     OK) 
        return_code=0 
       ;; 
      WARNING) 
       return_code=1 
        ;; 
      CRITICAL) 
       return_code=2 
        ;; 
      UNKNOWN) 
       return_code=-1 
        ;; 
    esac 

    /usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_code" "$4" | /usr/sbin/send_nsca 192.168.40.168 -c /etc/send_nsca.cfg 

實施例服務

define service { 
     host_name    example_host 
     service_description  PING 
     check_command   check_icmp 
     active_checks_enabled 1 
     passive_checks_enabled 0 
     obsess_over_service  1 
     max_check_attempts  5 
     normal_check_interval 5 
     retry_check_interval 3 
     check_period   24x7 
     notification_interval 30 
     notification_period  24x7 
     notification_options w,c,r 
     contact_groups   admins 
} 

從日誌非中央服務器上的輸出顯示:

Nov 29 22:52:52 nagios-server nagios3: SERVICE ALERT: example_host;PING;OK;HARD;5;OK - 192.168.1.1: rta nan, lost 0% 

從日誌在中央服務器上的輸出顯示:

EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;example_host;PING;0;$OUTPUT$ 

中央服務器(網絡接口)的狀態信息顯示:

PING OK 2016-11-29 22:54:50 0d 0h 54m 6s 1/5 $OUTPUT$ 

它不只是這兩種服務。所有服務,包括基本上爲Nagios服務器本身預配置的服務「check_load,check_proc等」。

任何援助將不勝感激。

回答

0

我發現了這個問題。原來,上面的submit_check_result腳本未正確格式化,無法將檢查結果提交給遠程服務器。它會這樣做,但它沒有正確地解釋狀態。以下是正確的腳本:

#!/bin/sh 
# SUBMIT_CHECK_RESULT_VIA_NSCA 
# Written by Ethan Galstad ([email protected]) 
# Last Modified: 10-15-2008 
# 
# This script will send passive check results to the 
# nsca daemon that runs on the central Nagios server. 
# If you simply want to submit passive checks from the 
# same machine that Nagios is running on, look at the 
# submit_check_result script. 
# 
# Arguments: 
# $1 = host_name (Short name of host that the service is 
#  associated with) 
# $2 = svc_description (Description of the service) 
# $3 = return_code (An integer that determines the state 
#  of the service check, 0=OK, 1=WARNING, 2=CRITICAL, 
#  3=UNKNOWN). 
# $4 = plugin_output (A text string that should be used 
#  as the plugin output for the service check)s 
# 
# 
# Note: 
# Modify the NagiosHost parameter to match the name or 
# IP address of the central server that has the nsca 
# daemon running. 

printfcmd="/usr/bin/printf" 

NscaBin="/usr/sbin/send_nsca" 
NscaCfg="/etc/send_nsca.cfg" 
NagiosHost="central_host_IP_address" 

# Fire the data off to the NSCA daemon using the send_nsca script 
$printfcmd "%s\t%s\t%s\t%s\n" "$1" "$2" "$3" "$4" | $NscaBin -H $NagiosHost -c $NscaCfg 

# EOF 

更好的結果。