-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateLogsCustomDestination_3120242932.java
More file actions
53 lines (49 loc) · 2.66 KB
/
CreateLogsCustomDestination_3120242932.java
File metadata and controls
53 lines (49 loc) · 2.66 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
// Create a Splunk custom destination with an empty string 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.CustomDestinationCreateRequest;
import com.datadog.api.client.v2.model.CustomDestinationCreateRequestAttributes;
import com.datadog.api.client.v2.model.CustomDestinationCreateRequestDefinition;
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;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
LogsCustomDestinationsApi apiInstance = new LogsCustomDestinationsApi(defaultClient);
CustomDestinationCreateRequest body =
new CustomDestinationCreateRequest()
.data(
new CustomDestinationCreateRequestDefinition()
.attributes(
new CustomDestinationCreateRequestAttributes()
.enabled(false)
.forwardTags(false)
.forwarderDestination(
new CustomDestinationForwardDestination(
new CustomDestinationForwardDestinationSplunk()
.accessToken("my-access-token")
.endpoint("https://example.com")
.type(
CustomDestinationForwardDestinationSplunkType
.SPLUNK_HEC)
.sourcetype("")))
.name("Nginx logs")
.query("source:nginx"))
.type(CustomDestinationType.CUSTOM_DESTINATION));
try {
CustomDestinationResponse result = apiInstance.createLogsCustomDestination(body);
System.out.println(result);
} catch (ApiException e) {
System.err.println(
"Exception when calling LogsCustomDestinationsApi#createLogsCustomDestination");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}