Prometheus blackbox exporter
I don't find the way the blackbox exporter config works intuitive. It could be that I'm doing things incorrectly but I have worked out how to get things to function how I need them to.
In the following example I needed to parse HTML from a page and make sure it had the text I expected. For this I used the fail_if_not_matches_regexp function of the http prober.
What confused me was that I wasn't able to define the URL of the website I was probing in the blackbox exporter config even though this is where I was defining the regex. Instead the website URL is sent as a param. This being the case you end up linking the URL and the module that the regex is defined in as params.
In the example below my target is https://www.ubuntu.com and my module is ubuntu within which I've set the regex (see yaml below)
http://localhost:9115/probe?target=https://www.ubuntu.com/&module=ubuntu
Here's the config file for this:
modules:
wikipedia:
prober: http
timeout: 5s
http:
fail_if_not_matches_regexp:
- "Welcome to Wikipedia"
preferred_ip_protocol: "ip4"
valid_http_versions:
- "HTTP/1.1"
- "HTTP/2"
method: GET
tls_config:
insecure_skip_verify: true
ubuntu:
prober: http
timeout: 5s
http:
fail_if_not_matches_regexp:
- "Everything you need to know about Ubuntu"
preferred_ip_protocol: "ip4"
valid_http_versions:
- "HTTP/1.1"
- "HTTP/2"
method: GET
tls_config:
insecure_skip_verify: true
and here's the blackbox exporters log entry:
ts=2018-11-24T21:24:37.6824918Z caller=main.go:174 module=ubuntu target=https://www.ubuntu.com/ level=debug msg="Probe succeeded" duration_seconds=0.2786691