Get Device DataSources
Last updated on 29 January, 2021Overview
You can use LogicMonitor’s REST API to get information about the DataSources associated with a device. Specifically, you can get a list of DataSources or information on a specific DataSource.
As with all of our API calls, authentication is required.
Get a List of Device DataSources
HTTP Method: GET
URI: /device/devices/{deviceId}/devicedatasources
(Where {deviceId} should be replaced with the desired device ID. You can get device IDs from the devices resource.)
Request Parameters: By default, 50 DataSources will be returned. You can include sort, filter, fields, size, and offset parameters 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?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/30/devicedatasources?filter=instanceNumber>0 |
fields | fields={list of properties separated by commas} | Filters the response to only include the following fields for each object | /device/devices/78/devicedatasources?fields=dataSourceName,id,instanceNumber |
size | size=integer | The number of results to display. A maximum of 50 results will be displayed by default, and size can be specified up to 1000 | /device/devices/90/devicedatasources?size=5 |
offset | offset=integer | The number of results to offset the displayed results by | /device/devices/45/devicedatasources?offset=2 |
Example 1
The following Python script requests the DataSources associated with device 427 that have at least one monitored instance:
#!/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/427/devicedatasources'
queryParams = '?filter=instanceNumber>0'
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)
Example 2
The following Python script loops through each device in the account api.logicmonitor.com & requests the DataSources that have at least one instance. A list of unique DataSources with at least one instance throughout the account is printed as a result.
#!/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'
#Construct URL
url = 'https://'+ Company +'.logicmonitor.com/santaba/rest' + resourcePath
#Get current time in milliseconds
epoch = str(int(time.time() * 1000))
#Concatenate Request details
requestVars = httpVerb + epoch + 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, headers=headers)
#Parse response
jsonResponse = json.loads(response.content)
#create list to keep datasources
datasources = []
#Loop through each device & get datasources
for i in jsonResponse['data']['items']:
deviceId = str(i['id'])
#Request Info
httpVerb ='GET'
resourcePath = '/device/devices/'+deviceId+'/devicedatasources'
queryParams ='?filter=instanceNumber>0'
#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 + 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 + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth}
#Make request
datasourceResponse = requests.get(url, headers=headers)
#Parse response & for each datasource, check if it's already been added to the list. If not, add it.
jsonDatasourceResponse = json.loads(datasourceResponse.content)
for j in jsonDatasourceResponse['data']['items']:
if not (j['dataSourceName'] in datasources):
datasources.append(j['dataSourceName'])
#Print result
print str(datasources).strip('[]')
Get Information About a Specific Device DataSource
HTTP Method: GET
URI: /device/devices/{deviceId}/devicedatasources/{deviceDataSourceId}
(Where {deviceId} should be replaced with the desired device id. You can get device ids from the devices resource. And {deviceDataSourceId} should be replaced with device DataSource id.)
Request Parameters: You can include the fields parameter to control which fields are included in the response.
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/78/devicedatasources/213?fields=dataSourceName,id,instanceNumber |