Script mode for HTTP monitor configuration
In addition to the usual configuration in the UI, 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 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), adapt locators across the whole script.
You aren't limited to just one mode—you can switch back and forth between the UI and script modes by clicking the UI Configuration/Script switch.
Access the script
To edit your HTTP monitor in script mode:
- Select Synthetic from the navigation menu.
- Select the HTTP monitor you want to edit.
- Click the Browse (...) button and select Edit.
- Click the HTTP Requests tab in the Monitor settings menu on the left.
- Click Script at the top.
Edit the script
You can download the script, 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 the 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.
Script structure
Main script object
Contains the monitor script.
Element | Type | Description | Required |
---|---|---|---|
version | string | Script version—use the 1.0 value here. |
required |
requests | Array of:
request |
A list of HTTP requests to be performed by the monitor.
The requests are executed in order they are presented in the script. |
required |
The request
object
Contains the parameters of an HTTP request.
Element | Type | Description | Required |
---|---|---|---|
description | string | A short description of the event to appear in the UI. | optional |
url | string | The URL to check. | required |
method | string | The HTTP method of the request. | required |
requestBody | string | The body of the HTTP request. You must escape all the JSON characters.
If the method of the request is GET, must be set as null .
|
optional |
validation | requestValidation | The validation configuration of the request. Validation helps you verify that your HTTP monitor loads the expected content. | optional |
configuration | requestConfiguration | The setup of the monitor. | optional |
preProcessingScript | string | The script executed before the request. You must escape all the JSON characters and break lines with /n . |
optional |
postProcessingScript | string | The script executed after the request. You must escape all the JSON characters and break lines with /n . |
optional |
The requestValidation
object
Contains the validation configuration for the request.
Element | Type | Description | Required |
---|---|---|---|
rules | Array of: validationRule |
A list of validation rules. | required |
rulesChaining | string | The logical operator that applies to rules. Possible values are:
and option is used.
|
optional |
The validationRule
object
Contains a validation rule.
Element | Type | Description | Required |
---|---|---|---|
type | string | The type of the rule. Possible values are:
|
required |
passIfFound | boolean | The condition of the validation:
|
required |
value | string | The content to look for. | required |
The requestConfiguration
object
Contains the setup of the monitor.
Element | Type | Description | Required |
---|---|---|---|
userAgent | string | The User agent of the request. | optional |
acceptAnyCertificate | boolean | Accept any (true ) or only trusted (false ) SSL certificate.
If set to false then the monitor fails with invalid SSL certificates.
If not set, then the false option is used.
|
optional |
followRedirects | boolean | Follow (true ) or don't follow (false ) the redirects.
If set to false the redirects are reported as successful requests with response code 3xx .
If not set, then the false option is used.
|
optional |
requestHeaders | Array of: requestHeader |
A list of additional headers for the request.
By default only the User-Agent header is set. You can't set or modify this header here. Use the userAgent field for that. |
optional |
The requestHeader
object
Contains an HTTP header of the request.
Element | Type | Description | Required |
---|---|---|---|
name | string | The key of the header. | required |
value | 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 get an example of a real monitor, you can check the script of an existing monitor.
synthetic-http-script-model.json
{
"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",
}
]
}