Verify Response Content (Optional)
You can create a regular expression (REGEX) to verify the response string content that a monitor in Synthetic Monitoring can return when creating a monitor.
During the Create a Monitor step, there's an optional checkbox: Verify Response Content to verify the response that a monitor can return by creating a REGEX.
Information about REGEX
- The REGEX should match the content in the response (response body and response headers) from the URL provided in the monitor.
- If the search REGEX contains single quotes (
'
) or double quotes ("
), you must prefix the quote with the following:.*,
The above prefix matches any escape characters prefixed to the quotes which handles certain cases where JSON from the response is not formed properly and it may add a backslash to quotes in the response body.
- Due to data formatting, there may be spaces in the response that you're trying to match. If that's the case, try adding
\s*
in the REGEX. This will handle zero or more spaces in the response. - You can use
https://regex101.com/
to validate the REGEX on the response (test string) before using it in the monitor. Ensure to select ECMAScript (JavaScript) in flavor.
REGEX Samples
- REGEX Sample 1
/"noOfSuccess":\s*(?!0\b)\d+/ /.*noOfSuccess.*:\s*(?!0\b)\d+/
Response:{ "mepType": "MEP00", "noOfAborted": 0, "noOfErrors": 0, "noOfMsgsProcessed": 46, "noOfMsgsReceived": 46, "noOfSuccess": 1, "successRate": 100, "version": "01.00.0000" }
- REGEX Sample 2:
/"server":\s*("envoy")/
Response:{ "cache-control":"no-store, no-cache, must-revalidate, proxy-revalidate", "content-type":"text/html; charset=utf-8", "date":"Fri, 16 Jun 2023 07:08:49 GMT", "expires":"Sat, 01 Jan 2000 00:00:00 GMT", "pragma": "no-cache", "server": "envoy", "vary":"Accept-Encoding", "via":"1.1 net-idcs-config", "x-content-type-options":"nosniff", "x-download-options":"noopen"}
REGEX for REST Monitor Type
When using REGEX validator for REST monitor type, the user can validate their string/REGEX with the inline response. It will return the result as either match or not matched.
The following is a list of common operators supported by APM Synthetic Monitoring:
Operator | Description | Example |
---|---|---|
Match-any-character Operator (. ) |
The period character represents this operator. | a.b matches any three-character string beginning with a and ending with b .
|
Match-zero-or-more Operator (* ) |
This operator repeats the smallest possible preceding regular expression as many times as necessary (including zero) to match the pattern. | a* matches any string made up of zero or more a 's. In another example, fo* has a repeating o , not a repeating fo . Hence, fo* matches f , fo , foo , and so on.
|
Match-one-or-more Operator (+ ) |
This operator is similar to the match-zero-or-more operator except that it repeats the preceding regular expression at least once. | ca+r matches car and caaaar , but not cr .
|
Match-zero-or-one Operator (? ) |
This operator is similar to the match-zero-or-more operator except that it repeats the preceding regular expression once or not at all. | ca?r matches both car and cr , but nothing else.
|
Negate (^ ) |
Negate an expression. | ^a matches any character except a |
Grouping Operators ((...) ) |
REGEX treats expressions inside the parenthesis just as mathematics and programming languages treat a parenthesized expression as a unit. The expressions are processed before the expression outside the parenthesis. | f(a|b)a matches faa and fba , which means the operation a|b is processed before the rest.
|
Alternation Operator (| ) |
Alternatives match one of a choice of regular expressions: if you put one or more characters representing the alternation operator between any two regular expressions a and b , the result matches the union of the strings that a and b match.
|
As another example, |
List Operators ([ ... ] and [^ ... ] ) |
A matching list matches a single character represented by one of the list items. An item is a character, a character class expression, or a range expression. Non-matching lists are similar to matching lists except that they match a single character not represented by one of the list items. |
As a non matching example, |
Range Operator (- ) |
Represents those characters that fall between two elements in the current collating sequence. | [a-f] represents all the characters from a through f inclusively.
|
Digit (\d ) |
Matches any digit character (0-9). | Same as [0-9] .
|
Not Digit (\D ) |
Matches any character that is not a digit character (0-9). | Same as [^0-9] .
|
Escape (\ ) |
Makes the next character in the expression means the character itself but not an operator. | \. means period, not the Match-any-character operator.
|
my
and are under the path /mybank
, then you can use the regular expression:\/mybank/my.*
The dot (.) and the star (*) together represents any sequence of zero or more consecutive characters after the prefix my
.
In this example, the following URLs: /mybank/myCredits
and /mybank/myDebits
match the above REGEX: \/mybank/my.*
, but the URL: /mybank/about
doesn't match it.