Splunk Search

How to REX an entire line if it contains a keyword

like2splunk
Explorer

I want to REX an entire line if it contains a particular keyword. The event looks like this:

2017-03-08 10:34:34,067 [ WARN] {Application Queue} (com.iba.tcs.beam.bds.devices.impl.gateway.rpc.ScanningControllerProxy) - ScanningController failure: NECU Transitioned to Error State
NECU Error: [0x0] _SynchronizationSGCUTimeout : Timeslice: 163 Submap: 83
FCU Error: [0x0] _SynchronizationSGCUTimeout : Timeslice: 163 Submap: 83
RCU Error: [0x1] Threshold Violation : Timeslice: 162 Submap: 83
(X_VOLT_SEC_FB: -1.858963 V MapThresholdLow: -6.005e-02 MapThresholdHigh: 4.256e-01)
SGCU Error: [0x10] _FilteringAbsolute : Timeslice: 159 Submap: 83
(MIN_CHARGE_PRIM: 6.159e-10 C AbsoluteThresholdLow: 7.119e-10 AbsoluteThresholdHigh: 7.569e-10)

This is one single event (one timestamp) with five total lines. I want to rex each one of the errors separately but I need to preserve the label. For example, I want the following the be the result of the rex from this event:

FCU Error: [0x0] _SynchronizationSGCUTimeout : Timeslice: 163 Submap: 83

In this case, the keyword is "FCU Error" but I need to keep that string instead of rexing everything after this string.
How do I rex the entire line if it matches this keyword?

Tags (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

This works for me in regex101.com:

(?<error>FCU Error: .*)
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

somesoni2
Revered Legend

How about this?
If the order of different types of error is fixed, they try like this

Your base search
| rex "NECU Error:\s*(?<NECU_ERROR>.+)([\r\n]+)FCU Error:\s*(?<FCU_Error>.+)([\r\n]+)RCU Error:\s*(?<RCU_Error>.+)([\r\n]+)SGCU Error:\s*(?<SGCU_Error>.+)"

If not then, try like htis

your base search
| rex "NECU Error:\s*(?<NECU_ERROR>.+)"
| rex "FCU Error:\s*(?<FCU_Error>.+)"
| rex "RCU Error:\s*(?<RCU_Error>.+)"
| rex "SGCU Error:\s*(?<SGCU_Error>.+)"
0 Karma

richgalloway
SplunkTrust
SplunkTrust

This works for me in regex101.com:

(?<error>FCU Error: .*)
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...