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

透過API存取報告資料庫

貢獻者

利用功能強大的API、使用者無需經過Cognos報告環境、即可直接查詢功能強大的功能。Cloud Insights Cloud Insights

註 本文件是指 Cloud Insights 報告功能、可在 Cloud Insights Premium Edition 中取得。

OData

以下是《需求報告API Cloud Insights "OData v4" (開放式資料傳輸協定)標準、用於查詢報告資料庫。如需詳細資訊或深入瞭解、請參閱 "本教學課程" 在OData上。

所有申請都會從URL _https://<Cloud Insights URL>/REST / v1/dwh-management / OData_開始

產生APIKey

深入瞭解 "資訊API Cloud Insights"

若要產生API金鑰、請執行下列動作:

  • 登入Cloud Insights 您的不完整環境、然後選取*管理> API存取*。

  • 按一下「+ API存取權杖」。

  • 輸入名稱與說明。

  • 針對類型、選擇_Data倉儲。

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

  • 設定期望到期日。

  • 按一下「Save(儲存)」、然後*複製金鑰並將其儲存*到安全的地方。您稍後將無法存取完整金鑰。

APIkeys 很適合 SyncAsynSync

直接查詢資料表

有了API金鑰、現在就能直接查詢報告資料庫。長URL可簡化為\https://…​/odata/以供顯示、而非完整的\https://<Cloud Insights url>/rest / v1/dwh管理/OData/

請嘗試類似的簡單查詢

  • https://<Cloud Insights URL>>/ REST / v1/dwh-management / OData/dwh_custom

  • https://<Cloud Insights URL>>/ REST / v1/dwh-management / OData/dwh_inventory

  • https://<Cloud Insights URL>>/ REST / v1/dwh管理/ OData/dwh庫存/儲存設備

  • https://<Cloud Insights URL>>/ REST / v1/dwh管理/OData/dwh目錄/磁碟

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

REST API範例

所有通話的URL都是:https://<Cloud Insights url>/rest / v1/dwh-management / OData

  • Get /{schema}/*-從報告資料庫擷取資料。

格式:https://<Cloud Insights url>/rest / v1/dwh管理/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字串

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

  • 雙引號必須轉義、例如:「

  • 索引標籤支援為\t

  • 避免留言

  • 支援大小寫較低的表格名稱

此外:

  • 需要2個標頭:

    • 名稱「X-CloudInsights - ApikKey」

    • 屬性值「<apikey>」

您的API金鑰將專屬於Cloud Insights 您的整個環境。

同步或非同步?

根據預設、 API 命令會以 Synchronity 模式運作、這表示您傳送要求、並立即傳回回應。不過、有時候查詢可能需要很長時間才能執行、這可能會導致要求逾時。若要解決此問題、您可以執行要求 _ 非同步 _ 。在非同步模式中、要求會傳回可監控執行的 URL 。URL 會在準備好時傳回結果。

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

Status Code: 202 (which means ACCEPTED)
preference-applied: respond-async
location: https://<Cloud 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://<Cloud Insights URL>/rest/v1/dwh-management/odata/dwh_custom/asyncList
回應的格式如下:
{
   "queries" : [
       {
           "Query": "https://<Cloud Insights URL>/rest/v1/dwh-management/odata/dwh_custom/heavy_left_join3?$count=true",
           "Location": "https://<Cloud Insights URL>/rest/v1/dwh-management/odata/dwh_custom/asyncStatus/<token>",
           "Finished": false
       }
   ]
}