Hi, I have string extracted by "multiline" and it looks like below:
"massage": "ts_action: 2019-08-23 01:22:14, Action ID: 1-13RK8A8Z, ts_action: 2019-08-23 01:22:14, Action ID: 1 + 1CU2 + 93, ts_action : 2019 -08-23 01:22:14, Action ID: 1-AZYY5O, ts_action: 2019-08-23 01:22:14, Action ID: 1-122RF15J "
I want to send the value of "massage" in the fields:
Ts_action1 = 2019-08-23 01:22:14
Action_id1 = 1-13RK8A8Z
Ts_action2 = 2019-08-23 01:22:14
Action_id2 = 1+1CU2+93
Ts_action3 = 2019-08-23 01:22:14
Action_id3 = 1-AZYY5O
Ts_action4 = 2019-08-23 01:22:14
Action_id4 = 1-122RF15J
I know the ruby plugin might be a solution, but I'm not familiar with ruby.
Thank you for your attention and help.
Badger
August 26, 2019, 10:40pm
2
Please edit your post, select the data
"massage": "ts_action: 2019-08-23 01:22:14, stock ID: 1-13RK8A8Z, ts_action: 2019-08-23 01:22:14, stock ID: 1 + 1CU2 + 93, ts_action : 2019 -08-23 01:22:14, Action ID: 1-AZYY5O, ts_action: 2019-08-23 01:22:14, Action ID: 1-122RF15J "
and click on </> in the toolbar above the edit pane. Make sure it starts looking like
"massage": "ts_action: 2019-08-23 01:22:14, stock ID: 1-13RK8A8Z, ts_action: 2019-08-23 01:22:14, stock ID: 1 + 1CU2 + 93, ts_action : 2019 -08-23 01:22:14, Action ID: 1-AZYY5O, ts_action: 2019-08-23 01:22:14, Action ID: 1-122RF15J "
in the preview pane on the right.
How can we know that 1-AZYY5O should be left out of the result set?
Thanks,
I already did it.
So, I already corrected the text! The "1-AZYY5O" isn't the left out. All key and values need to be set result.
I tried aother solution with KV. And now I have:
"action_id" => [
[0] "1-13RK8A8Z",
[1] "1+1CU2+93",
[2] "1-AZYY5O",
[3] "1-122RF15J"
"ts_action" => [
[0] "2019-08-23 01:25:07",
[1] "2019-08-23 01:25:07",
[2] "2019-08-23 01:25:07",
[3] "2019-08-23 01:25:07",
[4] "2019-08-23 01:25:07"
But, I'd need to replace in an unique field yet!
I used the code:
ruby {
code => '
action = event.get["ts_action"]
action.each_index { |i| event["ts_action{action[i]}"] = action[i] }
'
}
But the result was:
[1] "_rubyexception"
Badger
August 27, 2019, 3:17pm
4
Try this. scan returns an array of arrays, each of which contains the capture groups from the regexp.
ruby {
code => '
matches = event.get("massage").scan(/ts_action\s*: ([^,]+), Action ID: ([^,]+)/)
matches.each_index { |x|
event.set("ts_action#{x+1}", matches[x][0])
event.set("action_id#{x+1}", matches[x][1])
}
'
}
1 Like
system
(system)
Closed
September 24, 2019, 3:17pm
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.