Skip to content

Commit

Permalink
out_td: import TD sources into the main project.
Browse files Browse the repository at this point in the history
this patch adds the TD output plugin.

Some fixes for flushing data are coming in the next series of patches.

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed May 18, 2015
1 parent 81aa331 commit b7a4ecc
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/out_td/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(src
td_config.c
td.c)

FLB_PLUGIN(out_td "${src}" "mk_config")
target_link_libraries(flb-plugin-out_td "z")
85 changes: 85 additions & 0 deletions plugins/out_td/td.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015 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 <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include <fluent-bit/flb_output.h>
#include <fluent-bit/flb_utils.h>
#include <fluent-bit/flb_network.h>

#include "td.h"
#include "td_config.h"

struct flb_output_plugin out_td_plugin;

int cb_td_init(struct flb_config *config)
{
int ret;
struct flb_out_td_config *ctx;

if (!config->file) {
flb_utils_error_c("TD output requires a configuration file");
}

ctx = td_config_init(config->file);
if (!ctx) {
return -1;
}

ret = flb_output_set_context("td", ctx, config);
if (ret == -1) {
flb_utils_error_c("Could not set configuration for td output plugin");
}

return 0;
}

int cb_td_pre_run(void *out_context, struct flb_config *config)
{
int fd;
struct flb_out_td_config *ctx = out_context;

fd = flb_net_tcp_connect(out_td_plugin.host,
out_td_plugin.port);
if (fd <= 0) {
return -1;
}

ctx->fd = fd;
return 0;
}

int cb_td_flush(void *data, size_t bytes, void *out_context)
{
return 0;
}

/* Plugin reference */
struct flb_output_plugin out_td_plugin = {
.name = "td",
.description = "Treasure Data",
.cb_init = cb_td_init,
.cb_pre_run = cb_td_pre_run,
.cb_flush = cb_td_flush,
.flags = FLB_OUTPUT_TCP | FLB_OUTPUT_SSL | FLB_OUTPUT_NOPROT,
.host = "api.treasuredata.com",
.port = 80,
};
24 changes: 24 additions & 0 deletions plugins/out_td/td.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015 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.
*/

#ifndef FLB_OUT_TD_H
#define FLB_OUT_TD_H


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

/* Fluent Bit
* ==========
* Copyright (C) 2015 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 <stdlib.h>
#include <mk_config/mk_config.h>
#include <fluent-bit/flb_utils.h>

#include "td_config.h"

struct flb_out_td_config *td_config_init(struct mk_config *conf)
{
char *api;
char *db_name;
char *db_table;
struct mk_config_section *section;
struct flb_out_td_config *config;

section = mk_config_section_get(conf, "TD");
if (!section) {
return NULL;
}

/* Validate TD section keys */
api = mk_config_section_getval(section, "API", MK_CONFIG_VAL_STR);
db_name = mk_config_section_getval(section, "Database", MK_CONFIG_VAL_STR);
db_table = mk_config_section_getval(section, "Table", MK_CONFIG_VAL_STR);

if (!api) {
flb_utils_error_c("[TD] error reading API key value");
}

if (!db_name) {
flb_utils_error_c("[TD] error reading Database name");
}

if (!db_table) {
flb_utils_error_c("[TD] error reading Table name");
}

config = malloc(sizeof(struct flb_out_td_config));
config->fd = -1;
config->api = api;
config->db_name = db_name;
config->db_table = db_table;

flb_debug("TreasureData / database='%s' table='%s'",
config->db_name, config->db_table);

return config;
}
35 changes: 35 additions & 0 deletions plugins/out_td/td_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015 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.
*/

#ifndef FLB_TD_CONFIG_H
#define FLB_TD_CONFIG_H

#include <mk_config/mk_config.h>

struct flb_out_td_config {
int fd; /* Socket to destination/backend */

char *api;
char *db_name;
char *db_table;
};

struct flb_out_td_config *td_config_init(struct mk_config *conf);

#endif

0 comments on commit b7a4ecc

Please sign in to comment.