ウィジェットを取得する
最終更新日: 18 年 2020 月 XNUMX 日概要
LogicMonitorのRESTAPIを使用して、LogicMonitorウィジェットに関する情報をプログラムで取得できます。 具体的には、次のことができます。
- ウィジェットのリストを取得する
- 特定のウィジェットに関する情報を取得する
- 特定のダッシュボードのすべてのウィジェットを取得する
ウィジェットのリストを取得する
ウィジェットのリストを返します。
詳細依頼フォーム
HTTPメソッド: GET
URI: / dashboard / widgets
リクエストパラメータ: デフォルトでは、50個のウィジェットのリストが返されます。 リクエストに並べ替え、フィルター、フィールド、サイズ、オフセットのパラメーターを含めて、応答に含まれるデータとそのフォーマット方法を制御できます。 クエリパラメータはリソースパスの一部とは見なされないため、LMv1認証署名の計算に含めるべきではないことに注意してください。
プロパティ | 構文 | 説明 | URIの例 |
sort | sort = {+または-} property | 昇順(+)または降順(-)のいずれかで指定されたプロパティで応答を並べ替えます | / dashboard / widgets?sort = + name |
filter | filter = property {operator} value | 指定された演算子と値に従って応答をフィルタリングします。 *を使用して複数の文字に一致させることができることに注意してください。'。'を使用できますオブジェクト内の値(カスタムプロパティなど)をフィルタリングする文字。複数のフィルターはコンマで区切ることができます。 演算子は次のとおりです。
|
/ dashboard / widgets?filter = type:alert |
フィールド | fields = {コンマで区切られたプロパティのリスト} | 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます | / dashboard / widgets?fields = name、type |
サイズ | size = integer | 表示する結果の数。 最大は1000です。 | / dashboard / widgets?size = 5 |
オフセット | offset = integer | 表示された結果を相殺する結果の数 | / Dashboard / widgets?offset = 2 |
例
例:すべてのウィジェットを取得する
次の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 = '/dashboard/widgets'
#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()
#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スクリプトは、すべてのウィジェットのリストを返します。結果ごとに名前、タイプ、dashboardIdのみが返され、結果は名前に従って降順で並べ替えられます。
#!/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 = '/dashboard/widgets'
queryParams = '?fields=name,type,dashboardId&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
#Construct signature
hmac1 = hmac.new(AccessKey.encode(),msg=requestVars.encode(),digestmod=hashlib.sha256).hexdigest()
#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)
特定のウィジェットに関する情報を取得する
特定のウィジェットの詳細を返します。
詳細依頼フォーム
HTTPメソッド: GET
URI: / Dashboard / widgets / {id}
例
例:単一のウィジェットを取得する
次のPythonスクリプトは、api.logicmonitor.comのID174のウィジェットの詳細を返します。
#!/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 = '/dashboard/widgets/174'
#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()
#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)
例:サンプル応答
以下は、前のGETの例に対する応答の例です。
Response Status: 200
Response Body: {
"status" : 200,
"errmsg" : "OK",
"data" : {
"id" : 172,
"name" : "Web Server Status",
"description" : "",
"type" : "deviceNOC",
"lastUpdatedOn" : 1438888647,
"lastUpdatedBy" : "",
"dashboardId" : 26,
"columnIdx" : 2,
"order" : 2,
"theme" : "borderPurple",
"colSpan" : 1,
"rowSpan" : 1,
"userPermission" : "write",
"interval" : 1,
"timescale" : "day",
"extra" : "",
"sortBy" : "name",
"displayColumn" : 3,
"displayWarnAlert" : true,
"displayErrorAlert" : true,
"displayCriticalAlert" : true,
"ackChecked" : true,
"sdtChecked" : true,
"items" : [ {
"deviceGroupFullPath" : "*",
"deviceDisplayName" : "ip-172-31-33-214.us-west-2.compute.internal",
"dataSourceDisplayName" : "HTTP-",
"instanceName" : "*",
"dataPointName" : "*",
"groupBy" : "device",
"name" : "##HOSTNAME## - HTTP content/function"
}, {
"deviceGroupFullPath" : "*",
"deviceDisplayName" : "ip-172-31-33-214.us-west-2.compute.internal",
"dataSourceDisplayName" : "Apache-",
"instanceName" : "*",
"dataPointName" : "*",
"groupBy" : "device",
"name" : "##HOSTNAME## - Apache"
}, {
"deviceGroupFullPath" : "*",
"deviceDisplayName" : "ip-172-31-33-214.us-west-2.compute.internal",
"dataSourceDisplayName" : "Host Status",
"instanceName" : "*",
"dataPointName" : "*",
"groupBy" : "device",
"name" : "##HOSTNAME## - Host Status"
} ]
}
}
特定のダッシュボードのすべてのウィジェットを取得する
特定のダッシュボードのすべてのウィジェットを返します。
詳細依頼フォーム
HTTPメソッド: GET
リソースURI: / dashboard / dashboards / {dashboardID} / widgets
(ここで、dashboardIDは、ウィジェットを取得するダッシュボードのIDです。)
リクエストパラメータ: デフォルトでは、50個のウィジェットのリストが返されます。 リクエストに並べ替え、フィルター、フィールド、サイズ、オフセットのパラメーターを含めて、応答に含まれるデータとそのフォーマット方法を制御できます。 クエリパラメータはリソースパスの一部とは見なされないため、LMv1認証署名の計算に含めるべきではないことに注意してください。
プロパティ | 構文 | 説明 | URIの例 |
sort | sort = {+または-} property | 昇順(+)または降順(-)のいずれかで指定されたプロパティで応答を並べ替えます | / dashboard / dashboards / 90 / widgets?sort = + name |
filter | filter = property {operator} value |
指定された演算子と値に従って応答をフィルタリングします。 演算子は次のとおりです。
|
/ dashboard / dashboards / 87 / widgets?filter = type:alert |
フィールド | fields = {コンマで区切られたプロパティのリスト} | 応答をフィルタリングして、各オブジェクトの次のフィールドのみを含めます | / dashboard / dashboards / 45 / widgets?fields = name、type |
サイズ | size = integer | 表示する結果の数。 最大は300です。 | / dashboard / dashboards / 34 / widgets?size = 5 |
オフセット | offset = integer | 表示された結果を相殺する結果の数 | / dashboard / dashboards / 12 / widgets?offset = 2 |