デバイスグループのプロパティを取得する
最終更新日: 24 年 2021 月 XNUMX 日LogicMonitorのRESTAPIを使用して、カスタムかシステムか、継承されているかどうかに関係なく、デバイスのすべてのプロパティを取得できます。 プロパティ情報を取得するには、次のXNUMXつの方法があります。
注:すべてのAPI呼び出しと同様に、 認証が必要です.
すべてのデバイスグループのプロパティを取得する
HTTPメソッド:GET
リソースURI:/ device / groups / {groupID} / properties
ここで、groupIDは、プロパティを取得するグループのIDであり、から取得できます。 グループリソース.
リソースのプロパティ:
リクエストパラメータ: デフォルトでは、50個のデバイスグループプロパティのリストが返されます。 リクエストに並べ替え、フィルター、フィールド、サイズ、オフセットのパラメーターを含めて、応答に含まれるデータとそのフォーマット方法を制御できます。 クエリパラメータはリソースパスの一部とは見なされないため、LMv1認証署名の計算に含めるべきではないことに注意してください。
プロパティ |
構文 |
説明 |
URIの例 |
sort | sort = {+または-} property | 昇順(+)または降順(-)のいずれかで指定されたプロパティで応答を並べ替えます | / device / groups / 12 / properties?sort = -type |
filter | filter = property {operator} value | 指定された演算子と値に従って応答をフィルタリングします。 *を使用して複数の文字に一致させることができることに注意してください。 '。'を使用できますオブジェクト内の値(カスタムプロパティなど)をフィルタリングする文字。複数のフィルターはコンマで区切ることができます。
演算子は次のとおりです。
|
/ device / groups / 45 / properties?filter = name〜QA * |
フィールド | fields = {コンマで区切られたプロパティのリスト} | 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます | / device / groups / 89 / properties?fields = name、id |
サイズ | size = integer | 表示する結果の数。 最大は1000です。 | / device / groups / 65 / properties?size = 5 |
オフセット | offset = integer | 表示された結果を相殺する結果の数 | / device / groups / 76 / properties?offset = 2 |
特定のデバイスプロパティに関する情報を取得する
HTTPメソッド:GET
リソースURI:/ device / groups / {groupID} / properties / {propertyName}
ここで、groupIDは、プロパティを取得するグループのIDであり、から取得できます。 グループリソース。 propertyNameは、情報を取得するプロパティの名前であり、そこから取得できます。 すべてのデバイスグループプロパティの取得.
例1
次のPythonスクリプトは、グループ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 ='GET'
resourcePath = '/device/groups/34/properties'
queryParams =''
data = ''
#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.get(url, data=data, headers=headers)
#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)
例2
次のPythonスクリプトは、「proddc」という名前のプロパティに関する情報を取得します。
#!/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/34/properties/proddc'
queryParams =''
data = ''
#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.get(url, data=data, headers=headers)
#Print status and body of response
print('Response Status:',response.status_code)
print('Response Body:',response.content)