デバイスデータソースを取得する

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

概要

LogicMonitorのRESTAPIを使用して、デバイスに関連付けられているデータソースに関する情報を取得できます。 具体的には、データソースのリストまたは特定のデータソースに関する情報を取得できます。

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

デバイスデータソースのリストを取得する

HTTPメソッド: GET

URI: / device / devices / {deviceId} / devicedatasources
({deviceId}を目的のデバイスIDに置き換える必要があります。デバイスIDは、 デバイスリソース.)

リクエストパラメータ: デフォルトでは、50個のデータソースが返されます。 並べ替え、フィルター、フィールド、サイズ、オフセットのパラメーターを含めて、応答に含めるデータとそのフォーマット方法を制御できます。

プロパティ 構文 説明 URIの例
sort sort = {+または-} property 昇順(+)または降順(-)のいずれかで指定されたプロパティで応答を並べ替えます / device / devices / 12 / devicedatasources?sort = -id
filter filter = property {operator} value 指定された演算子と値に従って応答をフィルタリングします。 *を使用して複数の文字に一致させることができることに注意してください。「。」を使用できます。 オブジェクト内の値(カスタムプロパティなど)をフィルタリングする文字。複数のフィルターはコンマで区切ることができます。

 

演算子は次のとおりです。

  • 以上: >:
  • 以下: <:
  • 大なり記号: >
  • 未満: <
  • 等しくない: !:
  • 等しい: :
  • 以下の構成です: ~
  • 含まれていません: !~
/ device / devices / 30 / devicedatasources?filter = instanceNumber> 0
フィールド fields = {コンマで区切られたプロパティのリスト} 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます / device / devices / 78 / devicedatasources?fields = dataSourceName、id、instanceNumber
サイズ size = integer 表示する結果の数。 デフォルトでは最大50件の結果が表示され、サイズは最大1000件まで指定できます。 / device / devices / 90 / devicedatasources?size = 5
オフセット offset = integer 表示された結果を相殺する結果の数 / device / devices / 45 / devicedatasources?offset = 2

次のPythonスクリプトは、少なくとも427つの監視対象インスタンスを持つデバイスXNUMXに関連付けられたデータソースを要求します。

#!/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/devices/427/devicedatasources'
queryParams = '?filter=instanceNumber>0'
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)
Pythonの3

次のPythonスクリプトは、アカウントapi.logicmonitor.comの各デバイスをループし、少なくともXNUMXつのインスタンスを持つデータソースを要求します。 結果として、アカウント全体に少なくともXNUMXつのインスタンスを持つ一意のデータソースのリストが出力されます。

#!/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/devices'

#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 + 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, headers=headers)

#Parse response
jsonResponse = json.loads(response.content)

#create list to keep datasources
datasources = []

#Loop through each device & get datasources
for i in jsonResponse['data']['items']:
    deviceId = str(i['id'])

    #Request Info
    httpVerb ='GET'
    resourcePath = '/device/devices/'+deviceId+'/devicedatasources'
    queryParams ='?filter=instanceNumber>0'

    #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 + 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 + ':' + epoch
    headers = {'Content-Type':'application/json','Authorization':auth}

    #Make request
    datasourceResponse = requests.get(url, headers=headers)

    #Parse response & for each datasource, check if it's already been added to the list.  If not, add it.
    jsonDatasourceResponse = json.loads(datasourceResponse.content)
    for j in jsonDatasourceResponse['data']['items']:
        if not (j['dataSourceName'] in datasources):
            datasources.append(j['dataSourceName'])

#Print result
print str(datasources).strip('[]')
Pythonの3

特定のデバイスデータソースに関する情報を取得する

HTTPメソッド: GET

URI: / device / devices / {deviceId} / devicedatasources / {deviceDataSourceId}
({deviceId}を目的のデバイスIDに置き換える必要があります。デバイスIDはから取得できます。 デバイスリソース。 また、{deviceDataSourceId}はデバイスのデータソースIDに置き換える必要があります。)

リクエストパラメータ: fieldsパラメーターを含めて、応答に含めるフィールドを制御できます。

プロパティ 構文 説明 URIの例
フィールド fields = {コンマで区切られたプロパティのリスト} 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます / device / devices / 78 / devicedatasources / 213?fields = dataSourceName、id、instanceNumber

記事上で