-
Notifications
You must be signed in to change notification settings - Fork 54
/
CreateLogsCustomDestination_141236188.go
56 lines (50 loc) · 2.04 KB
/
CreateLogsCustomDestination_141236188.go
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
55
56
// Create an Elasticsearch custom destination returns "OK" response
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
)
func main() {
body := datadogV2.CustomDestinationCreateRequest{
Data: &datadogV2.CustomDestinationCreateRequestDefinition{
Attributes: datadogV2.CustomDestinationCreateRequestAttributes{
Enabled: datadog.PtrBool(false),
ForwardTags: datadog.PtrBool(false),
ForwardTagsRestrictionList: []string{
"datacenter",
"host",
},
ForwardTagsRestrictionListType: datadogV2.CUSTOMDESTINATIONATTRIBUTETAGSRESTRICTIONLISTTYPE_ALLOW_LIST.Ptr(),
ForwarderDestination: datadogV2.CustomDestinationForwardDestination{
CustomDestinationForwardDestinationElasticsearch: &datadogV2.CustomDestinationForwardDestinationElasticsearch{
Auth: datadogV2.CustomDestinationElasticsearchDestinationAuth{
Username: "my-username",
Password: "my-password",
},
IndexName: "nginx-logs",
IndexRotation: datadog.PtrString("yyyy-MM-dd"),
Endpoint: "https://example.com",
Type: datadogV2.CUSTOMDESTINATIONFORWARDDESTINATIONELASTICSEARCHTYPE_ELASTICSEARCH,
}},
Name: "Nginx logs",
Query: datadog.PtrString("source:nginx"),
},
Type: datadogV2.CUSTOMDESTINATIONTYPE_CUSTOM_DESTINATION,
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV2.NewLogsCustomDestinationsApi(apiClient)
resp, r, err := api.CreateLogsCustomDestination(ctx, body)
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `LogsCustomDestinationsApi.CreateLogsCustomDestination`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `LogsCustomDestinationsApi.CreateLogsCustomDestination`:\n%s\n", responseContent)
}