Splunk Search

Need help search tablename and count across multiple lines

Ckashton
New Member

I have data like this in splunk search

2024-10-29 20:14:49 (715) worker.6 worker.6 txid=XXXX JobPersistence Total records archived per table:
sn_vul_vulnerable_item: 1000
sn_vul_detection: 1167
Total records archived: 2167
Total related records archived: 1167

2024-10-29 20:13:17 (337) worker.0 worker.0 txid=YYYY JobPersistence Total records archived per table:
sn_vul_vulnerable_item: 1000
sn_vul_detection: 1066
Total records archived: 2066
Total related records archived: 1066

 

How can i prepare a table as below ? Basically prepare  a list of tables and sum of their counts between text "Total records archived per table:" and "Total records archived: "

sn_vul_vulnerable_item:2000

sn_vul_detection:2233

 

This is what i have so far

node=* "Total records archived per table" "Total related records archived:"
| rex field=_raw "Total records archived per table ((?m)[^\r\n]+)(?<tc_table>\S+): (?<tc_archived_count>\d+) Total related records archived:"

Labels (2)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Is this table what you are looking for?

sn_vul_detectionsn_vul_vulnerable_item
22332000

Here is a quick cheat:

 

| rex mode=sed "s/:\s*(\d+)\n/=\1\n/g"
| extract
| stats sum(sn_vul_*) as sn_vul_*

 

If you must have that colon-separated notation, add

 

| foreach *
    [eval notation = mvappend(notation, "<<FIELD>>: " . <<FIELD>>)]

 

Here is an emulation of your sample data.  Play with it and compare with real data

 

| makeresults
| eval data = mvappend("2024-10-29 20:14:49 (715) worker.6 worker.6 txid=XXXX JobPersistence Total records archived per table:
sn_vul_vulnerable_item: 1000
sn_vul_detection: 1167
Total records archived: 2167
Total related records archived: 1167",
"2024-10-29 20:13:17 (337) worker.0 worker.0 txid=YYYY JobPersistence Total records archived per table:
sn_vul_vulnerable_item: 1000
sn_vul_detection: 1066
Total records archived: 2066
Total related records archived: 1066")
| mvexpand data
| rename data as _raw
| eval _time = strptime(replace(_raw, "^(\S+ \S+).*", "\1"), "%F %T")
``` data emulation above ```

 

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

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

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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