Skip to main content
Data Infrastructure Insights
简体中文版经机器翻译而成,仅供参考。如与英语版出现任何冲突,应以英语版为准。

通过 API 访问报告数据库

贡献者 netapp-alavoie

直接通过符合 OData v4 标准的 API 访问 Data Infrastructure Insights Reporting 数据库,绕过 Cognos 界面以获得更大的灵活性。这为需要以编程方式访问其基础设施数据的用户提供了自定义集成、自动化报告工作流和高级数据分析。

备注 本文档涉及Data Infrastructure Insights报告功能,该功能在Data Infrastructure Insights高级版中提供。

奥达塔

Data Infrastructure Insights Reporting 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
Result:
{
   "@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
       }
   ]
}