Enriching Data with External Sources - The lookup Command
Our logs don't always have all the information we need for an analysis. Sometimes the logs only contain sets of IDs that mean nothing on their own, but that have an external source with their "translation".
One way to use this kind of information is with Splunk's lookup commands, which let us use predefined tables to enrich our data through a field that shares values with our index.
Taking the logs provided on Splunk's website as an example, our index has events related to purchases in an online store, but no details about the products in each transaction. Let's pay attention right away to the productId field available in our index:

Along with this sample data, Splunk provides the prices.csv file, which contains information such as price, product name and so on. Below we will see how to use this data to enrich the information in our index.
The first step is to open the Lookups menu:

Now let's add a new table with the option add new.

Here we select the destination app and the CSV file downloaded with Splunk's sample logs, and finally enter the name of the file that will hold its content on the Splunk server.

Now we can view the content of the file loaded on the server with the inputlookup command:
| inputlookup prices.csv
If you want to overwrite the file's content, just use the outputlookup command. Be careful with this command, because any change made in the results will overwrite the file on the server. I recommend testing with a new file with a different name:
| outputlookup novo_prices.csv
Notice that the new file now contains the results from our previous lookup file.
As mentioned earlier, we need a value shared by the index and the uploaded file to match the related values. Remember the productId field? Yes, it is also in our lookup table, so for an event related to a productId we can know exactly the price of that product.
Now let's see how to merge this information. Back in the Lookups menu, we create a lookup definition, entering only the file name and the name that will be used to call the lookup when the command runs.

And now we can finally use the lookup command to view the information:
index=web| lookup prices.csv productId as productId | table product_name, price, sale_price, Code
We used the table command, listing first the fields that exist only in the index, then the productId field and then the fields from our lookup table, to make the results easier to read.
You can now work with the data as usual, using the commands from our other posts, such as stats and timechart.

Want to practice? Try the free We Challenge sample, with Splunk questions and explanations.
To start from scratch, see the Introduction to Splunk course on Udemy (in Portuguese). For your team, see WeValuate's Splunk training.
Questions about the post? Content suggestions? Corrections? Criticism or praise?
Please contact us at wevaluatebr@gmail.com and we will reply as soon as possible.
If you liked it, share this post on your social networks and help us spread the word!



Comments