Getting Datasource Details

Last updated on 15 May, 2024

You can use LogicMonitor REST API v3 to get datasource details. You must authenticate yourself before making the API request.

Common Query Parameters

The following query parameters are common to all GET requests for Datasources APIs. 

ParameterTypeDescription
fieldsStringThe response is filtered to include only the specified fields for each object. You can provide a list of properties separated by a comma.
Example – /setting/datasources?fields=name,id
sizeIntegerIndicates the number of results to display. A maximum of 1000 results can be requested in a GET request. By default, a list of 50 DataSources is returned if a value is not provided for this parameter.
Example – /setting/datasources?size=5
offsetIntegerIndicates the number of results to offset the displayed result.
Example – /setting/datasources?offset=2
filterStringThe response is filtered according to the operator and specified value that is, filter=property:value
  • Use an asterisk (*) to match more than one character
  • Use a dot (.) character to filter values within an object (example – custom properties)
  • Use a comma (,) to separate multiple filters

Operators include:
  • Greater than or equals >:
  • Less than or equals <:
  • Greater than >
  • Less than <
  • Equals :
  • Does not equal !:
  • Includes ~
  • Does not include !~
Example – /setting/datasources?filter=name:QAservice

Getting Devices Associated with Datasource

URI: GET /setting/datasources/{id}/devices

The query parameters fieldssizeoffset, and filter should also be included while making the request GET /setting/datasources/{id}/devices. For details, see the common query parameters table.

An additional parameter id which is specific to GET /setting/datasources/{id}/devices is described in the following table.

ParameterTypeDescription
idInteger(Mandatory) It is the datasource ID whose list of associated devices you want to get.

Example

The following Python script requests devices for the datasource ID 247527051.

#!/bin/env python
 
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
 
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
 
#Request Info
httpVerb ='GET'
resourcePath = '/setting/datasources/247527051/devices'
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
digest = hmac.new(
        AccessKey.encode('utf-8'),
        msg=requestVars.encode('utf-8'),
        digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
 
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'3'}
 
#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)
Python 3

Getting Datasource List

URI: GET /setting/datasources

The query parameters fieldssizeoffset, and filter should also be included while making the request GET /setting/datasources. For details, see the common query parameters table.

An additional parameter format which is specific to GET /setting/datasources is described in the following table.

ParameterTypeDescription
formatStringThe response format can be JSON or xml. By default, it is set as JSON.

Example 1

The following Python script requests datasources in the api.logicmonitor.com account.

#!/bin/env python
 
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
 
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
 
#Request Info
httpVerb ='GET'
resourcePath = '/setting/datasources'
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
digest = hmac.new(
        AccessKey.encode('utf-8'),
        msg=requestVars.encode('utf-8'),
        digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
 
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'3'}
 
#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)
Python 3

Example 2

The following Python script returns the id and name for datasources in api.logicmonitor.com, and the response is displayed in the ascending order of the ID.

#!/bin/env python
 
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
 
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
 
#Request Info
httpVerb ='GET'
resourcePath = '/setting/datasources'
queryParams = '?fields=id,name&sort=+id'
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
digest = hmac.new(
        AccessKey.encode('utf-8'),
        msg=requestVars.encode('utf-8'),
        digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
 
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'3'}
 
#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)
Python 3

Example 3

The following Python request returns datasources in api.logicmonitor.com that have an applies to function including isLinux.

#!/bin/env python
 
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
 
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
 
#Request Info
httpVerb ='GET'
resourcePath = '/setting/datasources'
queryParams = '?filter=appliesTo~"isLinux"'
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
digest = hmac.new(
        AccessKey.encode('utf-8'),
        msg=requestVars.encode('utf-8'),
        digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
 
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'3'}
 
#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)
Python 3

Getting Datasources based on ID

URI: Get /setting/datasources/{id}

The query parameter fields should be included while making the request GET /setting/datasources/{id}. For details, see the common query parameters table.

Additional parameters id and format that are specific to GET /setting/datasources/{id} are described in the following table.

ParameterTypeDescription
idInteger(Mandatory) It is the datasource ID whose details you want to get.
formatStringThe response format can be JSON or xml. By default, it is set as JSON.

Example

The following Python script returns details for the datasource ID 345.

#!/bin/env python
 
import requests
import json
import hashlib
import base64
import time
import hmac
import getpass
 
#Account Info: LogicMonitor recommends to NEVER hardcode the credentials. Instead, retrieve the values from a secure storage.
#Note: The below is provided for illustration purposes only.
AccessId = getpass.getpass("Enter your AccessId: ")
AccessKey = getpass.getpass("Enter your AccessKey: ")
Company = 'apiAccount'
 
#Request Info
httpVerb ='GET'
resourcePath = '/setting/datasources/345'
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
digest = hmac.new(
        AccessKey.encode('utf-8'),
        msg=requestVars.encode('utf-8'),
        digestmod=hashlib.sha256).hexdigest()
signature = base64.b64encode(digest.encode('utf-8')).decode('utf-8')
 
#Construct headers
auth = 'LMv1 ' + AccessId + ':' + str(signature) + ':' + epoch
headers = {'Content-Type':'application/json','Authorization':auth,'X-Version':'3'}
 
#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)
Python 3

Getting Datasource Overview Graph List

URI: GET /setting/datasources/{dsId}/ographs

The query parameters fieldssizeoffset, and filter should be included while making the request GET /setting/datasources/{dsid}/ographs. For details, see the common query parameters table.

An additional parameter dsId which is specific to GET /setting/datasources/{dsid}/ographs is described in the following table.

ParameterTypeDescription
dsIdInteger(Mandatory) It is the ID of the datasource.

Getting Update Reason of Datasource

URI: GET /setting/datasources/{id}/updatereasons

The query parameters fieldssizeoffset, and filter should be included while making the request GET /setting/datasources/{id}/updatereasons. For details, see the common query parameters table.

An additional parameter id which is specific to GET /setting/datasources/{id}/updatereasons is described in the following table.

ParameterTypeDescription
idInteger(Mandatory) The datasource ID whose update history you want to get.
In This Article