gpt4 book ai didi

azure - 如何使用 azure api 运行日志分析查询?

转载 作者:行者123 更新时间:2023-12-03 05:34:09 27 4
gpt4 key购买 nike

我一直在尝试使用 Azure API 运行日志分析查询,但它返回一些错误{“错误”: {"message": "未提供有效的身份验证","code": "AuthorizationRequiredError",“correlationId”:“27301475d-cc29-4288-ae61-29e77d6d05cb”}}

这是我一直在尝试的请求

(ContainerLog)“search_data”中的 https://api.loganalytics.io/v1/workspaces/34567824-3432rewfsdewt435-3424jhh-dsa-/query?query=search|其中 TimeGenerate > datetime("2020-09-03")|项目LogEntry & Authorization=Bearer 000000000000000000000000000

如果你们知道什么请帮助我谢谢

最佳答案

当我们使用 Azure Log Analytics REST API 进行查询时,我们需要使用 Authorization=Bearer {token} 作为请求 header 。更多详情请引用hereenter image description here

例如

  1. 注册 Azure AD 应用程序

  2. 为 AD 应用程序配置 API 权限 enter image description here

  3. 授予 AAD 应用程序访问我们的 Log Analytics 工作区的权限。请将 Log Analytics Reader 角色分配给 AD 应用程序

  4. 获取访问 token

POST /<your tenant id>/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

grant_type =client_credentials
&client_id=<>
&client_secret=<>
&resource=https://westus2.api.loganalytics.io
  • 调用 API
  • a. POST method

    POST https://api.loganalytics.io/v1/workspaces/{workspaceId}/query
    Authorization: Bearer {access_token}
    Content-Type: application/json

    {
    "query": ""
    }

    enter image description here

    b. Get method

    GET https://api.loganalytics.io/v1/workspaces/{workspaceId}/query?query={query}

    Authorization: Bearer {access_token}

    enter image description here

    关于azure - 如何使用 azure api 运行日志分析查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63774491/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com