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 add new widgets to your LogicMonitor dashboards. As with all of our API resources, authentication is required.
HTTP Method: POST
URI: /dashboard/widgets
You can POST the following properties for all new widgets.
Note: colSpan and rowSpan can be used to adjust widget size, but will not allow you to change widget position (and do not allow half size widgets). The only way to currently change widget position (or create half size widgets) is to update the widgetsConfig string for the dashboard itself via the dashboards resource.
Additional properties are available depending on the widget you are adding.
You may additionally POST a ‘filters’ object with the following properties for all widgets of type alert (alert widgets).
You may additionally POST the following properties for all widgets of type batchjob (batchjob widgets).
All widgets of type bigNumber (big number widgets) must include an object bigNumberInfo with the following fields.
Note that a datapoint must be referenced in the bigNumberItems object in order to be displayed.
All widgets of type cgraph (custom graph widgets) must include an object graphInfo with the following fields.
You may also POST the following fields for widgets of type deviceNOC (device NOC widgets).
You may also POST the following fields for widgets of type gauge (gauge widgets).
You must also POST an object mapPoints with the following fields for widgets of type gmap (google map widgets).
You must also POST an object ‘resources’ with the following fields for widgets of type html (HTML widgets).
You may also POST the following fields for widgets of type ngraph (pinned device level graphs).
You must also POST an object pieChartInfo with the following fields for all widgets of type pieChart (pie chart widgets).
You may also POST the following fields for widgets of type serviceIndividualStatus (service individual status widgets).
You may also POST the following fields for widgets of type serviceNOC (service NOC widgets).
For widgets of type serviceOverallStatus (service overall status widgets) you must POST an object selectedServices with the following fields.
You can additionally POST the following fields for widgets of type serviceSLA (service SLA widgets).
You can additionally POST the following fields for widgets of type deviceSLA (device SLA widgets).
You can additionally POST the following fields for widgets of type sgraph (graph pinned from the services page).
All widgets of type table (table widgets) must include two additional objects. A ‘columns’ object must be included, where each column has the following fields.
And a ‘rows’ object needs to be included, where each row has the following fields.
And a ‘forecast’ object is required if you have enableForecast=true, where you need all three of the following fields.
All widgets of type text (text widgets) must include a content field.
The following examples illustrate adding various widgets to an account api.logicmonitor.com via Python.
The following Python script adds an Alert widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"name":"Website Alert Widget","dashboardId":26,"type":"alert","filters":{"group":"US - LA/Website*"}}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a BatchJob widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"batchjob","dashboardId":"26","name":"batch job test","deviceDisplayName":"10.36.11.240","batchJobName":"myBatchJob"}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Big Number Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"bigNumber","dashboardId":"26","name":"big number test","bigNumberInfo":{"dataPoints":[{"deviceGroupFullPath":"Website","deviceDisplayName":"ip-172-31-37-162.us-west-2.compute.interal","dataSourceId":559,"instanceName":"NetSNMPCPUwithCores-Core Count: 1","dataPointId":2899,"name":"CPUBusyPercent"}],"bigNumberItems":[{"dataPointName":"CPUBusyPercent","rounding":"0"}]}}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Device NOC Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"deviceNOC","dashboardId":"26","name":"Device NOC Widget","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"}]}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Gauge Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"gauge","dashboardId":"26","name":"Gauge Widget","maxValue":100,"minValue":0,"dataPoint":{"deviceGroupFullPath":"Production","deviceDisplayName":"ip-172-31-37-162.us-west-2.compute.interal","dataSourceId":"124","instanceName":"*","dataPointName":"Accesses","aggregateFunction":"SUM","rpn":"Accesses + 10","dataSeries":"average"}}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Google Map Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"gmap","dashboardId":"26","name":"Google Map Widget","mapPoints":[{"type":"device","deviceGroupFullPath":"US - LA/Website","deviceDisplayName":"ip-172-31-37-162.us-west-2.compute.interal"}]}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds an HTML widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"html","dashboardId":"26","name":"My HTML widget","resources":[{"type":"iframe","URL":"<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/s6Ax30Mz7uo\" frameborder=\"0\" allowfullscreen></iframe>"}]}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Device Graph to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"ngraph","dashboardId":"26","name":"NGRAPH WIDGET","hId":39,"dsiId":852,"graphId":2142}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Pie Chart Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"pieChart","dashboardId":"26","pieChartInfo":{"title":"testWidget","dataPoints":[{"deviceGroupFullPath":"Website","deviceDisplayName":"*","dataSourceFullName":"Apache-","instanceName":"Apache-80","dataPointName":"ExtendedStatusNotEnabled","name":"ExtendedStatusNotEnabled","aggregate":true,"aggregateFunction":"sum"}],"pieChartItems":[{"dataPointName":"ExtendedStatusNotEnabled","legend":"##HOSTNAME##_##DATASOURCENAME##_##INSTANCE##","color":"Auto"}]},"name":"PIE CHART WIDGET TEST"}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Service Individual Status Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"serviceIndividualStatus","dashboardId":"26","name":"SERVICE IND WIDGET","serviceId":21,"locations":[{"smgId":2,"geoInfo":"US - Washington DC","selected":true},{"smgId":3,"geoInfo":"US - San Francisco","selected":true},{"smgId":4,"geoInfo":"Europe - Dublin","selected":true},{"smgId":5,"geoInfo":"Asia - Singapore","selected":true},{"smgId":6,"geoInfo":"Sydney - Australia","selected":false}]}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Service NOC Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"serviceNOC","dashboardId":"26","name":"Service NOC Widget","items":[{"serviceGroupName":"Production","serviceName":"*","groupBy":"service","name":"##SERVICE##"},{"serviceGroupName":"Internal Services","serviceName":"*","groupBy":"service","name":"##SERVICE##"}]}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Service Overall Status Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"serviceOverallStatus","dashboardId":"26","name":"Service Overall Status","selectedServices":[{"serviceGroupId":1,"serviceGroupName":"api","chooseAll":true},{"serviceGroupId":1,"serviceGroupName":"api","chooseAll":false,"services":[{"id":21,"name":"main page"},{"id":22,"name":"a record (ELB)"}]}]}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Service SLA Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"serviceOverallStatus","dashboardId":"26","name":"Service Overall Status","selectedServices":[{"serviceGroupId":1,"chooseAll":true},{"serviceGroupId":1,"chooseAll":false,"services":[{"id":21,"name":"main page"},{"id":22,"name":"a record (ELB)"}]}]}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Service Graph Widget to dashboard 26 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 ='POST' resourcePath = '/dashboard/widgets' data = '{"type":"sgraph","dashboardId":"26","name":"SGRAPH Widget","serviceName":"CName_check","serviceCheckpointId":99,"graph":"responseTime"}' #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() # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.post(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 adds a Custom Graph Widget to dashboard 26 in api.logicmonitor.com.
#!/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 ='POST' resourcePath = '/dashboard/widgets' queryParams ='' data = '{"name":"Custom Graph Widget","dashboardId":26,"type":"cgraph","graphInfo":{"title":"My Custom Graph Widget","verticalLabel":"percent","dataPoints":[{"name":"cpu","dataPointName":"CPUBusyPercent","dataSourceFullName":"WinCPU","instanceName":"*","deviceDisplayName":"ip-172-31-37-162.us-west-2.compute.interal","deviceGroupFullPath":"*"}],"graphLines":[{"dataPointName":"cpu","legend":"##INSTANCE##","type":1}]}}' #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.post(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 adds a Table Widget to dashboard 26 in api.logicmonitor.com.
#!/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 ='POST' resourcePath = '/dashboard/widgets' queryParams ='' data = '{"name":"Table Widget","dashboardId":26,"type":"table","columns":[{"columnName":"cpu","dataPoint":{"dataSourceId":7960532,"dataPointId":5349}}],"rows":[{"label":"prodServer1","groupId":7,"deviceId":39,"instances":[{"instanceId":96678897,"dataPointId":5349}]}]}' #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.post(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 adds a Text Widget to dashboard 26 in api.logicmonitor.com.
#!/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 ='POST' resourcePath = '/dashboard/widgets' queryParams ='' data = '{"name":"Text Widget","dashboardId":26,"type":"text","content":"<p>My Text Widget</p>"}' #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.post(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