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!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...