Add Monitor

Last modified on March 27, 2024

To add a new monitor, send a POST request to /devices, with a JSON body containing monitor type, name, interval, and other configuration parameters.

The API allows you to add any monitor types except for BitBar. DéjàClick scripts, Selenium scripts, and SoapUI projects can be uploaded by including the file contents in the request body as explained below.

Syntax

Request URL

POST https://www.alertsite.com/alertsite-restapi/devices

Authentication

This operation requires authentication. The authenticating user’s role must allow the user to create monitors.

Request Body

The request body should be a JSON object containing the monitor configuration parameters. The required data fields for any monitor type are:

  • billing_plancode

  • site_type

  • interval

  • name

  • script (for DéjàClick, SoapUI and Selenium monitors)

Other required fields depend on the monitor type. For a full list and description of available fields, see Monitor Data Fields.

Parameters that are not specified in the request body will default to AlertSite defaults and your account defaults. For example, if you do not specify locations for the monitor, it will use your account’s default monitoring locations.

Below are minimal examples for various monitor types:

Web URL monitor

DéjàClick monitor

API endpoint monitor (HTTP GET with a JSON assertion)

SoapUI API monitor

Selenium monitor

The following example shows all fields. Note that some monitor types use just a subset of these fields – see Monitor Data Fields for details.

{
  "billing_plancode": "UBM - A/A",
  "site_type": "website-ssl",
  "name": "Home Page",
  "url": "https://smartbear.com",
  "interval": 5,
  "timeout": 30,
  "enabled": "y",
  "notify_on_error": "y",
  "traceroute_on_error": "y",
  "mode": "V",
  "home_location": 52,
  "locations": [
    {"id": "10"},
    {"id": "20"},
    {"id": "52"},
    {"id": "5130"}
  ],
  "monitor_location_count": "2",
  "http_method": "g",
  "http_version": "1.1",
  "port": ""
  "resolve_dns": "y",
  "script": "... contents of the DejaClick, SoapUI or Selenium file (see below)",
  "test_suite": "SoapUI test suite name",
  "test_case": "SoapUI test case name",
  "step_timeout": 30,
  "continue_playback_on_timeout": "n",
  "capture_level": 2,
  "check_ssl_expiration_dates": "Disabled",
  "notify_on_content_change": "n",
  "http_follow_redirects": "y",
  "http_302_is_error": "n",
  "http_401_is_error": "n",
  "http_caching": "Disabled",
  "interval_fullpage": 5,
  "fullpage_object_timeout": 60,
  "notify_on_fullpage_errors": "n",
  "check_fullpage_missing_objects": "n",
  "check_fullpage_object_sizes": "n",
  "keyword_string": "completed",
  "keyword_match_type": "PlainText",
  "keyword_match_invert": "Disabled",
  "assertions": [
    {
      "source": "Response",
      "comparison": "does not contain",
      "value": "error"
    },
    {
      "source": "JSON Response",
      "property": "store.book[0].title",
      "comparison": "equals",
      "value": "The Lord of the Rings"
    }
  ],
  "realm_password": "basic_auth_password",
  "realm_userid": "basic_auth_username",
  "smtp_hostname": "aspmx.l.google.com",
  "pop3_hostname": "pop3s://pop.gmail.com:995",
  "email": "[email protected]"
}

Response Body

On success, the operation returns the ID of the created monitor:

{
  "metadata": {
    "login": "[email protected]",
    "session": "ef770427109e343e",
    "status": "0",
    "message": "No errors."
  },
  "results": {
    "id": "54321"
  }
}

Error response contains a non-zero status:

{
  "metadata": {
    "login": "[email protected]",
    "session": "ef770427109e343e",
    "status": "64"
    "message": "Missing site_type"
  }
}

Upload DéjàClick, Selenium, and SoapUI Files

To create a DéjàClick, Selenium, or SoapUI monitor, you need to include the file contents in the script field in the request body.

Encode DéjàClick and SoapUI Files

DéjàClick scripts and SoapUI projects are XML files. The script field must contain the file content as is, with the only modification of making it a valid JSON string. That is, the " \ characters and characters with codes less than 32 (new lines, tabs and others) must be backslash-escaped:

" -> \"

\ -> \\

new line -> \n, \r or \r\n (depends on your operating system)

For example, assuming a SoapUI project file with this contents:

<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-project id="00e97f3f-a3b4-4c6f-a61b-0c8aca654746" ...
...
</con:soapui-project>

the script value would be:

"script": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<con:soapui-project id=\"e0b0c87d-7b83-4689-945a-18c250254943\" ... </con:soapui-project>",

JSON libraries typically do this encoding for you.

Note: Uploading password-protected SoapUI projects is not supported. They can only be uploaded manually in AlertSite.

Encode Selenium Scripts

Assuming you already created a JAR file as explained here, specify the base64-encoded file contents in the script field. Many programming languages provide methods to encode data as base64. For example, in Python, you would use:

import base64

with open('C:\MySeleniumScript.jar', 'rb') as jar_file:
   encoded_script = base64.b64encode(jar_file.read()).decode('ascii')

(See below for a complete example.)

Note: Selenium JAR files created for AlertSite are more than 9 MB in size, so the file upload may take a few minutes. Make sure your client timeout settings are sufficient for the upload to complete.

Code Examples

Create Web URL Monitor

cURL

The commands below create a 15-minute monitor for http://smartbear.com. Examples are provided for different authentication types.

Windows
Note: New lines are added for readability; the actual command should be one continuous line.

Using the session ID:

curl -X POST "https://www.alertsite.com/alertsite-restapi/devices?login=demo%40example.com&session=SESSION_ID"
    -H "Content-Type: application/json"
    -d "{\"billing_plancode\": \"UBM - A/A\", \"site_type\": \"website\", \"name\": \"Home Page\", \"url\": \"http://smartbear.com\", \"interval\": 15, \"enabled\": \"y\"}"

Using the Authorization header with a bearer token:

curl -k -X POST https://www.alertsite.com/alertsite-restapi/devices
    -H "Content-Type: application/json"
    -H "Authorization: Bearer PUT_TOKEN_HERE"
    -d "{\"billing_plancode\": \"UBM - A/A\", \"site_type\": \"website\", \"name\": \"Home Page\", \"url\": \"http://smartbear.com\", \"interval\": 15, \"enabled\": \"y\"}"

*nix, OS X

Using the session ID:

curl -X POST "https://www.alertsite.com/alertsite-restapi/devices?login=demo%40example.com&session=SESSION_ID" \
    -H "Content-Type: application/json" \
    -d '{"billing_plancode": "UBM - A/A", "site_type": "website", "name": "Home Page", "url": "http://smartbear.com", "interval": 15, "enabled": "y"}'

Using the Authorization header with a bearer token:

curl -k -X POST https://www.alertsite.com/alertsite-restapi/devices \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer PUT_TOKEN_HERE" \
    -d '{"billing_plancode": "UBM - A/A", "site_type": "website", "name": "Home Page", "url": "http://smartbear.com", "interval": 15, "enabled": "y"}'

Python

This code creates a monitor for http://smartbear.com that runs every 15 minutes.

Python

import requests # Requests library – http://docs.python-requests.org
import json
import base64

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password
monitor_params = {
    'billing_plancode': 'UBM - A/A',
    'site_type': 'website',
    'name': 'Home Page',
    'url': 'http://smartbear.com',
    'interval': 15,
    'enabled': 'y'
}

# Log in
payload = {'login': login, 'password': password}
r = requests.post(baseUrl + '/login', data=json.dumps(monitor_params), headers={'Content-Type': 'application/json'})
session = r.json()['metadata']['session']

# Generate the bearer token to authenticate subsequent requests
# For Python 2.4-2.x:
# token = base64.b64encode(login + ':' + session)
# for Python 3.6:
token = base64.b64encode((login + ':' + session).encode('ascii')).decode('ascii')

# Create the monitor
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
}
r = requests.post(baseUrl + '/devices', data=json.dumps(payload), headers=headers)

result = r.json()
if int(result['metadata']['status']) == 0:
    print('Created monitor with ID ' + result['results']['id'])
else:
    print('Error {status}: {message}'.format(**result['metadata']))

Create DéjàClick Monitor

Python

This code uploads the DéjàClick script C:\DejaClick Scripts\Checkout.xml as a monitor in AlertSite. The monitor is configured to use the Firefox browser, run every 15 minutes, and measure full page response time in addition to the usual response time.

Python

import requests # Requests library – http://docs.python-requests.org
import json
import base64

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password

fileName = 'C:\DejaClick Scripts\Checkout.xml' # Replace with your DejaClick script name
monitor_params = {
    'billing_plancode': 'UBM - A/A',
    'site_type': 'dejaclick',
    'name': 'Checkout',
    'browser_type': 'FF',
    'script': '',
    'interval': 15,
    'interval_fullpage': 15,
    'capture_level': 4, # All events on error
    'enabled': 'y',
    'notify_on_error': 'y'
}
# Read the contents of the DejaClick script and add it to the payload.
# "String to JSON-string" encoding will be done automatically
# by the json.dumps() call later in the code.
monitor_params['script'] = open(fileName).read()

# Log in
payload = {'login': login, 'password': password}
r = requests.post(baseUrl + '/login', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
session = r.json()['metadata']['session']

# Generate the bearer token to authenticate subsequent requests
# For Python 2.4-2.x:
# token = base64.b64encode(login + ':' + session)
# for Python 3.6:
token = base64.b64encode((login + ':' + session).encode('ascii')).decode('ascii')

# Create the monitor
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
}
r = requests.post(baseUrl + '/devices', data=json.dumps(monitor_params), headers=headers)
result = r.json()
if int(result['metadata']['status']) == 0:
    print('Created monitor with ID ' + result['results']['id'])
else:
    print('Error {status}: {message}'.format(**result['metadata']))

Create SoapUI API Monitor

Python

This example assumes the SoapUI project file is named C:\SoapUI Projects\Weather-API-soapui-project.xml and contains a test suite named TestSuite 1 with a test case named TestCase 1. The monitor is configured to run every 15 minutes.

Python

import requests # Requests library – http://docs.python-requests.org
import json
import base64

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password

fileName = 'C:\SoapUI Projects\Weather-API-soapui-project.xml' # Replace with your SoapUI project name
monitor_params = {
    'billing_plancode': 'UBM - A/A',
    'site_type': 'soapui',
    'name': 'Weather API',
    'script': '',
    'test_suite': 'TestSuite 1',
    'test_case': 'TestCase 1',
    'interval': 15,
    'enabled': 'y',
    'notify_on_error': 'y'
}
# Read the contents of the SoapUI project file, and add it to the request body.
# "String to JSON-string" encoding will be done automatically
# by the json.dumps() call later in the code.
monitor_params['script'] = open(fileName).read()

# Log in
payload = {'login': login, 'password': password}
r = requests.post(baseUrl + '/login', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
session = r.json()['metadata']['session']

# Generate the bearer token to authenticate subsequent requests
# For Python 2.4-2.x:
# token = base64.b64encode(login + ':' + session)
# for Python 3.6:
token = base64.b64encode((login + ':' + session).encode('ascii')).decode('ascii')

# Create the monitor
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
}
r = requests.post(baseUrl + '/devices', data=json.dumps(monitor_params), headers=headers)
result = r.json()
if int(result['metadata']['status']) == 0:
    print('Created monitor with ID ' + result['results']['id'])
else:
    print('Error {status}: {message}'.format(**result['metadata']))

Create Selenium Monitor

Python

This example creates a Selenium monitor from the JAR file C:\Tests\Checkout.jar. The monitor is configured to run every 15 minutes.

Python

import requests # Requests library – http://docs.python-requests.org
import json
import base64

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = '[email protected]' # Replace with your AlertSite login email
password = 'pa55w0rd' # Replace with your AlertSite password

fileName = 'C:\Tests\Checkout.jar' # Replace with your Selenium JAR file name
monitor_params = {
    'billing_plancode': 'UBM - A/A',
    'site_type': 'selenium',
    'name': 'Checkout',
    'script': '',
    'interval': 15,
    'enabled': 'y',
    'notify_on_error': 'y'
}

# Encode the contents of the Selenium JAR file as base64 and add it to the request body
with open(fileName, 'rb') as jar_file:
    # For Python 2.4-2.x:
    # encoded_script = base64.b64encode(jar_file.read())
    # For Python 3.6:
    encoded_script = base64.b64encode(jar_file.read()).decode('ascii')
    monitor_params['script'] = encoded_script

# Log in
payload = {'login': login, 'password': password}
r = requests.post(baseUrl + '/login', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
session = r.json()['metadata']['session']

# Generate the bearer token to authenticate subsequent requests
# For Python 2.4-2.x:
# token = base64.b64encode(login + ':' + session)
# for Python 3.6:
token = base64.b64encode((login + ':' + session).encode('ascii')).decode('ascii')
                                
# Create the monitor
headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token
}

r = requests.post(baseUrl + '/devices', data=json.dumps(monitor_params), headers=headers)
result = r.json()
if int(result['metadata']['status']) == 0:
    print('Created monitor with ID ' + result['results']['id'])
else:
    print('Error {status}: {message}'.format(**result['metadata']))

See Also

AlertSite JSON API
Monitor Data Fields
Edit Monitor

Highlight search results