【问题标题】:Different Nagios email notifications for different services针对不同服务的不同 Nagios 电子邮件通知
【发布时间】:2014-10-06 06:21:36
【问题描述】:

我正在尝试为 Nagios 中的特定服务发送不同样式的通知,即当用户帐户被 AD 锁定时。我不需要与普通电子邮件相关的所有多余信息(例如,服务所属的主机、IP 地址、服务状态等),因为我需要的所有信息都在$SERVICEOUTPUT 中从 Windows 发送的 SNMP 陷阱中给出.但是,我不能只更改 notify-service-by-email 命令,因为我需要使用所有其他服务的完整输出。

我需要找到一种方法:

  1. 发送为此服务定制的电子邮件通知

    define command{
            command_name    notify-service-by-email
            command_line    $~LongOutputCommand~$
    }
    
    define command{
            command_name    notify-lockouts-by-email
            command_line    $-ShortOutputCommand~$
    }
    
    define service{
            service_description        Account Lockouts
            service_notification       notify-lockouts-by-email
            ...
    }
    
  2. 在 Nagios 命令的 command_line 部分执行 if 语句:

    define command{
            command_name    notify-service-by-email
            command_line    if [ "$SERVICEDESC" == "Account Lockouts" ]; then $-ShortOutputCommand~$; else $~LongOutputCommand~$; fi
    }
    

由于它的编程方式,我不相信 Nagios 可以执行第一种方式,但无论我如何尝试第二种方式,它都不会将其作为正确的命令处理(“如果无法识别”等)。

【问题讨论】:

    标签: nagios


    【解决方案1】:

    您不能在命令行定义中添加“脚本”语法。将 command_line 视为调用脚本的处理程序:逻辑和 if 语句是“逻辑”,必须在您正在调用的脚本中移动。在脚本内部,只需对 $1(传递给脚本的第一个参数的位置变量)使用 if 语句,然后处理 $1 的值。所以,如果 $1(在我们的例子中,如果你将 $SERVICEDESC 作为第一个参数传递给脚本,在脚本中它被引用为 $1)等于...

    【讨论】:

      猜你喜欢
      • 2017-06-15
      • 2010-09-21
      • 1970-01-01
      • 2011-03-20
      • 1970-01-01
      • 2013-10-31
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      相关资源
      最近更新 更多