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 programmatically get information about your LogicMonitor widgets. Specifically, you can:
Returns a list of widgets.
HTTP Method: GET
URI: /dashboard/widgets
Request Parameters: By default, a list of 50 widgets will be returned. You can include sort, filter, fields, size and offset parameters in your request 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 the calculation of the LMv1 authentication signature.
The following Python script returns a list of all widgets in the api.logicmonitor.com portal.
#!/bin/env python import requests import json import hashlib import base64 import time import hmac #Account Info AccessId ='YQQ75w6Mxx9zWIeAMq5H' AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8' Company = 'api' #Request Info httpVerb ='GET' resourcePath = '/dashboard/widgets' #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 + 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, headers=headers) #Print status and body of response print('Response Status:',response.status_code) print('Response Body:',response.content)
The following Python script returns a list of all widgets, where only the name, type and dashboardId are returned for each result and the results are sorted in descending order according to the name.
#!/bin/env python import requests import json import hashlib import base64 import time import hmac #Account Info AccessId ='YQQ75w6Mxx9zWIeAMq5H' AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8' Company = 'api' #Request Info httpVerb ='GET' resourcePath = '/dashboard/widgets' queryParams = '?fields=name,type,dashboardId&sort=-name' #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 + 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, headers=headers) #Print status and body of response print('Response Status:',response.status_code) print('Response Body:',response.content)
Returns details for a particular widget.
URI: /dashboard/widgets/{id}
The following Python script returns the details for the widget with id 174 in api.logicmonitor.com.
#!/bin/env python import requests import json import hashlib import base64 import time import hmac #Account Info AccessId ='YQQ75w6Mxx9zWIeAMq5H' AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8' Company = 'api' #Request Info httpVerb ='GET' resourcePath = '/dashboard/widgets/174' #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 + 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, headers=headers) #Print status and body of response print('Response Status:',response.status_code) print('Response Body:',response.content)
The following is a sample response for the previous GET example.
Response Status: 200 Response Body: { "status" : 200, "errmsg" : "OK", "data" : { "id" : 172, "name" : "Web Server Status", "description" : "", "type" : "deviceNOC", "lastUpdatedOn" : 1438888647, "lastUpdatedBy" : "", "dashboardId" : 26, "columnIdx" : 2, "order" : 2, "theme" : "borderPurple", "colSpan" : 1, "rowSpan" : 1, "userPermission" : "write", "interval" : 1, "timescale" : "day", "extra" : "", "sortBy" : "name", "displayColumn" : 3, "displayWarnAlert" : true, "displayErrorAlert" : true, "displayCriticalAlert" : true, "ackChecked" : true, "sdtChecked" : true, "items" : [ { "deviceGroupFullPath" : "*", "deviceDisplayName" : "ip-172-31-33-214.us-west-2.compute.internal", "dataSourceDisplayName" : "HTTP-", "instanceName" : "*", "dataPointName" : "*", "groupBy" : "device", "name" : "##HOSTNAME## - HTTP content/function" }, { "deviceGroupFullPath" : "*", "deviceDisplayName" : "ip-172-31-33-214.us-west-2.compute.internal", "dataSourceDisplayName" : "Apache-", "instanceName" : "*", "dataPointName" : "*", "groupBy" : "device", "name" : "##HOSTNAME## - Apache" }, { "deviceGroupFullPath" : "*", "deviceDisplayName" : "ip-172-31-33-214.us-west-2.compute.internal", "dataSourceDisplayName" : "Host Status", "instanceName" : "*", "dataPointName" : "*", "groupBy" : "device", "name" : "##HOSTNAME## - Host Status" } ] } }
Returns all widgets for a particular dashboard.
Resource URI: /dashboard/dashboards/{dashboardID}/widgets (Where dashboardID is the id of the dashboard you’d like to get widgets for.)
In This Article