gpt4 book ai didi

linux - Nagios NSCA 第 4 个变量总是 $OUTPUT$

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:22:34 24 4
gpt4 key购买 nike

我已经在 Nagios 中实现了 nsca 用于分布式监控目的,一切似乎都在工作,除了一个我似乎无法找到答案的奇怪问题任何地方。

发送和接收被动检查,但输出显示第 4 个变量始终未初始化,因此显示为 $OUTPUT$。看起来好像支票在非中央服务器上显示了正确的信息,但是当它被发送时,它似乎没有正确插入。

命令.cfg

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

提交检查结果

#!/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 等”。

如有任何帮助,我们将不胜感激。

最佳答案

我发现了问题。原来上面的 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 "%s\t%s\t%s\t%s\n" "$1" "$2" "$3" "$4" | $NscaBin -H $NagiosHost -c $NscaCfg

# EOF

更好的结果。

关于linux - Nagios NSCA 第 4 个变量总是 $OUTPUT$,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40880122/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com