Icinga2 条件逻辑

Icinga2 条件逻辑

我有四种设备类型:apache11、apache12、apache22 和 apache24。前两个使用密码“4597”,后两个使用密码“9634”。所有这些 Web 服务器都具有相同的管理员用户“kingfish”。

以下是我的逻辑想法应该管用。

apply Service "HTTP/80: Apache Status" {
  import "generic-service"
  check_interval = 10m
  retry_interval = 3m
  check_command = "check-custom-apache"
  vars.gsuser = "kingfish"

    if ( host.vars.devtype == "apache22" || host.vars.devtype == "apache24" ) {
        vars.gspass = "9634"
    } else ( host.vars.devtype == "apache11" || host.vars.devtype == "apache12" ) {
        vars.gspass = "4597"
    }
  assign where host.vars.devtype == "apache22"
  assign where host.vars.devtype == "apache24"
  assign where host.vars.devtype == "apache11"
  assign where host.vars.devtype == "apache12"
}

我收到的错误是:

critical/config: Error: syntax error, unexpected '(', expecting if (T_IF) or '{'
Location: in /etc/icinga2/zones.d/global-templates/xrs-services.conf: 62:12-62:12
/etc/icinga2/zones.d/global-templates/xrs-services.conf(60):     if ( host.vars.devtype == "apache22" || host.vars.devtype == "apache24" ) {
/etc/icinga2/zones.d/global-templates/xrs-services.conf(61):       vars.gspass = "9634"
/etc/icinga2/zones.d/global-templates/xrs-services.conf(62):     } else ( host.vars.devtype == "apache11" || host.vars.devtype == "apache11" ) {
                                                                        ^
/etc/icinga2/zones.d/global-templates/xrs-services.conf(63):       vars.gspass = "4597"
/etc/icinga2/zones.d/global-templates/xrs-services.conf(64):     }

我所要做的就是对一组机器使用一个密码,对另一组机器使用另一个密码。

答案1

“if” 后面永远都是“else if”

if ( host.vars.devtype == "apache22" || host.vars.devtype == "apache24" ) {
    vars.gspass = "9634"
} else if ( host.vars.devtype == "apache11" || host.vars.devtype == "apache12" ) {
vars.gspass = "4597"
}

相关内容