BI: parameter in a regex

Hellows!
TL;DR: How can I use a parameter in a regex? $param$\d.example.com does not work. Adding 1 or 2 backslashes does not work either

I need to set up a BI Aggregation for some clustered services. The setup looks like this:
Three-ish servers, which have numbered hostnames

email1.example.com
email2.example.com
email3.example.com

and a Loadbalancer with the same name, but no number.
email.example.com

We use this naming-schema for multiple services (LDAP, WEB, …) and I wanted to create rules with parameters. The aggregation is a very flat tree:

Service $service="email"$ is available (Worst status of all children)
|--> Loadbalancer $service="email"$ (Worst)
|--> Cluster nodes $service="email"$\d (Worst, but limited to WARNING)

So I tried to set up a rule and set the Child Node Generator to Create Nodes based on a host search to capture the numbered cluster-hosts but it wants a regex, which seems to be incompatible with $parameters$ due to the dollar sign.

image

Is that correct or is there a trick to use parameters in regexes?
I was unable to find any reference and surfing the cmk code is too hard for me.

Cheers!
chris :slight_smile:
edit: add screenshot

Hello,
have you tried to create parameters for SERVICE and NUMBER?
Then the regex should look like: $SERVICE$$NUMBER$.example.com

Karl

Hello,
somethin like this works also: $MYPARAM$[0-9].example.com

Christian

Karl, Christian, thanks for the answers!

Alas, even with them I don’t get this to work. I documented the whole setup in this poster.


I hope it goes through in full resolution. Otherwise I’ll think of something and edit this post.
I just wonder how a dollar-sign, which means “end-of-line” in regular expressions, can be used here without some magic.

Did you try $HOSTNAME$ or $1$ for the Host itself form search result. This is what described in the Help of the Rule.

Aha. Thank you Christian. That put me on the right track.

I’ve been playing around and seen some funny things.
So these are my experiment-notes. First line is the Hostname Regex, second line is Nodes to create and third line is the result. To start my fun result without a parameter:

* "all hosts"
+ email\d.*
= 156 (!) nodes, 52x email1-3 - one for each of the 52 hostnames in the database.

* .* (which is effectively "all hosts")
+ email\d.
= 3 correct nodes
-> "all hosts" is not the same as "regex .*"

Now with the parameter. I’ll start with the correct answer and then add all my failures.

* $SERVICE$([0-9]).example.de
+ $HOSTNAME$
= Perfect result. but why?

* $SERVICE$[0-9].sim.lrz.(de)
+ $HOSTNAME$
= 1 correct host. seems like it kind of matters where the parens go.

* $SERVICE$[0-9].example.de
+ $HOSTNAME$
= 1 correct host. number one: email1.example.de - 2 missing

* $HOSTNAME$
+ $SERVICE$[0-9].example.de
= nothing

* $1$
+ $SERVICE$[0-9].example.de
= nothing

* $SERVICE$[0-9].example.de
+ $1$
= nothing

* ($SERVICE$[0-9]).example.de
+ $1$
= nothing

* ($SERVICE$[0-9]).example.de
+ $1$
= nothing

* $1$
+ ($SERVICE$[0-9]).example.de
= nothing

* $SERVICE$([0-9]).example.de
+ $SERVICE$$1$
= nothing

* $SERVICE$([0-9]).example.de
+ $HOSTNAME$$1$
= nothing

Now for some other fun: The same thing, but for services!
So far, I’ve been able to produce hosts with “Create nodes based on a service search”:

Create Nodes based on a service search
+ regex for host name 
+ nodes to create host - empty is not allowed
service regex is empty with the non-parameterized rules.
non-parameterized rules have "regex for host name" and "nodes to create host" the same value


+ $service$([0-9]).example.de
+ $HOSTNAME$
= added 3 host nodes. not a single service.

+ $service$([0-9]).example.de
+ same 
= nothing

+ $service$[0-9].example.de
+ same 
= nothing

+ $service$([0-9]).example.de
+ $1$
= nothing,

+ $service$.*
+ .*
= 52 different host entries. each server in the database.

+ $service$.*
+ same
= nothing

Any idea what is going on here?
Cheers!
chris :slight_smile:

I would like to prefer to call a rule to detect the needed services for the host from host serach. If you want more than one service you can use a pipe like “CPU.*|Memory.*” and so on.

Regards,
Christian