Return function value

Hi,

on my icinga config (on a template) I have some vars on my config template. So in icinga web I can see:

Custom Variables
var1 	Object of type 'Function'

Is there any mean to display this value there?
I’ve tested with string()… but no way.

Alex

Pretty old thread, but I would be interested in an answer, too.

I am using a function, similar to the “globals.group_specific_value” described in Advanced Topics - Icinga 2 (just without the group part). I am using it to set a default value, just as in the example:

apply Service "ping4" {
    import "generic-service"
    check_command = "ping4"

    vars.ping_wrta = group_specific_value("slow-lan", 300, 100)
    vars.ping_crta = group_specific_value("slow-lan", 500, 200)

    assign where true
}

But now both Icinga2 API and Icingaweb2 (of course) don’t show the actual value of vars.ping_wrta and vars.ping_crta.

In Icinga 2 API using the JSON output from that service:

        "type": "Service",
        "vars": {
          [...]
          "ping_wrta": {
            "arguments": [],
            "deprecated": false,
            "name": "<anonymous>",
            "side_effect_free": false,
            "type": "Function"
          },
          [...]
        },

In Icingaweb2, under “Custom Variables”, the value is just: Object of type ‘Function’

The checks however work correctly with the correct values - they’re just not “shown”. Any idea why that is the case and how can they be displayed?

Update: I just came across issue request Object inspection like in the director · Issue #117 · Icinga/icingadb-web · GitHub from Carsten. It’s late and I fail to see what exactly was done in Icingaweb2 to solve the issue. Is there an additional module to be installed to be able to do “inspect”?

It is part of the new webinterface for IcingaDB.
The issue for the ido webinterface got closed: Ability to evaluate dynamic custom var values on demand · Issue #2610 · Icinga/icingaweb2 · GitHub

This is not possible for the UI to perform. It would require an API endpoint that allows to evaluate custom expressions. However, due to security concerns this is not an option.

I want to add to this because this post comes up when I search for my issue.

In my service I have:

vars.test5 = {{get_service(host.name, "30m_checkInterface_FastEthernet1/1").last_check}}

When the vars output shows something like this:

test5: { arguments: [], deprecated: false, name: "<anonymous>", side_effect_free: false, type: "Function" },

This means it is a dynamic function and will be evaluated when it called. Since the value is not static it can’t be defined in vars.

If you scroll to the top of the inspection page and view the Executed Command you will see the actual output of that function alongside the parameter you defined in CheckCommand.

In my case this is:

'--previousPerformanceDataEpoch' '1697481930.881913'