AWS CloudWatch 选择第一个现有字段

发布于 2025-01-13 04:20:20 字数 450 浏览 5 评论 0原文

我在 AWS CloudWatch 中有两种消息,并且想要选择第一个包含一些文本的字段。例如,

消息 1:

"message": {
   "message": "I am the first priority"
}

消息 2:

"message": {
    "err": {
         "message": "I am second priority"
    }
}

我希望将这些消息放在 CloudWatch 表的单列中,具体取决于存在哪一个。有什么办法可以做到这一点吗?像这样的东西(这显然不起作用):

fields @timestamp, ispresent(message.message) ? message.message : message.err.message

I have two kinds of messages in the AWS CloudWatch and would like to select the first field that has some text in it. For example

Mesasge 1:

"message": {
   "message": "I am the first priority"
}

Message 2:

"message": {
    "err": {
         "message": "I am second priority"
    }
}

I would like to have these in a single column of the CloudWatch table depending which one is present. Is there any way to do this? Something like this (which obviously doesn't work):

fields @timestamp, ispresent(message.message) ? message.message : message.err.message

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥繁 2025-01-20 04:20:20

显然合并功能正是我所需要的。它选择了第一个不为空的值:

fields @timestamp, component, coalesce(message.message, message.err.message) as TheMessage

更多信息位于 CloudWatch Logs Insights查询语法

Apparently coalesce function is what I needed. It selected the first value that is not null:

fields @timestamp, component, coalesce(message.message, message.err.message) as TheMessage

More info at CloudWatch Logs Insights query syntax

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文