Script mode for HTTP monitor configuration
In addition to the configuration in the UI (Visual mode), you can use Script mode to configure your HTTP monitors. In this mode, you can access the underlying JSON script of your monitor. If you're a Synthetic Monitoring power user, this will make your life a lot easier and allow you to speed up monitor creation and management. Use the script editor to quickly find specific events (steps) or adapt locators across the entire script.
You aren't limited to just one mode—you can switch between the UI and script modes by selecting the Visual mode/Script mode.
Access the script
To edit your HTTP monitor in script mode:
- Go to the Synthetic monitors page and opt to view it in list mode.
- Select the check box next to the monitor that you want to edit > select Edit in the lower-left corner.
- Select the HTTP Requests tab of Monitor settings on the left.
- Select Script mode at the top.
Edit the script
You can download the script (Download script as .json) or just copy it from the editor and edit it in a text editor of your choice. However, you can also edit the script directly in the browser. This provides the following benefits:
- Autocomplete—just press Ctrl+Spacebar to see a list of suggestions.
- Syntax highlighting makes it easier for you to write script code.
- Instant error validation—the editor instantly shows a warning for any error in the script. Hover over the error to see what's wrong and a suggestion for how to fix it. You cannot save changes until the code is error free.
Note that you need to escape all special characters and break lines with a backslash (for example, a new line is \n
, double quotes is \"
, and tab is \t
).
Script structure
Main script object
Contains the monitor script.
Element | Type | Description | Required |
---|---|---|---|
| string | Script version—use the | required |
| Array of: | A list of HTTP requests to be performed by the monitor The requests are executed in the order in which they appear in the script. | required |
The request
object
Contains the parameters of an HTTP request.
Element | Type | Description | Required |
---|---|---|---|
| string | A short description of the event to appear in the web UI | optional |
| string | The URL to check | required |
| string | The HTTP method of the request | required |
| string | The body of the HTTP request—you need to escape all JSON characters. Is set to null if the request method is GET, HEAD, or OPTIONS. | optional |
| The validation configuration of the request Validation helps you verify that your HTTP monitor loads the expected content. | optional | |
| The setup of the monitor | optional | |
| string | The script executed before the request You must escape all JSON characters and break lines with | optional |
| string | The script executed after the request You must escape all JSON characters and break lines with | optional |
The requestValidation
object
Contains the validation configuration for the request.
Element | Type | Description | Required |
---|---|---|---|
| Array of: | A list of validation rules | optional |
The following types of rules (see validationRule) are evaluated for HTTP monitor validation:
- Response status code validation
- Text validation, where the response body is checked for a string of text or a regular expression
- SSL certificate expiry validation
This means that the monitor will fail if at least one of these rules with passIfFound
= false
is met or at least one rule with passIfFound
= true
is not met.
The monitor will succeed if all rules with passIfFound
= false
are not met and all rules with passIfFound
= true
are met.
The validationRule
object
Contains a validation rule.
Element | Type | Description | Required |
---|---|---|---|
| string | The type of rule—possible values are:
| required |
| boolean | The validation condition:
Always specify | required |
| string | The content to look for | required |
The requestConfiguration
object
Contains the setup of the monitor.
Element | Type | Description | Required |
---|---|---|---|
| string | The User agent of the request | optional |
| boolean | Accept any ( If set to If not set, the | optional |
| boolean | Follow ( If set to If not set, the | optional |
| Array of: | A list of additional headers for the request | optional |
The requestHeader
object
Contains an HTTP header of the request.
Element | Type | Description | Required |
---|---|---|---|
| string | The key of the header | required |
| string | The value of the header | required |
This is a model of the script JSON, showing all the possible elements. It has to be adjusted to be used as an actual script. To see an example script of a real monitor, you can check any existing HTTP monitor in script mode.
{
"version": "1.0",
"requests": [
{
"description": "string",
"url": "string",
"method": "POST",
"requestBody": "{\n\"customParameter1\": \"customValue1\",\n\"customParameter2\": true,\n\"customParameter3\": 452\n}",
"validation": {
"rules": [
{
"type": "patternConstraint",
"passIfFound": true,
"value": "string"
},
{
"type": "regexConstraint",
"passIfFound": true,
"value": "string"
}
],
"rulesChaining": "or"
},
"configuration": {
"userAgent": "string",
"acceptAnyCertificate": false,
"followRedirects": true,
"requestHeaders": [
{
"name": "string",
"value": "string"
}
]
},
"preProcessingScript": "string",
"postProcessingScript": "string"
}
]
}