# Problems monitoring services with array values

**URL:** <https://community.icinga.com/t/problems-monitoring-services-with-array-values/361>\
**Category:** Icinga Director\
**Created:** [February 13, 2019, 10:18am UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361 "2019-02-13T10:18:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon9497968](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anon9497968](https://community.icinga.com/u/anon9497968)\
**Post date:** [February 13, 2019, 10:18am UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/1 "2019-02-13T10:18:29Z")

</div>

Hello,

I’m trying to set up a check using `check_http` that checks a set of pages on a webserver based on a custom array attached to each host object. While the number of checks expands to match the number of array elements, the check command seems to include all of them (so all checks are the same).

As a result of all array elements being added to the command the check looks like this:

`'/usr/lib/nagios/plugins/check_http' '-H' 'sub.example.org' '-I' '172.16.4.65' '-S' '-u' '/GiveMeA404' '-u' '/'`

Whereas I’d expect two checks like this:  
`'/usr/lib/nagios/plugins/check_http' '-H' 'sub.example.org' '-I' '172.16.4.65' '-S' '-u' '/GiveMeA404'`  
and  
`'/usr/lib/nagios/plugins/check_http' '-H' 'sub.example.org' '-I' '172.16.4.65' '-S' '-u' '/'`

I don’t understand why Icinga is expanding the config to create the correct number of checks, yet the check command isn’t being expanded in the same way. The service template config is below.

Any advice would be gratefully appreciated. I’ve seen the [fields interface array example](https://github.com/Icinga/icingaweb2-module-director/blob/master/doc/14-Fields-example-interfaces-array.md) but it stops short of explaining how to use the configuration.

Many thanks in advance

* * *

**Command**

```auto
object CheckCommand "HTTP_PageCheck" {
    import "plugin-check-command"
    import "http"

    arguments += {
        "-H" = "$Web_DNS_name$"
        "-S" = {}
        "-u" = {
            required = true
            value = "$Pages_to_check$"
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![anon66228339](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@anon66228339](https://community.icinga.com/u/anon66228339)\
**Post date:** [February 13, 2019, 10:56am UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/2 "2019-02-13T10:56:49Z")

</div>

That is the command not the service 🙂  
We need to see your service apply rule and also an example of your array.

Regards,  
Carsten

---

<div class="post-metadata">

**Author:** ![anon9497968](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anon9497968](https://community.icinga.com/u/anon9497968)\
**Post date:** [February 13, 2019, 11:27am UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/3 "2019-02-13T11:27:22Z")

</div>

Hi Carsten, thanks for the swift reply.

Apologies, you’re correct. I’ve edited my original post to correct it.

**Service apply rule - zones.d/director-global/service\_apply.conf**

```auto
apply Service "Webpage check for " for (config in host.vars.Pages_to_check) {
    import "webpage-check"

    assign where host.vars.Pages_to_check

    import DirectorOverrideTemplate
}

```

**Example host showing the array - zones.d/master/hosts.conf**

```auto
object Host "Webserver" {
    import "generic-host"
    import "web-server"

    display_name = "webserver.example.local"
    address = "172.16.4.65"
    groups = ["Web Servers"]
    vars.Pages_to_check = ["/GiveMeA404", "/"]
    vars.Web_DNS_name = "sub.example.org"
}

```

Hope that helps,

Jonathan

---

<div class="post-metadata">

**Author:** ![twidhalm](https://community.icinga.com/user_avatar/community.icinga.com/twidhalm/32/18_2.png) [@twidhalm](https://community.icinga.com/u/twidhalm)\
**Post date:** [February 13, 2019, 12:33pm UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/4 "2019-02-13T12:33:10Z")

</div>

This doesn’t work this way.

Icinga doesn’t expand an array to multiple checks by just giving it an array for a variable.

After your `apply for` rule is through, you’ll end up with two services where one has `/GiveMeA404` the other one `/` as value of the `config` variable. You’ll have to use this in your Service definition.

A general tip: Normally you don’t have to change the CheckCommands from the ITL. If you have to do, think twice if you didn’t just go the wrong way. (But if you really have to, your solution of inheriting the command is still the best)

---

<div class="post-metadata">

**Author:** ![anon66228339](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@anon66228339](https://community.icinga.com/u/anon66228339)\
**Post date:** [February 13, 2019, 12:38pm UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/5 "2019-02-13T12:38:25Z")

</div>

Hello Jonathan,

can you post the full service please.

Edit: Thomas was faster 🙂

---

<div class="post-metadata">

**Author:** ![anon9497968](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anon9497968](https://community.icinga.com/u/anon9497968)\
**Post date:** [February 13, 2019, 2:26pm UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/6 "2019-02-13T14:26:47Z")

</div>

Thank you both for your replies. Icinga2 is still quite new to me, so apologies if I ask a lot of (possibly obvious) questions. There’s been a few changes to the environment over lunch, so I’m pasting the up-to-date version.

@twidhalm - if I understand you correctly, the apply rule takes the array defined in the _apply for_ box (so `Pages_to_check` in the config below) and puts that array into `$config$`. I should then use `$config$` in my arguments list on the command? Icinga does a `for each` on the elements of the `$config$` array. Have I got that correct?

Using `$config$` instead gives me

> “Error: Non-optional macro ‘config’ used in argument ‘-u’ is missing.”

The command looks like this once I’ve done that:

```auto
object CheckCommand "HTTPS_PageCheck" {
    import "plugin-check-command"
    import "http"

    arguments += {
        "-H" = "$Web_DNS_name$"
        "-S" = {}
        "-u" = {
            required = true
            value = "$config$"
        }
    }
}

```

I only created a new command (rather than using the provided `check_http`) because I couldn’t see how to add fields / arguments to the check. Suspect I’m missing something so any guidance appreciated.

@anon66228339 - by full service I’m assuming you mean the service with all of its imports? If so:

```auto
apply Service "Webpage check for " for (config in host.vars.Pages_to_check) {
    import "https_webpage-check"

    assign where host.vars.Pages_to_check

    import DirectorOverrideTemplate
}

template Service "https_webpage-check" {
    check_command = "HTTPS_PageCheck"
}

object CheckCommand "HTTPS_PageCheck" {
    import "plugin-check-command"
    import "http"

    arguments += {
        "-H" = "$Web_DNS_name$"
        "-S" = {}
        "-u" = {
            required = true
            value = "$Pages_to_check$"
        }
    }
}

```

Thanks again for your assistance

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [February 14, 2019, 5:56pm UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/7 "2019-02-14T17:56:00Z")

</div>

Hi,

## command fields

> [@anon9497968](#):
>
> I couldn’t see how to add fields / arguments to the check. Suspect I’m missing something so any guidance appreciated.

You might want to check [this howto](https://community.icinga.com/t/director-service-sets-add-service-checks-based-on-host-templates/267), specifically the first screenshot where you navigate into the external imported CheckCommand and pick the `Fields` tab on the right.

 ![director_service_set_requirements_check_command_fields](https://community.icinga.com/uploads/default/original/1X/2b2f517e98dd52cd75a235346cc1d97187e08f77.png)

## apply for

In terms of the other question, the apply for rule generated passes the `config` loop variable to the service apply rule.

In its context, it is missing to set the custom variable `Pages_to_check` expected from your CheckCommand object below.

In the DSL this would look like this

```auto
apply Service "Webpage check for " for (config in host.vars.Pages_to_check) {
    import "https_webpage-check"

    vars.Pages_to_check = config //added, config is the loop value from host.vars.Pages_to_check

    assign where host.vars.Pages_to_check

    import DirectorOverrideTemplate
}

```

Now your task is to figure out how this can be done in the interface, can you share a screenshot of what you’ve done thus far?

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![anon9497968](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anon9497968](https://community.icinga.com/u/anon9497968)\
**Post date:** [February 21, 2019, 2:33pm UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/8 "2019-02-21T14:33:00Z")

</div>

Hello,

I’ve been away a few days. I’ll have a look now and report back shortly.

Thanks

---

<div class="post-metadata">

**Author:** ![anon9497968](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anon9497968](https://community.icinga.com/u/anon9497968)\
**Post date:** [March 1, 2019, 12:00pm UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/9 "2019-03-01T12:00:41Z")

</div>

Hello,

OK, think I’m getting myself very confused here. Thank you all for your guidance so far and @dnsmichi for the link to that howto - that’s explained adding fields to checks nicely. I think I’ll need to specify my own command though as I need to say “this argument is populated with this field”.

To use the custom array on the host I’ve been following [this tutorial](https://blog.sleeplessbeastie.eu/2018/02/22/how-to-monitor-ssl-certificates-using-icinga2/). I’ve just tried to start from scratch but have got myself into a right mess. Screenshots etc. below.

**Command**  
I’ve got a command, `HTTP_Page_Check`, based on `HTTP`, which I apply arguments to for `-H` (hostname) and `-u` (URL to check, relative to `-H`):

 ![HTTP_PageCheck_Command](https://community.icinga.com/uploads/default/original/1X/ab7cb56cffc5375ce43af60fc553a11508e38f56.png)

Fields are specified (I’m not sure why I’m seeing them twice, I don’t recall seeing that before):

 ![HTTP_PageCheck_Fields](https://community.icinga.com/uploads/default/original/1X/bd2fd1930dcc292dc5814fe37344cd7e81647408.png)

Arguments are then mapped:

 ![HTTP_PageCheck_Arguments](https://community.icinga.com/uploads/default/original/1X/bbcda8cd5e2ad4783046b76c336b551aa27940fb.png)

That renders like this:

```auto
object CheckCommand "HTTP_PageCheck" {
    import "plugin-check-command"
    import "http"

    arguments += {
        "-H" = "$Web_DNS_name$"
        "-u" = {
            required = true
            value = "$config$"
        }
    }
}

```

**Service Template**

 ![Template2](https://community.icinga.com/uploads/default/original/1X/b4f28b04e5c8e4addd4429d5d6e98f03facd64eb.png)

The service template renders like so:

```auto
template Service "http-webpage-check" {
    check_command = "HTTP_PageCheck"
}

```

**Apply rule**

 ![ApplyRule_Service](https://community.icinga.com/uploads/default/original/1X/00214e02938c314c5b051e1e643dfc3dd423b3f8.png)

Generating:

```auto
apply Service "HTTP webpage check for " for (config in host.vars.HTTP_Pages_To_Check) {
    import "http-webpage-check"

    assign where host.vars.HTTP_Pages_To_Check

    import DirectorOverrideTemplate
}

```

The above configuration gives an error o the service (which seems to be correctly applied to various hosts):

> Error: Non-optional macro ‘config’ used in argument ‘-u’ is missing.

I don’t understand why `$config$` is missing. What am I doing wrong please?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [March 11, 2019, 1:15pm UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/10 "2019-03-11T13:15:00Z")

</div>

Hi,

back from vacation 🕶

`$config$` is a special macro introduced by the Director when using apply rules with for loops. I don’t know much about its specific rendering, but reading the tutorial you’ve linked, your generated apply rule is missing a field.

```auto
apply Service "Check SSL certificate for " for (config in host.vars.ssl_domains) {
    import "Check SSL certificates"

    assign where host.vars.ssl_domains
    vars.config = config //this one

    import DirectorOverrideTemplate
}

```

Meaning to say, the apply rule is missing the custom property `config` sourcing from your http pages to check.

Though, the host object holds that array, right? Maybe you can add the current config object for `Webserver`?

Besides, which Director version are you using now?

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![anon9497968](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anon9497968](https://community.icinga.com/u/anon9497968)\
**Post date:** [March 22, 2019, 9:13am UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/11 "2019-03-22T09:13:05Z")

</div>

Hello,

Sorry, lots of things happening at work at the moment so I’ve not had opportunity to look into this further. Hopefully next week! Hope you had a good vacation.

Current Director version is 1.6.2 which is the latest release.

> [@dnsmichi](#):
>
> Though, the host object holds that array, right? Maybe you can add the current config object for `Webserver` ?

Yes, the host holds the HTTP pages array. I haven’t seen an existing object for `Webserver` though?

Jonathan

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [March 22, 2019, 9:23am UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/12 "2019-03-22T09:23:37Z")

</div>

Hi,

re-iterating the CheckCommand attribute `config` for the `-u` parameter - I would change that, so that it looks like this:

```auto
object CheckCommand "HTTP_PageCheck" {
    import "plugin-check-command"
    import "http"

    arguments += {
        "-H" = "$http_web_dns_name$"
        "-u" = {
            required = true
            value = "$http_page$"
        }
    }
}

```

This requires the two fields `http_web_dns_name` and `http_page` to be defined as data field for this newly created CheckCommand. These fields should then be populated by service sets.

The apply for rule resulting from this should look like this:

```auto
apply Service "Webpage check for " for (config in host.vars.Pages_to_check) {
    import "https_webpage-check"

   //custom variables as data field attributes
   vars.http_web_dns_name = host.name //or something else
   vars.http_page = config //holds a single value, 1. iteration "/GiveMeA404" 2. iteration "/"

    assign where host.vars.Pages_to_check

    import DirectorOverrideTemplate
}

```

I’m not sure though how to configure that in the Director.

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![anon9497968](https://community.icinga.com/letter_avatar_proxy/v4/letter/a/22d042/32.png) [@anon9497968](https://community.icinga.com/u/anon9497968)\
**Post date:** [April 16, 2019, 8:43am UTC](https://community.icinga.com/t/problems-monitoring-services-with-array-values/361/13 "2019-04-16T08:43:42Z")

</div>

Apologies, not had time to look into this further. It may be it simply can’t be done in Director.

Sadly it’s not looking like I’ll have time to look into this any time soon 😢.
