Dashboards & Visualizations

JavaScript To create a saved search

qfjp
Explorer

// Retrieve the collection of saved searches

var mySavedSearches = service.savedSearches();

// Specify a name and search query

var searchName = "Test Search";

// Note: Do not include the 'search' keyword for a saved search

var searchQuery = "* | head 10";

// Create the saved search

mySavedSearches.create({
name: searchName,
search: searchQuery
}, function(err, newSearch) {
console.log("A new saved search was created");
});

Do not know is that in the above function.
How do I set time and schedule?

jameshgibson
Path Finder

You need to set a few more options, here is an example that would schedule the job to run every 10mins over the previous month.

opts = { name: "searchname", 
         search: "* | head 10", 
         is_scheduled: 1, 
         cron_schedule: "*/10 * * * *",
         'dispatch.earliest_time': '-1mon@d',
         'dispatch.latest_time': 'now',
};


mySavedSearches.create(opts, function(err, newSearch) {
    console.log("created!");
}); 
0 Karma

jameshgibson
Path Finder

your welcome, please feel free to vote the answer up or accept 😉

0 Karma

qfjp
Explorer

Thanks!! Were very helpful.

0 Karma

linu1988
Champion

Please refer this documentation for the Savedsearch parameters:

_http://dev.splunk.com/view/SP-CAAAEKZ

0 Karma
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 ...