Page 1 of 1

Regular expression to exclude host in hostgroup members

Posted: Fri Apr 17, 2020 5:51 am
by bcattapan
Hi,

I'm trying to define a host group which will take all hosts which have (odd numbers). But we do have one exception, and I would like to exclude it.
We have these configurations enabled in nagios.cfg:

use_regexp_matching=1
use_true_regexp_matching=1


This works perfectly, but I can't exclude that webapp17 server.

Code: Select all

define hostgroup{
        hostgroup_name	odd-servers
        alias		PROD Servers Odd
        members 	(^.*prod-.*\d*[13579]\..*$)
}
I tried the following. All without success (even though all regegular expressions below were tested and work in regex101.com)

Code: Select all

define hostgroup{
        hostgroup_name	odd-servers
        alias		PROD Servers Odd
        members 	(^.*prod-.*\d*[13579]\..*$)(?<!^blablabla-prod-webapp17\.foo\.bar\.com$)
}
This fails with: Error: Could not expand members specified in hostgroup

Code: Select all

define hostgroup{
        hostgroup_name	odd-servers
        alias		PROD Servers Odd
        members 	(^(?!^blablabla-prod-webapp17\.foo\.bar\.com$).*prod-.*\d*[13579]\..*$)
}
This fails with: Error: Could not expand members specified in hostgroup

Code: Select all

define hostgroup{
        hostgroup_name	odd-servers
        alias		PROD Servers Odd
        members 	(^.*prod-.*\d*[13579]\..*$),?!^blablabla-prod-webapp17\.foo\.bar\.com$
}
This fails with: Error: Could not expand members specified in hostgroup

I tried to define three host groups and try to use the exclusion on hostgroup_members, same thing.

Code: Select all

define hostgroup{
        hostgroup_name odd
        alias		odd servers
        members 	^.*prod-.*\d*[13579]\..*$
}

define hostgroup{
        hostgroup_name	odd-exception
        alias		odd server exception
        members 	blablabla-prod-webapp17.foo.bar.com
}

define hostgroup{
        hostgroup_name target-odd-servers
        alias		odd servers but the exceptional one
        hostgroup_members odd,?!odd-exception
}
This fails with: Could not find member group '?!odd-exception' specified in hostgroup 'target-odd-servers'.

Tried without the ?

Code: Select all

define hostgroup{
        hostgroup_name odd
        alias		odd servers
        members 	^.*prod-.*\d*[13579]\..*$
}

define hostgroup{
        hostgroup_name	odd-exception
        alias		odd server exception
        members 	blablabla-prod-webapp17.foo.bar.com
}

define hostgroup{
        hostgroup_name target-odd-servers
        alias		odd servers but the exceptional one
        hostgroup_members odd,!odd-exception
}
This fails with: Could not find member group '!odd-exception' specified in hostgroup 'target-odd-servers'.

Any clue how to get it working?