通过 API 访问报告数据库
Cloud Insights 功能强大的 API 允许用户直接查询 Cloud Insights 报告数据库,而无需通过 Cognos 报告环境。
|
本文档介绍了Cloud Insights高级版中提供的Cloud Insights报告功能。 |
OData
Cloud Insights 报告 API 遵循 "OData v4" (开放式数据协议)用于查询报告数据库的标准。要了解更多信息或了解更多信息,请查看 "本教程" 在 OData 上。
所有请求均以 URL : https://<Cloud Insights URL>/rest/v1/dwh-management/OData 开头
生成一个 APKey
了解更多信息 "Cloud Insights APIs"。
要生成 API 密钥,请执行以下操作:
-
登录到 Cloud Insights 环境并选择 * 管理 > API 访问 * 。
-
单击 "+ API Access Token" 。
-
输入名称和问题描述。
-
对于类型,请选择 _Data Warehouse 。
-
将权限设置为读 / 写。
-
设置所需要的到期日期。
-
单击 " 保存 " ,然后 * 复制密钥并将其保存 * 到安全位置。您稍后将无法访问完整密钥。
它非常适合使用 Sync_或_Async。
直接查询表
使用 API 密钥后,可以直接查询报告数据库。为了便于显示,长 URL 可以简化为 https://…/odata/ ,而不是完整的 https://<Cloud Insights URL>/rest/v1/dwh-management/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-management/OData/dwh_inventory/storage
-
https://<Cloud Insights URL>/rest/v1/dwh-management/OData/dwh_inventory/disk
REST API 示例
所有调用的 URL 为: https://<Cloud Insights URL>/rest/v1/dwh-management/OData 。
-
GET /{schema}/**-从报告数据库检索数据。
格式: https://<Cloud Insights URL>/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 字符串
-
查询有效负载必须包含在一行中
-
必须转义双引号,即 \"
-
选项卡支持为 \t
-
避免注释
-
支持小写表名称
此外:
-
需要 2 个标题:
-
将名称命名为 X-CloudInsights ApiKey
-
属性值 "<apikey>"
-
您的 API 密钥将特定于您的 Cloud Insights 环境。
同步还是异步?
默认情况下、API命令将在_synicate_mode下运行、这意味着您将发送请求、并立即返回响应。但是、有时执行查询可能需要很长时间、从而可能导致请求超时。要解决此问题、您可以执行_异 步_请求。在异步模式下、此请求将返回一个URL、通过该URL可以监控执行情况。此URL将在准备就绪后返回结果。
要在async模式下执行查询、请添加标题 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> }
要查看所有async查询的列表以及哪些查询已准备就绪、请使用以下命令:
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 } ] }