# Help understand Lambda Closures / Language Syntax

**URL:** <https://community.icinga.com/t/help-understand-lambda-closures-language-syntax/12627>\
**Category:** Icinga 2\
**Created:** [September 19, 2023, 11:48am UTC](https://community.icinga.com/t/help-understand-lambda-closures-language-syntax/12627 "2023-09-19T11:48:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fir3wall](https://community.icinga.com/letter_avatar_proxy/v4/letter/f/df788c/32.png) [@fir3wall](https://community.icinga.com/u/fir3wall)\
**Post date:** [September 19, 2023, 11:48am UTC](https://community.icinga.com/t/help-understand-lambda-closures-language-syntax/12627/1 "2023-09-19T11:48:36Z")

</div>

Hi,

I found great function wrote by somebody earlier that monitor overdue services. Trying to however change it into monitoring overdue services per service group (taken as parameter).

As you can say may need some work (but works from console) for example:

- Need to figure out how I can merge 2 filter arguments (so overdue + in groups - now just doing this stupid if/if thing)
- Same with passive (want to ignore these)

```auto
globals.getLateServicesPerEnv = function(env) {
  var res = []
  var env_filter = env + "-services"
  for (s in get_objects(Service).filter(s => s.last_check < get_time() - 2 * s.check_interval)) {
    if (env_filter in s.groups) {
        if (s.check_command == "passive") {
            true
        } else {
          res.add(s.__name)
        }
    }
  }
  return res
}

```

Calling this like that in my check

```auto

apply Service "ic2_overdue_checks-" for (key => config in host.vars.overdue_checks) {
....
  vars.overdue_services = {{ return getLateServicesPerEnv(key) }}

....

```

So in my host have simple vars.overdue\_services[“SOMETHING”'] = { } and I want to see only overdue checks for SOMETHING-services group that are not passive checks.

But this is no go - key value is not defined. I think it’s because this that I need to implement:  
[https://icinga.com/docs/icinga-2/latest/doc/17-language-reference/#lambda-expressions-with-closures](https://icinga.com/docs/icinga-2/latest/doc/17-language-reference/#lambda-expressions-with-closures)

But not so good in IC2 syntax - are anyone able to assist what need to be added?

And if you already stop laughing then feel free also to simplify my function!

Thanks  
D

---

<div class="post-metadata">

**Author:** ![Al2Klimov](https://community.icinga.com/user_avatar/community.icinga.com/al2klimov/32/959_2.png) [@Al2Klimov](https://community.icinga.com/u/Al2Klimov)\
**Post date:** [September 28, 2023, 8:16am UTC](https://community.icinga.com/t/help-understand-lambda-closures-language-syntax/12627/2 "2023-09-28T08:16:55Z")

</div>

Hi Dariusz!

You seem to want

`vars.overdue_services = () use(key) => getLateServicesPerEnv(key)`

Best,  
A/K
