デバイスグループを更新する

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

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

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

デバイスグループを更新するには、次のXNUMXつの方法があります。

  • PUT:PUTリクエストを使用すると、デバイスグループ定義全体を置き換える(およびプロセスのフィールドを更新する)ことができます。 デバイスグループの更新されたJSON定義を提供する場合は、PUTを使用してデバイスグループを更新する必要があります。 REST標準と一致して、PUTリクエストで指定されていないプロパティはデフォルト値に戻ることに注意してください。
  • PATCH:PATCHリクエストを使用すると、デバイスグループの特定のフィールドのみを置き換えることができます。 デバイスグループのJSON定義がなく、いくつかのフィールドのみを更新する場合は、PATCHを使用する必要があります。

PUT

HTTPメソッド:PUT

URI:/ device / groups /

デバイスグループを更新するには、PUTリクエストに次のプロパティを含めることができます。

プロパティ

説明

必須?

親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スクリプトは、グループ115を更新して、アラートを無効にします。

#!/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 ='PUT'
resourcePath = '/device/groups/115'
queryParams = ''
data = '{"name":"customerA","disableAlerting":true,"customProperties":[{"name":"customer","value":"A"}]}'

#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.put(url, data=data, headers=headers)

#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
Pythonの3

PATCH

HTTPメソッド:PATCH

URI:/ device /グループヘッド/ {id}

リクエストパラメータ:

すべてのPATCHリクエストには、クエリパラメータを含める必要があります パッチフィールド これは、更新する必要があるフィールドを示します。複数のフィールドはコンマで区切る必要があります。 フィールドがpatchFieldsパラメータで識別され、リクエストのペイロードに含まれている場合、その値は更新されます。 他のすべてのフィールド値は同じままです。 たとえば、デバイスグループの名前を更新する場合、URI +クエリパラメータは/ santaba / rest / device / groups / {id}?patchFields = nameになります。 名前フィールドもリクエストペイロードに含める必要があります。 次のフィールドは、PATCHを介して更新できます。

プロパティ

説明

必須?

親ID このデバイスグループの親グループのID(ルートデバイスグループのIDは1) いいえ。デフォルトは1(ルートグループ)です。 整数 「parentId」:1
デバイスグループの名前 有り 文字列 「名前」:「MyDeviceGroup」
説明 デバイスグループの説明 いいえ 文字列 「説明」:「デバイスグループの説明」
無効にするアラート このデバイスグループに対してアラートが無効(true)か有効(false)かを示します いいえ。デフォルトはfalseです。 ブーリアン 「disableAlerting」:false
に適用されます このグループのカスタムクエリに適用されます。 このフィールドを設定すると、これが動的グループになります。 いいえ。デフォルトは非動的グループです。 文字列 “ applyTo”:” system.displayname =〜\” Prod \””
カスタムプロパティ このデバイスグループのカスタムプロパティを定義します。 各プロパティには名前と値が必要です。 customPropertiesオブジェクトのXNUMXつまたはいくつかのデバイスグループプロパティを追加または更新するには、すべてではありませんが、opTypeクエリパラメーターを追加で使用する必要があります。 opTypeクエリパラメータは、追加、更新(デフォルト)、または置換するように設定できます。 opType = add ペイロードに含まれるプロパティが追加されるが、既存のすべてのプロパティは同じままであることを示します。 opType = replace リクエストペイロードに含まれるプロパティがまだ存在しない場合は追加され、存在する場合は更新されますが、他のすべての既存のプロパティは同じままであることを示します。 opType = refresh プロパティがリクエストペイロードに含まれるプロパティに置き換えられることを示します。 いいえ JSONオブジェクト “ customProperties”:[{“ name”:” location”、” value”:” 12 E. Carrillo、Santa Barbara、CA”}]

次のPythonスクリプトは、PATCHを介してグループ115を更新し、アラートを無効にします。

#!/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 = '/device/groups/115'
queryParams = '?patchFields=disableAlerting'
data = '{"disableAlerting":true}'

#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)
Pythonの3

次のPythonスクリプトは、PATCHを介してグループ4にプロパティを追加しますが、他のすべてのプロパティとフィールドは同じままです。

#!/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 = '/device/groups/4'
queryParams = '?patchFields=customProperties&opType=add'
data = '{"customProperties":[{"name":"billing","value":"Ops"}]}'

#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)t
Pythonの3
記事上で