如何在 Splunk 中统计结果并将其放入表格中?

Mar*_*rek 2 splunk

我正在尝试在 Splunk 中创建一个表,其中包含提取的多个字段以及当我向 Splunk 提供要搜索的字符串时返回的条目总数。我遇到的问题是,当我使用 stats 命令获取返回结果的计数并将其通过管道传送到表时,它只是将所有字段留空,但显示返回结果计数的值。如果没有计数逻辑,该表将显示我想要的所有值。下面是我的示例查询:

index=test "Failed to find file"
| table host, sourceUser, sourceApp, source
| rename host as "Server", sourceUser as "User", sourceApp as "Application", source as "Log"
Run Code Online (Sandbox Code Playgroud)

以下是示例结果(由于我无法发布图片,所以采用两行 CSV 格式):

服务器、用户、应用程序、日志

myserver1,joesmith,RadomApp,C:\Users\Joe\Log.txt

这将返回我要求的所有字段。如果我添加 stats 命令(如下所示),它会返回一个包含所有列的表,但唯一包含数据的是“错误计数”列:

index=test "Failed to find file"
| stats count as error
| table host, sourceUser, sourceApp, source, error
| rename host as "Server", sourceUser as "User", sourceApp as "Application", source as "Log", error as "Error Count"
Run Code Online (Sandbox Code Playgroud)

结果示例:

服务器、用户、应用程序、日志、错误计数

,,,,1

知道解决这个问题的最佳方法是什么吗?

Mar*_*rek 5

我认识的人提出了解决方案,我需要更改“统计”行,以便最终查询如下所示:

index=test "Failed to find file"
| stats count as error by host, sourceUser, sourceApp, source
| table host, sourceUser, sourceApp, source, error
| rename host as "Server", sourceUser as "User", sourceApp as "Application", source as "Log", error as "Error Count"
Run Code Online (Sandbox Code Playgroud)