Skip to content

Commit dd55c11

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add support for configuring Splunk sourcetype in Custom Destinations (DataDog#3883)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 333aa2a commit dd55c11

34 files changed

Lines changed: 1220 additions & 4 deletions

File tree

.generator/schemas/v2/openapi.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18216,6 +18216,16 @@ components:
1821618216
Must have HTTPS scheme and forwarding back to Datadog is not allowed.
1821718217
example: https://example.com
1821818218
type: string
18219+
sourcetype:
18220+
description: |-
18221+
The Splunk sourcetype for the events sent to this Splunk destination.
18222+
18223+
If absent, the default sourcetype `_json` is used. If set to null, the `sourcetype`
18224+
field is omitted from the Splunk HEC payload entirely. Otherwise, the provided string
18225+
value is used as the sourcetype.
18226+
example: my-source
18227+
nullable: true
18228+
type: string
1821918229
type:
1822018230
$ref: "#/components/schemas/CustomDestinationForwardDestinationSplunkType"
1822118231
required:
@@ -18491,6 +18501,16 @@ components:
1849118501
Must have HTTPS scheme and forwarding back to Datadog is not allowed.
1849218502
example: https://example.com
1849318503
type: string
18504+
sourcetype:
18505+
description: |-
18506+
The Splunk sourcetype for the events sent to this Splunk destination.
18507+
18508+
If absent, the default sourcetype `_json` is used. If set to null, the `sourcetype`
18509+
field is omitted from the Splunk HEC payload entirely. Otherwise, the provided string
18510+
value is used as the sourcetype.
18511+
example: my-source
18512+
nullable: true
18513+
type: string
1849418514
type:
1849518515
$ref: "#/components/schemas/CustomDestinationResponseForwardDestinationSplunkType"
1849618516
required:

api/datadogV2/model_custom_destination_forward_destination_splunk.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ type CustomDestinationForwardDestinationSplunk struct {
1717
// The destination for which logs will be forwarded to.
1818
// Must have HTTPS scheme and forwarding back to Datadog is not allowed.
1919
Endpoint string `json:"endpoint"`
20+
// The Splunk sourcetype for the events sent to this Splunk destination.
21+
//
22+
// If absent, the default sourcetype `_json` is used. If set to null, the `sourcetype`
23+
// field is omitted from the Splunk HEC payload entirely. Otherwise, the provided string
24+
// value is used as the sourcetype.
25+
Sourcetype datadog.NullableString `json:"sourcetype,omitempty"`
2026
// Type of the Splunk HTTP Event Collector (HEC) destination.
2127
Type CustomDestinationForwardDestinationSplunkType `json:"type"`
2228
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
@@ -92,6 +98,45 @@ func (o *CustomDestinationForwardDestinationSplunk) SetEndpoint(v string) {
9298
o.Endpoint = v
9399
}
94100

101+
// GetSourcetype returns the Sourcetype field value if set, zero value otherwise (both if not set or set to explicit null).
102+
func (o *CustomDestinationForwardDestinationSplunk) GetSourcetype() string {
103+
if o == nil || o.Sourcetype.Get() == nil {
104+
var ret string
105+
return ret
106+
}
107+
return *o.Sourcetype.Get()
108+
}
109+
110+
// GetSourcetypeOk returns a tuple with the Sourcetype field value if set, nil otherwise
111+
// and a boolean to check if the value has been set.
112+
// NOTE: If the value is an explicit nil, `nil, true` will be returned.
113+
func (o *CustomDestinationForwardDestinationSplunk) GetSourcetypeOk() (*string, bool) {
114+
if o == nil {
115+
return nil, false
116+
}
117+
return o.Sourcetype.Get(), o.Sourcetype.IsSet()
118+
}
119+
120+
// HasSourcetype returns a boolean if a field has been set.
121+
func (o *CustomDestinationForwardDestinationSplunk) HasSourcetype() bool {
122+
return o != nil && o.Sourcetype.IsSet()
123+
}
124+
125+
// SetSourcetype gets a reference to the given datadog.NullableString and assigns it to the Sourcetype field.
126+
func (o *CustomDestinationForwardDestinationSplunk) SetSourcetype(v string) {
127+
o.Sourcetype.Set(&v)
128+
}
129+
130+
// SetSourcetypeNil sets the value for Sourcetype to be an explicit nil.
131+
func (o *CustomDestinationForwardDestinationSplunk) SetSourcetypeNil() {
132+
o.Sourcetype.Set(nil)
133+
}
134+
135+
// UnsetSourcetype ensures that no value is present for Sourcetype, not even an explicit nil.
136+
func (o *CustomDestinationForwardDestinationSplunk) UnsetSourcetype() {
137+
o.Sourcetype.Unset()
138+
}
139+
95140
// GetType returns the Type field value.
96141
func (o *CustomDestinationForwardDestinationSplunk) GetType() CustomDestinationForwardDestinationSplunkType {
97142
if o == nil {
@@ -123,6 +168,9 @@ func (o CustomDestinationForwardDestinationSplunk) MarshalJSON() ([]byte, error)
123168
}
124169
toSerialize["access_token"] = o.AccessToken
125170
toSerialize["endpoint"] = o.Endpoint
171+
if o.Sourcetype.IsSet() {
172+
toSerialize["sourcetype"] = o.Sourcetype.Get()
173+
}
126174
toSerialize["type"] = o.Type
127175

128176
for key, value := range o.AdditionalProperties {
@@ -136,6 +184,7 @@ func (o *CustomDestinationForwardDestinationSplunk) UnmarshalJSON(bytes []byte)
136184
all := struct {
137185
AccessToken *string `json:"access_token"`
138186
Endpoint *string `json:"endpoint"`
187+
Sourcetype datadog.NullableString `json:"sourcetype,omitempty"`
139188
Type *CustomDestinationForwardDestinationSplunkType `json:"type"`
140189
}{}
141190
if err = datadog.Unmarshal(bytes, &all); err != nil {
@@ -152,14 +201,15 @@ func (o *CustomDestinationForwardDestinationSplunk) UnmarshalJSON(bytes []byte)
152201
}
153202
additionalProperties := make(map[string]interface{})
154203
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
155-
datadog.DeleteKeys(additionalProperties, &[]string{"access_token", "endpoint", "type"})
204+
datadog.DeleteKeys(additionalProperties, &[]string{"access_token", "endpoint", "sourcetype", "type"})
156205
} else {
157206
return err
158207
}
159208

160209
hasInvalidField := false
161210
o.AccessToken = *all.AccessToken
162211
o.Endpoint = *all.Endpoint
212+
o.Sourcetype = all.Sourcetype
163213
if !all.Type.IsValid() {
164214
hasInvalidField = true
165215
} else {

api/datadogV2/model_custom_destination_response_forward_destination_splunk.go

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ type CustomDestinationResponseForwardDestinationSplunk struct {
1515
// The destination for which logs will be forwarded to.
1616
// Must have HTTPS scheme and forwarding back to Datadog is not allowed.
1717
Endpoint string `json:"endpoint"`
18+
// The Splunk sourcetype for the events sent to this Splunk destination.
19+
//
20+
// If absent, the default sourcetype `_json` is used. If set to null, the `sourcetype`
21+
// field is omitted from the Splunk HEC payload entirely. Otherwise, the provided string
22+
// value is used as the sourcetype.
23+
Sourcetype datadog.NullableString `json:"sourcetype,omitempty"`
1824
// Type of the Splunk HTTP Event Collector (HEC) destination.
1925
Type CustomDestinationResponseForwardDestinationSplunkType `json:"type"`
2026
// UnparsedObject contains the raw value of the object if there was an error when deserializing into the struct
@@ -66,6 +72,45 @@ func (o *CustomDestinationResponseForwardDestinationSplunk) SetEndpoint(v string
6672
o.Endpoint = v
6773
}
6874

75+
// GetSourcetype returns the Sourcetype field value if set, zero value otherwise (both if not set or set to explicit null).
76+
func (o *CustomDestinationResponseForwardDestinationSplunk) GetSourcetype() string {
77+
if o == nil || o.Sourcetype.Get() == nil {
78+
var ret string
79+
return ret
80+
}
81+
return *o.Sourcetype.Get()
82+
}
83+
84+
// GetSourcetypeOk returns a tuple with the Sourcetype field value if set, nil otherwise
85+
// and a boolean to check if the value has been set.
86+
// NOTE: If the value is an explicit nil, `nil, true` will be returned.
87+
func (o *CustomDestinationResponseForwardDestinationSplunk) GetSourcetypeOk() (*string, bool) {
88+
if o == nil {
89+
return nil, false
90+
}
91+
return o.Sourcetype.Get(), o.Sourcetype.IsSet()
92+
}
93+
94+
// HasSourcetype returns a boolean if a field has been set.
95+
func (o *CustomDestinationResponseForwardDestinationSplunk) HasSourcetype() bool {
96+
return o != nil && o.Sourcetype.IsSet()
97+
}
98+
99+
// SetSourcetype gets a reference to the given datadog.NullableString and assigns it to the Sourcetype field.
100+
func (o *CustomDestinationResponseForwardDestinationSplunk) SetSourcetype(v string) {
101+
o.Sourcetype.Set(&v)
102+
}
103+
104+
// SetSourcetypeNil sets the value for Sourcetype to be an explicit nil.
105+
func (o *CustomDestinationResponseForwardDestinationSplunk) SetSourcetypeNil() {
106+
o.Sourcetype.Set(nil)
107+
}
108+
109+
// UnsetSourcetype ensures that no value is present for Sourcetype, not even an explicit nil.
110+
func (o *CustomDestinationResponseForwardDestinationSplunk) UnsetSourcetype() {
111+
o.Sourcetype.Unset()
112+
}
113+
69114
// GetType returns the Type field value.
70115
func (o *CustomDestinationResponseForwardDestinationSplunk) GetType() CustomDestinationResponseForwardDestinationSplunkType {
71116
if o == nil {
@@ -96,6 +141,9 @@ func (o CustomDestinationResponseForwardDestinationSplunk) MarshalJSON() ([]byte
96141
return datadog.Marshal(o.UnparsedObject)
97142
}
98143
toSerialize["endpoint"] = o.Endpoint
144+
if o.Sourcetype.IsSet() {
145+
toSerialize["sourcetype"] = o.Sourcetype.Get()
146+
}
99147
toSerialize["type"] = o.Type
100148

101149
for key, value := range o.AdditionalProperties {
@@ -107,8 +155,9 @@ func (o CustomDestinationResponseForwardDestinationSplunk) MarshalJSON() ([]byte
107155
// UnmarshalJSON deserializes the given payload.
108156
func (o *CustomDestinationResponseForwardDestinationSplunk) UnmarshalJSON(bytes []byte) (err error) {
109157
all := struct {
110-
Endpoint *string `json:"endpoint"`
111-
Type *CustomDestinationResponseForwardDestinationSplunkType `json:"type"`
158+
Endpoint *string `json:"endpoint"`
159+
Sourcetype datadog.NullableString `json:"sourcetype,omitempty"`
160+
Type *CustomDestinationResponseForwardDestinationSplunkType `json:"type"`
112161
}{}
113162
if err = datadog.Unmarshal(bytes, &all); err != nil {
114163
return datadog.Unmarshal(bytes, &o.UnparsedObject)
@@ -121,13 +170,14 @@ func (o *CustomDestinationResponseForwardDestinationSplunk) UnmarshalJSON(bytes
121170
}
122171
additionalProperties := make(map[string]interface{})
123172
if err = datadog.Unmarshal(bytes, &additionalProperties); err == nil {
124-
datadog.DeleteKeys(additionalProperties, &[]string{"endpoint", "type"})
173+
datadog.DeleteKeys(additionalProperties, &[]string{"endpoint", "sourcetype", "type"})
125174
} else {
126175
return err
127176
}
128177

129178
hasInvalidField := false
130179
o.Endpoint = *all.Endpoint
180+
o.Sourcetype = all.Sourcetype
131181
if !all.Type.IsValid() {
132182
hasInvalidField = true
133183
} else {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Create a Splunk custom destination with a sourcetype returns "OK" response
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
11+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
12+
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
13+
)
14+
15+
func main() {
16+
body := datadogV2.CustomDestinationCreateRequest{
17+
Data: &datadogV2.CustomDestinationCreateRequestDefinition{
18+
Attributes: datadogV2.CustomDestinationCreateRequestAttributes{
19+
Enabled: datadog.PtrBool(false),
20+
ForwardTags: datadog.PtrBool(false),
21+
ForwarderDestination: datadogV2.CustomDestinationForwardDestination{
22+
CustomDestinationForwardDestinationSplunk: &datadogV2.CustomDestinationForwardDestinationSplunk{
23+
AccessToken: "my-access-token",
24+
Endpoint: "https://example.com",
25+
Type: datadogV2.CUSTOMDESTINATIONFORWARDDESTINATIONSPLUNKTYPE_SPLUNK_HEC,
26+
Sourcetype: *datadog.NewNullableString(datadog.PtrString("my-sourcetype")),
27+
}},
28+
Name: "Nginx logs",
29+
Query: datadog.PtrString("source:nginx"),
30+
},
31+
Type: datadogV2.CUSTOMDESTINATIONTYPE_CUSTOM_DESTINATION,
32+
},
33+
}
34+
ctx := datadog.NewDefaultContext(context.Background())
35+
configuration := datadog.NewConfiguration()
36+
apiClient := datadog.NewAPIClient(configuration)
37+
api := datadogV2.NewLogsCustomDestinationsApi(apiClient)
38+
resp, r, err := api.CreateLogsCustomDestination(ctx, body)
39+
40+
if err != nil {
41+
fmt.Fprintf(os.Stderr, "Error when calling `LogsCustomDestinationsApi.CreateLogsCustomDestination`: %v\n", err)
42+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
43+
}
44+
45+
responseContent, _ := json.MarshalIndent(resp, "", " ")
46+
fmt.Fprintf(os.Stdout, "Response from `LogsCustomDestinationsApi.CreateLogsCustomDestination`:\n%s\n", responseContent)
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Create a Splunk custom destination without a sourcetype returns "OK" response
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
11+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
12+
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
13+
)
14+
15+
func main() {
16+
body := datadogV2.CustomDestinationCreateRequest{
17+
Data: &datadogV2.CustomDestinationCreateRequestDefinition{
18+
Attributes: datadogV2.CustomDestinationCreateRequestAttributes{
19+
Enabled: datadog.PtrBool(false),
20+
ForwardTags: datadog.PtrBool(false),
21+
ForwarderDestination: datadogV2.CustomDestinationForwardDestination{
22+
CustomDestinationForwardDestinationSplunk: &datadogV2.CustomDestinationForwardDestinationSplunk{
23+
AccessToken: "my-access-token",
24+
Endpoint: "https://example.com",
25+
Type: datadogV2.CUSTOMDESTINATIONFORWARDDESTINATIONSPLUNKTYPE_SPLUNK_HEC,
26+
}},
27+
Name: "Nginx logs",
28+
Query: datadog.PtrString("source:nginx"),
29+
},
30+
Type: datadogV2.CUSTOMDESTINATIONTYPE_CUSTOM_DESTINATION,
31+
},
32+
}
33+
ctx := datadog.NewDefaultContext(context.Background())
34+
configuration := datadog.NewConfiguration()
35+
apiClient := datadog.NewAPIClient(configuration)
36+
api := datadogV2.NewLogsCustomDestinationsApi(apiClient)
37+
resp, r, err := api.CreateLogsCustomDestination(ctx, body)
38+
39+
if err != nil {
40+
fmt.Fprintf(os.Stderr, "Error when calling `LogsCustomDestinationsApi.CreateLogsCustomDestination`: %v\n", err)
41+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
42+
}
43+
44+
responseContent, _ := json.MarshalIndent(resp, "", " ")
45+
fmt.Fprintf(os.Stdout, "Response from `LogsCustomDestinationsApi.CreateLogsCustomDestination`:\n%s\n", responseContent)
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Create a Splunk custom destination with a null sourcetype returns "OK" response
2+
3+
package main
4+
5+
import (
6+
"context"
7+
"encoding/json"
8+
"fmt"
9+
"os"
10+
11+
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
12+
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
13+
)
14+
15+
func main() {
16+
body := datadogV2.CustomDestinationCreateRequest{
17+
Data: &datadogV2.CustomDestinationCreateRequestDefinition{
18+
Attributes: datadogV2.CustomDestinationCreateRequestAttributes{
19+
Enabled: datadog.PtrBool(false),
20+
ForwardTags: datadog.PtrBool(false),
21+
ForwarderDestination: datadogV2.CustomDestinationForwardDestination{
22+
CustomDestinationForwardDestinationSplunk: &datadogV2.CustomDestinationForwardDestinationSplunk{
23+
AccessToken: "my-access-token",
24+
Endpoint: "https://example.com",
25+
Type: datadogV2.CUSTOMDESTINATIONFORWARDDESTINATIONSPLUNKTYPE_SPLUNK_HEC,
26+
Sourcetype: *datadog.NewNullableString(nil),
27+
}},
28+
Name: "Nginx logs",
29+
Query: datadog.PtrString("source:nginx"),
30+
},
31+
Type: datadogV2.CUSTOMDESTINATIONTYPE_CUSTOM_DESTINATION,
32+
},
33+
}
34+
ctx := datadog.NewDefaultContext(context.Background())
35+
configuration := datadog.NewConfiguration()
36+
apiClient := datadog.NewAPIClient(configuration)
37+
api := datadogV2.NewLogsCustomDestinationsApi(apiClient)
38+
resp, r, err := api.CreateLogsCustomDestination(ctx, body)
39+
40+
if err != nil {
41+
fmt.Fprintf(os.Stderr, "Error when calling `LogsCustomDestinationsApi.CreateLogsCustomDestination`: %v\n", err)
42+
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
43+
}
44+
45+
responseContent, _ := json.MarshalIndent(resp, "", " ")
46+
fmt.Fprintf(os.Stdout, "Response from `LogsCustomDestinationsApi.CreateLogsCustomDestination`:\n%s\n", responseContent)
47+
}

0 commit comments

Comments
 (0)