Splunk Search

How to create total average/median/max of field in a separate table?

LearningGuy
Builder


How to create total average/median/max of field in a separate table?
Thank you in advance

| index=testindex
| table company, ip, Vulnerability, Score

companyipVulnerabilityScore
CompanyAip1Vuln12
CompanyAip1Vuln20
CompanyAip2Vuln34
CompanyAip2Vuln42
CompanyAip3Vuln53
CompanyAip3Vuln65


Group by IP  => This worked just fine
| stats values(company), avg(Score) as AvgScore by ip

companyipAvgScore
CompanyAip11
CompanyAip23
CompanyAip34


Group by Company   =>  how do I group by company after group by ip (using stats) and put it on a separate table?
| stats avg(AvgScore) as Average, avgAvgScore) as Median, max( AvgScore) as Max by company

CompanyAverageMedianMax
CompanyA2.734
Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

A separate table requires a separate search.

If this is in a dashboard then consider making the first table a base search and the second table a post-processing of the first.  That will save you time and resources when the dashboard runs.

...
<search id="base"> <!-- "base" can be any string -->
  <query>| index=testindex
| table company, ip, Vulnerability, Score
| stats values(company), avg(Score) as AvgScore by ip</query>
...
</search>
...
<search base="base"> <!-- Use the same string as above -->
<query>| stats avg(AvgScore) as Average, avgAvgScore) as Median, max( AvgScore) as Max by company</query>
</search>
...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

LearningGuy
Builder

Hello,
I tried your suggestion and it worked fine. I am accepting this as a solution
Can you also suggest how to put the average, median and max on the bottom of the table?
Thank you again
Below is the example:  

companyipAvgScore
CompanyAip11
CompanyAip23
CompanyAip34
 Average2.7
 Median3
 Max4




0 Karma

richgalloway
SplunkTrust
SplunkTrust

I think you can do that with the appendpipe command, which processes the current results and adds new results to bottom.

 

| stats values(company), avg(Score) as AvgScore by ip
| appendpipe [ stats avg(AvgScore) as Average, median(AvgScore) as Median, max(AvgScore) as Max by company ]

 

 

---
If this reply helps you, Karma would be appreciated.

LearningGuy
Builder

Hello,

I tried the command you suggested and it did not show any effects
Please suggest.

Thanks

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I used the wrong case in the field name.  Try my edited answer.

---
If this reply helps you, Karma would be appreciated.

LearningGuy
Builder

Hello,
There would be no difference because I converted your suggestion to my real data, so I already fixed any details
Please suggest.

Thanks,

Marius

0 Karma

richgalloway
SplunkTrust
SplunkTrust

A separate table requires a separate search.

If this is in a dashboard then consider making the first table a base search and the second table a post-processing of the first.  That will save you time and resources when the dashboard runs.

...
<search id="base"> <!-- "base" can be any string -->
  <query>| index=testindex
| table company, ip, Vulnerability, Score
| stats values(company), avg(Score) as AvgScore by ip</query>
...
</search>
...
<search base="base"> <!-- Use the same string as above -->
<query>| stats avg(AvgScore) as Average, avgAvgScore) as Median, max( AvgScore) as Max by company</query>
</search>
...
---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...