@@ -40,6 +40,7 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
40
40
char * host = NULL ;
41
41
char * port = NULL ;
42
42
char * uri = NULL ;
43
+ char * site = NULL ;
43
44
44
45
/* Start resource creation */
45
46
ctx = flb_calloc (1 , sizeof (struct flb_out_datadog ));
@@ -98,6 +99,15 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
98
99
return NULL ;
99
100
}
100
101
102
+ /* Parse site parameter early so it's available for host construction */
103
+ tmp = flb_output_get_property ("site" , ins );
104
+ if (tmp ){
105
+ ctx -> site = flb_sds_create (tmp );
106
+ flb_plg_debug (ctx -> ins , "site parameter set to: %s" , ctx -> site );
107
+ } else {
108
+ flb_plg_debug (ctx -> ins , "no site parameter found" );
109
+ }
110
+
101
111
/* Tag Key */
102
112
if (ctx -> include_tag_key == FLB_TRUE ) {
103
113
ctx -> nb_additional_entries ++ ;
@@ -126,7 +136,7 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
126
136
tmp = flb_output_get_property ("provider" , ins );
127
137
ctx -> remap = tmp && (strlen (tmp ) == strlen (FLB_DATADOG_REMAP_PROVIDER )) && \
128
138
(strncmp (tmp , FLB_DATADOG_REMAP_PROVIDER , strlen (tmp )) == 0 );
129
-
139
+
130
140
ctx -> uri = flb_sds_create ("/api/v2/logs" );
131
141
if (!ctx -> uri ) {
132
142
flb_plg_error (ctx -> ins , "error on uri generation" );
@@ -138,18 +148,47 @@ struct flb_out_datadog *flb_datadog_conf_create(struct flb_output_instance *ins,
138
148
139
149
/* Get network configuration */
140
150
if (!ins -> host .name ) {
141
- tmp_sds = flb_sds_create (FLB_DATADOG_DEFAULT_HOST );
151
+ /* No explicit Host parameter, check for site */
152
+ if (ctx -> site ) {
153
+ flb_plg_debug (ctx -> ins , "using site for host construction: %s" , ctx -> site );
154
+ /* Construct hostname from site */
155
+ tmp_sds = flb_sds_create ("http-intake.logs." );
156
+ if (!tmp_sds ) {
157
+ flb_errno ();
158
+ flb_datadog_conf_destroy (ctx );
159
+ return NULL ;
160
+ }
161
+ flb_plg_debug (ctx -> ins , "created base hostname: %s" , tmp_sds );
162
+ flb_plg_debug (ctx -> ins , "about to concatenate site: %s (length: %zu)" , ctx -> site , flb_sds_len (ctx -> site ));
163
+ tmp_sds = flb_sds_cat (tmp_sds , (const char * )ctx -> site , flb_sds_len (ctx -> site ));
164
+ flb_plg_debug (ctx -> ins , "after concatenation: %s" , tmp_sds );
165
+ ctx -> host = tmp_sds ;
166
+ flb_plg_debug (ctx -> ins , "host constructed from site: %s" , ctx -> host );
167
+ } else {
168
+ flb_plg_debug (ctx -> ins , "no site specified, using default host" );
169
+ /* No site specified, use default */
170
+ tmp_sds = flb_sds_create (FLB_DATADOG_DEFAULT_HOST );
171
+ if (!tmp_sds ) {
172
+ flb_errno ();
173
+ flb_datadog_conf_destroy (ctx );
174
+ return NULL ;
175
+ }
176
+ ctx -> host = tmp_sds ;
177
+ flb_plg_debug (ctx -> ins , "host: %s" , ctx -> host );
178
+ }
142
179
}
143
180
else {
181
+ flb_plg_debug (ctx -> ins , "explicit Host parameter takes precedence: %s" , ins -> host .name );
182
+ /* Explicit Host parameter takes precedence */
144
183
tmp_sds = flb_sds_create (ins -> host .name );
184
+ if (!tmp_sds ) {
185
+ flb_errno ();
186
+ flb_datadog_conf_destroy (ctx );
187
+ return NULL ;
188
+ }
189
+ ctx -> host = tmp_sds ;
190
+ flb_plg_debug (ctx -> ins , "host: %s" , ctx -> host );
145
191
}
146
- if (!tmp_sds ) {
147
- flb_errno ();
148
- flb_datadog_conf_destroy (ctx );
149
- return NULL ;
150
- }
151
- ctx -> host = tmp_sds ;
152
- flb_plg_debug (ctx -> ins , "host: %s" , ctx -> host );
153
192
154
193
if (ins -> host .port != 0 ) {
155
194
ctx -> port = ins -> host .port ;
@@ -222,6 +261,9 @@ int flb_datadog_conf_destroy(struct flb_out_datadog *ctx)
222
261
if (ctx -> upstream ) {
223
262
flb_upstream_destroy (ctx -> upstream );
224
263
}
264
+ if (ctx -> site ){
265
+ flb_sds_destroy (ctx -> site );
266
+ }
225
267
flb_free (ctx );
226
268
227
269
return 0 ;
0 commit comments