Working on Blackbox's "fail_if_body_not_matches_regexp".

2,872 views
Skip to first unread message

yagyans...@gmail.com

unread,
Mar 15, 2021, 2:50:03 AM3/15/21
to Prometheus Users

Hi. I am using blackbox_exporter version 0.18.0 and I am using http prober to check if the response by my URL is "OK" or not. Below is the configuration of the module.

  http_healthcheck_ok:
    prober: http
    timeout: 10s
    http:
      valid_http_versions: ["HTTP/1.1", "HTTP/2.0", "HTTP/1.0"]
      fail_if_body_not_matches_regexp: ['OK']
      method: GET
      no_follow_redirects: false
      fail_if_ssl: false
      fail_if_not_ssl: false
      tls_config:
        insecure_skip_verify: true
      preferred_ip_protocol: "ip4"

So, whenever my URL throws anything other than OK in the response body, probe_failed_due_to_regex should 1 right? But when the URL was throwing NOK as the response body, probe_failed_due_to_regex was still 0, whereas it should be 1. Am I missing something here?

Thanks in advance!

yagyans...@gmail.com

unread,
Mar 22, 2021, 4:03:50 AM3/22/21
to Prometheus Users
Can someone please help! I am confused here.

Julius Volz

unread,
Mar 22, 2021, 9:20:56 AM3/22/21
to yagyans...@gmail.com, Prometheus Users
Hi,

the Blackbox exporter doesn't do full-string matching for these regexes, but substring matching, so it also matches if the body contains "OK" anywhere (which is true for "NOK"). Try '^OK$` instead?

Also, in case your HTTP endpoint returns a status code other than 2xx, you will have to set the "valid_status_codes" list to the allowed ones (it defaults to 2xx).

Regards,
Julius

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/e6db4504-48e6-4ad9-a640-1e63dc6e472en%40googlegroups.com.


--
Julius Volz
PromLabs - promlabs.com

Yagyansh S. Kumar

unread,
Mar 22, 2021, 12:09:11 PM3/22/21
to Julius Volz, Prometheus Users
Thanks, Julius.
--
Thanks & Regards
Yagyansh S. Kumar
DevOps Engineer, Dailyhunt - Bangalore
8696078312,8209496395

Yagyansh S. Kumar

unread,
Mar 22, 2021, 3:54:46 PM3/22/21
to Julius Volz, Prometheus Users
Hi Julius,

Using the expression "^OK$" leads to the failure of all the checks for which response was OK. This seems weird to me. Ideally, should have worked. Any more workarounds or suggestions to achieve this?

Marcelo Magallón

unread,
Mar 22, 2021, 5:18:45 PM3/22/21
to Yagyansh S. Kumar, Julius Volz, Prometheus Users
blackbox_exporter applies the provided regular expression against the entire body.

This means in particular that if your body is something like ['O', 'K', '\n'] (O, followed by K, followed by a carriage return), the regular expression '^OK$' WILL NOT match because '$' anchors it to the end of the body, not the end of the line.

In order to match lines, not the whole body, you have to write '(?m:^OK$)'. This will match 'OK' on a line by its own, but not say NOK on a line by its own. It will also match on a body like 'Something\nOK\nsomething\n'.

I hope this helps,

Marcelo



--
Marcelo Magallón

Julius Volz

unread,
Mar 23, 2021, 5:15:08 AM3/23/21
to Marcelo Magallón, Yagyansh S. Kumar, Prometheus Users
Thanks for clarifying, Marcelo! Having never used the regex matching myself, I also wasn't 100% sure about that :)

Yagyansh S. Kumar

unread,
Mar 24, 2021, 4:51:55 PM3/24/21
to Julius Volz, Marcelo Magallón, Prometheus Users
Thanks, Marcelo.
Reply all
Reply to author
Forward
0 new messages