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
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...