CMK version: 2.1.0p44
OS version: Debian 11
Error message: n/a
Standard REST API using requests, as per the documentation.
Creating a rule, “Hosts to be monitored”,
condition looks like this:
"host_name": {
"match_on": [condition],
"operator": "one_of",
}
Goal: Automatically create a rule to only monitor devices that have a host name matching a specific pattern.
The pattern is that the host name must contain 2 specific letters somewhere in the name.
For example: AB
Because it’s a “contains” like match, a regular expression would be the most logical use to create the filter.
To make a regular expression the tilde (~) needs to be put in front of the condition according to the documentation.
Resulting in:
condition='~AB'
Problem:
Outcome is a rule with a filter set to:
~^AB
It adds a ‘^’ on its own accord, which breaks the intent as it will now only match those hosts that have a name starting with AB, instead of AB being somewhere in the name.
Using the UI, i can enter ‘~AB’ without the regex being changed.
I am seeking a way to ensure that the API doesn’t add anything on it’s own accord and leaves the condition intact in the way i provided it.
I also consider it a bug that the REST API is behaving different from the UI.
I find it bad logic that the API call is adding characters that are not explicitly provided.