Come join our live training webinar every other Wednesday at 11am PST and hear LogicMonitor experts explain best practices and answer common questions. We understand these are uncertain times, and we are here to help!
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.
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:
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)
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()
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.
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:
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)
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.)
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)
In This Article