Icinga2:如何定义CheckCommand需要多个可能的参数之一?

时间:2016-08-27 14:04:56

标签: plugins monitoring icinga

我在Icinga2中定义了一个CheckCommand,如下所示:

object CheckCommand "foo" {
    import "plugin-check-command"
    command = [ "/opt/my_plugins/check_foo" ]

    arguments = {
        "-a" = {
            value = "$foo_a$"
            description = "Parameter A"
        }
        "-b" = {
            value = "$foo_b$"
            description = "Parameter B"
        }

    vars.foo_a = "$a$"
    vars.foo_b = "$b$"
}

命令需要a或b或两者,但如果它至少没有获得其中一个参数,则无法运行。我想在Icinga2命令定义中表达这个要求,是否可能?

1 个答案:

答案 0 :(得分:0)

注意:这适用于NRPE远程插件执行

我们也为自定义插件遇到了同样的问题。

通常Icinga会执行这样的命令

'/usr/local/nagios/libexec/check_nrpe' '-p' '56666' '-H' '10.104.16.214' \
'-a' '80' '90' '-c' 'nrpe_check_network_interface' 

这会导致问题,在解析此参数时,我们的插件会收到类似无效的参数。可能在bashshell中,我们使用shift转到可能导致问题的下一个参数。

Icinga2在Checkcommand中提供了更多选项,如订购。

object CheckCommand "foo" {
    import "plugin-check-command"
    command = [ "/opt/my_plugins/check_foo" ]

    arguments = {
// If you need you can give this also
        "-H" = {
           value="$host$"
           order=0
        }
        "-a" = {
            value = "$foo_a$"
            description = "Parameter A"
            order = 1
        }
        "-b" = {
            value = "$foo_b$"
            description = "Parameter B"
            order = 2
        }

//No need to give vars here since it will come from service trigger part as macro.
}

不确定,试试吧!这可能会有所帮助。