From 1c587858ed31011f64c16bb1e99be11e6d864fc9 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Thu, 20 Jun 2024 17:45:14 -0400 Subject: [PATCH] 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 --- plugins/out_datadog/datadog.c | 16 ++++++++++++++++ plugins/out_datadog/datadog.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/plugins/out_datadog/datadog.c b/plugins/out_datadog/datadog.c index c92992f534e..57f3cb42cce 100644 --- a/plugins/out_datadog/datadog.c +++ b/plugins/out_datadog/datadog.c @@ -247,6 +247,14 @@ static int datadog_format(struct flb_config *config, ctx->dd_service, flb_sds_len(ctx->dd_service)); } + /* dd_hostname */ + if (ctx->dd_hostname != NULL) { + dd_msgpack_pack_key_value_str(&mp_pck, + FLB_DATADOG_DD_HOSTNAME_KEY, + sizeof(FLB_DATADOG_DD_HOSTNAME_KEY) -1, + ctx->dd_hostname, flb_sds_len(ctx->dd_hostname)); + } + /* Append initial object k/v */ ind = 0; for (i = 0; i < map_size; i++) { @@ -514,6 +522,14 @@ static struct flb_config_map config_map[] = { "The tags you want to assign to your logs in Datadog. If unset, Datadog " "will expect the tags in the `ddtags` attribute." }, + { + FLB_CONFIG_MAP_STR, "dd_hostname", NULL, + 0, FLB_TRUE, offsetof(struct flb_out_datadog, dd_hostname), + "The host that emitted logs should be associated with. If unset, Datadog " + "will expect the host to be set as `host`, `hostname`, or `syslog.hostname` " + "attributes. See Datadog Logs preprocessor documentation for up-to-date " + "of recognized attributes." + }, { FLB_CONFIG_MAP_STR, "proxy", NULL, diff --git a/plugins/out_datadog/datadog.h b/plugins/out_datadog/datadog.h index 15856be399b..1b0714f2ecd 100644 --- a/plugins/out_datadog/datadog.h +++ b/plugins/out_datadog/datadog.h @@ -27,6 +27,7 @@ #define FLB_DATADOG_DEFAULT_PORT 443 #define FLB_DATADOG_DEFAULT_TIME_KEY "timestamp" #define FLB_DATADOG_DEFAULT_TAG_KEY "tagkey" +#define FLB_DATADOG_DD_HOSTNAME_KEY "hostname" #define FLB_DATADOG_DD_SOURCE_KEY "ddsource" #define FLB_DATADOG_DD_SERVICE_KEY "service" #define FLB_DATADOG_DD_TAGS_KEY "ddtags" @@ -65,6 +66,7 @@ struct flb_out_datadog { int nb_additional_entries; flb_sds_t dd_source; flb_sds_t dd_service; + flb_sds_t dd_hostname; flb_sds_t dd_tags; flb_sds_t dd_message_key;