REST API Developer's Guide

Add a Device Group

You can use LogicMonitor's REST API to programmatically add LogicMonitor device groups.

As with all of our API calls, authentication is required.

 

HTTP Method: POST

URI: /device/groups

You can POST the following properties for each device group:

Property

Description

Required?

Type

Example

parentId The id of the parent group for this device group (the root device group has an Id of 1) No. Defaults to 1 (root group) Integer "parentId":1
name The name of the device group Yes String "name":"MyDeviceGroup"
description The description of the device group No String "description":"My device group description"
disableAlerting Indicates whether alerting is disabled (true) or enabled (false) for this device group No. Defaults to false Boolean "disableAlerting":false
appliesTo The Applies to custom query for this group. Setting this field will make this a dynamic group. No. Defaults to a non-dynamic group String "appliesTo":"system.displayname =~ \"Prod\""
customProperties The properties associated with this device group No JSON object "customProperties":[{"name":"location","value":"12 E. Carrillo, Santa Barbara, CA"}]

 

Example

The following Python script adds a device group directly under the root group, and adds a property 'customer' for this group set to the value 'A':

#!/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'
data = '{"name":"customerA","customProperties":[{"name":"customer","value":"A"}]}'

#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
signature = base64.b64encode(hmac.new(AccessKey,msg=requestVars,digestmod=hashlib.sha256).hexdigest())

#Construct headers
auth = 'LMv1 ' + AccessId + ':' + signature + ':' + 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