Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Args option fro Saved Search history method #126

Closed
vineethsoma opened this issue May 3, 2018 · 4 comments
Closed

Adding Args option fro Saved Search history method #126

vineethsoma opened this issue May 3, 2018 · 4 comments

Comments

@vineethsoma
Copy link

Hello,
I have a use-case where I need to get the latest run of a scheduled saved search.

I know SavedSearch class has a history method which gets me all the old jobs runs. But it looks like the results are being paginated to the earliest 30 results.

The history method itself doesn't have any options to pass arguments for the GET call.

Is there any other way to achieve this? I know the REST API does support sort_dir=desc option for getting the history jobs in descending order.

I would also be happy to do these changes.

Thanks,

-Vineeth

@shakeelmohamed
Copy link
Contributor

Hi @vineethsoma,

This is a reasonable feature request. We're open to a pull request, and the change is pretty small to add support for this feature.

In SavedSearch we'd want to add an overload for history() that takes an Args map and passes it as the second argument to service.get(). Then in your code, you'd be able to pass in a map to the new history() overload with count set to whatever value you want (0 for all).

@BalasubramanyamEvani
Copy link
Contributor

I have made some changes. I think this should suffice. Please let me know if this works.

     public Job[] history() {
         ResponseMessage response = service.get(actionPath("history"));
-        AtomFeed feed;
+        return parseHistoryResponse(response);
+    }
+    
+    /**
+     * Returns an array of search jobs based on passed search arguments
+     * 
+     * @param args
+     * @return An array of search jobs
+     */
+    public Job[] history(Map<String, Object> args) {
+       ResponseMessage response = service.get(actionPath("history"), args);
+       return parseHistoryResponse(response);
+    }
+    
+    /**
+     * Parses response message from history action path
+     * 
+     * @param responseMessage
+     * @return result An array of Job
+     */
+    private Job[] parseHistoryResponse(final ResponseMessage responseMessage) {
+       AtomFeed feed;
         try {
-            feed = AtomFeed.parseStream(response.getContent());
+            feed = AtomFeed.parseStream(responseMessage.getContent());
         } catch (Exception e) {
             throw new RuntimeException(e);
         }
        int count = feed.entries.size();
        Job[] result = new Job[count];
        for (int i = 0; i < count; ++i) {
            String sid = feed.entries.get(i).title;
            result[i] = new Job(service, JobCollection.REST_PATH + "/" + sid);
        }
        return result;
}

@ashah-splunk
Copy link
Contributor

Hi @BalasubramanyamEvani, thank you for the sharing the code change.
@vineethsoma we have added the Args option and the same will be available in the Next SDK release.

@ashah-splunk
Copy link
Contributor

@BalasubramanyamEvani, @vineethsoma
we have added the "args" option for the Saved Search History method and it is available in the latest SDK. Hence closing this issue, please reopen the issue if you still face any issue regarding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants