Get SLAs

Last modified on July 26, 2024

Get all existing service-level agreements (SLAs), or get the SLA for the specified monitor ID.

Request URL

GET https://api.alertsite.com/api/v3/slas[?parameters]

Authentication

The request must include the Authorization header containing a user’s access token:

Authorization: Bearer ACCESS_TOKEN

See Authentication for more information.

Query parameters

Query parameters are optional, but can be used to filter the results.

monitor_id

Integer. The ID of the monitor whose SLA you want to get. If omitted, all existing SLAs are returned.

limit

Integer. The maximum number of results to return. Use together with offset to paginate through a large number of results.

offset

Integer. Return the results starting from this offset (0-based).

select

String. A comma-separated list of data fields to return in the response. The field names are case-sensitive. Unrecognized field names are ignored.

If this parameter is omitted, all fields are included. Note that select= with an empty value is not the same as an omitted parameter, and means no fields will be returned.

For more information, see Filter response fields.

For a list of field names that can be used in the select parameter, see SLA Object.

Response body

If the monitor_id parameter is not specified, the response body is an object containing metadata and results, where results is an array of SLA objects.

{
  "metadata": {
    "__permissions": {
      "acl": 7
    },
    "resultset": {
      "count": 1,
      "limit": null,
      "offset": "0"
    }
  },
  "results": [
    {
      "availability": 97,
      "description": "Home page SLA",
      "exclusions": [
        {
          "from_date": "2018-10-20 04:17:00",
          "id": 2413,
          "location_description": "-- All --",
          "location_id": 10,
          "note": "ISP outage",
          "thru_date": "2018-10-20 04:25:00"
        }
      ],
      "id": 1234,
      "monitor_id": 123456,
      "monitor_name": "Home page",
      "name": "Home Page SLA",
      "operating_periods": [
        {
          "exclude": false,
          "from_day": 1,
          "from_time": "00:00",
          "id": 3214,
          "thru_day": 7,
          "thru_time": "23:59"
        }
      ],
      "response_time": 2,
      "secondary_response_time": 0,
      "uptime": 99.5,
      "uptime_allowed": true,
      "use_fullpage_time": false,
      "use_fullpage_time_allowed": true
    }
  ]
}

If monitor_id is specified, and this monitor has an SLA, the operation returns just this SLA configuration without the metadata and results fields:

{
  "availability": 97,
  "description": "Home page SLA",
  "exclusions": [
    {
      "from_date": "2018-10-20 04:17:00",
      "id": 2413,
      "location_description": "-- All --",
      "location_id": 10,
      "note": "ISP outage",
      "thru_date": "2018-10-20 04:25:00"
    }
  ],
  "id": 1234,
  "monitor_id": 123456,
  "monitor_name": "Home page",
  "name": "Home Page SLA",
  "operating_periods": [
    {
      "exclude": false,
      "from_day": 1,
      "from_time": "00:00",
      "id": 3214,
      "thru_day": 7,
      "thru_time": "23:59"
    }
  ],
  "response_time": 2,
  "secondary_response_time": 0,
  "uptime": 99.5,
  "uptime_allowed": true,
  "use_fullpage_time": false,
  "use_fullpage_time_allowed": true
}

If no SLAs matching the specified criteria are found, the response contains an empty results array:

{
  "metadata": {
    "__permissions": {
      "acl": 7
    },
    "resultset": {
      "count": 0,
      "limit": null,
      "offset": "0"
    }
  },
  "results": []
}

Error responses have HTTP status codes in the 4xx range.

Try it out

Click here to test this operation in AlertSite’s interactive API console.

Code examples

cURL

Get all SLAs:

curl https://api.alertsite.com/api/v3/slas -H "Authorization: Bearer ACCESS_TOKEN"

Get the SLA for monitor ID 123456:

curl https://api.alertsite.com/api/v3/slas?monitor_id=123456 -H "Authorization: Bearer ACCESS_TOKEN"

Python

This code outputs a list of all SLAs, their availability and response time objectives, and associated monitors.

Python

# Python 3.5+
import requests  # Requests library http://docs.python-requests.org
import json

baseUrl = 'https://api.alertsite.com/api/v3'
username = '[email protected]'  # Replace with your AlertSite login email
password = 'pa55w0rd'          # Replace with your AlertSite password

# Log in
payload = {'username': username, 'password': password}
r = requests.post(baseUrl + '/access-tokens', data=json.dumps(payload), headers={'Content-Type': 'application/json'})
token = r.json()['access_token']

# Get all SLAs
r = requests.get(baseUrl + '/slas', headers={'Authorization': 'Bearer ' + token})
result = r.json()

if r.status_code == requests.codes.ok:
    slas = result['results']
    print('Total SLAs found:', len(slas), '\n')

    for sla in slas:
        print('SLA: {name} (ID {id})\n'
              'Monitor: {monitor_name} (ID {monitor_id})\n'
              'Objectives:\n'
              'Availability: {availability}%\n'
              'Response time: {response_time} sec\n'.format(**sla))
else:
    print('Could not get SLAs. The following error(s) occurred:', *result['errors'], sep='\n')

See Also

SLA Operations

Highlight search results