Splunk Search

how to use top alongside with tstats

romanpro
Explorer

how can I use top command after migrating to tstats? I need the same result, but looks like it can be done only using top, so I need it

index IN (add_on_builder_index, ba_test, cim_modactions, cisco_duo, cisco_etd, cisco_multicloud_defense, cisco_secure_fw, cisco_sfw_ftd_syslog, cisco_sma, cisco_sna, cisco_xdr, duo, encore, fw_syslog, history, ioc, main, mcd, mcd_syslog, notable, notable_summary, resource_usage_test_index, risk, secure_malware_analytics, sequenced_events, summary, threat_activity, ubaroute, ueba, whois) sourcetype="cisco:sma:submissions" status IN ("*")
| rename analysis.threat_score AS ats
| where isnum(ats)
| eval ats_num=tonumber(ats)
| eval selected_ranges="*"
| eval token_score="*"
| eval within_selected_range=0
| rex field=selected_ranges "(?<start>\d+)-(?<end>\d+)"
| eval start=tonumber(start), end=tonumber(end)
| eval within_selected_range=if(
(ats_num >= start AND ats_num <= end) OR token_score="*",
1,
within_selected_range
)
| where within_selected_range=1
| rename "analysis.behaviors{}.title" as "Behavioral indicator"
| top limit=10 "Behavioral indicator"


I tried this but it doesnt return me percent

| tstats prestats=true count as Count from datamodel=Cisco_Security.Secure_Malware_Analytics_Dataset where index IN (add_on_builder_index, ba_test, cim_modactions, cisco_duo, cisco_etd, cisco_multicloud_defense, cisco_secure_fw, cisco_sfw_ftd_syslog, cisco_sma, cisco_sna, cisco_xdr, duo, encore, fw_syslog, history, ioc, main, mcd, mcd_syslog, notable, notable_summary, resource_usage_test_index, risk, secure_malware_analytics, sequenced_events, summary, threat_activity, ubaroute, ueba, whois) sourcetype="cisco:sma:submissions" Secure_Malware_Analytics_Dataset.status IN ("*") by Secure_Malware_Analytics_Dataset.analysis_behaviors_title
| chart count by Secure_Malware_Analytics_Dataset.analysis_behaviors_title
| sort - count | head 20

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Not sure why you are using prestats=true - try something like this

| tstats count as Count from datamodel=Cisco_Security.Secure_Malware_Analytics_Dataset where index IN (add_on_builder_index, ba_test, cim_modactions, cisco_duo, cisco_etd, cisco_multicloud_defense, cisco_secure_fw, cisco_sfw_ftd_syslog, cisco_sma, cisco_sna, cisco_xdr, duo, encore, fw_syslog, history, ioc, main, mcd, mcd_syslog, notable, notable_summary, resource_usage_test_index, risk, secure_malware_analytics, sequenced_events, summary, threat_activity, ubaroute, ueba, whois) sourcetype="cisco:sma:submissions" Secure_Malware_Analytics_Dataset.status IN ("*") by Secure_Malware_Analytics_Dataset.analysis_behaviors_title
| eventstats sum(Count) as Total
| eval Percent=100*Count/Total
| sort - Count | head 20
0 Karma

romanpro
Explorer

good try, but it skipped the list of the titles I have in my input query, I have a correct output of counts, but without titles

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

I don't know what this means, please can you show what you are getting and what you expected to get?

0 Karma

romanpro
Explorer

here's what I get from my previous query, and what I expect to get

Environment Convicted Not Convicted

Environmentconvictednot convicted
browser812
win1079250
win10-x64-2-beta0117
win10-x64-browser126
win7-x642832

here's what I get from the query you provided, I hope it helps

Secure_Malware_Analytics_Dataset.analysis_behaviors_title Count Percent Total

Secure_Malware_Analytics_Dataset.analysis_behaviors_titlecountpercenttotal
Executable Imported the IsDebuggerPresent Symbol83514.4214162348877375790
PE Contains TLS Callback Entries69011.9170984455958555790
Executable with Encrypted Sections62210.74265975820385790
Executable Artifact Imports Tool Help Functions4287.3920552677029365790
PE Checksum is Invalid4036.9602763385146815790
Artifact With Multiple Extensions Detected3646.2867012089810025790
Executable Signed With Digital Certificate2774.7841105354058735790
Process Modified File in a User Directory2504.3177892918825565790
Executable Signing Date Invalid2203.79965457685664945790
Possible Registry Persistence Mechanism Detected1402.41796200345423135790
PE DOS Header Initial SP Value is Abnormal1382.3834196891191715790
Static Analysis Flagged Artifact As Anomalous861.48531951640759945790
Windows Crash Tool Execution Detected851.4680483592400695790
Artifact Flagged Malicious by Antivirus Service811.39896373056994835790
A Crash Dump File Was Created771.32987910189982735790
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Is what you expected to get what you got from your non-tstats search?

0 Karma

romanpro
Explorer

correct

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

So your conversion to tstats is not complete then? Using the data you get back from tstats is there sufficient information for you to compile the results you want (or do you need a different version of the tstats search?

0 Karma

romanpro
Explorer

this is exactly why I'm here. My tstats query isn't completed, I need this data to be shown in logs as it used to be in my usual query (non-tstats one)

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Without seeing your events it is difficult to determine what you need to do with the tstats to get the data you want.

0 Karma

romanpro
Explorer

I thought showing my logs is enough with that in mind  I need the exact command to be there

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Where did you show your events?

0 Karma

romanpro
Explorer

I need this query to use top command, but looks like it should be rewritten first in some kind of way 

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...