Skip to main content
Data Infrastructure Insights
本繁體中文版使用機器翻譯,譯文僅供參考,若與英文版本牴觸,應以英文版本為準。

透過 API 存取報告資料庫

貢獻者 netapp-alavoie

Data Infrastructure Insights強大的 API 允許使用者直接查詢Data Infrastructure Insights Reporting 資料庫,而無需經過 Cognos Reporting 環境。

註 本文檔涉及Data Infrastructure Insights報告功能,該功能在Data Infrastructure Insights高級版中提供。

奧達塔

Data Infrastructure Insights報告 API 遵循"OData v4"(開放資料協定)標準用於查詢報告資料庫。如需了解更多信息或了解更多信息,請查看"本教程"在 OData 上。

所有請求均以 url https://< Data Infrastructure Insights URL>/rest/v1/dwh-management/odata 開頭

產生 APIKey

若要產生 API 金鑰,請執行下列操作:

  • 登入您的Data Infrastructure Insights環境並選擇*管理>API 存取*。

  • 點選“+ API 存取令牌”。

  • 輸入名稱和描述。

  • 對於類型,選擇“資料倉儲”。

  • 將權限設定為讀取/寫入。

  • 設定願望到期日。

  • 點擊“儲存”,然後*複製金鑰並將其儲存*到安全的地方。您稍後將無法存取完整密鑰。

APIkey 適用於SyncAsync

直接查詢表

有了 API 金鑰,現在就可以直接查詢報告資料庫。為了顯示目的,長 URL 可能會簡化為 https://…​/odata/ 而不是完整的 https://< Data Infrastructure Insights URL>/rest/v1/dwh-management/odata/

嘗試一些簡單的查詢,例如

  • https://<Data Infrastructure InsightsURL>/rest/v1/dwh-management/odata/dwh_custom

  • https://<Data Infrastructure InsightsURL>/rest/v1/dwh-management/odata/dwh_inventory

  • https://<Data Infrastructure InsightsURL>/rest/v1/dwh-management/odata/dwh_inventory/storage

  • https://<Data Infrastructure InsightsURL>/rest/v1/dwh-management/odata/dwh_inventory/disk

  • https://…​/odata/dwh_custom/custom_queries

REST API 範例

所有呼叫的 URL 為 https://< Data Infrastructure Insights URL>/rest/v1/dwh-management/odata

  • GET /{schema}/** - 從報表資料庫檢索資料。

格式:https://<Data Infrastructure InsightsURL>/rest/v1/dwh-management/odata/<schema_name>/<query>

範例:

 https://<domain>/rest/v1/dwh-management/odata/dwh_inventory/fabric?$count=true&$orderby=name
結果:
{
   "@odata.context": "$metadata#fabric",
   "@odata.count": 2,
   "value": [
       {
           "id": 851,
           "identifier": "10:00:50:EB:1A:40:3B:44",
           "wwn": "10:00:50:EB:1A:40:3B:44",
           "name": "10:00:50:EB:1A:40:3B:44",
           "vsanEnabled": "0",
           "vsanId": null,
           "zoningEnabled": "0",
           "url": "https://<domain>/web/#/assets/fabrics/941716"
       },
       {
           "id": 852,
           "identifier": "10:00:50:EB:1A:40:44:0C",
           "wwn": "10:00:50:EB:1A:40:44:0C",
           "name": "10:00:50:EB:1A:40:44:0C",
           "vsanEnabled": "0",
           "vsanId": null,
           "zoningEnabled": "0",
           "url": "https://<domain>/web/#/assets/fabrics/941836"
        }
    ]
}

有用的提示

使用報告 API 查詢時請記住以下幾點。

  • 查詢負載必須是有效的 JSON 字串

  • 查詢有效負載必須包含在一行中

  • 雙引號必須轉義,即 \"

  • 支援 Tab 鍵為 \t

  • 避免評論

  • 支援小寫表名

另外:

  • 需要 2 個標題:

    • 名稱“X-CloudInsights-ApiKey”

    • 屬性值“<apikey>”

您的 API 金鑰將特定於您的Data Infrastructure Insights環境。

同步還是異步?

預設情況下,API 命令將以同步模式運行,這表示您發送請求並立即回傳回應。但是,有時查詢可能需要很長時間才能執行,這可能導致請求逾時。為了解決這個問題,您可以非同步執行請求。在非同步模式下,請求將傳回一個URL,可以透過該URL監控執行情況。 URL 準備就緒後將傳回結果。

若要以非同步模式執行查詢,請新增標頭 `Prefer: respond-async`響應請求。成功執行後,回應將包含以下標頭:

Status Code: 202 (which means ACCEPTED)
preference-applied: respond-async
location: https://<Data Infrastructure Insights URL>/rest/v1/dwh-management/odata/dwh_custom/asyncStatus/<token>

如果回應尚未準備好,則查詢位置 URL 將傳回相同的標頭;如果回應已準備好,則將傳回狀態 200。回應內容將為文字類型,包含原始查詢的 http 狀態和一些元數據,然後是原始查詢的結果。

HTTP/1.1 200 OK
 OData-Version: 4.0
 Content-Type: application/json;odata.metadata=minimal
 oDataResponseSizeCounted: true

 { <JSON_RESPONSE> }

若要查看所有非同步查詢的清單以及哪些查詢已準備就緒,請使用下列命令:

 GET https://<Data Infrastructure Insights URL>/rest/v1/dwh-management/odata/dwh_custom/asyncList
回應具有以下格式:
{
   "queries" : [
       {
           "Query": "https://<Data Infrastructure Insights URL>/rest/v1/dwh-management/odata/dwh_custom/heavy_left_join3?$count=true",
           "Location": "https://<Data Infrastructure Insights URL>/rest/v1/dwh-management/odata/dwh_custom/asyncStatus/<token>",
           "Finished": false
       }
   ]
}