Overview

You can use LogicMonitor’s REST API to programmatically get all config files for a ConfigSource instance. As with all of our API calls, authentication is required.

Resource Information

HTTP Method: GET

URI: 

/device/devices/{deviceId}/devicedatasources/{deviceDataSourceId}/instances/{instanceId}/config

Where:

Request Parameters: By default, a list of 50 stored config results will be returned. You can include the following query parameters to control what data is included in the response and how it is formatted. Note that query parameters are not considered part of the resource path, and should not be included in the calculation of the LMv1 authentication signature.

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/12/devicedatasources/45/instances/67/config?fields=id,version,deltaConfig
sort sort={+ or -}property Sorts the response by the property specified in either increasing (+) or decreasing (-) order /device/devices/9/devicedatasources/65/instances/84/config?sort=-version
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:

  • Greater than or equals: >:
  • Less than or equals: <:
  • Greater than: >
  • Less than: <
  • Does not equal: !:
  • Equals: :
  • Includes: ~
  • Does not include: !~
/device/devices/3/devicedatasources/65/instances/84/config?filter=changeStatus:Change
size size=integer The number of results to display. Max is 1000. /device/devices/5/devicedatasources/65/instances/84/config?size=5
offset offset=integer The number of results to offset the displayed results by /device/devices/6/devicedatasources/65/instances/84/config?offset=2

Each config will include an id, version, timestamp, the configuration file text, the differences detected from the last version, and any alerts that were triggered based on the changes. To get only the latest version of a config, you can sort by version and limit the results to one by using the following query parameters: ?sort=-version&size=1

Example

The following Python script will return config data for device 674, ConfigSource 14921, instance 210728286:

#!/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/674/devicedatasources/14921/instances/210728286/config'
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)
Python 3

Overview

You can use LogicMonitor’s REST API to get data for the websites in your account. As with all of our API calls, authentication is required.

Resource Information

HTTP Method: GET

URI: /service/services/{serviceID}/checkpoints/{checkpointID}/data (where serviceID is the service id, which can be obtained via the Services Resource; checkpointID is the id of the service checkpoint you’d like to obtain data for, which can be obtained from the checkpoints object in the service definition (make a GET request to get details for a particular service.)

Request Parameters: By default, data will be returned for the last hour. You can include the following query parameters in your request to control what data is included in the response.

Property Description Required?
start The start time to return data for, in epoch milliseconds No – the last hour of data will be returned by default
end The end time to return data for, in epoch milliseconds No – defaults to last hour of data
datapoints The metrics that data should be returned for No – defaults to all
format The format to return data in, where options are csv and json No – defaults to json

Example

The following Python script gets data from 1482865561 to 1482865719 for service 58, checkpoint 294.

#!/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 = '/service/services/58/checkpoints/294/data'
queryParams ='?start=1482865561&end=1482865719'
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()

# 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)
Python 3

Overview

You can use LogicMonitor’s REST API to get graph data, either in a numerical data format or in image format. There are three types of graph data you can request:

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

Get Instance-Level Graph Data

HTTP Method: GET

Resource URIs:

/device/devices/{deviceID}/devicedatasources/{deviceDataSourceID}/instances/{instanceID}/graphs/{graphID}/data
/device/devicedatasourceinstances/{instanceID}/graphs/{graphID}/data
/device/devicedatasources/{deviceDataSourceID}/groups/{instanceGroupId}/graphs/{overviewGraphID}/data

(Where deviceID is the ID of the device you’d like data for, which you can get from the device resource; deviceDataSourceID is the ID of the device datasource you’d like data for, which you can get from the datasources resource; and Instance ID is the ID of the instance you’d like data for, which you can get from the instance resource; instanceGroupID is the instance group for which you’d like to get overview graph data for, and you can get instance group information from the instance groups resource; graphID is the ID of the particular instance graph you’d like data for, and you can get all graph information for a particular DataSource from the datasources resource; overviewGraphID is the ID of the particular overview graph you’d like data for, and you can get all graph information for a particular DataSource from the DataSources resource.)

Request Parameters: By default, data will be returned for the configured graph time range. You can include the following query parameters in your request to control what data is included in the response:

Property Description Required?
format data | image | csv – Whether returned data is formatted as number values (data = json) or an image No – defaults to data
width The width of the image, in pixels, if format=image No
height The height of the image, in pixels, if format=image No
start The start time for returned data, in epoch seconds No – defaults to the selected graph time range
end The end time for returned data, in epoch seconds No – defaults to the selected graph time range

Examples

Example: Get Data from Graph

The following Python script gets data from 1482865561 to 1482865719 for graph 253, associated with instance 26657295, datasource 6842, device 258:

#!/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/258/devicedatasources/6842/instances/26657295/graphs/253/data'
queryParams ='?start=1482865561&end=1482865719'
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)
Python 3

Example: Save Image File

The following Python script saves an image file ‘instanceGraph.png’ for graph 4825, associated with device DataSource instance 420576596:

#!/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/devicedatasourceinstances/420576596/graphs/4825/data'
queryParams = '?format=image'
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 write image data to a png file
print('Response Status:',response.status_code)
file_ = open('instanceGraph.png', 'wb')
file_.write(response.content)
file_.close()
Python 3

Get Widget Data

Note: This data resource doesn’t work for text, HTML and flash widgets. For widgets without time series data, like the map widget and the alert widget, data will be returned based on what is displayed in the widget (locations, matching alerts) independent of time. For widgets with time series data, like the custom graph widget and the device graph widget, data will be returned based on the time range configured or specified in the request.

HTTP Method: GET

Resource URI: /dashboard/widgets/{widgetID}/data
(Where widgetID is the id of the widget you’d like to get data for. You can get widgetID from the widgets resource.)

Request Parameters: By default, data will be returned for the configured widget time range. You can include the following query parameters in your request to control what data is included in the response:

Property Description Required?
format data | image – Whether returned data is formatted as number values or an image No – defaults to data
start The start time for returned data, in epoch seconds No – defaults to the selected widget time range
end The end time for returned data, in epoch seconds No – defaults to the selected widget time range

Example

The following Python script gets data from 1482865561 to 1482865719 for widget 362:

#!/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 = '/dashboard/widgets/362/data'
queryParams ='?start=1482865561&end=1482865719'
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)
Python 3

Get Service Graph Data

HTTP Method: GET

Resource URI: /service/services/{serviceID}/checkpoints/{checkpointID}/graphs/{graphName}/data
(Where serviceID is the service you’d like to get data for; you can get serviceID from the services resource. CheckpointID is the ID of the service checkpoint you’d like data for; you can get checkpointIDs by making a GET request to get details for a particular service. graphName is the graph you’d like data for, where possible values are status, performance (only for individual checkpoints) and responsetime.)

Request Parameters: By default, data will be returned for the configured graph time range. You can include the following query parameters in your request to control what data is included in the response:

Property Description Required?
format data | image – Whether returned data is formatted as number values or an image No – defaults to data
start The start time for returned data, in epoch seconds No – defaults to the selected graph time range
end The end time for returned data, in epoch seconds No – defaults to the selected graph time range

Example

The following Python script requests performance graph data from 1482865561 to 1482865719 for service 58, checkpoint 294:

#!/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 = '/service/services/58/checkpoints/294/graphs/performance/data'
queryParams ='?start=1482865561&end=1482865719'
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)
Python 3

Overview

You can use LogicMonitor’s REST API to programmatically get data. There are two ways to get data for instances:

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

Get Data for All Instances of a DataSource

HTTP Method: GET

URI: /device/devices/{deviceId}/devicedatasources/{deviceDatasourceId}/data
(Where deviceId is the device id, which can be obtained via the devices resource, and deviceDatasourceId is the id of a device datasource, which can be obtained via the device DataSource resource.

Request Parameters: By default, data will be returned for the last hour. You can include the following query parameters in your request to control what data is included in the response and how it is formatted:

Property Description Required?
period The number of hours data should be returned for, ending at the current time (e.g. period=2 means last 2 hours). No – defaults to 1
start The start time to return data for, in epoch format. No – period will be used if start/end are omitted
end The end time for the returned data, in epoch format Only if start is specified
format The format to return data in, where options are csv and json No – defaults to json
datapoints The datapoints for which data should be returned (e.g. ?datapoints=TunnelState,TunnelDataIn will result in data only being returned for the TunnelState and TunnelDataIn datapoints) No – defaults to all datapoints

Note: A maximum of 500 values can be returned in one request. As a result, if you’d like to get more than 500 values, you’ll need to make multiple requests with different start/end values. We recommend doing this with a script.

Examples

Example 1

The following Python script will return data for device 533, device datasource 10256, between 1478296606 and 1478297686:

#!/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/data'
queryParams = '?start=1478296606&end=1478297686'
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)
Python 3

Example 2

The following Python script gets all DataSources with at least one instance for device 533, and then loops through the response and, for each of those DataSources, gets data for all instances between epoch times 1478296606 and 1478297686:

#!/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 to get all datasources with >0 instances for device 533
httpVerb ='GET'
resourcePath = '/device/devices/533/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)

#Parse response
jsonResponse = json.loads(response.content)

#Open a file to save data to
file_ = open('Device533Data.txt', 'a')

#Loop through each datasource & get data
for i in jsonResponse['data']['items']:
    deviceDatasourceId = str(i['id'])

    #Request Info
    httpVerb ='GET'
    resourcePath = '/device/devices/533/devicedatasources/'+deviceDatasourceId+'/data'
    queryParams ='?start=1478296606&end=1478297686'
    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)
    response_json = json.loads(response.content)
    data = response_json['data']

    #Save data to file
    file_.write(json.dumps(data) + '\n')

file_.close()
Python 3

Example 3

The following Python script requests data for all instances of datasource 11287 for device 674, in a CSV format:

#!/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/674/devicedatasources/11287/data'
data=''
queryParams ='?format=csv'

#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 + 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)
Python 3

Get Data for One Instance of a DataSource

HTTP Method: GET

URI: /device/devices/{deviceId}/devicedatasources/{deviceDatasourceId}/instances/{instanceId}/data
(Where deviceId is the device id, which can be obtained via the Devices Resource; deviceDatasourceId is the id of a device datasource, which can be obtained via the Device Datasource Resource; and instanceId is the id of an instance, and can be obtained via GET /device/devices/{deviceId}/devicedatasources/{deviceDatasourceId}/instances.)

Request Parameters: By default, data will be returned for the last hour. You can include the following query parameters in your request to control what data is included in the response:

Property Description Required?
period The number of hours data should be returned for, ending at the current time (e.g. period=2 means last 2 hours). No – defaults to 1
start The start time to return data for, in epoch format. No – period will be used if start/end are omitted
end The end time for the returned data, in epoch format Only if start is specified
format The format to return data in, where options are csv and json No – defaults to json

Example

The following Python script returns the last two hours of data for device 533, device datasource 12506, 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/data'
queryParams = '?period=2'
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)
Python 3