@@ -926,6 +926,30 @@ static int get_ec2_metadata(struct flb_filter_aws *ctx)
926
926
ctx -> metadata_retrieved = FLB_TRUE ;
927
927
}
928
928
929
+ if (ctx -> enable_entity ) {
930
+ if (!ctx -> account_id ) {
931
+ ret = flb_aws_imds_request_by_key (ctx -> client_imds , FLB_AWS_IMDS_ACCOUNT_ID_PATH ,
932
+ & ctx -> account_id , & ctx -> account_id_len ,
933
+ "accountId" );
934
+
935
+ if (ret < 0 ) {
936
+ flb_plg_error (ctx -> ins , "Failed to get Account ID" );
937
+ return -1 ;
938
+ }
939
+ }
940
+
941
+ if (!ctx -> instance_id ) {
942
+ ret = flb_aws_imds_request (ctx -> client_imds , FLB_AWS_IMDS_INSTANCE_ID_PATH ,
943
+ & ctx -> instance_id ,
944
+ & ctx -> instance_id_len );
945
+ if (ret < 0 ) {
946
+ flb_plg_error (ctx -> ins , "Failed to get instance ID" );
947
+ return -1 ;
948
+ }
949
+ }
950
+ }
951
+
952
+ ctx -> metadata_retrieved = FLB_TRUE ;
929
953
return 0 ;
930
954
}
931
955
@@ -1104,6 +1128,23 @@ static int cb_aws_filter(const void *data, size_t bytes,
1104
1128
}
1105
1129
}
1106
1130
1131
+ if (ctx -> enable_entity &&
1132
+ ctx -> instance_id &&
1133
+ ctx -> account_id &&
1134
+ ret == FLB_EVENT_ENCODER_SUCCESS ) {
1135
+ ret = flb_log_event_encoder_append_body_values (
1136
+ & log_encoder ,
1137
+ FLB_LOG_EVENT_CSTRING_VALUE (FLB_FILTER_AWS_ENTITY_INSTANCE_ID_KEY ),
1138
+ FLB_LOG_EVENT_STRING_VALUE (ctx -> instance_id ,
1139
+ ctx -> instance_id_len ));
1140
+ ret = flb_log_event_encoder_append_body_values (
1141
+ & log_encoder ,
1142
+ FLB_LOG_EVENT_CSTRING_VALUE (FLB_FILTER_AWS_ENTITY_ACCOUNT_ID_KEY ),
1143
+ FLB_LOG_EVENT_STRING_VALUE (ctx -> account_id ,
1144
+ ctx -> account_id_len ));
1145
+ }
1146
+
1147
+
1107
1148
if (ret == FLB_EVENT_ENCODER_SUCCESS ) {
1108
1149
ret = flb_log_event_encoder_commit_record (& log_encoder );
1109
1150
}
@@ -1273,6 +1314,12 @@ static struct flb_config_map config_map[] = {
1273
1314
0 , FLB_TRUE , offsetof(struct flb_filter_aws , retry_required_interval ),
1274
1315
"Defines minimum duration between retries for fetching metadata groups"
1275
1316
},
1317
+ {
1318
+ FLB_CONFIG_MAP_BOOL , "enable_entity" , "false" ,
1319
+ 0 , FLB_TRUE , offsetof(struct flb_filter_aws , enable_entity ),
1320
+ "Enable entity prefix for fields used for constructing entity."
1321
+ "This currently only affects instance ID"
1322
+ },
1276
1323
{0 }
1277
1324
};
1278
1325
0 commit comments