Alertra API: Integrations

Overview

Integrations allow you to connect Alertra events to other services. You can manage integration configuration using our API.

Let’s say you need a script to add new monitoring endpoints (devices) to your Alertra account. You have an integration you created using the Alertra UI and you want your script to add the new devices to that integration as well.

First, you’ll need the integration_id.


curl "https://api.alertra.com/v1.1/integrations" -H "Alertra-API-Key: <YOUR-API-KEY>"

This will return a list of integrations, just find the one you want to add the endpoint to and copy the integration_id.

Now it’s time to write the script.

Step 1: Get ready to use the API.


import json
import requests

api_url = 'https://api.alertra.com/v1.1'

headers = {
    'Alertra-API-Key': '<YOUR-API-KEY>',
    'Content-Type': 'application/json',
}

integration_id = '<INTEGRATION-ID>'

Step 2: Create the device.

Optional: You can include nschedule_id and mschedule_id if you don’t want the new device to use the default notification or maintenance schedules.


url = f'{api_url}/devices'
payload = {
    "Method": "HTTP",
    "ShortName": "WWW",
    "FullName": "WWW for example.com",
    "URL": "https://www.example.com",
    "Frequency": 60,
}
r = requests.post(url, data=json.dumps(payload), headers=headers)

Step 3: Get the new device_id and add it to the integration.


# this is the response from the previous step
device_id = r.json()['device_id']

# retrieve the integration
url = f'{api_url}/integrations/{integration_id}'
r = requests.get(url, headers=headers)
integration = r.json()

# add the device to the integration
integration['Devices'].append(device_id)

# update the integration
r = requests.put(url, data=json.dumps(integration), headers=headers)