Splunk Search

How can I search not only filter messages also couple of messages around it?

Uday1
New Member

How can I search not only filter messages also couple of messages around it?

Labels (1)
0 Karma

Uday1
New Member

For example I want to search acc=9045 and also events before and after in the event pipeline 
index="abc" | search app_name="*my_app*" | ??



0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Here is a runanywhere example demonstrating a technique for finding events either side of acc 9045

| makeresults count=100 
| streamstats count as row
| eval acc=9045 + random()%10
``` the lines above set up some dummy data ```
| eval flag=if(acc=9045,1,null()) ``` flag the events you are interested in ```
| streamstats count(flag) as after reset_before=acc=9045 ``` count the flags - all this really does is set field to zero until the first flag, and to one from the first flag ```
| streamstats sum(after) as after reset_before=acc=9045 ``` sum the previous ones to give a running count - reset count when the event you are interested in appears ```
| reverse ``` reverse the pipeline to count in the opposite direction ```
| streamstats count(flag) as before reset_before=acc=9045 ``` count the flags - all this really does is set field to zero until the first flag, and to one from the first flag ```
| streamstats sum(before) as before reset_before=acc=9045 ``` sum the previous ones to give a running count - reset count when the event you are interested in appears ```
| where before==1 OR before==2 OR after==2 ``` keep events either side of the events of interest ```
0 Karma

isoutamo
SplunkTrust
SplunkTrust

Hi

Maybe not what you are looking for, but one way to try to find events just before and after selected events is just search and select Time field. That opens on pop up where you can set some time values for next search. But remember that if you have some earliest/latest on cmd line then those override this settings.

isoutamo_0-1685952924915.png

r. Ismo

0 Karma

Uday1
New Member

Can you please provide  some example

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You need to be more specific - when you say "around it", do you mean events before and after in the event pipeline?

You need to identify the events you are interested in, then count the events afterwards with streamstats; then reverse the events pipeline and count the events afterwards in that direction with streamstats. then filter by counts.

0 Karma

Uday1
New Member

Yes I mean events before and after in the event pipeline

 

0 Karma
Get Updates on the Splunk Community!

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...

Everything Community at .conf24!

You may have seen mention of the .conf Community Zone 'round these parts and found yourself wondering what ...

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...