事实证明,我误读了文档并且没有意识到这time-generated-field
不是您传入的参数,而是您发送到日志分析工作区的 JSON 数据主体中的一个属性。
可以以这种方式引用它(这是一种方法的示例):
def post_data(customer_id, shared_key, body, log_type):
method = 'POST'
#The string "raised" assigned to the TimeStampField variable below
#is an actual property in the JSON object that I am sending to log
#analytics, it contains the datetime in the expected format.
TimeStampField = "raised"
content_type = 'application/json'
resource = '/api/logs'
rfc1123date = datetime.datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
content_length = len(body)
signature = build_signature(customer_id, shared_key, rfc1123date, content_length, method, content_type, resource)
uri = 'https://' + customer_id + '.ods.opinsights.azure.com' + resource + '?api-version=2016-04-01'
headers = {
'content-type': content_type,
'Authorization': signature,
'Log-Type': log_type,
'x-ms-date': rfc1123date,
'time-generated-field': TimeStampField
}
肯定会创建一个拉取请求来修改此处的措辞:
https ://docs.microsoft.com/en-us/azure/azure-monitor/logs/data-collector-api#create-a-request
我觉得是不是很直观