Reporting

saved search index

mdmaala
Communicator

is there a way that I can save a search that is common to all, so that when I ran it to make another search I wont have to include it in the search bar again? also to optimize the searching and make it faster

my search goes like this:
for machine 1:
source="C:\Users\Administrator\Documents\PATLITE\*" host="DESKTOP-G546H69" sourcetype="csv"
| rename "Green information" AS "Green" | rename "Amber information" AS "Yellow" | rename "Red information" AS "Red" | rename "User name" AS Username
| fields Date_Time, Username, Green, Yellow, Red |rex field=Date_Time "(?P\d{4}\/\d{2}\/\d{2})\s(?P\d{2}:\d{2}:\d{2})"
|sort -Time
|table Time, Username, Green, Yellow, Red

|search Username="Machine1"
|dedup Time
|sort 0 Time Username Green Yellow Red
|eval Time=strptime(Time, "%H:%M:%S")
|streamstats window=1 current=f last(Time) as prevTime last(Green) as cGREEN last(Yellow) as cYELLOW last(Red) as cRED by Username
|eval Duration=round(Time-prevTime)
|eval Duration = tostring(Duration, "Duration")
|eval Time=strftime(Time,"%H:%M:%S")
|eval prevTime=strftime(prevTime,"%H:%M:%S")
|table Duration cGREEN cYELLOW cRED

for machine 2:
source="C:\Users\Administrator\Documents\PATLITE\*" host="DESKTOP-G546H69" sourcetype="csv"
| rename "Green information" AS "Green" | rename "Amber information" AS "Yellow" | rename "Red information" AS "Red" | rename "User name" AS Username
| fields Date_Time, Username, Green, Yellow, Red |rex field=Date_Time "(?P\d{4}\/\d{2}\/\d{2})\s(?P\d{2}:\d{2}:\d{2})"
|sort -Time
|table Time, Username, Green, Yellow, Red

|search Username="Machine2"
|dedup Time
|sort 0 Time Username Green Yellow Red
|eval Time=strptime(Time, "%H:%M:%S")
|streamstats window=1 current=f last(Time) as prevTime last(Green) as cGREEN last(Yellow) as cYELLOW last(Red) as cRED by Username
|eval Duration=round(Time-prevTime)
|eval Duration = tostring(Duration, "Duration")
|eval Time=strftime(Time,"%H:%M:%S")
|eval prevTime=strftime(prevTime,"%H:%M:%S")
|table Duration cGREEN cYELLOW cRED

the ones in bold are the ones I want to save

0 Karma
1 Solution

nickhills
Ultra Champion

What you are describing is a macro. See here:
https://docs.splunk.com/Documentation/Splunk/7.2.4/Knowledge/Usesearchmacros

You create a macro which contains the first part of your search, and then run it with:

`my_macro`|search Username="Machine2" .....
If my comment helps, please give it a thumbs up!

View solution in original post

nickhills
Ultra Champion

What you are describing is a macro. See here:
https://docs.splunk.com/Documentation/Splunk/7.2.4/Knowledge/Usesearchmacros

You create a macro which contains the first part of your search, and then run it with:

`my_macro`|search Username="Machine2" .....
If my comment helps, please give it a thumbs up!

mdmaala
Communicator

thank you so much i'll try this!

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, ...