How do I add fixed attributes to the expanded array? #8644
-
How do I add fixed attributes to the expanded array Vector Versionvector 0.15.0 [sources.httpSources]
type = "http"
address = "172.16.1.41:7001"
path = "/client-lua"
encoding = "json"
headers = ["x-forwarded-for"]
[transforms.parse_logs]
type = "remap"
inputs = ["httpSources"]
source = '''
. = .msg
.clientIp = .x-forwarded-for
'''
[sinks.print]
type = "console"
inputs = ["parse_logs"]
encoding.codec = "json" {
"x-forwarded-for":"192.168.1.1",
"msg":[
{
"name":"tom"
},
{
"name":"mimi"
}
]
}
I hope to get: {
"clientIp":"192.168.1.1",
"name":"tom"
},
{
"clientIp":"192.168.1.1",
"name":"mimi"
}
|
Beta Was this translation helpful? Give feedback.
Answered by
spencergilbert
Aug 10, 2021
Replies: 1 comment 9 replies
-
source = '''
. = .msg
.clientIp = .x-forwarded-for
''' The first line here will replace the entire event ( Could you share an example of an event that would be going into the EDIT: if that second snippet is the example input, I think you may just want to use source = """
. = unnest!(.msg)
.clientIp = del(.x-forwarded-for)
""" EDIT2: 💭 might require two remaps: [transforms.parse_logs]
type = "remap"
inputs = ["httpSources"]
source = '''
. = unnest(.msg)
'''
[transforms.parse_logs]
type = "remap"
inputs = ["parse_logs"]
source = '''
. |= .msg
.clientIp = ."x-forwarded-for"
''' |
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
PanHywel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first line here will replace the entire event (
.
) with the the.msg
field, if present. The following line should set a root level field namedclientIp
to the contents of the.x-forwarded-for
field (presumably a part of the.msg
key you used above?).Could you share an example of an event that would be going into the
remap
transform here?EDIT: if that second snippet is the example input, I think you may just want to use
unnest
on.msg
EDIT2: 💭 might require two remaps: