Skip to content

Commit

Permalink
in_http: add HTTP input plugin (#18)
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Jan 8, 2021
1 parent 78b0f6d commit d2696ed
Show file tree
Hide file tree
Showing 14 changed files with 844 additions and 302 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ option(FLB_IN_DOCKER_EVENTS "Enable Docker events input plugin" Yes)
option(FLB_IN_EXEC "Enable Exec input plugin" Yes)
option(FLB_IN_FORWARD "Enable Forward input plugin" Yes)
option(FLB_IN_HEALTH "Enable Health input plugin" Yes)
option(FLB_IN_HTTP "Enable HTTP input plugin" No)
option(FLB_IN_HTTP "Enable HTTP input plugin" Yes)
option(FLB_IN_MEM "Enable Memory input plugin" Yes)
option(FLB_IN_KMSG "Enable Kernel log input plugin" Yes)
option(FLB_IN_LIB "Enable library mode input plugin" Yes)
Expand Down
55 changes: 5 additions & 50 deletions plugins/in_http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,8 @@
set(src
in_http.c)

FLB_PLUGIN(in_http "${src}" "")
target_link_libraries(flb-plugin-in_http
monkey-core-static
${CMAKE_DL_LIBS})

# Configuration files
# ===================
# Default values for conf/in_http.conf

set(MK_CONF_LISTEN "8080")
set(MK_CONF_WORKERS "1")
set(MK_CONF_TIMEOUT "15")
set(MK_CONF_INDEXFILE "index.html index.htm index.php")
set(MK_CONF_HIDEVERSION "Off")
set(MK_CONF_RESUME "On")
set(MK_CONF_KA "On")
set(MK_CONF_KA_TIMEOUT "5")
set(MK_CONF_KA_MAXREQ "1000")
set(MK_CONF_REQ_SIZE "32")
set(MK_CONF_SYMLINK "Off")
set(MK_CONF_TRANSPORT "liana")
set(MK_CONF_DEFAULT_MIME "text/plain")
set(MK_CONF_FDT "On")
set(MK_CONF_OVERCAPACITY "Resist")

# Virtual Host
# ============
set(MK_VH_SERVERNAME "127.0.0.1")
set(MK_PATH_WWW "${PROJECT_SOURCE_DIR}/lib/monkey/htdocs")
set(IN_HTTP_CONF_PATH "${PROJECT_BINARY_DIR}/conf/")

configure_file(
"in_http_info.h.in"
"${PROJECT_SOURCE_DIR}/plugins/in_http/in_http_info.h"
http.c
http_conn.c
http_prot.c
http_config.c
)

configure_file(
"conf/in_http.conf.in"
"${PROJECT_BINARY_DIR}/conf/in_http.conf"
)

configure_file(
"conf/sites/default.in"
"${PROJECT_BINARY_DIR}/conf/sites/default"
)

configure_file(
"conf/mimetypes.conf.in"
"${PROJECT_BINARY_DIR}/conf/mimetypes.conf"
)
FLB_PLUGIN(in_http "${src}" "")
18 changes: 0 additions & 18 deletions plugins/in_http/conf/in_http.conf.in

This file was deleted.

145 changes: 0 additions & 145 deletions plugins/in_http/conf/mimetypes.conf.in

This file was deleted.

3 changes: 0 additions & 3 deletions plugins/in_http/conf/sites/default.in

This file was deleted.

147 changes: 147 additions & 0 deletions plugins/in_http/http.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


#include <fluent-bit/flb_input_plugin.h>
#include <fluent-bit/flb_network.h>
#include <fluent-bit/flb_config.h>

#include "http.h"
#include "http_conn.h"
#include "http_config.h"

/*
* For a server event, the collection event means a new client have arrived, we
* accept the connection and create a new TCP instance which will wait for
* JSON map messages.
*/
static int in_http_collect(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
{
int fd;
struct flb_http *ctx = in_context;
struct http_conn *conn;

/* Accept the new connection */
fd = flb_net_accept(ctx->server_fd);
if (fd == -1) {
flb_plg_error(ctx->ins, "could not accept new connection");
return -1;
}

flb_plg_trace(ctx->ins, "new TCP connection arrived FD=%i", fd);
conn = http_conn_add(fd, ctx);
if (!conn) {
return -1;
}
return 0;
}

static int in_http_init(struct flb_input_instance *ins,
struct flb_config *config, void *data)
{
int ret;
struct flb_http *ctx;

/* Create context and basic conf */
ctx = http_config_create(ins);
if (!ctx) {
return -1;
}

/* Set the context */
flb_input_set_context(ins, ctx);

ctx->evl = config->evl;

/* Create HTTP listener */
ctx->server_fd = flb_net_server(ctx->tcp_port, ctx->listen);
if (ctx->server_fd > 0) {
flb_plg_info(ctx->ins, "listening on %s:%s", ctx->listen, ctx->tcp_port);
}
else {
flb_plg_error(ctx->ins, "could not bind address %s:%s. Aborting",
ctx->listen, ctx->tcp_port);
http_config_destroy(ctx);
return -1;
}

/* Set the socket non-blocking */
flb_net_socket_nonblocking(ctx->server_fd);

/* Collect upon data available on the standard input */
ret = flb_input_set_collector_socket(ins,
in_http_collect,
ctx->server_fd,
config);
if (ret == -1) {
flb_plg_error(ctx->ins, "Could not set collector for IN_TCP input plugin");
http_config_destroy(ctx);
return -1;
}

return 0;
}

static int in_http_exit(void *data, struct flb_config *config)
{
struct flb_http *ctx = data;
(void) config;

if (!ctx) {
return 0;
}

http_config_destroy(ctx);
return 0;
}

/* Configuration properties map */
static struct flb_config_map config_map[] = {
{
FLB_CONFIG_MAP_SIZE, "buffer_max_size", HTTP_BUFFER_MAX_SIZE,
0, FLB_TRUE, offsetof(struct flb_http, buffer_max_size),
""
},

{
FLB_CONFIG_MAP_SIZE, "buffer_chunk_size", HTTP_BUFFER_CHUNK_SIZE,
0, FLB_TRUE, offsetof(struct flb_http, buffer_chunk_size),
""
},

/* EOF */
{0}
};

/* Plugin reference */
struct flb_input_plugin in_http_plugin = {
.name = "http",
.description = "HTTP",
.cb_init = in_http_init,
.cb_pre_run = NULL,
.cb_collect = in_http_collect,
.cb_flush_buf = NULL,
.cb_pause = NULL,
.cb_resume = NULL,
.cb_exit = in_http_exit,
.config_map = config_map,
.flags = FLB_INPUT_NET,
};
Loading

0 comments on commit d2696ed

Please sign in to comment.