Splunk - 使用 dot/period 提取字段

Splunk - extract a field with dot/period

似乎无法提取名称中带有 . 的字段。

我正在尝试对旧数据使用字段提取器来创建与新数据 JSON 字段相匹配的字段。

{ "pirate": { "say ": "Shiver me timbers" } }

pirate.say = "Shiver me timbers"

要对此进行测试,您可以这样做:

| metadata type=hosts index=_internal
| head 1
| eval message="Shiver me timbers, goes the pirate"
| table message
| rex field=message "(?<pirate.say>[^,]+)"

但我的努力得到的只是上述 'rex' 原型和 'Field extractions' 页面中的相同错误消息。

从 'rex' 原型我得到:

Error in 'rex' command: Encountered the following error while compiling the regex '(?[^,]+)': Regex: syntax error in subpattern name (missing terminator)

从 'Fields » Field extractions » Add new' 我得到:

Encountered the following error while trying to save: Regex: syntax error in subpattern name (missing terminator)

关于如何解决这个问题有什么想法吗?

这里发生了几件不同的事情。

首先,不,您不能创建在要提取的字段名称中带有点的正则表达式。 (在 regex101.com 测试过,但它不起作用。)

从 JSON 中提取时,splunk 可以创建其中有一个点的字段,表示 JSON 的层次结构。

另一方面,当从正常数据中自动提取时,splunk 通常会将无效字符替换为下划线。

要提取 JSON,通常使用 spath 命令。

要提取正则表达式,只需给它一个有效的名称,然后重命名以包含点。

| makeresults
| eval message="Shiver me timbers, goes the pirate"
| table message
| rex field=message "(?<piratesays>[^,]+)"
| rename piratesays as "pirate.say"

我忘记了对于奇数名称是否需要单引号或双引号,所以如果这不起作用,请试试这个。

| rename piratesays as 'pirate.say'