Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set_if documentation wrong?! #9299

Open
pbirokas opened this issue Mar 28, 2022 · 1 comment
Open

Set_if documentation wrong?! #9299

pbirokas opened this issue Mar 28, 2022 · 1 comment
Labels
area/documentation End-user or developer help bug Something isn't working good first issue Good for newcomers

Comments

@pbirokas
Copy link

pbirokas commented Mar 28, 2022

Describe the bug

I try to implement the set_if functrion in one of my CheckCommands, but failed to succussed.
Orientation was the documentation found here Use Functions in Command Arguments set_if

I also describe my tests on the Icinga Community.

To Reproduce

example host:

object Host "s002.domain.net" {
    import "generic-agent"

    display_name = "s002"
    address = "xxx.xxx.240.12"
    zone = "xxx"
    vars.centos = {
        centos7 = {
            cluster = true
        }
    }
    vars.redhatel = true
    vars.redhatel7 = true
    vars.server = true
    vars.sys = {
        icinga2 = {
            client = true
            zone = {
                xxx = true
            }
        }
        infiniband = {
            mlx5_port1_100 = true
        }
        openssh = true
        platform_mpi = true
        prometheus = true
        racadm = true
        resolver = true
    }
    vars.vendor = {
        dell = {
            poweredge = {
                c6525 = true
            }
        }
    }
}

Example CheckCommand:

object CheckCommand "check_ib" {
  command   = [ "/usr/bin/check_ib" ]
  arguments   = {
    "--dev"  = {
      set_if = {{
        var host_vars = host.vars
        log(host_vars)
        var infiniband = host_vars.sys.infiniband
        log(infiniband)
        return infiniband.keys()
      }}
    }
  }
}

I was not able to get the hosts vars into the check command.
The variable host_vars was always empty logged.

Expected behavior

Documented examples should work.

Workaround / Possible Solution

Calling macro() when importing the vars:

object CheckCommand "check_ib" {
  command   = [ "/usr/bin/check_ib" ]
  arguments   = {
    "--dev"  = {
      set_if = {{
        var host_vars = macro("$host.vars$")
        log(host_vars)
        var infiniband = host_vars.sys.infiniband
        log(infiniband)
        return infiniband.keys()
      }}
    }
  }
}

Your Environment

Director version (System - About):1.9.0
Icinga Web 2 version and modules (System - About): 2.9.5
Icinga 2 version (icinga2 --version): 2.13.2-1
Operating System and version: RockyLinux 8
Webserver, PHP versions:
Apache 2.4.37-41
PHP 7.4.19

@Al2Klimov Al2Klimov added the area/documentation End-user or developer help label Mar 29, 2022
@Al2Klimov Al2Klimov added the bug Something isn't working label Apr 5, 2022
@Al2Klimov Al2Klimov added the good first issue Good for newcomers label Apr 12, 2022
@marc-delgado-ferreres
Copy link

When trying to access the host variables using host.vars, it seems that these variables are not being recognized or are not available in the context where you are trying to use them.

The alternative approach you proposed using the macro("$host.vars$") function may work as a temporary solution to the problem, as it retrieves the host variables in a different way. However, it would be important to further investigate why the original way of accessing the host variables is not working as expected.

Make sure that the structure of the host objects is correctly defined and that the variables you are trying to access are within the vars structure of the host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation End-user or developer help bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants