Splunk Enterprise Security

Taking all pairs of elements in a multivalue field to use it in a macro

eduardoduarte
Explorer

Hello.

I would like to be able to loop along all the elements of a multivalued field to compare all against each other. There is a macro in the following example that receives two arguments, I would like to check all the possible pairs from the mfield "MyField". Is this possible ?

In this example I am just checking the 0th element with the 1st element, but I want to check along all possible pairs in the multivalued field MyField if the outcome of the macro is higher than some value.

| makeresults
| eval MyField="AAA,ZAB,ZAA,RAA"
| makemv delim="," MyField
| eval f0=mvindex(MyField,0)
| eval f1=mvindex(MyField,1)
| `ut_levenshtein(f0,f1)`
| table MyField,f0,f1,ut_levenshtein

0 Karma
1 Solution

jawaharas
Motivator

You can use map command as shown below for your usecase

The map command is a looping operator that runs a search repeatedly for each input event or result.

| makeresults 
| eval MyField1="AAA,ZAB,ZAA,RAA" 
| makemv delim="," MyField1 
| mvexpand MyField1 
| map search="
    | makeresults 
    | eval MyField1=\"$MyField1$\", MyField2=\"AAA,ZAB,ZAA,RAA\" 
    | makemv delim=\",\" MyField2 
    | mvexpand MyField2
    |table MyField1, MyField2 " 
| `ut_levenshtein(MyField1,MyField2)`
| table *

View solution in original post

jawaharas
Motivator

You can use map command as shown below for your usecase

The map command is a looping operator that runs a search repeatedly for each input event or result.

| makeresults 
| eval MyField1="AAA,ZAB,ZAA,RAA" 
| makemv delim="," MyField1 
| mvexpand MyField1 
| map search="
    | makeresults 
    | eval MyField1=\"$MyField1$\", MyField2=\"AAA,ZAB,ZAA,RAA\" 
    | makemv delim=\",\" MyField2 
    | mvexpand MyField2
    |table MyField1, MyField2 " 
| `ut_levenshtein(MyField1,MyField2)`
| table *

eduardoduarte
Explorer

oh, thank you very much. I did modification to your command in order to avoid the hardcoding of MyField2 in the map command.

However, I dunno if you can make a two line summary of what you are doing since I do not understnad how do you get all the combinations in different order.

| makeresults
| eval MyField1="AAA,ZAB,ZAA,RAA"
| eval tField=MyField1
| makemv delim="," MyField1
| mvexpand MyField1
| map search="
| makeresults
| eval MyField1=\"$MyField1$\"
| eval MyField2=\"$tField$\"
| makemv delim=\",\" MyField2
| mvexpand MyField2
|table MyField1, MyField2 "
| ut_levenshtein(MyField1,MyField2)
| table *

0 Karma

jawaharas
Motivator

Glad it helped you.

  • The map command is a looping operator that runs a search repeatedly for each input event
  • The parent query (section before 'map' command) generates 'MyField1' field
  • In the subquery (under 'map' command), 'MyField1' variable is passed in and for each event of parent query, all the events in subquery are executed.

Below SPL might explain you visually

| makeresults 
 | eval MyField1="A,B,C,D" 
 | makemv delim="," MyField1 
 | mvexpand MyField1 
 | map search="
     | makeresults 
     | eval MyField1=\"$MyField1$\", MyField2=\"One,Two,Three,Four\" 
     | makemv delim=\",\" MyField2 
     | mvexpand MyField2
     |table MyField1, MyField2 " 
 | `ut_levenshtein(MyField1,MyField2)`
 | table *

Can you upvote and accept the answer if it's helped you? Thanks.

eduardoduarte
Explorer

Thank you very much! This was really helpful.

0 Karma
Get Updates on the Splunk Community!

Modern way of developing distributed application using OTel

Recently, I had the opportunity to work on a complex microservice using Spring boot and Quarkus to develop a ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had 3 releases of new security content via the Enterprise Security ...

Archived Metrics Now Available for APAC and EMEA realms

We’re excited to announce the launch of Archived Metrics in Splunk Infrastructure Monitoring for our customers ...