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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...