Splunk Search

How do I list valid sids for a loadjob command programmatically/by subsearch?

hylam
Contributor
| loadjob <sid> savedsearch="admin:search:test2"

sids looks like the epoch time of the job start time. How do I list them? Can I run a subsearch to list them and pick the 5th one? Can I run a subsearch to list them and pick a random one?

Tags (3)
0 Karma
1 Solution

MuS
Legend

Hi hylam,

assuming your saved search is named foo...

How do I list them?

 index=_audit savedsearch_name="foo" search_id='scheduler_*' 

Can I run a subsearch to list them and pick the 5th one?

 | loadjob [ search index=_audit savedsearch_name="foo" search_id='scheduler_*' | fields _time, search_id | sort - _time | head 5 | tail 1 | rename search_id AS search | eval search=replace(search, "\'","")  ]

Can I run a subsearch to list them and pick a random one?

| loadjob [ search index=_audit savedsearch_name="foo" search_id='scheduler_*' | fields _time, search_id | sort - _time  |  eval random=random() | eval random=substr(random, 1, 1) | table search_id, random | dedup random | where random="7" | rename search_id AS search | eval search=replace(search, "\'","") | fields - random ]

Some messy work around since tail and head don't like to use $boo$ values 😉

Hope this helps ...

cheers, MuS

View solution in original post

MuS
Legend

Hi hylam,

assuming your saved search is named foo...

How do I list them?

 index=_audit savedsearch_name="foo" search_id='scheduler_*' 

Can I run a subsearch to list them and pick the 5th one?

 | loadjob [ search index=_audit savedsearch_name="foo" search_id='scheduler_*' | fields _time, search_id | sort - _time | head 5 | tail 1 | rename search_id AS search | eval search=replace(search, "\'","")  ]

Can I run a subsearch to list them and pick a random one?

| loadjob [ search index=_audit savedsearch_name="foo" search_id='scheduler_*' | fields _time, search_id | sort - _time  |  eval random=random() | eval random=substr(random, 1, 1) | table search_id, random | dedup random | where random="7" | rename search_id AS search | eval search=replace(search, "\'","") | fields - random ]

Some messy work around since tail and head don't like to use $boo$ values 😉

Hope this helps ...

cheers, MuS

Get Updates on the Splunk Community!

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

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...