Getting Datasource Details
Last updated on 07 October, 2024You 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.
Parameter | Type | Description |
fields | String | The 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 |
size | Integer | Indicates 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 |
offset | Integer | Indicates the number of results to offset the displayed result. Example – /setting/datasources?offset=2 |
filter | String | The response is filtered according to the operator and specified value that is, filter=property:value
Operators include:
/setting/datasources?filter=name:QAservice |
Getting Devices Associated with Datasource
URI: GET /setting/datasources/{id}/devices
The query parameters fields
, size
, offset
, 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.
Parameter | Type | Description |
id | Integer | (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)
Getting Datasource List
URI: GET /setting/datasources
The query parameters fields
, size
, offset
, 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.
Parameter | Type | Description |
format | String | The 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)
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)
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)
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.
Parameter | Type | Description |
id | Integer | (Mandatory) It is the datasource ID whose details you want to get. |
format | String | The 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)
Getting Datasource Overview Graph List
URI: GET /setting/datasources/{dsId}/ographs
The query parameters fields
, size
, offset
, 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.
Parameter | Type | Description |
dsId | Integer | (Mandatory) It is the ID of the datasource. |
Getting Update Reason of Datasource
URI: GET /setting/datasources/{id}/updatereasons
The query parameters fields
, size
, offset
, 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.
Parameter | Type | Description |
id | Integer | (Mandatory) The datasource ID whose update history you want to get. |