Use this operation to modify SLA configuration: service-level objectives, operating periods, and exclusions. Send the updated configuration via a PATCH request to /slas/{id}
, where {id}
is the SLA ID.
Tip: | To update the SLAs for multiple monitors at once, use the Bulk Edit SLAs operation instead. |
Request URL
PATCH https://api.alertsite.com/api/v3/slas/{id}
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 containing the SLA fields you want to update.
Notes:
-
When updating array fields, such as
exclusions
andoperating_periods
, you need to send back the whole array. That is, the specifiedexclusions
andoperating_periods
will replace the previous values, but not get added on top of them.Tip: The Bulk Edit SLA operation can be used to add new exclusions while keeping existing exclusions. -
monitor_id
cannot be changed and is ignored by this operation.
Examples
Change the availability and response time goals:
{
"availability": 97,
"response_time": 2.5
}
Add an exclusion (assuming no other exclusions currently exist):
{
"exclusions": [
{
"from_date": "2018-10-20 04:17:00",
"location_id": 10,
"note": "ISP outage",
"thru_date": "2018-10-20 06:25:00"
}
]
}
List of all editable fields:
{
"name": "Home Page SLA",
"description": "Home page SLA - description",
"availability": 95,
"response_time": 2,
"secondary_response_time": 5,
"uptime": 97.5,
"use_fullpage_time": false,
"operating_periods": [
{
"exclude": false,
"from_day": 1,
"from_time": "00:00",
"thru_day": 7,
"thru_time": "23:59"
}
],
"exclusions": [
{
"from_date": "2018-10-20 04:17:00",
"location_id": 10,
"note": "ISP outage",
"thru_date": "2018-10-20 06:25:00"
}
]
}
Response body
On success, the operation returns HTTP status 200 with the SLA ID as a string:
{
"id": "1234"
}
Error responses have a non-200 status code and include the errors
list:
{
"errors": [
{
"code": 404,
"message": "Record not found"
}
]
}
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 goals for the SLA with ID 1234.
cURL (Windows)
curl -X PATCH https://api.alertsite.com/api/v3/slas/1234
-H "Authorization: Bearer ACCESS_TOKEN"
-H "Content-Type: application/json"
-d "{\"availability\": 97, \"response_time\": 2.5}"
Note: New lines are added for readability.
The actual command should be one continuous line.
cURL (bash)
curl -X PATCH https://api.alertsite.com/api/v3/slas/1234 \
-H 'Authorization: Bearer ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"availability": 97, "response_time": 2.5}'
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
sla_id = 1234
sla_params = {
'availability': 97,
'response_time': 2.5
}
# 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']
# Update SLA
url = baseUrl + '/slas/' + str(sla_id)
headers = {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
}
r = requests.patch(url, data=json.dumps(sla_params), headers=headers)
if r.status_code == requests.codes.ok:
print('SLA has been updated.')
else:
print('Could not update SLA {}. The following error(s) occurred:'.format(sla_id), *r.json()['errors'], sep='\n')