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
SplunkTrust
SplunkTrust

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
SplunkTrust
SplunkTrust

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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...