レポートを取得する

最終更新日: 09 年 2022 月 XNUMX 日

LogicMonitorのRESTAPIを使用して、LogicMonitorレポートに関する情報をプログラムで取得できます。 レポートのリストを取得することも、特定のレポートの詳細を取得することもできます。

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

レポートのリストを取得する

レポートのリストを返します

HTTPメソッド:GET

URI:/ report / reports

リクエストパラメータ: デフォルトでは、50個のレポートのリストが返されます。 リクエストに並べ替え、フィルター、フィールド、サイズ、オフセットのパラメーターを含めて、応答に含まれるデータとそのフォーマット方法を制御できます。 すべてのクエリパラメータは、必要に応じてURLエンコードする必要があることに注意してください。 クエリパラメータはリソースパスの一部とは見なされないため、LMv1認証署名の計算に含めるべきではないことに注意してください。

プロパティ

構文

説明

URIの例

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

 

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

  • 以上: >:
  • 以下: <:
  • 大なり記号: >
  • 未満: <
  • 等しくない: !:
  • 等しい: :
  • 含まれていません: !~
  • 以下の構成です: ~
/ report / reports?filter = type:Alert%20trends
フィールド fields = {コンマで区切られたプロパティのリスト} 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます / report / reports?fields = name、type
サイズ size = integer 表示する結果の数。 最大は1000です。 / report / reports?size = 5
オフセット offset = integer 表示された結果を相殺する結果の数 / report / reports?offset = 2

特定のレポートに関する情報を取得する

特定のレポートの詳細を返します

HTTPメソッド:GET

URI:/ report / reports / {id}

次の例は、レポートリソースへのさまざまなGETリクエストを示しています。

リクエストの例1:すべてのレポートを取得する

次のPythonスクリプトは、api.logicmonitor.comポータル内のすべてのレポートのリストを返します。

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='YQQ75w6Mxx9zWIeAMq5H'
AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/report/reports'

#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

print requestVars

#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)

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

リクエストの例2:すべてのレポートを取得する

次のPythonスクリプトは、すべてのレポートのリストを返します。結果ごとに名前、タイプ、形式のみが返され、結果は名前に従って降順で並べ替えられます。

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='YQQ75w6Mxx9zWIeAMq5H'
AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/report/reports'
queryParams = '?fields=name,type,format&sort=-name'

#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

print requestVars

#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)

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

リクエスト例3:XNUMXつのレポートを取得

次のPythonスクリプトは、ID1のレポートの詳細を返します。

#!/bin/env python

import requests
import json
import hashlib
import base64
import time
import hmac

#Account Info
AccessId ='YQQ75w6Mxx9zWIeAMq5H'
AccessKey ='f)!Z}%spR=6en+4^s2$t32r-3=NpdQ]2T{-deI)8'
Company = 'api'

#Request Info
httpVerb ='GET'
resourcePath = '/report/reports/1'

#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

print requestVars

#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)

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

応答例

以下は、上記のリクエスト例のXNUMXつに対する応答例です。

Response Status: 200
Response Body: {
  "status" : 200,
  "errmsg" : "OK",
  "data" : {
    "id" : 1,
    "name" : "All Alerts from last 24 hours",
    "description" : "",
    "type" : "Alert",
    "groupId" : 0,
    "format" : "PDF",
    "delivery" : "email",
    "recipients" : [ {
      "type" : "admin",
      "method" : "email",
      "addr" : "sarah",
      "additionInfo" : "[email protected]"
    }, {
      "type" : "admin",
      "method" : "email",
      "addr" : "Bill",
      "additionInfo" : "[email protected]"
    }, {
      "type" : "arbitrary",
      "method" : "email",
      "addr" : "[email protected]",
      "additionInfo" : ""
    } ],
    "schedule" : "45 9 * * *",
    "lastmodifyUserId" : 4,
    "lastmodifyUserName" : "sarah",
    "enableViewAsOtherUser" : false,
    "userPermission" : "write",
    "lastGenerateOn" : 1466613956,
    "lastGenerateSize" : 92007,
    "lastGeneratePages" : 1,
    "customReportTypeId" : 0,
    "reportLinkNum" : 43,
    "dateRange" : "Last 24 hours",
    "groupFullPath" : "*",
    "deviceDisplayName" : "*",
    "dataSourceInstanceName" : "*",
    "dataPoint" : "*",
    "level" : "all",
    "sortedBy" : "count",
    "includePreexist" : false,
    "activeOnly" : false,
    "summaryOnly" : true,
    "ackFilter" : "all",
    "sdtFilter" : "all",
    "timming" : "overlap",
    "dataSource" : "*",
    "rule" : "*",
    "chain" : "*",
    "columns" : [ {
      "name" : "Alerts",
      "isHidden" : false
    }, {
      "name" : "Group",
      "isHidden" : false
    }, {
      "name" : "Device",
      "isHidden" : false
    }, {
      "name" : "Instance",
      "isHidden" : false
    }, {
      "name" : "Datapoint",
      "isHidden" : false
    }, {
      "name" : "Datasource",
      "isHidden" : false
    } ]
  }
}
記事上で