Icinga Check Command with multiples of the same flag allowed how to handle

Hi Icinga Community,

The ITL command dns has a ‘-a’ parameter that allows for multiples of this flag.

https://icinga.com/docs/icinga-2/latest/doc/10-icinga-template-library/#dns
dns_expected_answers Optional. The answer(s) to look for. A hostname must end with a dot. Multiple answers must be defined as array.

Also, this is documented in the command definitions: -
dns_expected_answers Optional ip address or host you expect the DNS server to return. Host must end with a dot (.). This option can be repeated multiple times (Returns OK if any value match). If multiple addresses are returned at once, you have to match the whole string of addresses separated with commas (sorted alphabetically).

I defined a service and added an array as a string for the -a variable ‘dns_expected_answers’ like this.

[10.70.55.23, ns2.services.somedomain.net]

But the check fails:
DNS CRITICAL - expected ‘[10.70.55.23, ns2.services.somedomain.net]’ but got ‘10.70.55.23’

We use Directory for managing the commands/services/hosts etc.

I can execute the check manually on the server

/usr/lib64/nagios/plugins/check_dns -H ns2.services.somedomain.net -slocalhost -qA -a 
ns2.services.trakm8.net -a 10.70.55.23 -w1 -c5
DNS OK: 0.010 seconds response time. ns2.services.somedomain.net returns 
10.70.55.23|time=0.009936s;1.000000;5.000000;0.000000

How do you define multiple ‘-a’ values for this check in icinga2 director?

Thank you in advance.

If you are looking up a hostname, then the result/s will be IP address/es.

If you are looking up an address, then the result/s will be hostname/s.

It doesn’t make sense to combine an IP address and a hostname in the expected
list of results; there is nothing you could look up which would return both of
these.

Antony.

Well I figured it out. The key is to locate the variable in Director under ‘Define Data Fields’ and set it to type array. In the service created for the command you have the option to add each item you want multiples of for this field.

  1. Monitoring Plugins - check_dns

     -a, --expected-address=IP-ADDRESS|CIDR|HOST
     Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end
     with a dot (.). This option can be repeated multiple times (Returns OK if any
     value matches).
    
  2. ITL defines -a with a parameter

    object CheckCommand “dns” {

    "-a" = {
          description = "Optional ip address or host you expect the DNS server to return. Host must end
          with a dot (.). This option can be repeated multiple times (Returns OK if any value match). If
           multiple addresses are returned at once, you have to match the whole string of addresses
           separated with commas (sorted alphabetically)."
          value = "$dns_expected_answers$"
    }
    
  3. Define dns_expected_answers in Icinga Director under ‘Define Data Fields’ and set it to type array

  4. Create a service for the command

Hope this helps someone.

@Anthony Stone - Thanks but what if I wanted to specify multiple hostnames as the command states its possible to use the ‘-a’ flag multiple times.