Nagios NSCA 第 4 个变量总是 $OUTPUT$
Nagios NSCA 4th variable always $OUTPUT$
我已经在 Nagios
中实施了 nsca
用于分布式监控目的,一切似乎都在工作,除了一个奇怪的地方,我似乎无法在任何地方找到答案。
发送和接收被动检查,但输出显示第 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 "" 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" "" "" "$return_code" "" | /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, etc"。
如有任何帮助,我们将不胜感激。
我发现了问题。原来上面的 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:
# = host_name (Short name of host that the service is
# associated with)
# = svc_description (Description of the service)
# = return_code (An integer that determines the state
# of the service check, 0=OK, 1=WARNING, 2=CRITICAL,
# 3=UNKNOWN).
# = 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" "" "" "" "" | $NscaBin -H $NagiosHost -c $NscaCfg
# EOF
更好的结果。
我已经在 Nagios
中实施了 nsca
用于分布式监控目的,一切似乎都在工作,除了一个奇怪的地方,我似乎无法在任何地方找到答案。
发送和接收被动检查,但输出显示第 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 "" 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" "" "" "$return_code" "" | /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, etc"。
如有任何帮助,我们将不胜感激。
我发现了问题。原来上面的 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:
# = host_name (Short name of host that the service is
# associated with)
# = svc_description (Description of the service)
# = return_code (An integer that determines the state
# of the service check, 0=OK, 1=WARNING, 2=CRITICAL,
# 3=UNKNOWN).
# = 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" "" "" "" "" | $NscaBin -H $NagiosHost -c $NscaCfg
# EOF
更好的结果。