查询:
index = test
| stats values(*) as * by ip_addr, location
| where location="USA"
| fields timestamp, user, ip, location, message
结果:
+--------------------------------------------------------------------+
| timestamp | user | ip | location | message |
+--------------------------------------------------------------------+
| 08/08/2020 17:00 | thomas | 10.10.10.10 | USA | Hello, world!|
| 08/08/2020 17:05. | unknown| | | I love steak!|
| 08/08/2020 17:10. | | | | I love soda! |
+--------------------------------------------------------------------+
| 08/08/2020 17:00 | jeffry | 10.10.10.20 | USA | Hello, world!|
| 08/08/2020 17:35 | unknown| | | I love pancke|
| 08/08/2020 17:40 | | | | I love waffle|
+--------------------------------------------------------------------+
我想:
- 将多个时间戳变成一个时间戳
- 删除“用户”字段中的“未知”值
- 让“message”字段只显示“Hello, world!” - 我不关心剩下的。
我尝试过:
index = test
| stats values(*) as * by ip_addr
| where location="USA"
| eval user=replace(user, "unknown", "")
| fields timestamp, user, ip, location, message
但它删除了“用户”字段下的所有值。有什么建议吗?我的 2 号和 3 号目标看起来很相似。如果我能破解其中一个,我想我可以轻松解决另一个。
最佳答案
是的,时间戳可以取平均值,如果它们是纪元(整数)形式的话。 values(*)
函数的结果是一个多值字段,它不能很好地与 replace
或大多数其他不是为它们设计的命令和函数一起使用。这就是我使用下面的 mvfilter
和 mvdedup
命令的原因。
index = test
| where location="USA"
| stats earliest(timestamp) as timestamp, values(*) as * by ip_addr
| eval user=mvdedup(mvfilter(!match(user, "unknown")),
message=mvdedup(mvfilter(match(message, "Hello, world!"))
| fields timestamp, user, ip, location, message
关于splunk - 使用 stats() 时如何从字段中提取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64655271/