NAGIOS NSCA第四变量始终$输出$



我已经在Nagios中实现了nsca用于分布式监视目的,并且一切似乎都在起作用,除了我似乎找不到任何地方的一个奇怪之处。

被动检查是发送和接收的,但是输出显示了第四变量始终是非初始化的,因此显示为$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 "%st%st%st%sn" "$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$

中央服务器(Web界面)上的状态信息显示:

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

也不只是这项服务。所有服务,包括那些基本上针对Nagios Server本身" check_load,check_proc等"的服务。

任何帮助将不胜感激。

我发现了这个问题。事实证明,上面的submit_check_result脚本未正确格式用于将检查结果提交到远程服务器。它将做到这一点,但不能正确解释状态。以下是正确的脚本:

#!/bin/sh
# SUBMIT_CHECK_RESULT_VIA_NSCA
# Written by Ethan Galstad (egalstad@nagios.org)
# 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 "%st%st%st%sn" "$1" "$2" "$3" "$4" | $NscaBin -H $NagiosHost -c $NscaCfg
# EOF

更好的结果。

最新更新