Regular Expression in Explicit Hosts Does not Work as Expected in Rule Definition

CMK version: 2.1.0.p44 CEE
OS version: Debian 11

Intention

I’d like to define a service discovery rule Disabled checks to disable mysql_capacity section of mk_mysql plugin on some of our database servers named:

  • maria-db1
  • maria-db2
  • maria-db3

What I did

As described in inline help, I added this to Explicit hosts in rule definition:

~maria-db

The condition is recognized as regex in rules list: Host name matches regex maria-db
But no success, the rule does not apply to any of above mentioned hosts.

I also tried these, but without success as well:

~maria-db.*
~maria-db.

To make sure rule definition works at all, I tried to define each host manually by adding each to explicit hosts, which worked as expected. Disabled Checks was listed in used host rules.

Question
How to use regex in explicit hosts correctly?
Does it work in CEE 2.1.0.p44 at all?

Not sure about 2.1.0 However

my regex is ~^p[1-4] and it matches p1server p3server

so your solution is probably

~^maria-db[1-3]$
or simply
~^maria-db

1 Like

I tried with 2.1.0p38 cee and it works for me with just

~maria-db

Of course, I used a different hostname, but I just used the beginning of my actual hostnames. The above won’t work, if the hosts are called e.g. my-maria-db or something. In that case, use ~.*maria-db

Maybe your rule unintentionally has some other conditions? A folder, for example?

Thanks for your hint, but that doesn’t work either.

As expected, because inline help says so:

… The names that you enter here are compared with case sensitive exact matching. Alternatively you can use regular expressions if you enter a tilde (~) as the first character. That regular expression must match the beginning of the host names in question…

Thanks for your ideas!

Double checked anything conflicting again and again and kept everything related as simple as possible. No success.

Adding host names without regex (e.g. maria-db1) does work though. So nothing else should prevent the rule to be applied.

1 Like

hi

try to use this RegEx ~^maria-db[1-9]$
if you have maria-db15 or 30 add this before $ ,
[0-9]?

in my case it has been successful

Hi Mario,

generally speaking, I am quite used to regex, but no success at all in this case.

Your suggestion doesn’t work as well. It is almost the same as MarkusH tipp, which I already checked before.

There must be something else which I did not considered yet or there is relly something wrong in 2.1.0p44CEE…

1 Like

shot in the dark, but would you mind sharing screenshots of the rule + the Setup Menu and the hosts location + a view of the service in the host?
Maybe the issue is not with the regex but something else? (I guess we’ve all been there, looking at a problem for too long that one focuses on the wrong aspect)

1 Like

Sure, I’d be happy if that would help finding what I probably have missed…

As you can see, the rule definition is recognized as a regex beneath three other explicit host names

All hosts mentioned in this rule reside in exact same host folder.

Defining e.g. sp-maria-db1 explicitly works as expected; rule is applied and service is disabled for sp-maria-db1 then.

Changing rule using regex as shown above, does not :roll_eyes: