We’ve added three new options for matching conditions in HTTP responses when you create a new Synthetic monitor:
- Not equal (!=)
- Starts with
- Does not contain
Let’s share an example of when you might want to use each of them.
Not equal (!=)
Imagine you are monitoring an API that’s returning a JSON response such as {"name":"Cache", "message":"foo", "status":"Initializing"}
or {"name":"Cache", "message":"foo", "status":"Running"}
or {"name":"Cache", "message":"foo", "status":"Healthy"}
or when things are OK, but when things are not OK it returns {"name":"Cache", "message":"foo", "status":"Error"}
Instead of creating a condition that somehow matches all status values when things are OK, you could use the “!=” operator with value “Error” to make the condition pass when the status value in the response is not “Error”.
Starts with
Say you are hitting an API that can return different 2XX response codes. You don’t necessarily care whether the response code is 200 or 201 or 202 or …. As long as it’s some HTTP response code that signifies success, which is what all 2XX response codes mean. With the new “Starts with” operator you can simply specify “2” for the value.
Does not contain
Imagine you are monitoring an API that checks the health of various backend services, databases, etc. It might return something like this:
{ "results":[ { "name":"Database", "message":"", "status":"OK" }, { "name":"Cache", "message":"", "status":"OK" }, { "name":"Redis", "message":"", "status":"OK" }, { "name":"Elasticsearch", "message":"", "status":"OK" }, { "name":"NotificationEngine", "message":"", "status":"OK" } ] }
Without using the new “Does not contain” operator you would have to check each “status” value separately with something like $.results[0].status = “OK”, $.results[1].status = “OK”, and so on. However, with “Does not contain” all we would have to do is $.results[:].status “does not contain” “Error”
.
Here is an example of a failure…
…and of success…