Splunk Search

How to display count of related events in a column?

rkassabov
Path Finder

I am trying to get the following query to show the related_vulnerabilities as a count column, instead of showing all the related vulns.

My query without the count produces this result:
alt text

However after adding the logic for the count, I get this result:
alt text

This is what my query looks like with the added stats count statement:

index=xxx md_type=xxx
info_owner_orgID="xxx"
| dedup id 

| rex mode=sed field="related_vulnerabilities" "s/[][]//g"
| rex mode=sed field="related_vulnerabilities" "s/'//g"
| makemv delim="," related_vulnerabilities
| eval RV = mvindex(related_vulnerabilities,0)

| stats count(related_vulnerabilities) by info_name

| table info_name info_class related_vulnerabilities

How can I add a count column that shows the count of related_vulnerabilities?

Tags (3)
0 Karma
1 Solution

Shan
Builder

@ rkassabov

you need to provide a alias name for the filed in stats and use that alias name in table .. While using stats, If you want to display any field in table. Then you need to do some operation or at-least you need to simply use that field in stats by using function like values(distinct values will be shown ) or list(duplicate values also shown ) as i shown below (info_class). I have used eval for showcasing the data. you dont want to consider it .. you can use stats and table in ur query.

Sample for ur understanding

|makeresults

| eval related_vulnerabilities="values"
| eval info_name="search"

| eval info_class="class name"
| stats count(related_vulnerabilities) as related_vulnerabilities, values(info_class) as info_class by info_name
| table info_name info_class related_vulnerabilities

Use This Query

index=xxx md_type=xxx
info_owner_orgID="xxx"
| dedup id
| rex mode=sed field="related_vulnerabilities" "s/[][]//g"
| rex mode=sed field="related_vulnerabilities" "s/'//g"
| makemv delim="," related_vulnerabilities
| eval RV = mvindex(related_vulnerabilities,0)
| stats count(related_vulnerabilities) as related_vulnerabilities, values(info_class) as info_class by info_name
| table info_name info_class related_vulnerabilities

once u got what u needed .. please accept the answer 🙂 ..

View solution in original post

Shan
Builder

@ rkassabov

you need to provide a alias name for the filed in stats and use that alias name in table .. While using stats, If you want to display any field in table. Then you need to do some operation or at-least you need to simply use that field in stats by using function like values(distinct values will be shown ) or list(duplicate values also shown ) as i shown below (info_class). I have used eval for showcasing the data. you dont want to consider it .. you can use stats and table in ur query.

Sample for ur understanding

|makeresults

| eval related_vulnerabilities="values"
| eval info_name="search"

| eval info_class="class name"
| stats count(related_vulnerabilities) as related_vulnerabilities, values(info_class) as info_class by info_name
| table info_name info_class related_vulnerabilities

Use This Query

index=xxx md_type=xxx
info_owner_orgID="xxx"
| dedup id
| rex mode=sed field="related_vulnerabilities" "s/[][]//g"
| rex mode=sed field="related_vulnerabilities" "s/'//g"
| makemv delim="," related_vulnerabilities
| eval RV = mvindex(related_vulnerabilities,0)
| stats count(related_vulnerabilities) as related_vulnerabilities, values(info_class) as info_class by info_name
| table info_name info_class related_vulnerabilities

once u got what u needed .. please accept the answer 🙂 ..

rkassabov
Path Finder

Brilliant, thanks!

0 Karma

Shan
Builder

@rkassabov

your welcome. Thank you..
Happy Splunking 🙂

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!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...