デバイスグループを追加する

最終更新日: 24 年 2021 月 XNUMX 日

LogicMonitorのRESTAPIを使用して、LogicMonitorデバイスグループをプログラムで追加できます。

すべてのAPI呼び出しと同様に、 認証が必要です.

HTTPメソッド:POST

URI:/ device / groups

デバイスグループごとに次のプロパティをPOSTできます。

プロパティ

説明

必須?

タイプ

親ID このデバイスグループの親グループのID(ルートデバイスグループのIDは1) いいえ。デフォルトは1(ルートグループ)です。 整数 「parentId」:1
デバイスグループの名前 有り 文字列 「名前」:「MyDeviceGroup」
説明 デバイスグループの説明 いいえ 文字列 「説明」:「デバイスグループの説明」
無効にするアラート このデバイスグループに対してアラートが無効(true)か有効(false)かを示します いいえ。デフォルトはfalseです。 ブーリアン 「disableAlerting」:false
に適用されます このグループのカスタムクエリに適用されます。 このフィールドを設定すると、これが動的グループになります。 いいえ。デフォルトは非動的グループです。 文字列 “ applyTo”:” system.displayname =〜\” Prod \””
カスタムプロパティ このデバイスグループに関連付けられているプロパティ いいえ JSONオブジェクト “ customProperties”:[{“ name”:” location”、” value”:” 12 E. Carrillo、Santa Barbara、CA”}]

次のPythonスクリプトは、ルートグループのすぐ下にデバイスグループを追加し、このグループのプロパティ「customer」を値「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
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)
Pythonの3