Skip to content

Commit

Permalink
PP-893: disable splunk preview doesnt work. filter preview instead
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhaller committed Mar 3, 2021
1 parent b064387 commit 263849a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public class SplunkResponse {
private Boolean preview;
private SplunkResult result;

private SplunkResult result;
public Boolean getPreview() {
return preview;
}

public SplunkResult getResult() {
return result;
}
public void setPreview(Boolean preview) {
this.preview = preview;
}

public void setResult(SplunkResult result) {
this.result = result;
}
public SplunkResult getResult() {
return result;
}

@Override
public String toString() {
return "SplunkResponse [result=" + result + "]";
}
public void setResult(SplunkResult result) {
this.result = result;
}

@Override
public String toString() {
return "SplunkResponse{" + "preview=" + preview + ", result=" + result + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ private MultiValueMap<String, String> createRequestParams(String query) {
params.add("earliest_time", "-" + daysBack + "d@d");
params.add("latest_time", "-" + queryEndDaysBack + "d@d");
params.add("output_mode", "json");
params.add("preview", "false");
return params;
}

Expand All @@ -283,7 +282,6 @@ private MultiValueMap<String, String> createRequestParamsForLastXDays(String que
params.add("earliest_time", "-" + daysBack + "d@d");
params.add("latest_time", "now");
params.add("output_mode", "json");
params.add("preview", "false");
return params;
}

Expand All @@ -306,14 +304,16 @@ private List<SplunkResult> extractResultFromSplunkApiString(String splunkApiResp
throws JsonMappingException, JsonProcessingException {
String sanitizedSplunkApiStrint = splunkApiResponse.replaceAll("\"NO_DATA\"", "null");
ObjectMapper om = new ObjectMapper();
List<SplunkResult> result = new ArrayList<>();
List<SplunkResult> results = new ArrayList<>();
String[] lines = sanitizedSplunkApiStrint.split("\\n");
for (String line : lines) {
SplunkResponse response = om.readValue(line, SplunkResponse.class);
result.add(response.getResult());
if (!Boolean.TRUE.equals(response.getPreview())) {
results.add(response.getResult());
}
}
Collections.sort(
result, Collections.reverseOrder(Comparator.comparing(SplunkResult::getTime)));
return result;
results, Collections.reverseOrder(Comparator.comparing(SplunkResult::getTime)));
return results;
}
}

0 comments on commit 263849a

Please sign in to comment.