Update Website Groups
Last updated on 25 February, 2021With LogicMonitor’s REST API you can programmatically update your LogicMonitor website groups.
There are two ways to update a website group:
- PUT: A PUT request enables you to replace an entire website group definition (and update fields in the process). You should use PUT to update a website group if you want to provide an updated JSON definition for the website group. Note that consistent with REST standards, any properties not specified in a PUT request will revert back to their default values.
- PATCH: A PATCH request enables you to replace only certain fields for a website group. You should use PATCH if you don’t have the JSON definition for the website group and you only want to update a few fields.
PUT
Note that you cannot update the root group.
HTTP Method:PUT
URI: /service/groups/{id}
Request Parameters:
Note: Consistent with REST standards, any properties not specified in a PUT request will revert back to their default values.
Property |
Description |
Required? |
Values |
Type |
name | The name of the website group | Yes | – | String |
description | The description of the website group | No | This value defaults to a blank String | String |
stopMonitoring | If this value is true then monitoring is disabled for the websites in the website group. Note that if monitoring is disabled, alerting will also be disabled. | No | true | false. This value defaults to false. | Boolean |
disableAlerting | If this value is true then alerting is disabled for the websites in the group. Note that if monitoring is disabled, alerting will also be disabled. | No | true | false. This value defaults to false. | Boolean |
parentId | The Id of the parent group. If parentId=1 then the group exists under the root group. | No | Defaults to 1 | Integer |
serviceProperties | The properties set for the group (does not include inherited properties) | No | “serviceProperties” : [ {“name” : “PropertyName1″,”value” : “PropertyValue1”},{“name” : “PropertyName2″,”value” : “PropertyValue2”} ] | JSON Object |
testLocation | The locations from which the websites within the group are monitored. Locations are: | Yes | 1 : US – LA 2 : US – DC 3 : US – SF 4 : US – DC 5 : Europe – Dublin 6 : Asia – Singapore testLocation:”{all:true}” indicates that the service will be monitored from all checkpoint locations testLocation:”{smgIds:[1,2,3]}” indicates that the service will be monitored from checkpoint locations 1, 2 and 3 |
JSON Object |
Example PUT:
The following request updates the website group with id 9.
curl --user 'apiUser:example' -H "Content-Type: application/json" -d '{"name":"newServiceGroup","description":"testSites","disableAlerting":false,"testLocation":"{smgIds:[1,2,3,4,5]}"}' -X PUT "https://api.logicmonitor.com/santaba/rest/service/groups/9"</pre>
<p><strong>Response: </strong></p>
<pre class="programlisting">{
"status" : 200,
"errmsg" : "OK",
"data" : {
"id" : 16,
"name" : "newServiceGroup",
"description" : "testSites",
"disableAlerting" : false,
"stopMonitoring" : false,
"parentId" : 1,
"alertStatus" : "none",
"sdtStatus" : "none-none-none",
"alertDisableStatus" : "none-none-none",
"hasServicesDisabled" : false,
"numOfServices" : 0,
"userPermission" : "write",
"serviceProperties" : [ ],
"numOfDirectServices" : 0,
"testLocation" : "{smgIds:[1,2,3,4,5]}",
"fullPath" : "newServiceGroup",
"subGroups" : [ ]
}
PATCH
HTTP Method: PATCH
URI: /service/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 service group’s name, the URI + query parameter would be /santaba/rest/service/groups/{id}?patchFields=name. The name field would also need to be included in the request payload.
Note that to add or update just one or a few website group properties in the serviceProperties object, but not all of them, you’ll need to additionally use the opType query parameter. The opType query parameter can be set to add or replace. opType=add indicates that the properties included in the payload will be added, but all existing properties will remain the same. opType=replace indicates that the properties included in the request payload will be added if they don’t already exist, or updated if they do already exist, but all other existing properties will remain the same.
Example PATCH
The following Python script adds a property to website group 21, without changing any other values:
#!/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 = '/service/groups/21'
queryParams ='?patchFields=serviceProperties&opType=add'
data = '{"serviceProperties":[{"name":"project","value":"demo"}]}'
#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)