Dashboards & Visualizations

Capture text between events

Kindred
Path Finder

I have some logs being indexed that contain the output from another program, and Splunk indexes like this:

Event 1:

commandOuput=
/some/random/command blah blah blah

Event 2:

line1 output from the command

Event 3:

line2 output from the command

Event XX:

lineXX output from the command

Event Z:

commandExitcode=0

I want to capture and concatenate all text between the first event, and the last event (Z). I've tried using transaction and matched the start with startswith and end with endswith, but that only seems to keep the start and end event, not the events inbetween.

Is there an easier way of just extracting the raw data between two events?

Tags (2)
0 Karma

MuS
Legend

Hi Kindred,

try something like this:

 your base search | rex field=_raw "Event\s1\:(?<myNewField).*)Event\sZ\:" | table myNewField

this will get everything between Event 1: and Event Z:.

hope this helps ...
cheers, MuS

0 Karma

Kindred
Path Finder

I tried, it doesn't change anything - it still only gives me the first event (startswith) and last events (endswith) - the events in between are not included.

0 Karma

MuS
Legend

take this run everywhere search and you will see that using _indextime works fine:

index=_internal source=*access.log | transaction clientip _indextime maxspan=5min

by using it with startswith and endswith you should be able to get what you want

0 Karma

Kindred
Path Finder

_indextime changes over the course of time as the command output is logged, so won't help unfortunately.

0 Karma

MuS
Legend

try using the _indextime field as additional transaction field if there is no other field in common over all events

0 Karma

Kindred
Path Finder

We don't have control over the "command output" that gets logged, so no way to tag it for consideration in the transaction - that's why I originally had trouble, I could match the start and end transaction events, but the text "in between" the events can't be correlated.

What I need is like saying "give me all the events between startswith=foo and endswith=bar regardless of whats in the events".

0 Karma

MuS
Legend

Sorry it is way to hot in the office to have a clear thought 😉 Now I see your problem, this pasted example is not the raw test of one event, those are different events facepalm
So keep the transaction with startswith and endswith and create or use a common field for all the other events you need. Add this field to the transaction command like this:

transaction startswith="commandOuput=" endswith="commandExitcode=0" thenewfield

where the newfield cound be for example a regex for line1 output

hope this makes sense now

0 Karma

Kindred
Path Finder

I can see what you're trying to do and I've done regex extractions before, but it still won't extract over multiple events - it only pulls out the first line of the first event.

0 Karma

MuS
Legend

My bad, there is a typo and a copy / paste error in it 😉

This one is tested with your provided example and it works:

"commandOuput=(\r)+(?<myField>(.+\r)+)(\r)+commandExitcode=0"
0 Karma

Kindred
Path Finder

That doesn't seem to match anything. If I remove commandExitcode then it matches the first line in the first event, but nothing after.

0 Karma

MuS
Legend

well, then try:

 your base search | rex field=_raw "commandOuput=(?<myNewField).*)commandExitcode=0" | table myNewField
0 Karma

Kindred
Path Finder

Sorry didn't meant "Event .." was in the text, I was just identifying them as different events from Splunk's point of view.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

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

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...