|
99 | 99 | PATH_INDEXES = "data/indexes/" |
100 | 100 | PATH_INPUTS = "data/inputs/" |
101 | 101 | PATH_JOBS = "search/jobs/" |
| 102 | +PATH_JOBS_V2 = "search/v2/jobs/" |
102 | 103 | PATH_LOGGER = "/services/server/logger/" |
103 | 104 | PATH_MESSAGES = "messages/" |
104 | 105 | PATH_MODULAR_INPUTS = "data/modular-inputs" |
@@ -2658,10 +2659,10 @@ def oneshot(self, path, **kwargs): |
2658 | 2659 |
|
2659 | 2660 |
|
2660 | 2661 | class Job(Entity): |
| 2662 | + |
2661 | 2663 | """This class represents a search job.""" |
2662 | 2664 | def __init__(self, service, sid, **kwargs): |
2663 | | - path = PATH_JOBS + sid |
2664 | | - Entity.__init__(self, service, path, skip_refresh=True, **kwargs) |
| 2665 | + Entity.__init__(self, service, '', skip_refresh=True, **kwargs) |
2665 | 2666 | self.sid = sid |
2666 | 2667 |
|
2667 | 2668 | # The Job entry record is returned at the root of the response |
@@ -2714,8 +2715,13 @@ def events(self, **kwargs): |
2714 | 2715 | :return: The ``InputStream`` IO handle to this job's events. |
2715 | 2716 | """ |
2716 | 2717 | kwargs['segmentation'] = kwargs.get('segmentation', 'none') |
2717 | | - kwargs.pop('search', None) |
2718 | | - return self.get("events", **kwargs).body |
| 2718 | + path = "{path}{sid}/events" |
| 2719 | + |
| 2720 | + # Splunk version doesn't support v2 (pre-9.0) or the 'search' arg is included (which is v1 specific) |
| 2721 | + if self.splunk_version < (9,) or 'search' in kwargs: |
| 2722 | + return self.get(path.format(PATH_JOBS, self.sid), **kwargs).body |
| 2723 | + else: |
| 2724 | + return self.get(path.format(PATH_JOBS_V2, self.sid), **kwargs).body |
2719 | 2725 |
|
2720 | 2726 | def finalize(self): |
2721 | 2727 | """Stops the job and provides intermediate results for retrieval. |
@@ -2803,8 +2809,13 @@ def results(self, **query_params): |
2803 | 2809 | :return: The ``InputStream`` IO handle to this job's results. |
2804 | 2810 | """ |
2805 | 2811 | query_params['segmentation'] = query_params.get('segmentation', 'none') |
2806 | | - query_params.pop('search', None) |
2807 | | - return self.get("results", **query_params).body |
| 2812 | + path = "{path}{sid}/results" |
| 2813 | + |
| 2814 | + # Splunk version doesn't support v2 (pre-9.0) or the 'search' arg is included (which is v1 specific) |
| 2815 | + if self.splunk_version < (9,) or 'search' in query_params: |
| 2816 | + return self.get(path.format(PATH_JOBS, self.sid), **query_params).body |
| 2817 | + else: |
| 2818 | + return self.get(path.format(PATH_JOBS_V2, self.sid), **query_params).body |
2808 | 2819 |
|
2809 | 2820 | def preview(self, **query_params): |
2810 | 2821 | """Returns a streaming handle to this job's preview search results. |
@@ -2845,8 +2856,13 @@ def preview(self, **query_params): |
2845 | 2856 | :return: The ``InputStream`` IO handle to this job's preview results. |
2846 | 2857 | """ |
2847 | 2858 | query_params['segmentation'] = query_params.get('segmentation', 'none') |
2848 | | - query_params.pop('search', None) |
2849 | | - return self.get("results_preview", **query_params).body |
| 2859 | + path = "{path}{sid}/results_preview" |
| 2860 | + |
| 2861 | + # Splunk version doesn't support v2 (pre-9.0) or the 'search' arg is included (which is v1 specific) |
| 2862 | + if self.splunk_version < (9,) or 'search' in query_params: |
| 2863 | + return self.get(path.format(PATH_JOBS, self.sid), **query_params).body |
| 2864 | + else: |
| 2865 | + return self.get(path.format(PATH_JOBS_V2, self.sid), **query_params).body |
2850 | 2866 |
|
2851 | 2867 | def searchlog(self, **kwargs): |
2852 | 2868 | """Returns a streaming handle to this job's search log. |
@@ -2935,7 +2951,12 @@ class Jobs(Collection): |
2935 | 2951 | """This class represents a collection of search jobs. Retrieve this |
2936 | 2952 | collection using :meth:`Service.jobs`.""" |
2937 | 2953 | def __init__(self, service): |
2938 | | - Collection.__init__(self, service, PATH_JOBS, item=Job) |
| 2954 | + # Splunk 9 introduces the v2 endpoint |
| 2955 | + if self.splunk_version >= (9,): |
| 2956 | + path = PATH_JOBS_V2 |
| 2957 | + else: |
| 2958 | + path = PATH_JOBS |
| 2959 | + Collection.__init__(self, service, path, item=Job) |
2939 | 2960 | # The count value to say list all the contents of this |
2940 | 2961 | # Collection is 0, not -1 as it is on most. |
2941 | 2962 | self.null_count = 0 |
|
0 commit comments