#include "collectd.h"
-#include "common.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include <netdb.h>
#include <netinet/in.h>
"CollectRoutes", "CollectTopology"};
static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
-static char *config_node = NULL;
-static char *config_service = NULL;
+static char *config_node;
+static char *config_service;
#define OLSRD_WANT_NOT 0
#define OLSRD_WANT_SUMMARY 1
static const char *olsrd_get_node(void) /* {{{ */
{
if (config_node != NULL)
- return (config_node);
- return (OLSRD_DEFAULT_NODE);
+ return config_node;
+ return OLSRD_DEFAULT_NODE;
} /* }}} const char *olsrd_get_node */
static const char *olsrd_get_service(void) /* {{{ */
{
if (config_service != NULL)
- return (config_service);
- return (OLSRD_DEFAULT_SERVICE);
+ return config_service;
+ return OLSRD_DEFAULT_SERVICE;
} /* }}} const char *olsrd_get_service */
static void olsrd_set_node(const char *node) /* {{{ */
buffer[buffer_len] = 0;
}
- return (buffer_len);
+ return buffer_len;
} /* }}} size_t strchomp */
static size_t strtabsplit(char *string, char **fields, size_t size) /* {{{ */
break;
}
- return (i);
+ return i;
} /* }}} size_t strtabsplit */
static FILE *olsrd_connect(void) /* {{{ */
if (ai_return != 0) {
ERROR("olsrd plugin: getaddrinfo (%s, %s) failed: %s", olsrd_get_node(),
olsrd_get_service(), gai_strerror(ai_return));
- return (NULL);
+ return NULL;
}
fh = NULL;
ai_ptr = ai_ptr->ai_next) {
int fd;
int status;
- char errbuf[1024];
fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0) {
- ERROR("olsrd plugin: socket failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("olsrd plugin: socket failed: %s", STRERRNO);
continue;
}
status = connect(fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0) {
- ERROR("olsrd plugin: connect failed: %s",
- sstrerror(errno, errbuf, sizeof(errbuf)));
+ ERROR("olsrd plugin: connect failed: %s", STRERRNO);
close(fd);
continue;
}
freeaddrinfo(ai_list);
- return (fh);
+ return fh;
} /* }}} FILE *olsrd_connect */
__attribute__((nonnull(2))) static void
static int olsrd_cb_ignore(int lineno, /* {{{ */
size_t fields_num, char **fields) {
- return (0);
+ return 0;
} /* }}} int olsrd_cb_ignore */
static int olsrd_cb_links(int lineno, /* {{{ */
char *endptr;
if (config_want_links == OLSRD_WANT_NOT)
- return (0);
+ return 0;
/* Special handling of the first line. */
if (lineno <= 0) {
nlq_sum = 0.0;
nlq_num = 0;
- return (0);
+ return 0;
}
/* Special handling of the last line. */
olsrd_submit(/* p.-inst = */ "links", /* type = */ "signal_quality",
"average-nlq", nlq);
- return (0);
+ return 0;
}
if (fields_num != 6)
- return (-1);
+ return -1;
links_num++;
if (config_want_links == OLSRD_WANT_DETAIL) {
char type_instance[DATA_MAX_NAME_LEN];
- ssnprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
- fields[1]);
+ snprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
+ fields[1]);
DEBUG("olsrd plugin: links: type_instance = %s; lq = %g;", type_instance,
lq);
if (config_want_links == OLSRD_WANT_DETAIL) {
char type_instance[DATA_MAX_NAME_LEN];
- ssnprintf(type_instance, sizeof(type_instance), "%s-%s-rx", fields[0],
- fields[1]);
+ snprintf(type_instance, sizeof(type_instance), "%s-%s-rx", fields[0],
+ fields[1]);
DEBUG("olsrd plugin: links: type_instance = %s; nlq = %g;", type_instance,
lq);
}
}
- return (0);
+ return 0;
} /* }}} int olsrd_cb_links */
static int olsrd_cb_routes(int lineno, /* {{{ */
char *endptr;
if (config_want_routes == OLSRD_WANT_NOT)
- return (0);
+ return 0;
/* Special handling of the first line */
if (lineno <= 0) {
etx_sum = 0.0;
etx_num = 0;
- return (0);
+ return 0;
}
/* Special handling after the last line */
olsrd_submit(/* p.-inst = */ "routes", /* type = */ "route_etx", "average",
etx);
- return (0);
+ return 0;
}
if (fields_num != 5)
- return (-1);
+ return -1;
routes_num++;
}
}
- return (0);
+ return 0;
} /* }}} int olsrd_cb_routes */
static int olsrd_cb_topology(int lineno, /* {{{ */
char *endptr;
if (config_want_topology == OLSRD_WANT_NOT)
- return (0);
+ return 0;
/* Special handling of the first line */
if (lineno <= 0) {
lq_num = 0;
links_num = 0;
- return (0);
+ return 0;
}
/* Special handling after the last line */
olsrd_submit(/* p.-inst = */ "topology", /* type = */ "signal_quality",
/* t.-inst = */ "average", lq);
- return (0);
+ return 0;
}
if (fields_num != 5)
- return (-1);
+ return -1;
links_num++;
if (config_want_topology == OLSRD_WANT_DETAIL) {
char type_instance[DATA_MAX_NAME_LEN] = {0};
- ssnprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
- fields[1]);
+ snprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
+ fields[1]);
DEBUG("olsrd plugin: type_instance = %s; lq = %g;", type_instance, lq);
olsrd_submit(/* p.-inst = */ "topology", /* type = */ "signal_quality",
type_instance, lq);
} else {
char type_instance[DATA_MAX_NAME_LEN] = {0};
- ssnprintf(type_instance, sizeof(type_instance), "%s-%s-nlq", fields[0],
- fields[1]);
+ snprintf(type_instance, sizeof(type_instance), "%s-%s-nlq", fields[0],
+ fields[1]);
DEBUG("olsrd plugin: type_instance = %s; nlq = %g;", type_instance, nlq);
olsrd_submit(/* p.-inst = */ "topology", /* type = */ "signal_quality",
type_instance, nlq);
}
}
- return (0);
+ return 0;
} /* }}} int olsrd_cb_topology */
static int olsrd_read_table(FILE *fh, /* {{{ */
lineno++;
} /* while (fgets) */
- return (0);
+ return 0;
} /* }}} int olsrd_read_table */
static int olsrd_config(const char *key, const char *value) /* {{{ */
olsrd_set_detail(&config_want_topology, value, key);
else {
ERROR("olsrd plugin: Unknown configuration option given: %s", key);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
} /* }}} int olsrd_config */
static int olsrd_read(void) /* {{{ */
fh = olsrd_connect();
if (fh == NULL)
- return (-1);
+ return -1;
fputs("\r\n", fh);
fflush(fh);
fclose(fh);
- return (0);
+ return 0;
} /* }}} int olsrd_read */
static int olsrd_shutdown(void) /* {{{ */
sfree(config_node);
sfree(config_service);
- return (0);
+ return 0;
} /* }}} int olsrd_shutdown */
void module_register(void) {
plugin_register_read("olsrd", olsrd_read);
plugin_register_shutdown("olsrd", olsrd_shutdown);
} /* void module_register */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */