Add Monitor

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 Perfecto. 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:

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.

Minimal example to create a web URL monitor:

{
  "billing_plancode": "UBM - A/A",
  "site_type": "website",
  "name": "Home Page",
  "url": "http://smartbear.com",
  "interval": 15,
  "enabled": "y"
}

Minimal example to create a DéjàClick monitor:

{
  "billing_plancode": "UBM - A/A",
  "site_type": "dejaclick",
  "browser_type": "FF",
  "name": "Checkout",
  "script": "... XML file contents, see below ...",
  "interval": 15,
  "enabled": "y"
}

Minimal example to create a SoapUI API monitor:

{
  "billing_plancode": "UBM - A/A",
  "site_type": "soapui",
  "name": "Weather API",
  "script": "... SoapUI project file contents, see below ...",
  "test_suite": "TestSuite 1",
  "test_case": "TestCase 1",
  "interval": 60,
  "enabled": "y"
}

Minimal example to create a Selenium monitor:

{
  "billing_plancode": "UBM - A/A",
  "site_type": "selenium",
  "name": "Checkout",
  "script": "... base64-encoded contents of the JAR file, see below ...",
  "interval": 20,
  "enabled": "y"
}

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",
  "name": "Home Page",
  "url": "http://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 script or SoapUI XML file, or base64-encoded contents of the Selenium JAR 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": "performance",
  "keyword_match_type": "PlainText",
  "keyword_match_invert": "Disabled",
  "realm_password": "",
  "realm_userid": "",
  "smtp_hostname": "",
  "pop3_hostname": "",
  "email": ""
}

Response Body

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

{
  "metadata": {
    "login": "demo@example.com",
    "session": "ef770427109e343e",
    "status": "0",
    "message": "No errors."
  },
  "results": {
    "id": "54321"
  }
}

Error response contains a non-zero status:

{
  "metadata": {
    "login": "demo@example.com",
    "session": "ef770427109e343e",
    "status": "64"
    "message": "Missing site_type",
  }
}

Uploading 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.

Encoding 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.

Encoding 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.

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

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = 'demo@example.com'  # 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.

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

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = 'demo@example.com'  # 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.

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

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = 'demo@example.com'  # 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.

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

baseUrl = 'https://www.alertsite.com/alertsite-restapi'
login = 'demo@example.com'  # 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

© 2017 SmartBear Software. All rights reserved.      Terms of Use · Privacy Policy