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 manage Azure groups. Azure groups are device groups with a few key differences. This document covers the differences, as well as how to add and update Azure groups.
URI: /device/groups
Azure groups have a special groupType value. Specifically, normal and dynamic groups will have a groupType value of Normal, while Azure device groups will have a value of Azure/SERVICE, where SERVICE is the Azure service the group was created for (for example, VirtualMachine, SQLDatabase, AppService, and so on). The Azure account level group will have a groupType value of Azure/AzureRoot.
The azureRegionsInfo, azureTestResult and azureTestResultCode are all read-only fields specific to Azure groups. More importantly, Azure group specific information such as Azure account credentials and Azure service/region configurations are included in the “extra” object in the device group JSON.
Specifically, the extra object includes the following information:
LogicMonitor requires a Monitoring Reader Azure AD role to authenticate Azure Monitor API requests. When you add your Azure account into LogicMonitor, you’ll need to provide such a role. As such, to add an Azure Group you’ll need to:
The following Python script request adds an Azure Group named “LM Azure” with the following parameters:
#!/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 = '/device/groups' queryParams ='' data = '{"parentId" : 1, "name" : "LM Azure", "description" : "This is a test description for an Azure account.", "groupType" : "Azure/AzureRoot", "disableAlerting" : false, "customProperties" : [{"name": "customer", "value":"customerA"}], "extra":{"account": {"schedule": "0 * * * *", "country": "USA", "billingInfo": [], "clientId": "1912c6eb-e51f-40a0-a4c7-a939ded64cae", "secretKey": "********", "collectorDescription": "Cloud Collector", "subscriptionIds": "d499ee70-fb15-454a-9c72-dcfa08078448", "tenantId": "dc818e23-4f5a-4b7e-bdfa-66de5eb19691", "collectorId": -2}, "default": {"disableTerminatedHostAlerting": true, "normalCollectorConfig": null, "customNSPSchedule": "", "selectAll": true, "monitoringRegions": ["CENTRAL_US", "EAST_US", "EAST_US_2", "WEST_US" ], "deviceDisplayNameTemplate": "", "disableStopTerminateHostMonitor": true, "deadOperation": "KEEP_7_DAYS", "useDefault": true, "nameFilter": [], "tags": []}, "services": {"VIRTUALMACHINE": {"disableTerminatedHostAlerting": true, "normalCollectorConfig": {"collectors": [], "enable": false}, "customNSPSchedule": "", "selectAll": true, "monitoringRegions": ["CENTRAL_US", "EAST_US_2", "WEST_US" ], "deviceDisplayNameTemplate": "", "disableStopTerminateHostMonitor": true, "deadOperation": "KEEP_7_DAYS", "useDefault": true, "nameFilter": [], "tags": [{"foo": "bar"}]}}}}' #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.post(url, data=data, headers=headers) # Print status and body of response print('Response Status:',response.status_code) print('Response Body:',response.content)
If you’re updating an Azure Group, we recommend first making a GET request to get the group JSON, parsing the output, replacing the desired values, and then using PUT to update the resource.
The following Python script makes a GET request to get device group 39 (which happens to be the Azure root group), parses out the response, replaces the assigned Collector, adds the configuration object, and then makes a PUT request to update the group 39.
#!/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 ='GET' resourcePath = '/device/groups/39' #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() signature = base64.b64encode(hmac1.encode()) # Construct headers auth = 'LMv1 ' + AccessId + ':' + signature.decode() + ':' + epoch headers = {'Content-Type':'application/json','Authorization':auth} #Make request response = requests.get(url, headers=headers) #Parse response jsonResponse = json.loads(response.content) #Change Collector Id and add configuration object group = jsonResponse['data'] group['extra']['account']['collectorId'] = 218 #PUT Request Info httpVerb ='PUT' resourcePath = '/device/groups/39' queryParams ='' data = str(json.dumps(group)) #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 putResponse = requests.put(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