Syntax error after upgrade to 2.11.2

Hi,
I’m having troubles with latest Icinga2 release:

[2019-11-13 13:34:20 +0000] critical/config: Error: Error while evaluating expression: Cannot convert value of type 'String' to an object.
Location: in /etc/icinga2/zones.d/global-templates/system.conf: 542:3-542:22
/etc/icinga2/zones.d/global-templates/system.conf(540):   check_command = "check_smart_log"
/etc/icinga2/zones.d/global-templates/system.conf(541):   command_endpoint = host.name
/etc/icinga2/zones.d/global-templates/system.conf(542):   vars = vars + config
                                                          ^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-templates/system.conf(543):   assign where "physical-servers" in host.groups
/etc/icinga2/zones.d/global-templates/system.conf(544):   ignore where !host.vars.client_endpoint || !host.vars.hdd

[2019-11-13 13:34:20 +0000] critical/config: Error: Error while evaluating expression: Cannot convert value of type 'String' to an object.
Location: in /etc/icinga2/zones.d/global-templates/system.conf: 542:3-542:22
/etc/icinga2/zones.d/global-templates/system.conf(540):   check_command = "check_smart_log"
/etc/icinga2/zones.d/global-templates/system.conf(541):   command_endpoint = host.name
/etc/icinga2/zones.d/global-templates/system.conf(542):   vars = vars + config
                                                          ^^^^^^^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-templates/system.conf(543):   assign where "physical-servers" in host.groups
/etc/icinga2/zones.d/global-templates/system.conf(544):   ignore where !host.vars.client_endpoint || !host.vars.hdd

[2019-11-13 13:34:20 +0000] critical/config: 2 errors
[2019-11-13 13:34:20 +0000] critical/cli: Config validation failed. Re-run with 'icinga2 daemon -C' after fixing the config.

the full config looks like this:

apply Service for (disk_name => config in host.vars.hdd) {
  import "generic-service"

  display_name = "SMART-" + disk_name
  check_command = "check_smart_log"
  command_endpoint = host.name
  vars = vars + config
  assign where "physical-servers" in host.groups
  ignore where !host.vars.client_endpoint || !host.vars.hdd
}

I haven’t changed anything in configuration, the check used to be valid. Any idea how to debug this? The variable host.vars.hdd is non-empty for all hosts as far as I can tell:

icinga2 object list --type Host | grep "hdd" -A 5

Hi,

vars += config

is the correct syntax - update your service definition.

Greetz

1 Like

It should be the same, right?

The configuration is generated by puppet-icinga2, which didn’t support the syntax earlier (now it seems to be possible).

In the same file I have the statement vars = vars + config 4 times and it appears to be valid. Moreover it iterates over the same variable.

I’ve updated the puppet module to support + config syntax. The error remains basically the same:

[2019-11-13 14:03:31 +0000] critical/config: Error: Error while evaluating expression: Cannot convert value of type 'String' to an object.
Location: in /etc/icinga2/zones.d/global-templates/system.conf: 542:3-542:16
/etc/icinga2/zones.d/global-templates/system.conf(540):   check_command = "check_smart_log"
/etc/icinga2/zones.d/global-templates/system.conf(541):   command_endpoint = host.name
/etc/icinga2/zones.d/global-templates/system.conf(542):   vars += config
                                                          ^^^^^^^^^^^^^^
/etc/icinga2/zones.d/global-templates/system.conf(543):   assign where "physical-servers" in host.groups
/etc/icinga2/zones.d/global-templates/system.conf(544):   ignore where !host.vars.client_endpoint

Hi,

can you show us the host definition on which the service gets applied?

Greetz

There are about 153 hosts that matches the condition. Basically the definition looks like this:

object Host "x01.example.com" {
  address = "192.168.1.62"
  groups = [ "physical-servers", ]
  check_command = "hostalive"
  check_interval = 1m
  retry_interval = 30s
  zone = "eu-west"
  vars.os = "Linux"
  vars.hdd["sda"] = {
    smart_device = "/dev/sda"
  }
  vars.hdd["sdb"] = {
    smart_device = "/dev/sdb"
  }
}

I wish icinga would print on which Host it’s failing, but it’s not showing in icinga daemon -C output. Is there some option to enable more verbose output?

Hi,

you can use the script debugger within the config validation to halt on errors. At that scope, you can print the object which is affected. Likely you have a host, where vars.hdd has a key with a string value instead of a dictionary.

https://icinga.com/docs/icinga2/latest/doc/20-script-debugger/#debugging-configuration-errors

Cheers,
Michael

1 Like

Thanks Michael, that actually helps a lot. There was an erroneous config that got merged from Puppet’s exported resources.

1 Like