prometheus / blackbox_exporter

Blackbox prober exporter
https://prometheus.io
Apache License 2.0
4.7k stars 1.05k forks source link

Add support for JSONPath matchers #1100

Open mem opened 1 year ago

mem commented 1 year ago

Currently blackbox_exporter supports using regular expressions to match the output of an HTTP request. While regular expressions are great for some use cases, they cannot be used in others, like matching JSON values.

It would be nice to have support for JSONPath. Basically introduce another validation that takes a JSONPath expression, an operator (contains, not contains, etc) and a value, and pass/fail based on that.

In order to support this properly, this would have to work with header validations, where you assert that the content-type header has an appropriate value (but I imagine that part would be up to the user to set up correctly).

There's an xpath package (https://github.com/antchfx/xpath) that supports XML, JSON and HTML.

There's an xmlpath package that supports XML and HTML (https://pkg.go.dev/gopkg.in/xmlpath.v2).

And there's a JSONPath package (https://github.com/PaesslerAG/jsonpath).

donghoon-lee-mrt commented 3 months ago

really love to have this feature. It would work for most of all REST APIs.