Monitoring same hosts from multiple locations

Is there a specific example on local expressions you’d need here?

Enabling / disabling notifications.

The host object is not available in this scope for anonymous lamdba functions, there’s nothing which binds this into the scope.

Ok. As you can see in my example, I put in log() for debugging purposes. It does output the proper value for mygroup to the icinga log. Is log() handled in some special way?

I cannot make it work with your suggestion either. That’s what I tried:

var myhost = macro("$host.name$")
log(myhost)
var myobj = get_host(myhost)
var mygroup = myobj.vars.aggregate_group
log(mygroup)
var nodes = get_objects(Host).filter(node => mygroup in node.groups)

log() both times output the correct value for myhost and mygroup. But still … undefined script variable …

Next try:

globals.get_hostgroup_status_array = function(mygroup) {
    log(mygroup)
    var nodes = get_objects(Host).filter(node => mygroup in node.groups)
}

Then in the debugger console: <1> => get_hostgroup_status_array(“DEMO”)

Results in Tried to access undefined script variable ‘mygroup’. Even if log() outputs the proper value to the icinga log. I guess I shouldn’t have a scoping issue here, as the variable has been explicitly passed to the function?

As of now, I’m continuing with:

globals.get_hostgroup_status_array = function(mygroup) {
    var nodes = get_objects(Host)
    for (node in nodes) {
      if (mygroup !in node.groups) {
        continue
      }
      [...]