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!

Exciting News: The AppDynamics Community Joins Splunk!

Hello Splunkers,   I’d like to introduce myself—I’m Ryan, the former AppDynamics Community Manager, and I’m ...

The All New Performance Insights for Splunk

Splunk gives you amazing tools to analyze system data and make business-critical decisions, react to issues, ...

Good Sourcetype Naming

When it comes to getting data in, one of the earliest decisions made is what to use as a sourcetype. Often, ...