Skip to content

Commit

Permalink
in_collectd: Use 'Listen' instead of 'Address' as an option name
Browse files Browse the repository at this point in the history
This makes the plugin more conforming to the established interface
standard, thus makes it easier to maintain.

Signed-off-by: Fujimoto Seiji <[email protected]>
  • Loading branch information
fujimotos committed Aug 16, 2019
1 parent 31ab6bc commit 08070c0
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions plugins/in_collectd/in_collectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
*/
#define BUFFER_SIZE 65535

#define DEFAULT_ADDRESS "0.0.0.0"
#define DEFAULT_PORT "25826"
#define DEFAULT_LISTEN "0.0.0.0"
#define DEFAULT_PORT 25826

/* This is where most Linux systems places a default TypesDB */
#define DEFAULT_TYPESDB "/usr/share/collectd/types.db";
Expand All @@ -46,9 +46,9 @@ struct flb_in_collectd_config {
char *buf;
int bufsize;

/* Listen Address */
const char *address;
const char *port;
/* Server */
char listen[256]; /* RFC-2181 */
char port[6]; /* RFC-793 */

/* Sockets */
flb_sockfd_t server_fd;
Expand All @@ -70,6 +70,8 @@ static int in_collectd_init(struct flb_input_instance *in,
const char *tmp;
struct flb_in_collectd_config *ctx;
struct mk_list *tdb;
char *listen = DEFAULT_LISTEN;
int port = DEFAULT_PORT;

/* Initialize context */
ctx = flb_calloc(1, sizeof(struct flb_in_collectd_config));
Expand All @@ -88,19 +90,22 @@ static int in_collectd_init(struct flb_input_instance *in,
}

/* Listening address */
tmp = flb_input_get_property("address", in);
if (tmp) {
ctx->address = tmp;
} else {
ctx->address = DEFAULT_ADDRESS;
if (in->host.listen) {
listen = in->host.listen;
}

tmp = flb_input_get_property("port", in);
if (tmp) {
ctx->port = tmp;
} else {
ctx->port = DEFAULT_PORT;
if (strlen(listen) > sizeof(ctx->listen) - 1) {
flb_error("[in_collectd] too long address '%s'", listen);
flb_free(ctx);
return -1;
}
strcpy(ctx->listen, listen);

/* Listening port */
if (in->host.port) {
port = in->host.port;
}
snprintf(ctx->port, sizeof(ctx->port), "%hu", port);

/* TypesDB */
tmp = flb_input_get_property("typesdb", in);
Expand All @@ -122,9 +127,9 @@ static int in_collectd_init(struct flb_input_instance *in,
/* Set the context */
flb_input_set_context(in, ctx);

ctx->server_fd = flb_net_server_udp(ctx->port, ctx->address);
ctx->server_fd = flb_net_server_udp(ctx->port, ctx->listen);
if (ctx->server_fd < 0) {
flb_error("[in_collectd] failed to bind to %s:%s", ctx->address,
flb_error("[in_collectd] failed to bind to %s:%s", ctx->listen,
ctx->port);
typesdb_destroy(ctx->tdb);
flb_free(ctx->buf);
Expand All @@ -147,7 +152,7 @@ static int in_collectd_init(struct flb_input_instance *in,
}
ctx->coll_fd = ret;

flb_info("[in_collectd] start listening to %s:%s", ctx->address,
flb_info("[in_collectd] start listening to %s:%s", ctx->listen,
ctx->port);
return 0;
}
Expand Down

0 comments on commit 08070c0

Please sign in to comment.