From b59e1e9e3cc12429b9c225ec12e5164b18ee0e77 Mon Sep 17 00:00:00 2001 From: Hiroshi Hatake Date: Fri, 23 Aug 2024 11:29:55 +0900 Subject: [PATCH] in_splunk: test: Handle 1.0 suffixed endpoints Signed-off-by: Hiroshi Hatake --- plugins/in_splunk/splunk_prot.c | 12 ++++++++---- tests/runtime/in_splunk.c | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/plugins/in_splunk/splunk_prot.c b/plugins/in_splunk/splunk_prot.c index a6f9be57ed3..cf614b06679 100644 --- a/plugins/in_splunk/splunk_prot.c +++ b/plugins/in_splunk/splunk_prot.c @@ -834,7 +834,8 @@ int splunk_prot_handle(struct flb_splunk *ctx, struct splunk_conn *conn, flb_log_event_encoder_reset(&ctx->log_encoder); if (request->method == MK_METHOD_POST) { - if (strcasecmp(uri, "/services/collector/raw") == 0) { + if (strcasecmp(uri, "/services/collector/raw/1.0") == 0 || + strcasecmp(uri, "/services/collector/raw") == 0) { ret = process_hec_raw_payload(ctx, conn, tag, session, request); if (!ret) { @@ -842,7 +843,8 @@ int splunk_prot_handle(struct flb_splunk *ctx, struct splunk_conn *conn, } send_json_message_response(conn, 200, "{\"text\":\"Success\",\"code\":0}"); } - else if (strcasecmp(uri, "/services/collector/event") == 0 || + else if (strcasecmp(uri, "/services/collector/event/1.0") == 0 || + strcasecmp(uri, "/services/collector/event") == 0 || strcasecmp(uri, "/services/collector") == 0) { ret = process_hec_payload(ctx, conn, tag, session, request); @@ -1151,7 +1153,8 @@ int splunk_prot_handle_ng(struct flb_http_request *request, return -1; } - if (strcasecmp(request->path, "/services/collector/raw") == 0) { + if (strcasecmp(request->path, "/services/collector/raw/1.0") == 0 || + strcasecmp(request->path, "/services/collector/raw") == 0) { ret = process_hec_raw_payload_ng(request, response, tag, context); if (ret != 0) { @@ -1163,7 +1166,8 @@ int splunk_prot_handle_ng(struct flb_http_request *request, ret = 0; } - else if (strcasecmp(request->path, "/services/collector/event") == 0 || + else if (strcasecmp(request->path, "/services/collector/event/1.0") == 0 || + strcasecmp(request->path, "/services/collector/event") == 0 || strcasecmp(request->path, "/services/collector") == 0) { ret = process_hec_payload_ng(request, response, tag, context); diff --git a/tests/runtime/in_splunk.c b/tests/runtime/in_splunk.c index 77eb80b50f3..666866442c7 100644 --- a/tests/runtime/in_splunk.c +++ b/tests/runtime/in_splunk.c @@ -370,7 +370,7 @@ void flb_test_splunk_collector_event() flb_test_splunk(8810, "/services/collector/event"); } -void flb_test_splunk_raw(int port) +void flb_test_splunk_raw(int port, char *endpoint) { struct flb_lib_out_cb cb_data; struct test_ctx *ctx; @@ -413,7 +413,7 @@ void flb_test_splunk_raw(int port) ctx->httpc = splunk_client_ctx_create(port); TEST_CHECK(ctx->httpc != NULL); - c = flb_http_client(ctx->httpc->u_conn, FLB_HTTP_POST, "/services/collector/raw", buf, strlen(buf), + c = flb_http_client(ctx->httpc->u_conn, FLB_HTTP_POST, endpoint, buf, strlen(buf), "127.0.0.1", port, NULL, 0); ret = flb_http_add_header(c, FLB_HTTP_HEADER_CONTENT_TYPE, strlen(FLB_HTTP_HEADER_CONTENT_TYPE), JSON_CONTENT_TYPE, strlen(JSON_CONTENT_TYPE)); @@ -448,7 +448,7 @@ void flb_test_splunk_raw(int port) void flb_test_splunk_collector_raw() { - flb_test_splunk_raw(8811); + flb_test_splunk_raw(8811, "/services/collector/raw"); } void flb_test_splunk_raw_multilines(int port) @@ -910,11 +910,25 @@ void flb_test_splunk_collector_raw_hec_token_key() flb_test_splunk_auth_header(8817, "/services/collector/raw"); } +/* 1.0 endpoints */ + +void flb_test_splunk_collector_raw_1_0() +{ + flb_test_splunk_raw(8818, "/services/collector/raw/1.0"); +} + +void flb_test_splunk_collector_event_1_0() +{ + flb_test_splunk(8819, "/services/collector/event/1.0"); +} + TEST_LIST = { {"health", flb_test_splunk_health}, {"collector", flb_test_splunk_collector}, {"collector_event", flb_test_splunk_collector_event}, + {"collector_event_1.0", flb_test_splunk_collector_event_1_0}, {"collector_raw", flb_test_splunk_collector_raw}, + {"collector_raw_1.0", flb_test_splunk_collector_raw_1_0}, {"collector_raw_multilines", flb_test_splunk_collector_raw_multilines}, {"collector_gzip", flb_test_splunk_collector_gzip}, {"collector_event_gzip", flb_test_splunk_collector_event_gzip},