Skip to content

Commit

Permalink
in_splunk: test: Handle 1.0 suffixed endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed Aug 23, 2024
1 parent 4427d42 commit 8c11fb5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
12 changes: 8 additions & 4 deletions plugins/in_splunk/splunk_prot.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,15 +834,17 @@ 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) {
send_json_message_response(conn, 400, "{\"text\":\"Invalid data format\",\"code\":6}");
}
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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down
20 changes: 17 additions & 3 deletions tests/runtime/in_splunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(8810, "/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},
Expand Down

0 comments on commit 8c11fb5

Please sign in to comment.