Get Widgets

Last updated on 18 November, 2020

Overview

You can use LogicMonitor’s REST API to programmatically get information about your LogicMonitor widgets. Specifically, you can:

  • Get a list of widgets
  • Get information about a particular widget
  • Get all widgets for a particular dashboard

Get a List of Widgets

Returns a list of widgets.

Request Information

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.

Property Syntax Description Example URI
sort sort={+ or -}property Sorts the response by the property specified in either increasing (+) or decreasing (-) order /dashboard/widgets?sort=+name
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: !~
/dashboard/widgets?filter=type:alert
fields fields={list of properties separated by commas} Filters the response to only include the following fields for each object /dashboard/widgets?fields=name,type
size size=integer The number of results to display. Max is 1000. /dashboard/widgets?size=5
offset offset=integer The number of results to offset the displayed results by /dashboard/widgets?offset=2

Examples

Example: GET All Widgets

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

Example: GET All Widgets (less detail)

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

Get Information About a Particular Widget

Returns details for a particular widget.

Request Information

HTTP Method: GET

URI: /dashboard/widgets/{id}

Examples

Example: GET a Single Widget

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

Example: Sample Response

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"
    } ]
  }
}
HTML

Get All Widgets for a Particular Dashboard

Returns all widgets for a particular dashboard.

Request Information

HTTP Method: GET

Resource URI: /dashboard/dashboards/{dashboardID}/widgets
(Where dashboardID is the id of the dashboard you’d like to get widgets for.)

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.

Property Syntax Description Example URI
sort sort={+ or -}property Sorts the response by the property specified in either increasing (+) or decreasing (-) order /dashboard/dashboards/90/widgets?sort=+name
filter filter=property{operator}value Filters the response according to the operator and value specified. Operators include:

  • Greater than or equals: >:
  • Less than or equals: <:
  • Greater than: >
  • Less than: <
  • Does not equal: !:
/dashboard/dashboards/87/widgets?filter=type:alert
fields fields={list of properties separated by commas} Filters the response to only include the following fields for each object /dashboard/dashboards/45/widgets?fields=name,type
size size=integer The number of results to display. Max is 300. /dashboard/dashboards/34/widgets?size=5
offset offset=integer The number of results to offset the displayed results by /dashboard/dashboards/12/widgets?offset=2
In This Article