0

我正在为 Azure 存储帐户(在本例中为表)构建查询。我尝试接收最后一天的最后一个日志条目。

过滤器在存储查询构建器中如下所示:

{
  "filter": [
    {
      "id": "{ID}",
      "andOr": "And",
      "field": "TIMESTAMP",
      "type": "DateTime",
      "operator": ">=",
      "value": "datetime'2019-11-18T10:08:41.296Z'",
      "timeValue": "Last 24 hours",
      "timestampType": "time",
      "customTimestamp": {
        "lastNumber": 7,
        "lastTimeUnit": "Days"
      },
      "isLocal": true
    }
  ],
  "select": null,
  "group": {
    "id": "{ID}",
    "children": [
      "{CHILD}"
    ]
  },
  "top": null,
  "filterType": "Query Builder",
  "fileVersion": 0.2
}

此查询返回最后一天的所有条目。我尝试在 Azure REST API 调用中使用此筛选器。在这样的powershell函数中:

function GetTableEntityAll($TableName) {
    $version = "2017-04-17"
    $resource = "$tableName()" 
    $DST =  [DateTime]::Today.AddDays(-1)
    $table_url = "https://$storageAccount.table.core.windows.net/$resource"+ '?$filter=Timestamp gt datetime' + "'"+ $DST.ToString("s") + "'"
write-host $table_url
    $GMTTime = (Get-Date).ToUniversalTime().toString('R')
    $stringToSign = "$GMTTime`n/$storageAccount/$resource"
    $hmacsha = New-Object System.Security.Cryptography.HMACSHA256
    $hmacsha.key = [Convert]::FromBase64String($accesskey)
    $signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign))
    $signature = [Convert]::ToBase64String($signature)
    $headers = @{
        'x-ms-date'    = $GMTTime
        Authorization  = "SharedKeyLite " + $storageAccount + ":" + $signature
        "x-ms-version" = $version
        Accept         = "application/json;odata=fullmetadata"
    }
    $item = Invoke-RestMethod -Method GET -Uri $table_url -Headers $headers -ContentType application/json
    return $item.value
}

我用这个生成的 URL 是:

https://{Accountname}.table.core.windows.net/{Tablename}()?$filter=Timestamp gt datetime'2019-11-18T00:00:00'

这不会返回任何记录。我也尝试对 url 进行编码,但这也不起作用。如果我将日期时间更改为 2016 年,我会收到前几条记录。

Azure 文档:https ://docs.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities

有任何想法吗?

4

0 回答 0