英文:
How can I connect Log Analytics Workspace via rest api with Azure Data Factory without Authentication
问题
我想从 Log Analytics 工作区的查询结果中检索数据,我尝试使用管道来完成,其中第一个函数是 Web 活动,配置如下:
我按照这个示例进行操作:https://datasavvy.me/2020/12/24/retrieving-log-analytics-data-with-data-factory/
然后我得到了复制数据活动:
请求方法: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)
当我调试时,我收到了以下错误:
英文:
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:
I followed this example:https://datasavvy.me/2020/12/24/retrieving-log-analytics-data-with-data-factory/
Then I got Copy data activity:
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)
I get this error when I debugged:
答案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令牌:
- 要从REST API查询Log Analytics,请创建以下设置的Rest API链接服务。
基本URL: https://api.loganalytics.io/v1/workspaces/<Workspace_Id>/query
源设置:
请求方法: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/<Apps_tenant_ID>/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"
Bearer token:
- To query Log analytics from Rest API. create a linked service for Rest API with below settings.
>Base URL: https://api.loganalytics.io/v1/workspaces/<Workspace_Id>/query
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)"
- Add appropriate SINK and run the pipeline.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论