デバイスグループのプロパティを追加する
最終更新日: 24 年 2021 月 XNUMX 日LogicMonitorのRESTAPIを使用して、デバイスグループのプロパティをプログラムで追加できます。 これは、次のXNUMXつの方法のいずれかで実行できます。
- デバイスグループリソースを使用したPATCHメソッド – PATCHを使用して、デバイスのcustomPropertiesオブジェクトのみを更新できます。また、opTypeパラメーターを使用して、このオブジェクト内の単一のプロパティを追加または更新できます。
- デバイスグループのプロパティリソースにPOSTリクエストを送信する
注:すべてのAPI呼び出しと同様に、 認証が必要です.
デバイスグループのプロパティリソースを介してプロパティを追加します
HTTPメソッド:POST
リソースURI:/ device / groups / {groupID} / properties
ここで、groupIDは、プロパティを追加するグループのIDです。
リソースのプロパティ: プロパティごとに次のパラメータをPOSTできます。
プロパティ |
説明 |
種類 |
名 | プロパティの名前 | String |
値 | プロパティの値 | String |
例
次のPythonスクリプトは、値が「LA」のプロパティ「prodDC」をグループ34に追加します。
#!/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/34/properties'
queryParams =''
data = '{"name":"prodDC","value":"LA"}'
#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)