7

I'm having difficulty finding good documentation for wildcards and regular expressions (particularly as they work with exclusions) in Nagios. Here is an example of what I'm trying to do:

In nagios.cfg, the following are set, supposedly enabling * and ? as wildcards:

use_regexp_matching=1
use_true_regexp_matching=0

In services.cfg, we have a service that we would like to apply to all but a few objects; that is all Linux hosts, but not load balancers. Explicit exclusion works:

define service {
     use                  generic-service
     service_description  Puppet check
     hostgroup_name       prod, staging, !prod-site_a-lbs
     check_command        check_puppet_alive_nrpe
}

But, we have many sites, each with load balancers in their own hostgroups (so notifications can be easily managed by site). Rather than having a long list of !prod-site_a-lbs, !staging-site_a-lbs, !prod-site_b-lbs. I'd hoped to be able to modify the hostgroup_name line to:

     hostgroup_name       prod, staging, !*-lbs

I have tried this, and while we don't get an error, this service check is still being applied to our load balancers. To double check, I have also tried:

     hostgroup_name        prod, staging, !.*-lbs

But, this fails, as expected (since use_true_regexp_matching is not set), when running checkconfig-noprecache:

 Error: Could not find any hostgroup matching '!.*lbs' ...

In testing, .* is accepted by checkconfig-noprecache if ! is removed.

Is what we're trying possible? Can we use wildcards to exclude matching hostgroups? Or, is there an alternative that would be just as clean?


Update (2015-09-21): After testing Keith's answer, this configuration is working:

In services.cfg:

define service {
    use                  generic-service
    service_description  Puppet check
    hostgroup_name       prod, staging, !lbs
    check_command        check_puppet_alive_nrpe
}

And in hostgroups.cfg, I have defined a new hostgroup using a regular expression in the 'members' directive:

define hostgroup {
    hostgroup_name  lbs
    alias           Load Balancers
    members         ^lb.*
}
Jeremy Koppel
  • 73
  • 1
  • 6

1 Answers1

4

The only way I believe you can achieve this is by making a new hostgroup comprised of the hosts in question (using a wildcard), and then excluding this new hostgroup.

Keith
  • 4,637
  • 15
  • 25