This check (along with the other accompanying http variables) tries to confirm that the page includes an IP address or subnet:
http_expect_body_regex = "^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}($|\/)"
However, the updated conf file didn’t pass validation:
sudo /usr/sbin/icinga2 daemon --validate
...
[lots of output]
...
[2024-05-02 21:12:39 -0500] critical/config: Error: Bad escape sequence found: \.
...
How am I supposed to check for a literal dot (.
) without a backslash?
The Icinga2 documentation’s language reference includes a list of string literals escape sequences. I just needed to replace the backslash (\
) with a double-backslash (\\
).
I updated the variable:
http_expect_body_regex = "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}($|\\/)"
That still didn’t pass validation:
sudo /usr/sbin/icinga2 daemon --validate
...
[lots of output]
...
[2024-05-02 21:21:12 -0500] critical/config: Error: Validation failed for object 'blocklist!https' of type 'Service'; Attribute 'vars' -> 'http_expect_body_regex': Closing $ not found in macro format string '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}($|\/)'.
...
Now it doesn’t like the dollar sign ($
). The dollar sign isn’t listed in the language reference as a character that needs escaping though.
Fortunately, I ran into this Icinga2 community post: Which characters within a string need to be escaped in Icinga’s configs?
That page indicates that the dollar sign is used in macros and can be escaped with another dollar sign.
I updated the variable again:
http_expect_body_regex = "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}($$|\\/)"
That passed validation!
There is a note in the Icinga2 documentation under Monitoring Basics – Runtime Macros:
When using the $ sign as single character you must escape it with an additional dollar character ($$).