Looking up product code descriptions

Log data can be filled with identification numbers, short codes, error numbers, or other values that don't always make the information easy to read or understand quickly.

This recipe will show you how to add a lookup table to your Operational Intelligence application so that when a product code field is present in an event, a description field can automatically be added and populated with the full description of that product.

Getting ready

To step through this recipe, you will need a running Splunk Enterprise server, with the sample data loaded from Chapter 1, Play Time – Getting Data In. You should be familiar with navigating the Splunk user interface.

How to do it…

Follow the steps in this recipe to create an automatic product code lookup:

  1. Create a new file called productdescriptions.csv using your favorite text editor on your local computer and add the following lines, taking care to ensure that the commas are typed correctly:
    itemId,itemName,itemDescription
    4728475,Rolux Navigator,Stylish men's watch with metal band
    38492,Rolux Sportsman,Men's sport watch with timer
    1000014,Ripple BookPro 13,13 inch laptop - 5PB HDD/200GB RAM
    1000015,Ripple Jukebox 500,Portable music player - 984 hour battery life
    1000016,Poku Castbox,Video streaming device - HDMI compatible
    1000017,Ripple Jukebox 300,Music streaming device 300GB storage capacity
    1000020,Ripple MyPhone 8,The latest phone from Ripple - 8 inch with 8TB of storage capacity
  2. You can alternatively use the productdescriptions.csv file that is provided.
  3. Save the file in a location that is easily accessible from your web browser.
  4. Log in to your Splunk server.
  5. Select the Operational Intelligence application.
    How to do it…
  6. Click on the Settings menu and then select the Lookups menu item.
    How to do it…
  7. Click on Lookup table files.
    How to do it…
  8. Click on New.
    How to do it…
  9. Select the Destination app as operational_intelligence.
  10. Click on the Choose File button (may be different depending on your browser or operating system) and select your productdescriptions.csv file.
    How to do it…

    As the file is much smaller than the maximum 500 MB file size, we are able to upload it via the GUI without any issue.

    Tip

    Larger files can be uploaded through the backend filesystem to $SPLUNK_HOME/etc/apps/operational_intelligence/lookups.

  11. In the Destination filename field, enter productdescriptions.csv and then click on Save.
    How to do it…
  12. Now, we need to define our lookup in Splunk.
  13. Click on Lookups.
    How to do it…
  14. Click on Lookup definitions:
    How to do it…
  15. Click on New.
    How to do it…
  16. In the Name field, enter Product_Descriptions, set the Type field to File-based, and select the productdescriptions.csv file in the Lookup file field. Then, click on Save.
    How to do it…
  17. Finally, we are going to automate the lookup so that the lookup is performed automatically when searching for the log4j sourcetype. Click on Lookups again.
    How to do it…
  18. This time, click on Automatic lookups.
    How to do it…
  19. Click on New.
    How to do it…
  20. Select operational_intelligence in the Destination app field and enter Product_Descriptions in the Name field.
  21. In the Lookup table dropdown, select Product_Descriptions.
    How to do it…
  22. Select sourcetype in the Apply to field and enter log4j in the named field.
  23. Enter itemId in both fields for Lookup input fields.
    How to do it…
  24. Set itemDescription to ProductDescription and itemName to ProductName in Lookup output fields.
    How to do it…
  25. Click on Save.
  26. Click on Apps and select the Operational Intelligence app.
  27. In the search bar, enter the following search over Last 24 hours:
    index=main sourcetype="log4j" itemId=* | table itemId ProductDescription, ProductName
  28. It should now display the ProductDescription and ProductName entries for each field.
    How to do it…

How it works…

When you issue a search in Splunk, it checks its configuration to see if there are any lookups defined. If it finds a lookup that matches the appropriate host, source, or sourcetype for the events returned in the search, it takes the input fields that are defined and matches them against the data in the lookup file and the fields in the events. If the field values match, it adds the output fields from the lookup table to the events as the new fields, as defined.

There are many different configurations possible with lookup tables. For example, it is possible to have input field matches on more than one field, and you can have the output fields overwrite the fields that already exist in the search results.

In this recipe, we chose to implement an automatic lookup. Automatic lookups negate the need to explicitly use the lookup command in your search but can carry a performance cost. For example, every search of the log4j sourcetype will now perform this product lookup automatically, whether we need the fields and associated values returned from the lookup or not.

Tip

Automatic lookups are only recommended where it makes sense to do so and where every search of that sourcetype, source, or host would benefit from the automatic lookup.

There's more…

As with most configurations in Splunk, there is more than one way to do something. While the product lookup can be configured via the web interface, it can also be performed manually.

Manually adding the lookup to Splunk

Follow the given steps to manually add the lookup to Splunk:

  1. Upload your productdescriptions.csv file to $SPLUNK_HOME/etc/apps/operational_intelligence/lookups directory (create the lookups directory if required).
  2. Add the following stanza to $SPLUNK_HOME/etc/apps operational_intelligence/local/transforms.conf (create the local directory if required):
     [Product_Descriptions]
    filename = productdescriptions.csv
  3. Add the following stanza to $SPLUNK_HOME/etc/apps operational_intelligence/local/props.conf (create the local directory if required):
     [log4j]
    LOOKUP-Product_Descriptions = Product_Descriptions itemId AS itemId OUTPUTNEW itemDescription AS ProductDescription, itemName AS ProductName

See also

You can refer to the following recipes for more information:

  • The Flagging suspect IP addresses recipe
  • The Creating a session state table recipe
  • The Looking up inventory from an external database recipe
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.163.58