Get Datasource Instances
Last updated on 29 June, 2022You can use LogicMonitor’s REST API to programmatically get instances of a datasource.
Note: As with all of our API calls, authentication is required.
Get a list of datasource instances
HTTP Method: GET
URI: /device/devices/{deviceId}/devicedatasources/{deviceDatasourceId}/instances
Where:
- {deviceId} is the device id, which you can get from a GET request to the devices resource
- {deviceDatasourceId} is the device datasource id, which you can get from a GET request to the device datasources resource
Request Parameters: By default, a list of 50 instances will be returned. You can include sort, filter, fields, size and offset parameters in your request to control what data is included in the response and how it is formatted.
Property |
Syntax |
Description |
Example URI |
sort | sort={+ or -}property | Sorts the response by the property specified in either increasing (+) or decreasing (-) order | /device/devices/12/devicedatasources/98/instances?sort=-id |
filter | filter=property{operator}value | Filters the response according to the operator and value specified. Note that you can use * to match on more than one character. You can use the ‘.’ character to filter values within an object (e.g. custom properties), and multiple filters can be separated by a comma.
Operators include:
|
/device/devices/43/devicedatasources/76/instances?filter=name~prod43* |
fields | fields={list of properties separated by commas} | Filters the response to only include the following fields for each object | /device/devices/9/devicedatasources/24/instances?fields=name,id |
size | size=integer | The number of results to display. Max is 1000. | /device/devices/87/devicedatasources/54/instances?size=5 |
offset | offset=integer | The number of results to offset the displayed results by | /device/devices/34/devicedatasources/90/instances?offset=2 |
Example
The following Python script will return all instances for device 533, device-datasource 10256:
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'
#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/533/devicedatasources/10256/instances'
queryParams = ''
data = ''
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath +queryParams
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
#Make request
response = requests.get(url, data=data, headers=headers)
#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Get information about a particular datasource instance
HTTP Method: GET
URI: /device/devices/{deviceId}/devicedatasources/{deviceDatasourceId}/instances/{instanceId}
Where:
- {deviceId} is the device id, which you can get from a GET request to the devices resource
- {deviceDatasourceId} is the device datasource id, which you can get from a GET request to the device datasources resource
- {instanceId} is the instance id
Request Parameters: You can include a fields parameter in your request to control what data is included in the response and how it is formatted.
Property |
Syntax |
Description |
Example URI |
fields | fields={list of properties separated by commas} | Filters the response to only include the following fields for each object | /device/devices/9/devicedatasources/24/instances/45?fields=name,id |
Example
The following Python script will return all instances for device 533, device-datasource 10256, instance 23:
#!/bin/env python
import requests
import json
import hashlib
import base64
import time
import hmac
#Account Info
AccessId ='48v2wRzfK94y53sq5EuF'
AccessKey ='H_D9i(f5~B^U36^K6i42=^nS~e75gy382Bf6{)P+'
Company = 'api'
#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/533/devicedatasources/10256/instances/23'
queryParams = ''
data = ''
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath +queryParams
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + data + resourcePath
#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(hmac1.encode())
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
#Make request
response = requests.get(url, data=data, headers=headers)
#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)