Cloudwatch Logs Insights 在多条消息中搜索过滤器

问题描述 投票:0回答:1

这就是我的日志的样子

2024-03-16T23:21:21.275Z ff84d7a6-991a-**** unauthorized_error
2024-03-16T23:21:21.275Z ff84d7a6-991a-**** client: client1

我想搜索:

unauthorized_error
但如果客户不是
client1
正如您所看到的,另一个过滤器位于另一条消息中,因此这样做不起作用

fields @timestamp, @message, @logStream, @log 
| filter @message like /(?i)unauthorized/ and @message not like /(?i)client1/
| sort @timestamp desc
| limit 10000
amazon-cloudwatch amazon-cloudwatchlogs aws-cloudwatch-log-insights
1个回答
0
投票

使用“过滤器”选项与正则表达式相结合。一个例子: 当 B 的“MyValue”等于 0 时查询过滤消息 A: 假设您的日志与您共享的日志类似:

2024-03-16T23:21:21.275Z ff84d7a6-991a-**** 未经授权的_错误 2024-03-16T23:21:21.275Z ff84d7a6-991a-**** 客户:client1

您只想在消息 B 包含 'MyValue': 0 时显示消息 A。 这是您可以使用的查询:

字段@timestamp、@message |过滤@message,如/A:|B:/ |过滤@message,如/B: {'MyValue':0}/

仅当消息 B 的“MyValue”值等于 0 时,才会返回消息 A。

此查询将返回包含任何指定字符串的记录。 请记住使这些查询适应您的日志的确切格式。我希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.