Splunk Search

How to create a table showing the sum of values across dictionaries in multiple queries?

beaverjustin1
Engager

If I have queries with dictionaries containing events as the key and frequencies as the value:

line.Data = {"eventOne": 4, "eventThree" : 2};  line.Data = {"eventOne": 2, "eventTwo" : 3}

How can I create a table that shows the sum of the different events:

eventOne: 6

eventTwo: 3

eventThree: 2

Labels (6)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Here is a runanywhere example showing how you could approach this.

| makeresults
| fields - _time
| eval line.Data = split("{\"eventOne\": 4, \"eventThree\" : 2};{\"eventOne\": 2, \"eventTwo\" : 3}",";")
| mvexpand line.Data
``` the lines above create sample events, one event per line.Data ```
| spath input=line.Data
| untable line.Data event count
| stats sum(count) as count by event

TrangCIC81
Communicator

 

<your base search>
| stats sum(*) as * by _time
| transpose

 

  1. Replace <your base search> with the search that produces the line.Data field containing the dictionaries.
  2. Use the stats command with the sum(*) function to calculate the sum of all values in each event category for each _time value. This will create a table with columns _time, eventOne, eventTwo, and eventThree.
  3. Use the transpose command to switch the rows and columns of the table so that the event categories become rows and the _time values become columns.

    Let me know if it works.
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...