REST API Developer's Guide

Get Device Datasources

You can use LogicMonitor's REST API to get a list of datasources associated with a Device.

As with all of our API calls, authentication is required.

 

Get a list of device datasources

Returns a list of 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

sortsort={+ or -}propertySorts the response by the property specified in either increasing (+) or decreasing (-) order/device/devices/12/devicedatasources?sort=-id
filterfilter=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:
  • Greater than or equals: >:
  • Less than or equals: <:
  • Greater than: >
  • Less than: <
  • Does not equal: !:
  • Equals: :
  • Includes: ~
  • Does not include: !~
/device/devices/30/devicedatasources?filter=instanceNumber>0
fieldsfields={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
sizesize=integerThe 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
offsetoffset=integerThe 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 1 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
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + 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
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + 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
    signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

    #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 particular device datasource

Returns 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. {deviceDataSourceId} should be replaced with device datasource id

Request Parameters:

You can include a fields parameters to control which fields are included in the response.

Property

Syntax

Description

Example URI

fieldsfields={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