diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6ff012f8..d4cdce89 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,8 @@ jobs: server-id: splunk-artifactory - name: build run: mvn package --file pom.xml -DskipTests=true + - name: Create temp artifacts apidocs folder + run: mkdir apidocs - name: Create GitHub Release uses: softprops/action-gh-release@v1 with: @@ -32,3 +34,12 @@ jobs: env: MAVEN_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} MAVEN_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} + + - name: Zip docs + run: zip -r apidocs/docs.zip splunk/target/apidocs + + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: apidocs + path: apidocs/docs.zip diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1df987b9..84ca35c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: java-version: - 1.8 splunk-version: - - "8.0" + - "8.2" - "latest" runs-on: ${{ matrix.os }} diff --git a/README.md b/README.md index 77483b8a..fa72ab54 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Here's what you need to get going with the Splunk SDK for Java. If you haven't already installed Splunk, download it [here](http://www.splunk.com/download). For more about installing and running Splunk and system requirements, see -[Installing & Running Splunk](http://dev.splunk.com/view/SP-CAAADRV). The Splunk SDK for Java has been tested with Splunk Enterprise 8.0 and 8.2.0. +[Installing & Running Splunk](http://dev.splunk.com/view/SP-CAAADRV). The Splunk SDK for Java has been tested with Splunk Enterprise 9.0 and 8.2. #### Splunk SDK for Java diff --git a/splunk/pom.xml b/splunk/pom.xml index 4e0e361d..dd142867 100644 --- a/splunk/pom.xml +++ b/splunk/pom.xml @@ -71,7 +71,7 @@ org.jacoco jacoco-maven-plugin - 0.8.7 + 0.8.8 diff --git a/splunk/src/main/java/com/splunk/HttpService.java b/splunk/src/main/java/com/splunk/HttpService.java index ef7d335d..5f2ad877 100644 --- a/splunk/src/main/java/com/splunk/HttpService.java +++ b/splunk/src/main/java/com/splunk/HttpService.java @@ -208,7 +208,7 @@ public int getPort() { /** * Sets Custom Headers of this service * - * @param headers + * @param headers The custom headers. */ public void setCustomHeaders(Map headers) { if (Objects.nonNull(headers)) { diff --git a/splunk/src/main/java/com/splunk/Job.java b/splunk/src/main/java/com/splunk/Job.java index 3456b1e0..d101eeaf 100644 --- a/splunk/src/main/java/com/splunk/Job.java +++ b/splunk/src/main/java/com/splunk/Job.java @@ -35,6 +35,7 @@ public class Job extends Entity { * * @param service The connected {@code Service} instance. * @param path The search jobs endpoint. + * @param sid The sid of the job. */ Job(Service service, String path) { super(service, path); @@ -367,7 +368,19 @@ private InputStream getEventsMethod(String methodPath, Map args) { args.put("segmentation", "none"); } - ResponseMessage response = service.get(path + methodPath, args); + // Splunk version pre-9.0 doesn't support v2 + // v1(GET), v2(POST) + String fullPath; + ResponseMessage response; + if (service.versionIsEarlierThan("9.0")) { + fullPath = path.replace(JobCollection.REST_PATH_V2, JobCollection.REST_PATH) + methodPath; + response = service.get(fullPath, args); + } + else { + fullPath = path.replace(JobCollection.REST_PATH, JobCollection.REST_PATH_V2) + methodPath; + response = service.post(fullPath, args); + } + return response.getContent(); } diff --git a/splunk/src/main/java/com/splunk/JobCollection.java b/splunk/src/main/java/com/splunk/JobCollection.java index 529fb9da..b47feadc 100644 --- a/splunk/src/main/java/com/splunk/JobCollection.java +++ b/splunk/src/main/java/com/splunk/JobCollection.java @@ -27,13 +27,14 @@ public class JobCollection extends EntityCollection { static String oneShotNotAllowed = String.format( "Oneshot not allowed, use service oneshot search method"); static final String REST_PATH = "search/jobs"; + static final String REST_PATH_V2 = "search/v2/jobs"; /** * Class constructor. * * @param service The connected {@code Service} instance. */ JobCollection(Service service) { - super(service, REST_PATH, Job.class); + super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class); this.refreshArgs.put("count", "0"); } @@ -45,7 +46,7 @@ public class JobCollection extends EntityCollection { * return and how to sort them (see {@link CollectionArgs}). */ JobCollection(Service service, Args args) { - super(service, REST_PATH, Job.class, args); + super(service, service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH, Job.class, args); this.refreshArgs.put("count", "0"); } @@ -86,7 +87,8 @@ public Job create(String query, Map args) { .item(0) .getTextContent(); - Job job = new Job(service, REST_PATH + "/" + sid); + String path = service.versionIsAtLeast("9.0") ? REST_PATH_V2 : REST_PATH; + Job job = new Job(service, path + "/" + sid); job.refresh(); return job; diff --git a/splunk/src/main/java/com/splunk/OutputServer.java b/splunk/src/main/java/com/splunk/OutputServer.java index 2bcd19b3..cafec3f6 100644 --- a/splunk/src/main/java/com/splunk/OutputServer.java +++ b/splunk/src/main/java/com/splunk/OutputServer.java @@ -92,7 +92,7 @@ public String getStatus() { /** * Returns client certificate path. * - * @return + * @return Path of client certificate. */ public String getClientCert() { return getString("clientCert", ""); diff --git a/splunk/src/main/java/com/splunk/Service.java b/splunk/src/main/java/com/splunk/Service.java index 4f4edcad..cbe63b4a 100644 --- a/splunk/src/main/java/com/splunk/Service.java +++ b/splunk/src/main/java/com/splunk/Service.java @@ -223,7 +223,13 @@ public InputStream export(String search, Map args) { if (!args.containsKey("segmentation")) { args.put("segmentation", "none"); } - ResponseMessage response = get(JobCollection.REST_PATH + "/export", args); + ResponseMessage response; + + if (versionIsAtLeast("9.0")) + response = post(JobCollection.REST_PATH_V2 + "/export", args); + else { + response = post(JobCollection.REST_PATH + "/export", args); + } return new ExportResultsStream(response.getContent()); } @@ -1251,7 +1257,11 @@ public ResponseMessage parse(String query) { */ public ResponseMessage parse(String query, Map args) { args = Args.create(args).add("q", query); - return get("search/parser", args); + + if (versionIsAtLeast("9.0")) + return post("search/v2/parser", args); + else + return get("search/parser", args); } /** diff --git a/splunk/src/test/java/com/splunk/SearchJobTest.java b/splunk/src/test/java/com/splunk/SearchJobTest.java index 5993417d..fbb7cbce 100644 --- a/splunk/src/test/java/com/splunk/SearchJobTest.java +++ b/splunk/src/test/java/com/splunk/SearchJobTest.java @@ -62,6 +62,18 @@ public void testEventsFromJob() { job.cancel(); } + @Test + public void testEventsWithSearchParams() { + Job job = jobs.create(QUERY); + waitUntilDone(job); + + Map args = new HashMap(); + args.put("search","| head 1"); + Assert.assertEquals(1, countEvents(job.getEvents(args))); + + job.cancel(); + } + @Test public void testResultsFromJob() { Job job = jobs.create(QUERY); @@ -71,6 +83,18 @@ public void testResultsFromJob() { job.cancel(); } + + @Test + public void testResultsWithSearchParams() { + Job job = jobs.create(QUERY); + waitUntilDone(job); + + Map args = new HashMap(); + args.put("search","| head 1"); + Assert.assertEquals(1, countEvents(job.getResults(args))); + + job.cancel(); + } @Test public void testGetJobBySid() { @@ -584,6 +608,26 @@ public void testPreview() throws InterruptedException { job.cancel(); } + @Test + public void testPreviewWithSearchParams() throws InterruptedException { + JobArgs args = new JobArgs(); + args.put("field_list", "source,host,sourcetype"); + args.setStatusBuckets(100); + + Job job = jobs.create(QUERY, args); + + while (!job.isReady()) { + Thread.sleep(100); + } + + Map argsSearchQuery = new HashMap(); + argsSearchQuery.put("search","| head 1"); + // Assert.assertTrue(1 >= countEvents(job.getResultsPreview(args))); + Assert.assertEquals(1, countEvents(job.getResultsPreview(argsSearchQuery))); + + job.cancel(); + } + @Test public void testSearchLog() { Job job = jobs.create(QUERY);