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

[backend] Improv tracing for tanium endpoint #1927

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.openbas.executors.tanium.client;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.openbas.executors.tanium.config.TaniumExecutorConfig;
Expand All @@ -8,7 +9,9 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import lombok.RequiredArgsConstructor;
import lombok.extern.java.Log;
import org.apache.hc.client5.http.ClientProtocolException;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
Expand All @@ -19,6 +22,7 @@

@RequiredArgsConstructor
@Service
@Log
public class TaniumExecutorClient {

private static final String KEY_HEADER = "session";
Expand Down Expand Up @@ -52,8 +56,19 @@ public DataEndpoints endpoints() {
Map<String, Object> body = new HashMap<>();
body.put("query", query);
String jsonResponse = this.post(body);
if (jsonResponse == null || jsonResponse.isEmpty()) {
log.log(Level.SEVERE, "Received empty response from API for query: {}", query);
throw new RuntimeException("API returned an empty response");
}
return this.objectMapper.readValue(jsonResponse, new TypeReference<>() {});
} catch (JsonProcessingException e) {
log.log(Level.SEVERE, "Failed to parse JSON response. Error: {}", e.getMessage());
throw new RuntimeException(e);
} catch (IOException e) {
log.log(Level.SEVERE, "I/O error occurred during API request. Error: {}", e.getMessage());
throw new RuntimeException(e);
} catch (Exception e) {
log.log(Level.SEVERE, "Unexpected error occurred. Error: {}", e.getMessage());
throw new RuntimeException(e);
}
}
Expand Down