Tried to access undefined script variable

Hello!
I have defined in secret.conf which is in include_recursive “conf.d”

const WlcPassword = "test"
const WlcUsername = "test"

My host object is defined:

object Host "test.local.com" {
    address = "192.168.64.4.3"
    check_command = "hostalive"

            vars.mac_address = "00999999"

            vars.function_v = "am"
                vars.serial_number = "80062"

            vars.vendor = "Cisco"

            vars.model = "Ap300"

        if (WlcPassword) {
        vars.wlc_password = WlcPassword
    }
    if (WlcUsername) {
        vars.wlc_username = WlcUsername
    }

}

I restart icinga2 in I appears error:

critical/config: Error: Error while evaluating expression: Tried to access undefined script variable 'WlcPassword'

Just change it to

    vars.wlc_password = WlcPassword
    vars.wlc_username = WlcUsername

And it should work, if constant is not set, the vars will be empty.

Hi,

are you sure that the file is really included in your icinga2.conf? Please share its content.

I’m not able to reproduce this, the below compiles just good.

const UserDefinedConst = "abc"

object Host "user-defined-host" {
  check_command = "dummy"

  if (UserDefinedConst) {
    vars.user_defined_const = UserDefinedConst
  }
}

Cheers,
Michael

The icina2.conf contains:

include "constants.conf"
include "zones.conf"
include <itl>
include <plugins>
include "features-enabled/*.conf"
include_recursive "conf.d"

The file, that contains constant is in directory conf.d/AA/.

If I move file to /etc/icinga2 and include in icinga2.conf then it works.
Best regards
Tadeja

Strange. If you put it back there, does it get included when you run config validation in verbose mode?

icinga2 daemon -C -x debug | grep secret

Does not find anything. Whatever in conf/AA or any other directory conf/something are not included. Icinga includes only conf/hosts.

Hi,

are you sure that you’ve edited the correct file and below is just a typo?

Also, you can try to just include the single file instead like this:

include "conf.d/secrets.conf"

Cheers,
Michael

I found solution. It was permission of the directory conf/AA. Previous was permission 644, now it works with permission 775.

1 Like