If 条件从 JSON 的不同字段获取用户标识

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

我正在处理一个 splunk 查询,我需要从两个不同的地方获取用户 ID。这是我的示例 splunk 事件。

{
  "name": "HIVE-5336eac7-7974-43cb",
  "applicationId": "application_16831546",
  "mr2AppInformation": {},
  "runningContainers": -1,
  "endTime": "2023-05-15T13:30:08.110Z",
  "applicationTags": [
    "hive_20230515120843_b1778593-0dab",
    "userid=xxx"
  ],
  "allocatedMemorySeconds": 251266964,
  "state": "FINISHED",
  "allocatedMB": -1,
  "attributes": {
    "diagnostics": "Session timed out, lastDAGCompletionTime=1684157098509 ms, sessionTimeoutInterval=300000 ms\nSession stats:submittedDAGs=1, successfulDAGs=1, failedDAGs=0, killedDAGs=0\n"
  },
  "pool": "root.grp",
  "user": "hive",
  "allocatedVcoreSeconds": 43970,
  "progress": 100.0,
  "allocatedVCores": -1,
  "startTime": "2023-05-15T13:20:56.078Z"
}

如果“用户”字段是配置单元,那么我想从 ApplicationTags(userid=xxx) 获取用户 ID。

我正在提取如下所示的“用户”字段。 spath 输出=用户id 路径=用户

所以我有这个正则表达式,我想用它来获取用户 ID。

rex 字段=_raw "userid=(?.*)"]"

现在我的问题是我想写一个 if 条件,当“用户”是配置单元时我想从应用程序标签中的用户获取用户标识。

请帮忙

我想写一个 if 条件,当“用户”是配置单元时,我想从应用程序标签中的用户那里获取用户标识。

if-statement splunk splunk-query
1个回答
0
投票

当“用户”字段为“蜂巢”时从应用程序标签中提取用户 ID 的 if 条件:

eval 'raw=_raw' | if(user=="hive", rex field=raw "userid=(?<userid>.*)\"", spath output=userid path=user)

另一种方法:

index=<your_index_here> user=hive
| spath output=userid path=applicationTags{}
| search userid="*"
| rex field=userid "userid=(?<userid>.+)"
| table userid

这使用搜索来过滤“user”字段等于“hive”的事件,然后使用spath从“applicationTags”字段中提取“userid”值。

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