Skip to content

Commit 1c58785

Browse files
jszwedkoedsiper
authored andcommitted
out_datadog: Add support for setting a static hostname
This PR adds support for setting a static hostname in the Datadog output plugin. This field is analogous to the existing `dd_service` and `dd_source` configuration options that can be used to set a static value. If unset, the default behavior is backwards compatible. This behavior is to not set an explicity `hostname` field, but if the record has a field that is detected as the hostname in Datadog (such as `host` or `syslog.hostname`), it will be picked up. Closes: #8971 Signed-off-by: Jesse Szwedko <[email protected]>
1 parent d2e01ad commit 1c58785

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

plugins/out_datadog/datadog.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ static int datadog_format(struct flb_config *config,
247247
ctx->dd_service, flb_sds_len(ctx->dd_service));
248248
}
249249

250+
/* dd_hostname */
251+
if (ctx->dd_hostname != NULL) {
252+
dd_msgpack_pack_key_value_str(&mp_pck,
253+
FLB_DATADOG_DD_HOSTNAME_KEY,
254+
sizeof(FLB_DATADOG_DD_HOSTNAME_KEY) -1,
255+
ctx->dd_hostname, flb_sds_len(ctx->dd_hostname));
256+
}
257+
250258
/* Append initial object k/v */
251259
ind = 0;
252260
for (i = 0; i < map_size; i++) {
@@ -514,6 +522,14 @@ static struct flb_config_map config_map[] = {
514522
"The tags you want to assign to your logs in Datadog. If unset, Datadog "
515523
"will expect the tags in the `ddtags` attribute."
516524
},
525+
{
526+
FLB_CONFIG_MAP_STR, "dd_hostname", NULL,
527+
0, FLB_TRUE, offsetof(struct flb_out_datadog, dd_hostname),
528+
"The host that emitted logs should be associated with. If unset, Datadog "
529+
"will expect the host to be set as `host`, `hostname`, or `syslog.hostname` "
530+
"attributes. See Datadog Logs preprocessor documentation for up-to-date "
531+
"of recognized attributes."
532+
},
517533

518534
{
519535
FLB_CONFIG_MAP_STR, "proxy", NULL,

plugins/out_datadog/datadog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define FLB_DATADOG_DEFAULT_PORT 443
2828
#define FLB_DATADOG_DEFAULT_TIME_KEY "timestamp"
2929
#define FLB_DATADOG_DEFAULT_TAG_KEY "tagkey"
30+
#define FLB_DATADOG_DD_HOSTNAME_KEY "hostname"
3031
#define FLB_DATADOG_DD_SOURCE_KEY "ddsource"
3132
#define FLB_DATADOG_DD_SERVICE_KEY "service"
3233
#define FLB_DATADOG_DD_TAGS_KEY "ddtags"
@@ -65,6 +66,7 @@ struct flb_out_datadog {
6566
int nb_additional_entries;
6667
flb_sds_t dd_source;
6768
flb_sds_t dd_service;
69+
flb_sds_t dd_hostname;
6870
flb_sds_t dd_tags;
6971
flb_sds_t dd_message_key;
7072

0 commit comments

Comments
 (0)