如何在 Icinga/Nagios 中做出持久确认?

如何在 Icinga/Nagios 中做出持久确认?

我还使用 Icinga(Nagios 分支)来监控外部主机和服务的正常运行时间。目前,当查看“严重”计数时,我发现很难确定是内部服务受到影响(我应该立即采取行动)还是外部服务受到影响(我只是承认存在问题)。

有没有办法保留问题确认,以备将来检查的主机/服务停机?有没有办法自动确认外部主机/服务的状态变化?

答案1

已经找到如何对外部主机进行自动确认的方法。

首先为外部主机定义一个事件处理程序:

define host {
        name            some-external-server
        # ...
        event_handler   handle_external_host
        # ...
}

然后定义要用作事件处理程序的命令:

define command {
        command_name    handle_external_host
        command_line    $USER1$/eventhandlers/acknowledge_host_problem $HOSTNAME$ icingaadmin "Handled by external user"
}

最后将事件处理程序脚本放入文件 /usr/local/icinga/libexec/eventhandlers/acknowledge_host_problem (或安装事件处理程序的位置):

#!/bin/sh

printf_cmd="/usr/bin/printf"
command_file="/usr/local/icinga/var/rw/icinga.cmd"

hostname="$1"
author="$2"
comment="$3"

# get the current date/time in seconds since UNIX epoch
now=`date +%s`

# pipe the command to the command file
$printf_cmd "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;1;0;%s;%s\n" $now "$hostname" "$author" "$comment" >> $command_file

不要忘记使用命令“chmod +x”或类似命令使脚本可执行。有关 ACKNOWLEDGE_HOST_PROBLEM 的详细信息,请参阅 Icinga 文档

答案2

谢谢!为 nagios 制作脚本。

#!/bin/sh

### use "acknowledge hostname" or "acknowledge hostname service" ###
#Example ./acknowledge GPON-Maerchaka-65-D1D2-SPD "1/6 10562_SosinCV_Kot.21_194.226.63.253"
# a list of external commands here: http://www.nagios.org/development/apis/externalcommands/
printf_cmd="/usr/bin/printf"
command_file="/var/lib/nagios3/rw/nagios.cmd"

hostname="$1"
servicename="$2"

#type of comments (Постоянный, т.е. не удаляется после снятия подтверждения)
persistent=0

#Send notification
notification=0

author="script"
comment="auto ack by $0"

# get the current date/time in seconds since UNIX epoch
now=`date +%s`

if [ -n "$servicename" ]; then
    $printf_cmd "[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;1;%s;%s;%s;%s\n" $now "$hostname" "$servicename" "$notification" "$persistent" "$author" "$comment" >> $command_file
    else
    $printf_cmd "[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;1;%s;%s;%s;%s\n" $now "$hostname" "$notification" "$persistent" "$author" "$comment" >> $command_file
fi

#Host Name
#Service (if service)
#Sticky Acknowledgement
#Send Notification
#Persistent Comment
#Author
#Comment

相关内容