curl http200,blackbox 400 why

76 views
Skip to first unread message

李毅

unread,
May 12, 2020, 6:17:33 AM5/12/20
to Prometheus Users

Use curl with parameters to return status code 200, use blackbox to return 400, why?

prometheus  v2.15.2
blackbox-exporter:master

blackbox.yml

  http_2xx_estate:
    prober: http
    timeout: 5s
    http:
      method: post
      headers:
        key: abc
        data: 123
        Content-Type: application/json;charset=UTF-8
        body: '{}'

prometheus.yml

  - job_name: 'blackbox_estate'
    metrics_path: /probe
    params:
      module: [http_2xx_estate]  # Look for a HTTP 200 response.
    static_configs:
      - targets:
        - https://xx.com/xxl/get/xxx

    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 192.168.201.165:9115  # The blackbox exporter's real hostname:port.

curl

curl -i -H "Content-Type:application/json" -X POST -d '{"key":"abc","data":"123"} https://xx.com/xxl/get/xxx 
HTTP/1.1 200 OK
Server: openresty/1.15.8.3
Date: Tue, 12 May 2020 01:52:42 GMT
Content-Type: application/json;charset=UTF-8

Brian Candler

unread,
May 12, 2020, 6:36:58 AM5/12/20
to Prometheus Users
On Tuesday, 12 May 2020 11:17:33 UTC+1, 李毅 wrote:

Use curl with parameters to return status code 200, use blackbox to return 400, why?


What you've done in your curl command is to post JSON containing "key" and "data".  What you've done in blackbox exporter is to post an empty JSON object {}, and to add HTTP headers "key" and "data".

Try the curl command which does the same:

curl -iv -H "Content-Type:application/json;charset=UTF-8" -H "key:abc" -H "data:123" -X POST -d '{}' https://xx.com/xxl/get/xxx 


李毅

unread,
May 12, 2020, 9:59:41 PM5/12/20
to Prometheus Users
I think I've set it up in blackbox?
  http_2xx_estate:
    prober: http
    timeout: 5s
    http:
      method: post
      headers:
        key: abc
        data: 123
        Content-Type: application/json;charset=UTF-8
        body: '{}'

在 2020年5月12日星期二 UTC+8下午6:36:58,Brian Candler写道:

Brian Candler

unread,
May 13, 2020, 3:21:33 AM5/13/20
to Prometheus Users
That doesn't match what you curl command does.

I didn't spot this before, but you have 'body' at the wrong level too. This means:

      headers:
        key: abc
        data: 123
        Content-Type: application/json;charset=UTF-8
        body: '{}'

gives four different headers, and no body.  It is the same as:

curl -H "key: abc" -H "data: 123" -H "Content-Type: application/json;charset=UTF-8" -H "body: {}" -X POST -d "" <url>

What you want to match the original curl command you showed is:

    http:
      method: post
      headers:
        Content-Type: application/json
      body: '{"key":"abc","data":"123"}'

Note the alignment of "body" at the same level as "headers" and "method"
Reply all
Reply to author
Forward
0 new messages