Skip to content

Adding Args option fro Saved Search history method #126

Closed

Description

@vineethsoma

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

Activity

  1. shakeelmohamed commented on May 23, 2018

    @shakeelmohamed
    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).

  2. BalasubramanyamEvani commented on Nov 19, 2021

    @BalasubramanyamEvani
    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;
    }
  3. ashah-splunk commented on Jul 12, 2022

    @ashah-splunk
    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.

  4. ashah-splunk commented on Oct 6, 2022

    @ashah-splunk
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions