REST API Developer's Guide

Get Graph Data

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:

  1. Get instance level graph data
  2. Get widget data
  3. Get service graph data

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

 

Get instance 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. 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 milliseconds No - defaults to the selected graph time range
end The end time for returned data, in epoch milliseconds No - defaults to the selected graph time range

 

Example 1

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
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'multipart/form-data','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 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
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 write image data to a png file
print 'Response Status:',response.status_code
file_ = open('instanceGraph.png', 'wb')
file_.write(response.content)
file_.close()



Get widget data

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.  Note that 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.  

 

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 milliseconds No - defaults to the selected widget time range
end The end time for returned data, in epoch milliseconds 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
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'multipart/form-data','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

 

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) & 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 milliseconds No - defaults to the selected graph time range
end The end time for returned data, in epoch milliseconds No - defaults to the selected graph time range

 

Example

The following Python script requests perfomance 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
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + epoch
headers = {'Content-Type':'multipart/form-data','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