Alertra API v1.1

Quickstart


curl https://api.alertra.com/v1.1/hello

Hello 192.168.1.10
The time is 2013-02-25 22:38:03 UTC.
Have a splendid day.

Get a list of your devices:


>>> import requests
>>> url = 'https://api.alertra.com/v1.1/devices'
>>> headers = {'Alertra-API-Key': '{YOUR-API-KEY}'}
>>> r = requests.get(url, headers=headers)
>>> r.json()[0]
{
    "Status": "Up",
    "URL": "https://www.alertra.com",
    "Method": "HTTP",
    "Frequency": 60,
    "LastCheckResult": "200 OK",
    "StatusSince": "2000-01-01T00:00:38-06:00",
    "ShortName": "WWW",
    "FullName": "Alertra WWW site",
    "device_id": "7af3be92c14d8e9a5f62d1c8b3e7094567d2891acd345f2e"
}

Get check data for one of your devices:


>>> import requests
>>> url = 'https://api.alertra.com/v1.1/devices/{device_id}/checks'
>>> headers = {'Alertra-API-Key': '{YOUR-API-KEY}'}
>>> r = requests.get(url, headers=headers)
>>> r.json()
[
  {
    "check_id": "9df4ce83b25e9f0a6e73d2b9c4f8105678e3902bde456g3f",
    "Location": "Stockholm SWE",
    "Timestamp": "2014-02-11T20:30:37-05:00",
    "BlockTime": 0,
    "ConnectTime": 0,
    "DNSTime": 0,
    "SSLTime": 0,
    "TTFB": 0,
    "TTLB": 3520.77,
    "RequestTime": 3520.77392578125,
    "Kbps": 0,
    "PerfStat": "Ok",
    "ResultCode": 1,
    "DataSize": 0
  }
]

Put a device into maintenance for two hours:


>>> import json
>>> import requests
>>> url = 'https://api.alertra.com/v1.1/devices/{device_id}/start-maintenance'
>>> payload = {'Duration': '02:00'}
>>> headers = {'Alertra-API-Key': '{YOUR-API-KEY}', 'Content-Type': 'application/json'}
>>> r = requests.put(url, data=json.dumps(payload), headers=headers)
>>> r.status_code
200

Your API Key

Please contact support to obtain an API key for your account. You may want to use different keys for different applications. You can have as many as you want.

Caution

Your API key is a secret and should not be shared with anyone. Anyone who has your key will be able to access your account configuration and data. If your key is ever compromised, we can delete it and give you a new one.

Requests

HTTP/1.1 methods GET, POST, PUT and DELETE are supported.

Location

The API is located at api.alertra.com. SSL is required. URLs must include the API version:


https://api.alertra.com/v1.1/devices

Authentication

It’s not really necessary or helpful, but you can specify a username and password when you request your key. The API will require an HTTP Basic Authentication header to be included with each request.


Authorization: Basic USER:PASS

Important

USER:PASS must be base64 encoded.

Identification

Your account is identified based on the presence of this header in the HTTP request:


Alertra-API-Key: {YOUR-API-KEY}

Or, by using a query string parameter in the URL:


api_key={YOUR-API-KEY}

Which is better? We recommend sending the key as a header for increased security.

Authorization

API keys have authorization levels:

When the API receives a request, it verifies that the requestor is authorized for the access it is requesting. If it isn’t, an HTTP 400 error is returned (API error 1002, Authorization failed).

Request Body

Important

If a request includes data in the request body, the data must be in JSON format and the correct header must be included.


Content-Type: application/json

Responses

If the request is processed successfully, an HTTP 200 response is returned.

Otherwise, an HTTP 400 response is returned along with a JSON message body:


{
  "code": 1002,
  "message": "Access denied."
}

Data for most methods will be returned in JSON format with the header:


Content-Type: application/json

Add a fmt=xml query parameter to a URL to get the response in XML.

Add a fmt=csv query parameter to get the response in CSV (we’ll do our best, not all API responses fit the two-dimensional CSV model very well).

Add a filename=EXAMPLE.CSV parameter if you’re using a browser and you want to save the data as a file. Just replace EXAMPLE.CSV with whatever you want the file to be named.

Timestamps

All timestamps returned by the API will be converted to the account’s configured timezone and returned in ISO 8601 format.

Timestamp parameters sent to the API must be in ISO 8601 format:


2000-01-01T00:00:00-05:00
2000-01-01T00:00:00Z

This is designed so that timestamps returned by the API can easily be passed back to the API on subsequent calls.

API Scope

If you need the API to do something that is not currently supported, just let us know and we can probably help you out.

Reference

Checks

Devices

Tags