Splunk Search

Grouping and Counting the Group Values

kanda18
Explorer

Hello.
I have a requirement of presenting a table with Countries, users and the number of users in that country..
SO I have a query :
…{query}..| stats count values(user) by country

This will give me :

something like :

country User

USA-------u1

-------------u2

-------------u3

-------------u4

UK -------u5

-------------u6

What do I do to the query , so that it gives me the count of the number of users in the third column: something like :

country User UserCount

USA-------u1------ 4

-------------u2

-------------u3

-------------u4

UK -------u5----------2

-------------u6

Tags (2)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Try this:

... | stats count values(user) dc(user) by country

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Try this:

... | stats count values(user) dc(user) by country

martin_mueller
SplunkTrust
SplunkTrust

Rendering in the UI and in an inline table of an email is inherently different. Off the top of my head you could try two things: You could mvexpand the values(user) field, giving you one copied event per user along with the counts... or you could indeed try to mvjoin() the users with a \n newline character... if that doesn't work, try joining them with an HTML <br> tag, provided Splunk isn't smart and replaces that with ampersand-entities.

If all that fails, you could create your own version of the sendemail.py script and build the inline tables as you need them.

0 Karma

kanda18
Explorer

Hey,
This works great on the splunk interface, but when I generate a report to be sent to an email, with the inline results, the users show on single line. In the splunk search, the table is neat, with the users on a new line. Is there a way to make sure that the splunk result shows in email as is ? with the new lines etc?I tried to do eval userNames=mvjoin(UsersMV,"#") .I think i need to do something to replace the # from the userNames and add a new line \n in regex? not sure. I am surprised that the results in the Splunk interface is different from the results in the email

0 Karma

kanda18
Explorer

Thank you sir..

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...