Icinga2 abstract function for inherit assigning

hi guys,

I would like to define service groups, per host, with always the same services and would like to maintain the services redundantly, since the templates only support properties and are not there for the inheritance of assignments, I wanted to help myself with a function, but here I get the error

My function is referenced here =>
“critical/config: Error: Argument is not a callable object.”

Example configuration:
##############################################
 function service_matches(host, service) {
    return regex(“^Live$”, host.vars.roles, MatchAny) && (match(“*CustomService*”, service.name))
  }

object ServiceGroup “Test” {
  display_name = “TestSG”
  assign where host.name in [“aaa.test.de”, “bbb.test.de”] && service_matches(host, service)
}

I look forward to your feedback

1 Like

Maybe I don’t get it but what is wrong with:

object ServiceGroup "Test" {
  display_name = "TestSG"
  assign where match("Live*", host.vars.roles) && match("*CustomService*", service.name)
}

thanks for your answer,

thanks for your answer, the problem is that there are several services and I would not like to redefine them again and again, but only want to define the target hosts per service group and load the services additionally using a function

I am not sure I understand the business case, but we are using the Service Set functionality offered by Icinga Director.

I could not find the description of that functionality in the official documentation, but here is a start point: Director Service Sets: Add service checks based on host templates - Meta Icinga / Tutorials and Guides - Icinga Community

Basically, you group the Services in a Service Set, and you assign the Service Set to a range of Hosts using an Apply Rule.

Hey,

thanks for providing the documentation, we don’t use the director and write the rules ourselves, it’s okay if that doesn’t work, the idea was to save the countless redundant service definitions, just define them once and then only create specific ServiceGroups per host, we’re talking about over 50 services, that otherwise fills the config, but if that’s the way to go, we’ll do it that way, thanks!

I just wanted to stick to the dont repeat your self method here and that’s what I have to do.

We do not have the case that we are interested in all hosts per ServiceGroup, but the ServiceGroup must be grouped per host, so it only works for us.

Hi @lrutz97, you have to put your function into the globals like this.

globals.service_matches = function(host, service) { 
  return regex("^Live$", host.vars.roles, MatchAny) && (match("*CustomService*", service.name)) 
}

Hey,

thanks for the tip with globals now it is so that it is basically seen by the config as okay, but I can not find the ServiceGroup objects, where is the error?

Thanks for the help!

  globals.service_matches = function(host, service) { 
  return regex("^Live$", host.vars.roles, MatchAny) && (match("*CustomService*", service.name)) 
} 

object ServiceGroup "Test" {
  display_name = "TestSG"
  assign where host.name in [ "aaa.test.de" ] && service_matches(host, service)
}

Hey guys,

yeah… thanks it worked, of course if you use a service as an example that is no longer used, then it looks bad with the check

You are welcome to close the task