You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何创建可打开Log Analytics并运行指定查询的URL?遇格式错误求解决方案

生成Log Analytics直接运行指定查询的URL方案

核心要求说明

Log Analytics的直接运行查询URL中,query参数必须是GZIP压缩后再经过URL安全Base64编码的字符串,这是你之前尝试普通编码失败的原因。以下是仅用KQL实现编码并生成可用URL的步骤:

步骤1:用KQL生成符合要求的查询编码字符串

假设你要预定义的查询是AppRequests | take 5,运行以下KQL代码,即可得到编码后的字符串:

let targetQuery = "AppRequests | take 5"; // 替换成你需要的目标查询
let compressedBytes = zip(pack_string(targetQuery));
let base64Encoded = tobase64(compressedBytes);
let urlSafeBase64 = replace_string(replace_string(base64Encoded, "+", "-"), "/", "_");
let finalQueryParam = replace_string(urlSafeBase64, "=", "");
print finalQueryParam

代码逻辑说明:

  • pack_string:将查询字符串转换为字节数组
  • zip:对字节数组执行GZIP压缩
  • tobase64:将压缩后的字节转为Base64字符串
  • 两次replace_string:将Base64中的+替换为-、/替换为_,去掉末尾的=,生成URL安全的编码结果

步骤2:拼接最终可运行的URL

将步骤1得到的finalQueryParam,替换到修正后的URL模板中(注意修正原URL的拼写错误:resoruceGroup→resourceGroup,workspceName→workspaceName):

https://portal.azure.com/#blade/Microsoft_OperationsManagementSuite_Workspace/AnalyticsBlade/initiator/AnalyticsShareLinkToQuery/isQueryEditorVisible/true/scope/resources/resourceId/subscriptions/{subscriptionId}/resourcegroups/{resourceGroup}/providers/microsoft.operationalinsights/workspaces/{workspaceName}/query/{finalQueryParam}/isQueryBase64Compressed/true

替换模板中的{subscriptionId}、{resourceGroup}、{workspaceName}为实际值后,即可直接打开该URL运行预定义查询。

注意事项

  • 若目标查询包含双引号,需用双引号转义,例如查询为where name == "test"时,KQL中应写为let targetQuery = "where name == ""test""";
  • isQueryBase64Compressed参数必须保持为true,否则门户无法识别压缩后的查询内容

内容的提问来源于stack exchange,提问作者Matt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 04:55:20