在json数组中获取指定的元素 - SPLUNK

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

I im newbie in splunk.I have this json.I need to pick value when property name has "x-real-ip" value:

"request": {
    "headers": [
        {
            "name": "x-real-ip",
            "value": "10.31.68.186"
        },
        {
            "name": "x-forwarded-for",
            "value": "10.31.68.186"
        },
        {
            "name": "x-nginx-proxy",
            "value": "true"
        }

当属性名有 "x-real-ip "值时,我需要选择一个值。

javascript analytics splunk
1个回答
0
投票

有几种方法可以做到这一点--这是我最常用的一种方法(假设你是 要的 value 旁边 name):

index=ndx sourcetype=srctp request.headers{}.name="x-real-ip"
| eval combined=mvzip(request.headers{}.name,request.headers{}.value,"|")
| mvexpand combined
| search combined="x-real-ip*"

这将跳过所有没有""的事件。x-real-ip"在某处 request.headers{}.name 多值域

接下来,它将两个多值字段(name & value)合并成一个mv字段,并以 | 性格

然后扩展结果集,使你一次只看一行。

最后,你要找 只是 值为""的结果。x-real-ip"在他们

如果你想然后提取 value 的组合字段中,添加以下一行。

| rex field-combined "|(?<x_real_ip>.+)"

当然,你还可以对你的数据进行任何其他的SPL操作。


-1
投票
your search
| rex max_match=0 "name\":\s\"(?<fieldname>[^\"]+)"
| rex max_match=0 "value\":\s\"(?<fieldvalue>[^\"]+)"
| eval tmp=mvzip(fieldname,fieldvalue,"=")
| rename tmp as _raw
| kv
| fields - _* field*

当你提出问题时,请出示正确的信息.你在这个过程中已经耗尽了日志。

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