如何从 URL 中提取特定的子目录名称
How to extract specific sub directory names from URL
给定以下请求 URL:
- https://example.com/api/foos/123/bars/456
- https://example.com/api/foos/123/bars/456
常用结构:https://example.com/api/foos/{foo-id}
/bars/{bar-id}
我希望为 {foo-id}
和 {bar-id}
的值获取单独的列
我试过的
requests
| where timestamp > ago(1d)
| extend parsed_url=parse_url(url)
| extend path = tostring(parsed_url["Path"])
| extend: foo = "value of foo-id"
| extend: bar = "value of bar-id"
这给了我 /api/foos/{foo-id}/bars/{bar-id}
作为新的路径列。
我可以不使用正则表达式来解决这个问题吗?
相关但不是同一个问题:
拆分 '/' 字符将为您提供一个数组,然后只要路径保持一致,您就可以提取要查找的元素。使用 parse_url()
是可选的 - 您可以使用 substring()
或只调整您检索的索引。
requests
| extend path = parse_url(url)
| extend elements = split(substring(path.Path, 1), "/") //gets rid of the leading slash
| extend foo=tostring(elements[2]), bar=tostring(elements[4])
| summarize count() by foo, bar
给定以下请求 URL:
- https://example.com/api/foos/123/bars/456
- https://example.com/api/foos/123/bars/456
常用结构:https://example.com/api/foos/
{foo-id}
/bars/{bar-id}
我希望为 {foo-id}
和 {bar-id}
我试过的
requests
| where timestamp > ago(1d)
| extend parsed_url=parse_url(url)
| extend path = tostring(parsed_url["Path"])
| extend: foo = "value of foo-id"
| extend: bar = "value of bar-id"
这给了我 /api/foos/{foo-id}/bars/{bar-id}
作为新的路径列。
我可以不使用正则表达式来解决这个问题吗?
相关但不是同一个问题:
拆分 '/' 字符将为您提供一个数组,然后只要路径保持一致,您就可以提取要查找的元素。使用 parse_url()
是可选的 - 您可以使用 substring()
或只调整您检索的索引。
requests
| extend path = parse_url(url)
| extend elements = split(substring(path.Path, 1), "/") //gets rid of the leading slash
| extend foo=tostring(elements[2]), bar=tostring(elements[4])
| summarize count() by foo, bar