I have a field called key. key has multivalues that are also dynamic. I have another field called values, that is also multivalued and dynamic. The values in "values" line-up with the values in "key".
Example:
key | values |
AdditionalInfo | user has removed device with id alpha_numeric_field" in area "alpha_numeric_field" for user "alpha_numeric_field". |
DeviceID | alpha_numeric_field |
DeviceType | mobile_device |
OS | Windows |
Thanks in advance and I hope this makes sense.
I want to create a new field using the values from the field "key" and have the values be the values from "values".
The oucome would be:
AdditionalInfo | user has removed device with id alpha_numeric_field" in area "alpha_numeric_field" for user "alpha_numeric_field". |
DeviceID | alpha_numeric_field |
DeviceType | mobile_device |
OS | Windows |
First, I suspect that you meant the input looks like
key | values |
AdditionalInfo DeviceID DeviceType OS | user has removed device with id "alpha_numeric_field" in area "alpha_numeric_field" for user "alpha_numeric_field". alpha_numeric_field mobile_device Windows |
Second, I have a question about the origin of "key" and "values". Could they come from a structure such as JSON? Maybe there is a better opportunity than at the end of processing.
Third, I suspect that you meant "the output would be"
AdditionalInfo | DeviceID | DeviceType | OS |
user has removed device with id "alpha_numeric_field" in area "alpha_numeric_field" for user "alpha_numeric_field". | alpha_numeric_field | mobile_device | Windows |
Finally, if your Splunk is 8.1 or later, you can use JSON functions and the multivalue mode of foreach to do the job:
| eval idx = mvrange(0, mvcount(key))
| eval keyvalue = json_object()
| foreach idx mode=multivalue
[eval keyvalue = json_set(keyvalue, mvindex(key, <<ITEM>>), mvindex(values, <<ITEM>>))]
| spath input=keyvalue
| fields - idx key values keyvalue
Here is an emulation for you to play with and compare with real data
| makeresults format=csv data="key,values
AdditionalInfo,user has removed device with id \"alpha_numeric_field\" in area \"alpha_numeric_field\" for user \"alpha_numeric_field\".
DeviceID,alpha_numeric_field
DeviceType,mobile_device
OS,Windows"
| stats list(*) as *
``` data emulation above ```
First, I suspect that you meant the input looks like
key | values |
AdditionalInfo DeviceID DeviceType OS | user has removed device with id "alpha_numeric_field" in area "alpha_numeric_field" for user "alpha_numeric_field". alpha_numeric_field mobile_device Windows |
Second, I have a question about the origin of "key" and "values". Could they come from a structure such as JSON? Maybe there is a better opportunity than at the end of processing.
Third, I suspect that you meant "the output would be"
AdditionalInfo | DeviceID | DeviceType | OS |
user has removed device with id "alpha_numeric_field" in area "alpha_numeric_field" for user "alpha_numeric_field". | alpha_numeric_field | mobile_device | Windows |
Finally, if your Splunk is 8.1 or later, you can use JSON functions and the multivalue mode of foreach to do the job:
| eval idx = mvrange(0, mvcount(key))
| eval keyvalue = json_object()
| foreach idx mode=multivalue
[eval keyvalue = json_set(keyvalue, mvindex(key, <<ITEM>>), mvindex(values, <<ITEM>>))]
| spath input=keyvalue
| fields - idx key values keyvalue
Here is an emulation for you to play with and compare with real data
| makeresults format=csv data="key,values
AdditionalInfo,user has removed device with id \"alpha_numeric_field\" in area \"alpha_numeric_field\" for user \"alpha_numeric_field\".
DeviceID,alpha_numeric_field
DeviceType,mobile_device
OS,Windows"
| stats list(*) as *
``` data emulation above ```
This looks very promising. Thank you for your valued input!
For creating fields dynamicaly you can use the {} syntax. Like
| makeresults
| eval field="field1",{field}="value"
But the important question and a possible issue here is where did you get the multivalued fields from. Remember that two distinct multivalued fields are... well, distinct. There is no relationship between their values whatsoever. And if you are creating multivalued field by means of list() or values() and the original data didn't have some values, you can't tel, which ones were empty. You're just getting a "squashed" list as a result.
I appreciate the help, but this is not what I'm looking to do. I want to create the new fields so they could be used for searching. I already have a field using the mvzip command. Thanks again.