Bulk Edit SLAs

Last modified on July 26, 2024

Edit SLA objectives, operating periods or exclusions for one or several monitors specified in the monitors list. The specified monitors must have existing SLAs.

Request URL

POST https://api.alertsite.com/api/v3/slas/bulk-edit

Authentication

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

Authorization: Bearer ACCESS_TOKEN

See Authentication for more information.

Request body

The request body is a JSON object that specifies the monitors whose SLAs you want to update, and the new SLA parameters. The complete payload looks as follows. Most of these fields are the same as in the SLA Object.

{
  "monitors": [
    123456,
    203752
  ],

  "update_sla_objectives": true,
  "availability": 95,
  "uptime": 97.5,
  "response_time": 4,
  "secondary_response_time": 10,
  "use_fullpage_time": true,

  "update_operating_periods": true
  "operating_periods": [
    {
      "exclude": false,
      "from_day": 1,
      "from_time": "00:00",
      "thru_day": 7,
      "thru_time": "23:59"
    }
  ],

  "update_exclusions": true,
  "update_exclusions_action": "append",
  "exclusions": [
    {
      "from_date": "2018-10-20 04:17:00",
      "thru_date": "2018-10-20 06:25:00",
      "location_id": 10,
      "note": "ISP outage",
    }
  ]
}

The following fields are required:

  • monitors specifies the list of monitor IDs. All of these monitors must have existing SLAs, otherwise, the request will be rejected.

    Tip: To get the monitor ID by SLA ID, call GET /slas/{id} and use the monitor_id response field. To check if a monitor has an SLA, call GET /slas?monitor_id={id} and check the response code – 200 means an SLA exists for this monitor.
  • update_sla_objectives, update_operating_periods, and update_exclusions specify what parts of SLA configuration need to be updated. At least one of these fields must be true.

Other required fields depend on what is being updated.

Update SLA objectives

To update SLA objectives for availability, response time, uptime:

  • Specify update_sla_objectives = true.

  • Specify the availability goal (0 < ... ≤ 100 %), the response_time objective, and use_fullpage_time (true/false).

  • (Optional.) Specify the uptime goal (0 < ... ≤ 100 %) and secondary_response_time.

    If uptime is not specified or is null, the uptime value will be copied from availability.

    If secondary_response_time is not specified, it will be changed to null, meaning the default value of 4 ×response_time.

For example, to update SLA objectives for monitors 123456 and 203752:

{
  "monitors": [123456, 203752],

  "update_sla_objectives": true,
  "availability": 97,
  "response_time": 2.5
  "use_fullpage_time": false,

  "update_operating_periods": false,
  "update_exclusions": false
}

Update SLA operating periods

To update the SLA hours, use update_operating_periods = true and specify the operating_periods array. See here for the data fields used to represent the operating periods.

Example: Set SLA hours to Monday–Friday, 9 AM–5 PM

Add or replace SLA exclusions

To update one-time SLA exclusions:

  • Specify update_exclusions = true.

  • Specify the exclusions array. See here for the exclusion data fields.

  • Specify update_exclusions_action – either append (add to existing exclusions) or replace (replace existing exclusions).

For example, to add a new SLA exclusion on top of existing exclusions:

{
  "monitors": [123456, 203752],
  "update_sla_objectives": false,
  "update_operating_periods": false,

  "update_exclusions": true,
  "update_exclusions_action": "append",
  "exclusions": [
    {
      "from_date": "2018-10-20 04:17:00",
      "thru_date": "2018-10-20 06:25:00",
      "note": "ISP outage"
    }
  ]
}

Response body

On success, the operation returns HTTP status 200 with the following response body:

{
  "success": true
}

Error responses have HTTP status in the 4xx range, and contain the errors list, for example:

{
  "errors": [
    {
      "code": 400,
      "message": "invalid_request - User authentication failed."
    }
  ]
}

Try it out

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

Code examples

This code updates the availability and response time SLA objectives for monitors 123456 and 203752.

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

bulk_edit = {
    'monitors': [123456, 203752],
    'update_sla_objectives': True,
    'update_operating_periods': False,
    'update_exclusions': False,

    'availability': 97,
    'response_time': 2.5,
    'use_fullpage_time': False
}

# 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']

# Bulk edit SLAs
headers = {
    'Authorization': 'Bearer ' + token,
    'Content-Type': 'application/json'
}
r = requests.post(baseUrl + '/slas/bulk-edit', data=json.dumps(bulk_edit), headers=headers)

if r.status_code == requests.codes.ok:
    print('SLAs have been updated.')
elsex:
    print('Could not bulk edit SLAs. The following error(s) occurred:', *r.json()['errors'], sep='\n')

See Also

SLA Operations

Highlight search results