Nagios 松弛通道集成

时间:2021-06-07 16:06:02

标签: linux ubuntu slack channel nagios

我正在使用 slack_nagios.pl 脚本。 Ubuntu 14.05 和 Nagios 4.4.5 https://raw.githubusercontent.com/tinyspeck/services-examples/master/nagios.pl 我有一个频道在工作,但我需要向不同的频道发送通知。就我而言:警告已转到“it_warning”,关键警报必须转到“it_critical”。我创建了 2 组松弛通知命令,如下所示,但我始终只在一个通道中收到警报(警告)。就像 slack 无法区分这两个命令,尽管在“slack”联系人的 service_notification_options 部分中,“slack”联系人有 w,r,而“slack_critical” 中有 c,r。

未收到错误,单独测试通道工作正常。 你能帮我或给我指明正确的方向吗?。

define contact {
   contact_name                     slack
   alias                            Slack
   service_notification_period      24x7
   host_notification_period         24x7
   service_notification_options     w,r
   host_notification_options        d,r
   service_notification_commands    notify-service-by-slack
   host_notification_commands       notify-host-by-slack
   }

define contact {
   contact_name                     slack_critical
   alias                            Slack_critical
   service_notification_period      24x7
   host_notification_period         24x7
   service_notification_options     c,r
   host_notification_options        d,r
   service_notification_commands    notify-service-critical-by-slack
   host_notification_commands       notify-host-critical-by-slack
   }

define contactgroup{
    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 slack,nagiosadmin,slack_critical
    }


define command {
   command_name     notify-service-by-slack
   command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#it-warnings -field HOSTALIAS="$HOSTNAME$" -field SERVICEDESC="$SERVICEDESC$" -field SERVICESTATE="$SERVICESTATE$$
   }

define command {
   command_name     notify-host-by-slack
   command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#it-warnings -field HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" -field HOSTOUTPUT="$HOSTOUTPUT$" -field$
   }

    define command {
   command_name     notify-service-critical-by-slack
   command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#it-critical -field HOSTALIAS="$HOSTNAME$" -field SERVICEDESC="$SERVICEDESC$" -field SERVICESTATE="$SERVICESTATE$$
   }

define command {
   command_name     notify-host-critical-by-slack
   command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#it-critical -field HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" -field HOSTOUTPUT="$HOSTOUTPUT$" -field$
   }

1 个答案:

答案 0 :(得分:0)

我已经找到了解决方案。此处介绍了将警告警报配置为发送到特定通道并将关键警报发送到另一个通道的步骤。

您必须使用联系人、组和命令创建 2 个单独的文件,如下所示,更改频道、service_notification_options、service_notification_commands、host_notification_commands 不要忘记将contact_groups(将为2)添加到您定义服务的文件中。如果可以,请给我一些喜欢。谢谢!

define contact {
  contact_name                             slack
  alias                                    Slack
  service_notification_period              24x7
  host_notification_period                 24x7
  service_notification_options             w,u,r
  host_notification_options                d,r
  service_notification_commands            notify-service-by-slack
  host_notification_commands               notify-host-by-slack 
  }

define contactgroup{
    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin,slack
    }


define command {
  command_name     notify-service-by-slack
  command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#it-alerts-test -field HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" -field HOSTOUTPUT="$HOSTOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$"
  }

define command {
  command_name     notify-host-by-slack
  command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#it-alerts-test -field HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" -field HOSTOUTPUT="$HOSTOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" 
  }


define service {
name                            generic-service  
retain_status_information       1                   
retain_nonstatus_information    1              
is_volatile                     0                      
check_period                    24x7                 
max_check_attempts              3                      
check_interval                  10                      
retry_interval                  2   
contact_groups                  admins,admins_critical  
notification_interval           60                     
notification_period             24x7
}