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!

Financial Services Industry Use Cases, ITSI Best Practices, and More New Articles ...

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

Splunk Federated Analytics for Amazon Security Lake

Thursday, November 21, 2024  |  11AM PT / 2PM ET Register Now Join our session to see the technical ...

Splunk With AppDynamics - Meet the New IT (And Engineering) Couple

Wednesday, November 20, 2024  |  10AM PT / 1PM ET Register Now Join us in this session to learn all about ...