Get_host().state always results 1 even if the host is in Up state

Has anyone encountered this issue already?

I want to use the get_host(host).state function but it always results 1 instead of 0 if the given host is in Up state.

Other attributes like get_host(host).name gives the correct result for the same host.

Please help,

Regards,
Endre

Hello,

in which context you want this information? Over API, as DSL in a service/host or other object?

Regards,
Carsten

Hello Carsten,

Thanks for you reply!

It is DSL. I defined a simple service but the get_host(host).state always results1 :frowning:

apply Service "Host Cluster: " for (cluster in host.vars.clusters) {
import “generic-service”
check_command = “check_cluster”
display_name = "Host Cluster: " + cluster.cluster_displayname

vars.cluster_host = true
vars.cluster_label = cluster.cluster_displayname
vars.cluster_warning = cluster.cluster_warning
vars.cluster_critical = cluster.cluster_critical

vars.cluster_data = “”

for (host in cluster.cluster_hosts) {
vars.cluster_data += get_host(host).state + “,”
}

assign where “hostcluster” in host.vars.services
}

Regards,
Endre

Hi,

without check if it works in general. This line gets only resolved during reload/startup of icinga

vars.cluster_data += get_host(host).state + “,”

to make it work during runtime you have to use it like this one (it will return an array!)

vars.cluster_data = {{
    var cluster_hosts = macro("$cluster.cluster_hosts$")
    var tmp_data = [ ]
    for (ahost in cluster_hosts) {
        tmp_data += get_host(ahost).state
    }
    return tmp_data
}}

Regards,
Carsten

1 Like

Hello Carsten,

Thanks a lot, now I see what was wrong.
Now it works, thanks again!

Regards,
Endre

2 Likes