Icinga / Icinga/icinga2

Set_if documentation wrong?!

Open
#9,299 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/documentation bug good first issue
Dominant language
C++
Stars
2.2k
Forks
616
Avg merge
5d 6h
Merged PRs (30d)
10

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked “Use Functions in Command Arguments set_if” documentation section and compare its example with the CheckCommand reproduction in this issue. Verify the behavior using the supplied host and command definitions, then update the documentation so the example accurately describes how host variables are accessed; done means the documented example works or clearly states the required workaround.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.