While you could use the "query" template function to achieve this (see
https://prometheus.io/docs/prometheus/latest/configuration/template_reference/
 and
https://prometheus.io/docs/prometheus/latest/configuration/template_examples/),
it's probably easiest to just make the alerting expression itself return
the value you want by only returning status codes for checks that have
failed:

  expr: probe_http_status_code{job=~"blackbox_Service-HealthChecks"} and
(probe_success{job=~"blackbox_Service-HealthChecks"} == 0)

Btw., you could change the "=~" to just "=" because that regex is just
doing a full string equality match anyway.

On Fri, Apr 17, 2020 at 7:06 PM Yagyansh S. Kumar <yagyanshsku...@gmail.com>
wrote:

> Hi. I am using Blackbox exporter to monitor my Application's and LB's
> HealthCheck URLs.
>
> My alert for this looks like below:
>
>   - alert: ServiceHTTPChecks
>     expr: probe_success{job=~"blackbox_Service-HealthChecks"} == 0
>     for: 2m
>     labels:
>       severity: "CRITICAL"
>     annotations:
>       summary: "Healthcheck *{{ $labels.checkname }}* failed."
>       description: *I NEED THE RESPONSE CODE THAT THE INSTANCE HAS AT THIS
> POINT OF TIME*
>       identifier: "*URL:* `{{ $labels.instance }}`, *Cluster:* `{{
> $labels.cluster }}`, *node:* `{{ $labels.node }}` "
>
> Whenever the probe_success is 0, I also want the response code for my
> instance at that time which probe_success itself does not have and is
> provided by probe_http_status_code.
> My question is can I append the response code from the
> probe_http_status_code query to the labels of probe_success using the
> group_left?
> If no, what other way is there to get the response code printed in my
> alert whenever my URL is down.
> Thanks in advance!
>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/prometheus-users/2447ca8c-c2a0-4bb7-bcf4-23fed0c30654%40googlegroups.com
> <https://groups.google.com/d/msgid/prometheus-users/2447ca8c-c2a0-4bb7-bcf4-23fed0c30654%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/CA%2BT6Yow0cKh__kCzJ1T3k4UyLoDA1sWatyq-f_uJY%3DASNeUaBA%40mail.gmail.com.

Reply via email to