Splunk Search

How to filter number from text with regular expression

dabroma5
Explorer

Hi,

I have two types of messages, I would like to receive the numbers from these logs :

2020-03-16 15:12:15,304 services/text123456: Periodic connection check - 1659 active services!
2020-03-16 15:11:56,173 services/textabcdef: NUMBER OF ACTIVE services: 1123

Thanks for help

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

This regex works with your examples. (?:check - |services: )(?<services>\d+)

---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

rmmiller
Contributor

As a first cut, add these lines to the end of your current search:

| rex field=_raw "Periodic\sconnection\scheck\s\-\s(?<num_active_svcs_chkd>\d+)\sactive\sservices"
| rex field=_raw "NUMBER\sOF\sACTIVE\sservices\:\s(?<num_active_svcs>\d+)"

This will give you 2 new fields, num_active_svcs_chkd and num_active_svcs. Theses names are completely arbitrary -- you can change them to suit your needs.

Once you're happy with how these extractions are going, work with your Splunk admin to get these added into props.conf.

Hope that helps!
rmmiller

0 Karma

richgalloway
SplunkTrust
SplunkTrust

This regex works with your examples. (?:check - |services: )(?<services>\d+)

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...