简体   繁体   English

将自定义日志发送到 Azure 使用 Azure 数据工厂进行日志分析

[英]Sending Custom Logs to Azure Log analytics using Azure Data Factory

I am trying to ingest custom logs in to the Azure log analytics using Azure Data factory.我正在尝试使用 Azure 数据工厂将自定义日志引入 Azure 日志分析。 HTTP Data collector is the API that Microsoft provided to ingest custom logs to Azure log analytics. HTTP 数据收集器是 Microsoft 提供的 API,用于将自定义日志提取到 Azure 日志分析。 I have created a pipeline with a Web Activity in Azure Data factory to post some sample log to Log analytics.我在 Azure 数据工厂中创建了一个带有 Web 活动的管道,以将一些示例日志发布到日志分析。 Below are the settings for the Web Activity.以下是 Web 活动的设置。

URL: https://xxloganalyticsworkspaceIDxx.ods.opinsights.azure.com/api/logs?api-version=2016-04-01 Method: POST Headers: Authorization - SharedKey xxloganalyticsworkspaceIDxx: Log-Type - ADFRecord Content-Type - application/json x-ms-date - <Signature created using PowerShell RFC 1123 format> Body - [{"StringValue":"MyString1","NumberValue":42,"BooleanValue":true,"DateValue":"2019-09-12T20:00:00.625Z","GUIDValue":"9909ED01-A74C-4874-8ABF-D2678E3AE23D"}] URL: https://xxloganalyticsworkspaceIDxx.ods.opinsights.azure.com/api/logs?api-version=2016-04-01 Method: POST Headers: Authorization - SharedKey xxloganalyticsworkspaceIDxx: Log-Type - ADFRecord Content-Type - application/ json x-ms-date - <使用 PowerShell RFC 1123 格式创建的签名> 正文 - [{"StringValue":"MyString1","NumberValue":42,"BooleanValue":true,"DateValue":"2019-09-12T20 :00:00.625Z","GUIDValue":"9909ED01-A74C-4874-8ABF-D2678E3AE23D"}]

I am aware that that Authorization and x-ms-date headers should be provided dynamically however for testing I have created these headers using the PowerShell code provided by Microsoft in the article https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api#request-headers and used the same headers in the web activity.我知道应该动态提供 Authorization 和 x-ms-date 标头但是为了测试我已经使用 Microsoft 在文章https: //docs.microsoft.com/en-us/azure 中提供的 PowerShell 代码创建了这些标头/azure-monitor/logs/data-collector-api#request-headers并在 web 活动中使用了相同的标头。 The pipeline fails with the error below:管道失败并出现以下错误:

{"Error":"InvalidAuthorization","Message":"An invalid signature was specified in the Authorization header"} {"Error":"InvalidAuthorization","Message":"授权标头中指定了无效签名"}

I have tried pushing the same data with same headers using postman and the REST call was successful implying the header signature generated using PowerShell works. I have tried pushing the same data with same headers using postman and the REST call was successful implying the header signature generated using PowerShell works. I can see the customs logs are pushed to Log analytics.我可以看到海关日志被推送到 Log Analytics。

Would appreciate any help on this to fix the problem and also please let me know how can I provide Authorization headers in Web activity dynamically.感谢您对此问题的任何帮助,也请让我知道如何在 Web 活动中动态提供授权标头。

The data factory web activity seem to have some issue with sending custom log to log analytics workspace, after some try-and-error I have found the way that managed to work.数据工厂 web 活动似乎在将自定义日志发送到日志分析工作区时遇到了一些问题,经过一些尝试和错误后,我找到了成功的方法。

  1. Make sure you try with alternate approach eg python/C#/etc and get the request working.确保您尝试使用替代方法,例如 python/C#/etc 并让请求正常工作。 (I used python for example https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api#python-sample ) (我使用 python 例如https://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api#python-sample

  2. In data factory web activity body section, wrap the request with [] to make it an array, ie {"A":6} would become [{"A":6}] (not sure the exact reason but seem to work, there may be some process around how they process the body)在数据工厂 web 活动主体部分中,用 [] 包装请求以使其成为数组,即 {"A":6} 将变为 [{"A":6}] (不确定确切原因,但似乎有效,可能有一些关于他们如何处理身体的过程)

  3. Remove all redundant space as seems azure would compress your body before it sent, ie [{"A": 6, "B": 7}] should become [{"A":6,"B":7}]删除所有冗余空间,因为 azure 会在发送之前压缩你的身体,即 [{"A": 6, "B": 7}] 应该变成 [{"A":6,"B":7}]

  4. Now use that processed body string's content_length for building your signature, you may test it using python first and copy(hard-coding) the value of Authorization(signature) and x-ms-date to data factory web activity for testing and it should work now.现在使用已处理的正文字符串的 content_length 来构建您的签名,您可以先使用 python 对其进行测试,然后将 Authorization(signature) 和 x-ms-date 的值复制(硬编码)到数据工厂 web 活动进行测试,它应该可以工作现在。

Please share if there is a proper solution for this, thanks:)如果有合适的解决方案,请分享,谢谢:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM