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 update LogicMonitor device groups.
As with all of our API calls, authentication is required.
There are two ways to update a device group:
HTTP Method: PUT
URI: /device/groups/<id>
You can include the following properties in your PUT request to update a device group:
The following Python script updates group 115 to disable alerting:
#!/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 ='PUT' resourcePath = '/device/groups/115' queryParams = '' data = '{"name":"customerA","disableAlerting":true,"customProperties":[{"name":"customer","value":"A"}]}' #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.put(url, data=data, headers=headers) #Print status and body of response print('Response Status:',response.status_code) print('Response Body:',response.content)
HTTP Method: PATCH
URI: /device/groups/{id}
Request Parameters:
With every PATCH request you must include a query parameter patchFields that indicates which fields should be updated, where multiple fields should be comma separated. If a field is identified in the patchFields parameter and included in the payload of the request, its value will be updated. All other field values will remain the same. E.g. to update a device group’s name, the URI + query parameter would be /santaba/rest/device/groups/{id}?patchFields=name. The name field would also need to be included in the request payload. The following fields can be updated via PATCH:
The following Python script updates group 115 via PATCH to disable alerting:
#!/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 ='PATCH' resourcePath = '/device/groups/115' queryParams = '?patchFields=disableAlerting' data = '{"disableAlerting":true}' #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.patch(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 property to group 4 via PATCH, all other properties and fields remain the same:
#!/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 ='PATCH' resourcePath = '/device/groups/4' queryParams = '?patchFields=customProperties&opType=add' data = '{"customProperties":[{"name":"billing","value":"Ops"}]}' #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.patch(url, data=data, headers=headers) #Print status and body of response print('Response Status:',response.status_code) print('Response Body:',response.content)t
In This Article