-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathUpdateLogsCustomDestination_213195663.java
More file actions
54 lines (49 loc) · 2.74 KB
/
UpdateLogsCustomDestination_213195663.java
File metadata and controls
54 lines (49 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Update a Splunk custom destination with a sourcetype returns "OK" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.LogsCustomDestinationsApi;
import com.datadog.api.client.v2.model.CustomDestinationForwardDestination;
import com.datadog.api.client.v2.model.CustomDestinationForwardDestinationSplunk;
import com.datadog.api.client.v2.model.CustomDestinationForwardDestinationSplunkType;
import com.datadog.api.client.v2.model.CustomDestinationResponse;
import com.datadog.api.client.v2.model.CustomDestinationType;
import com.datadog.api.client.v2.model.CustomDestinationUpdateRequest;
import com.datadog.api.client.v2.model.CustomDestinationUpdateRequestAttributes;
import com.datadog.api.client.v2.model.CustomDestinationUpdateRequestDefinition;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsCustomDestinationsApi apiInstance = new LogsCustomDestinationsApi(defaultClient);
// there is a valid "custom_destination_splunk" in the system
String CUSTOM_DESTINATION_SPLUNK_DATA_ID = System.getenv("CUSTOM_DESTINATION_SPLUNK_DATA_ID");
CustomDestinationUpdateRequest body =
new CustomDestinationUpdateRequest()
.data(
new CustomDestinationUpdateRequestDefinition()
.attributes(
new CustomDestinationUpdateRequestAttributes()
.forwarderDestination(
new CustomDestinationForwardDestination(
new CustomDestinationForwardDestinationSplunk()
.type(
CustomDestinationForwardDestinationSplunkType
.SPLUNK_HEC)
.endpoint("https://example.com")
.accessToken("my-access-token")
.sourcetype("new-sourcetype"))))
.type(CustomDestinationType.CUSTOM_DESTINATION)
.id(CUSTOM_DESTINATION_SPLUNK_DATA_ID));
try {
CustomDestinationResponse result =
apiInstance.updateLogsCustomDestination(CUSTOM_DESTINATION_SPLUNK_DATA_ID, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println(
"Exception when calling LogsCustomDestinationsApi#updateLogsCustomDestination");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}