Pass service custom var to another services checks

Hi all,
I need to select a custom vars from specific services from a service group :slight_smile:

means… I have services assigned to a group “A12” I need to select the custom var called “CV001” from all these services and pass it as argument to a command/service check.

is that possible ?

icinga2 version: r2.8.1-1
Platform version: 16.04.4 LTS (Xenial Xerus)

How exactly would these multiple custom attribute values be compiled into one parameter value?

could it be passed as --CVAR “Value1” --CVAR “Value2” --CVAR “ValueN”

Actually I need the Value to be “SVC.Name=CV001(Value)”… and passed to --CVAR “”

I do this, because i have a service check for more than 100 services per service from a http server page.

I don’t need to hit that http very frequently, so I want to pass some of params of those services(inside the page), to the main service check.

So basically your resulting value for this custom attribute could be an array. Your CheckCommand uses just that, and sets repeat_key = true (look into the disk command for examples).

Well, you probably need to understand the magic behind functions, runtime lambda functions, custom attributes and object accessors then.


Custom Attributes


Object Accessors



Below is an idea from my mind, nothing tested.

apply Service "a12-group-check" {
  check_command = "group-check"

  //runtime evaluate lambda function
  vars.group_check_params = {{ 
    var result = []

    for(s in get_objects(Service)) {
      //skip all services which do not belong to group "A12"
      if ("A12" !in s.groups) {

      //found a service, look if it provides our value
      if(s.vars.contains("CV001")) {

      return result



  assign where ...
object CheckCommand "group-check" {

  arguments = {
     "--CVAR" = "$group_check_params$"

## Notes

This solution is expensive if you have many services (obviously the loop). If you are not familiar with all the above, start simple with the debug console and learn the DSL and its expression. Tackle how lambda functions work in general, and start developing your code bit by bit.

Hi dnsmichi!
Thanks a lot for your help…

I could do the below

var result = []
for(s in get_objects(Service)) { 
    if ( myGroup in s.groups ) {
# continue;  } ## commented
        if(s.vars.contains("Sessions")) {
            var tmpresult= + "=" + s.vars.Sessions;
return result

the if ("A12" !in s.groups) wasn’t matching for me :frowning: so I commented it out and reversed the logic to match and include the rest of logic inside it… is it harmful that way?

I add it directly to the argument … in the command definition…
does that mean that every check it will do resolve this function every time ? if yes, could it be added to field and/or cached somewhere ? I have around 70 main service with sub-services of 100 each.

I’m using the director latest version as of today.

That snippet only works inside static configuration files, that won’t be possible inside the Director itself.

If the reversed logic works for you, very nice. I did not test my example, it was just an idea how I would code it.