How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

huangapple go评论66阅读模式
英文:

How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

问题

我想从 Log Analytics 工作区的查询结果中检索数据,我尝试使用管道来完成,其中第一个函数是 Web 活动,配置如下:
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication 我按照这个示例进行操作:https://datasavvy.me/2020/12/24/retrieving-log-analytics-data-with-data-factory/
然后我得到了复制数据活动:
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication
请求方法:post
请求体:

{
    "query": "ADFPipelineRun | project PipelineName, Status, TimeGenerated, _ResourceId, Type | where Status == 'Succeeded'"
}| ConvertTo-Json

两个头部:
Content-Type: application/json; charset=utf-8
Authentication: @concat('Bearer ', activity('GetBearerToken').output.access_token)
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

当我调试时,我收到了以下错误:
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

英文:

I want to retrieve data from the result of a query in Log analytics workspace, I tried to do that using pipeline, where as the first function I got the Web activity, configured as follows:
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication I followed this example:https://datasavvy.me/2020/12/24/retrieving-log-analytics-data-with-data-factory/
Then I got Copy data activity:
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication
request method: post
request body:

{
    "query": "ADFPipelineRun | project PipelineName, Status,TimeGenerated,  _ResourceId, Type | where Status == 'Succeeded'"
}| ConvertTo-Json

two headers:
Content-Type: application/json; charset=utf-8
Authentication: @concat('Bearer ', activity('GetBearerToken').output.access_token)
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

I get this error when I debugged:
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

答案1

得分: 0

连接Log Analytics Workspace通过Azure Data Factory的REST API,无需认证。

首先,您需要获取一个Bearer令牌,以授权执行查询。 要获取它,请按照以下步骤进行:

  • 在Azure Active Directory中创建一个Azure AD应用程序,并记下租户ID、客户端ID和客户端密钥(在您的工作区中,将IAM权限授予您创建的AAD应用程序作为Contributor)。现在在ADF中创建一个管道,并使用Web活动获取Bearer令牌。

    URL: https://login.microsoftonline.com/<Apps_tenant_ID>/oauth2/token
    方法:POST
    Body:grant_type=client_credentials &client_id=<Apps_Client_ID>&resource=https://api.loganalytics.io/&client_secret=<Apps_Client_Secret>
    Header: "Content-Type: application/x-www-form-urlencoded"

Bearer令牌:

How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

源设置:

请求方法:POST
请求主体:{"query": "search * | where PipelineName contains 'pipe'"}
标头: "Content-Type:application/json"
"Authorization: @concat('Bearer ',activity('Web2').output.access_token)"

  • 添加适当的SINK并运行管道。
英文:

To connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication.

First you need to get a bearer token, which gives you the authorization to execute the query. To get this follow below steps:

  • Create an Azure AD App in Azure Active Directory and note down the tenant Id, Client Id and client secret. (In your workspace grant IAM privileges to the AAD Application you created as Contributor) Now in ADF Create a pipeline and take web activity to get bearer token.
    >URL: https://login.microsoftonline.com/&lt;Apps_tenant_ID&gt;/oauth2/token
    >Method: POST
    >Body: grant_type=client_credentials &client_id=<Apps_Client_ID>&resource=https://api.loganalytics.io/&client_secret=<Apps_Client_Secret>
    >Header : "Content-Type: application/x-www-form-urlencoded"

How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

Bearer token:

How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

Source settings:
> Request method: POST
> Request Body: {"query": "search * | where PipelineName contains 'pipe'"}
> Headers: "Content-Type:application/json"
> "Authorization: @concat('Bearer ',activity('Web2').output.access_token)"

How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication

  • Add appropriate SINK and run the pipeline.

huangapple
  • 本文由 发表于 2023年7月27日 21:29:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780257.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定