They don't do any harm but they are not really needed either.
Contributors are not used to following this style, and reviewers have to
keep pointing it out in reviews. This takes up valuable time for both
the contributor and the reviewer and distracts from the more important
issues.
I used the following Coccinelle patch:
@@
expression e;
@@
- return (e);
+ return e;
spatch is having trouble with some files so I have cleaned up the rest
with a few regexes.
201 files changed:
&& (c[2] == 0xc0) && (c[3] == 0xc7)
&& (c[4] == 0x43) && (c[5] == 0x2b)
&& (c[6] == 0x1f) && (c[7] == 0x5b))
&& (c[2] == 0xc0) && (c[3] == 0xc7)
&& (c[4] == 0x43) && (c[5] == 0x2b)
&& (c[6] == 0x1f) && (c[7] == 0x5b))
- return (0);
- return (1);
&& (c[2] == 0xc0) && (c[3] == 0xc7)
&& (c[4] == 0x43) && (c[5] == 0x2b)
&& (c[6] == 0x1f) && (c[7] == 0x5b))
&& (c[2] == 0xc0) && (c[3] == 0xc7)
&& (c[4] == 0x43) && (c[5] == 0x2b)
&& (c[6] == 0x1f) && (c[7] == 0x5b))
- return (0);
- return (1);
&& (c[2] == 0xc0) && (c[3] == 0xc7)
&& (c[4] == 0x43) && (c[5] == 0x2b)
&& (c[6] == 0x1f) && (c[7] == 0x5b))
&& (c[2] == 0xc0) && (c[3] == 0xc7)
&& (c[4] == 0x43) && (c[5] == 0x2b)
&& (c[6] == 0x1f) && (c[7] == 0x5b))
- return (0);
- return (1);
]],
[[
int retval = TCA_STATS2;
]],
[[
int retval = TCA_STATS2;
]],
[[
int retval = TCA_STATS;
]],
[[
int retval = TCA_STATS;
size_t len;
if (str == NULL)
size_t len;
if (str == NULL)
len = strlen(str);
if (len < 3)
len = strlen(str);
if (len < 3)
if ((str[0] == '/') && (str[len - 1] == '/'))
if ((str[0] == '/') && (str[len - 1] == '/'))
} /* }}} _Bool agg_is_regex */
static void agg_destroy(aggregation_t *agg) /* {{{ */
} /* }}} _Bool agg_is_regex */
static void agg_destroy(aggregation_t *agg) /* {{{ */
} /* }}} int agg_instance_create_name */
/* Create a new aggregation instance. */
} /* }}} int agg_instance_create_name */
/* Create a new aggregation instance. */
inst = calloc(1, sizeof(*inst));
if (inst == NULL) {
ERROR("aggregation plugin: calloc() failed.");
inst = calloc(1, sizeof(*inst));
if (inst == NULL) {
ERROR("aggregation plugin: calloc() failed.");
}
pthread_mutex_init(&inst->lock, /* attr = */ NULL);
}
pthread_mutex_init(&inst->lock, /* attr = */ NULL);
agg_instance_destroy(inst); \
free(inst); \
ERROR("aggregation plugin: calloc() failed."); \
agg_instance_destroy(inst); \
free(inst); \
ERROR("aggregation plugin: calloc() failed."); \
agg_instance_list_head = inst;
pthread_mutex_unlock(&agg_instance_list_lock);
agg_instance_list_head = inst;
pthread_mutex_unlock(&agg_instance_list_lock);
} /* }}} agg_instance_t *agg_instance_create */
/* Update the num, sum, min, max, ... fields of the aggregation instance, if
} /* }}} agg_instance_t *agg_instance_create */
/* Update the num, sum, min, max, ... fields of the aggregation instance, if
"data source. This is currently not supported by this plugin. "
"Sorry.",
ds->type);
"data source. This is currently not supported by this plugin. "
"Sorry.",
ds->type);
}
rate = uc_get_rate(ds, vl);
}
rate = uc_get_rate(ds, vl);
FORMAT_VL(ident, sizeof(ident), vl);
ERROR("aggregation plugin: Unable to read the current rate of \"%s\".",
ident);
FORMAT_VL(ident, sizeof(ident), vl);
ERROR("aggregation plugin: Unable to read the current rate of \"%s\".",
ident);
}
if (isnan(rate[0])) {
sfree(rate);
}
if (isnan(rate[0])) {
sfree(rate);
}
pthread_mutex_lock(&inst->lock);
}
pthread_mutex_lock(&inst->lock);
pthread_mutex_unlock(&inst->lock);
sfree(rate);
pthread_mutex_unlock(&inst->lock);
sfree(rate);
} /* }}} int agg_instance_update */
static int agg_instance_read_func(agg_instance_t *inst, /* {{{ */
} /* }}} int agg_instance_update */
static int agg_instance_read_func(agg_instance_t *inst, /* {{{ */
* COUNTER or a DERIVE, it will return EAGAIN. Catch this and handle
* gracefully. */
if (status == EAGAIN)
* COUNTER or a DERIVE, it will return EAGAIN. Catch this and handle
* gracefully. */
if (status == EAGAIN)
WARNING("aggregation plugin: rate_to_value failed with status %i.", status);
WARNING("aggregation plugin: rate_to_value failed with status %i.", status);
vl->values = NULL;
vl->values_len = 0;
vl->values = NULL;
vl->values_len = 0;
} /* }}} int agg_instance_read_func */
static int agg_instance_read(agg_instance_t *inst, cdtime_t t) /* {{{ */
} /* }}} int agg_instance_read_func */
static int agg_instance_read(agg_instance_t *inst, cdtime_t t) /* {{{ */
vl.meta = meta_data_create();
if (vl.meta == NULL) {
ERROR("aggregation plugin: meta_data_create failed.");
vl.meta = meta_data_create();
if (vl.meta == NULL) {
ERROR("aggregation plugin: meta_data_create failed.");
}
meta_data_add_boolean(vl.meta, "aggregation:created", 1);
}
meta_data_add_boolean(vl.meta, "aggregation:created", 1);
meta_data_destroy(vl.meta);
vl.meta = NULL;
meta_data_destroy(vl.meta);
vl.meta = NULL;
} /* }}} int agg_instance_read */
/* lookup_class_callback_t for utils_vl_lookup */
} /* }}} int agg_instance_read */
/* lookup_class_callback_t for utils_vl_lookup */
data_set_t const *ds,
value_list_t const *vl,
void *user_class) {
data_set_t const *ds,
value_list_t const *vl,
void *user_class) {
- return (agg_instance_create(ds, vl, (aggregation_t *)user_class));
+ return agg_instance_create(ds, vl, (aggregation_t *)user_class);
} /* }}} void *agg_class_callback */
/* lookup_obj_callback_t for utils_vl_lookup */
} /* }}} void *agg_class_callback */
/* lookup_obj_callback_t for utils_vl_lookup */
value_list_t const *vl,
__attribute__((unused)) void *user_class,
void *user_obj) {
value_list_t const *vl,
__attribute__((unused)) void *user_class,
void *user_obj) {
- return (agg_instance_update((agg_instance_t *)user_obj, ds, vl));
+ return agg_instance_update((agg_instance_t *)user_obj, ds, vl);
} /* }}} int agg_lookup_obj_callback */
/* lookup_free_class_callback_t for utils_vl_lookup */
} /* }}} int agg_lookup_obj_callback */
/* lookup_free_class_callback_t for utils_vl_lookup */
value);
} /* for (ci->values) */
value);
} /* for (ci->values) */
} /* }}} int agg_config_handle_group_by */
static int agg_config_aggregation(oconfig_item_t *ci) /* {{{ */
} /* }}} int agg_config_handle_group_by */
static int agg_config_aggregation(oconfig_item_t *ci) /* {{{ */
agg = calloc(1, sizeof(*agg));
if (agg == NULL) {
ERROR("aggregation plugin: calloc failed.");
agg = calloc(1, sizeof(*agg));
if (agg == NULL) {
ERROR("aggregation plugin: calloc failed.");
}
sstrncpy(agg->ident.host, "/.*/", sizeof(agg->ident.host));
}
sstrncpy(agg->ident.host, "/.*/", sizeof(agg->ident.host));
if (!is_valid) /* {{{ */
{
sfree(agg);
if (!is_valid) /* {{{ */
{
sfree(agg);
} /* }}} */
status = lookup_add(lookup, &agg->ident, agg->group_by, agg);
if (status != 0) {
ERROR("aggregation plugin: lookup_add failed with status %i.", status);
sfree(agg);
} /* }}} */
status = lookup_add(lookup, &agg->ident, agg->group_by, agg);
if (status != 0) {
ERROR("aggregation plugin: lookup_add failed with status %i.", status);
sfree(agg);
}
DEBUG("aggregation plugin: Successfully added aggregation: "
}
DEBUG("aggregation plugin: Successfully added aggregation: "
"Type \"%s\", TypeInstance \"%s\")",
agg->ident.host, agg->ident.plugin, agg->ident.plugin_instance,
agg->ident.type, agg->ident.type_instance);
"Type \"%s\", TypeInstance \"%s\")",
agg->ident.host, agg->ident.plugin, agg->ident.plugin_instance,
agg->ident.type, agg->ident.type_instance);
} /* }}} int agg_config_aggregation */
static int agg_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int agg_config_aggregation */
static int agg_config(oconfig_item_t *ci) /* {{{ */
if (lookup == NULL) {
pthread_mutex_unlock(&agg_instance_list_lock);
ERROR("aggregation plugin: lookup_create failed.");
if (lookup == NULL) {
pthread_mutex_unlock(&agg_instance_list_lock);
ERROR("aggregation plugin: lookup_create failed.");
pthread_mutex_unlock(&agg_instance_list_lock);
pthread_mutex_unlock(&agg_instance_list_lock);
} /* }}} int agg_config */
static int agg_read(void) /* {{{ */
} /* }}} int agg_config */
static int agg_read(void) /* {{{ */
* Therefore we need to handle this case separately. */
if (agg_instance_list_head == NULL) {
pthread_mutex_unlock(&agg_instance_list_lock);
* Therefore we need to handle this case separately. */
if (agg_instance_list_head == NULL) {
pthread_mutex_unlock(&agg_instance_list_lock);
}
for (agg_instance_t *this = agg_instance_list_head; this != NULL;
}
for (agg_instance_t *this = agg_instance_list_head; this != NULL;
pthread_mutex_unlock(&agg_instance_list_lock);
pthread_mutex_unlock(&agg_instance_list_lock);
- return ((success > 0) ? 0 : -1);
+ return (success > 0) ? 0 : -1;
} /* }}} int agg_read */
static int agg_write(data_set_t const *ds, value_list_t const *vl, /* {{{ */
} /* }}} int agg_read */
static int agg_write(data_set_t const *ds, value_list_t const *vl, /* {{{ */
(void)meta_data_get_boolean(vl->meta, "aggregation:created",
&created_by_aggregation);
if (created_by_aggregation)
(void)meta_data_get_boolean(vl->meta, "aggregation:created",
&created_by_aggregation);
if (created_by_aggregation)
if (lookup == NULL)
status = ENOENT;
if (lookup == NULL)
status = ENOENT;
} /* }}} int agg_write */
void module_register(void) {
} /* }}} int agg_write */
void module_register(void) {
char *ret;
if ((in == NULL) || (in->bytes == NULL))
char *ret;
if ((in == NULL) || (in->bytes == NULL))
ret = malloc(in->len + 1);
if (ret == NULL)
ret = malloc(in->len + 1);
if (ret == NULL)
memcpy(ret, in->bytes, in->len);
ret[in->len] = 0;
memcpy(ret, in->bytes, in->len);
ret[in->len] = 0;
} /* }}} char *camqp_bytes_cstring */
static _Bool camqp_is_error(camqp_config_t *conf) /* {{{ */
} /* }}} char *camqp_bytes_cstring */
static _Bool camqp_is_error(camqp_config_t *conf) /* {{{ */
r = amqp_get_rpc_reply(conf->connection);
if (r.reply_type == AMQP_RESPONSE_NORMAL)
r = amqp_get_rpc_reply(conf->connection);
if (r.reply_type == AMQP_RESPONSE_NORMAL)
} /* }}} _Bool camqp_is_error */
static char *camqp_strerror(camqp_config_t *conf, /* {{{ */
} /* }}} _Bool camqp_is_error */
static char *camqp_strerror(camqp_config_t *conf, /* {{{ */
case AMQP_RESPONSE_LIBRARY_EXCEPTION:
#if HAVE_AMQP_RPC_REPLY_T_LIBRARY_ERRNO
if (r.library_errno)
case AMQP_RESPONSE_LIBRARY_EXCEPTION:
#if HAVE_AMQP_RPC_REPLY_T_LIBRARY_ERRNO
if (r.library_errno)
- return (sstrerror(r.library_errno, buffer, buffer_size));
+ return sstrerror(r.library_errno, buffer, buffer_size);
#else
if (r.library_error)
#else
if (r.library_error)
- return (sstrerror(r.library_error, buffer, buffer_size));
+ return sstrerror(r.library_error, buffer, buffer_size);
#endif
else
sstrncpy(buffer, "End of stream", buffer_size);
#endif
else
sstrncpy(buffer, "End of stream", buffer_size);
ssnprintf(buffer, buffer_size, "Unknown reply type %i", (int)r.reply_type);
}
ssnprintf(buffer, buffer_size, "Unknown reply type %i", (int)r.reply_type);
}
} /* }}} char *camqp_strerror */
#if HAVE_AMQP_RPC_REPLY_T_LIBRARY_ERRNO
} /* }}} char *camqp_strerror */
#if HAVE_AMQP_RPC_REPLY_T_LIBRARY_ERRNO
amqp_exchange_declare_ok_t *ed_ret;
if (conf->exchange_type == NULL)
amqp_exchange_declare_ok_t *ed_ret;
if (conf->exchange_type == NULL)
ed_ret = amqp_exchange_declare(
conf->connection,
ed_ret = amqp_exchange_declare(
conf->connection,
ERROR("amqp plugin: amqp_exchange_declare failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
ERROR("amqp plugin: amqp_exchange_declare failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
}
INFO("amqp plugin: Successfully created exchange \"%s\" "
"with type \"%s\".",
conf->exchange, conf->exchange_type);
}
INFO("amqp plugin: Successfully created exchange \"%s\" "
"with type \"%s\".",
conf->exchange, conf->exchange_type);
} /* }}} int camqp_create_exchange */
#else
static int camqp_create_exchange(camqp_config_t *conf) /* {{{ */
} /* }}} int camqp_create_exchange */
#else
static int camqp_create_exchange(camqp_config_t *conf) /* {{{ */
struct amqp_table_entry_t_ argument_table_entries[1];
if (conf->exchange_type == NULL)
struct amqp_table_entry_t_ argument_table_entries[1];
if (conf->exchange_type == NULL)
/* Valid arguments: "auto_delete", "internal" */
argument_table.num_entries = STATIC_ARRAY_SIZE(argument_table_entries);
/* Valid arguments: "auto_delete", "internal" */
argument_table.num_entries = STATIC_ARRAY_SIZE(argument_table_entries);
ERROR("amqp plugin: amqp_exchange_declare failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
ERROR("amqp plugin: amqp_exchange_declare failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
}
INFO("amqp plugin: Successfully created exchange \"%s\" "
"with type \"%s\".",
conf->exchange, conf->exchange_type);
}
INFO("amqp plugin: Successfully created exchange \"%s\" "
"with type \"%s\".",
conf->exchange, conf->exchange_type);
} /* }}} int camqp_create_exchange */
#endif
} /* }}} int camqp_create_exchange */
#endif
if (qd_ret == NULL) {
ERROR("amqp plugin: amqp_queue_declare failed.");
camqp_close_connection(conf);
if (qd_ret == NULL) {
ERROR("amqp plugin: amqp_queue_declare failed.");
camqp_close_connection(conf);
}
if (conf->queue == NULL) {
}
if (conf->queue == NULL) {
if (conf->queue == NULL) {
ERROR("amqp plugin: camqp_bytes_cstring failed.");
camqp_close_connection(conf);
if (conf->queue == NULL) {
ERROR("amqp plugin: camqp_bytes_cstring failed.");
camqp_close_connection(conf);
}
INFO("amqp plugin: Created queue \"%s\".", conf->queue);
}
INFO("amqp plugin: Created queue \"%s\".", conf->queue);
ERROR("amqp plugin: amqp_queue_bind failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
ERROR("amqp plugin: amqp_queue_bind failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
}
DEBUG("amqp plugin: Successfully bound queue \"%s\" to exchange \"%s\".",
}
DEBUG("amqp plugin: Successfully bound queue \"%s\" to exchange \"%s\".",
ERROR("amqp plugin: amqp_basic_consume failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
ERROR("amqp plugin: amqp_basic_consume failed: %s",
camqp_strerror(conf, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
} /* }}} int camqp_setup_queue */
static int camqp_connect(camqp_config_t *conf) /* {{{ */
} /* }}} int camqp_setup_queue */
static int camqp_connect(camqp_config_t *conf) /* {{{ */
#endif
if (conf->connection != NULL)
#endif
if (conf->connection != NULL)
time_t now = time(NULL);
if (now < (last_connect_time + conf->connection_retry_delay)) {
DEBUG("amqp plugin: skipping connection retry, "
"ConnectionRetryDelay: %d",
conf->connection_retry_delay);
time_t now = time(NULL);
if (now < (last_connect_time + conf->connection_retry_delay)) {
DEBUG("amqp plugin: skipping connection retry, "
"ConnectionRetryDelay: %d",
conf->connection_retry_delay);
} else {
DEBUG("amqp plugin: retrying connection");
last_connect_time = now;
} else {
DEBUG("amqp plugin: retrying connection");
last_connect_time = now;
conf->connection = amqp_new_connection();
if (conf->connection == NULL) {
ERROR("amqp plugin: amqp_new_connection failed.");
conf->connection = amqp_new_connection();
if (conf->connection == NULL) {
ERROR("amqp plugin: amqp_new_connection failed.");
}
#ifdef HAVE_AMQP_TCP_SOCKET
}
#ifdef HAVE_AMQP_TCP_SOCKET
ERROR("amqp plugin: amqp_tcp_socket_new failed.");
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
ERROR("amqp plugin: amqp_tcp_socket_new failed.");
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
}
status = amqp_socket_open(socket, CONF(conf, host), conf->port);
}
status = amqp_socket_open(socket, CONF(conf, host), conf->port);
sstrerror(status, errbuf, sizeof(errbuf)));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
sstrerror(status, errbuf, sizeof(errbuf)));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
}
#else /* HAVE_AMQP_TCP_SOCKET */
#define CLOSE_SOCKET() close(sockfd)
}
#else /* HAVE_AMQP_TCP_SOCKET */
#define CLOSE_SOCKET() close(sockfd)
sstrerror(status, errbuf, sizeof(errbuf)));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
sstrerror(status, errbuf, sizeof(errbuf)));
amqp_destroy_connection(conf->connection);
conf->connection = NULL;
}
amqp_set_sockfd(conf->connection, sockfd);
#endif
}
amqp_set_sockfd(conf->connection, sockfd);
#endif
amqp_destroy_connection(conf->connection);
CLOSE_SOCKET();
conf->connection = NULL;
amqp_destroy_connection(conf->connection);
CLOSE_SOCKET();
conf->connection = NULL;
}
amqp_channel_open(conf->connection, /* channel = */ 1);
}
amqp_channel_open(conf->connection, /* channel = */ 1);
amqp_destroy_connection(conf->connection);
CLOSE_SOCKET();
conf->connection = NULL;
amqp_destroy_connection(conf->connection);
CLOSE_SOCKET();
conf->connection = NULL;
}
INFO("amqp plugin: Successfully opened connection to vhost \"%s\" "
}
INFO("amqp plugin: Successfully opened connection to vhost \"%s\" "
status = camqp_create_exchange(conf);
if (status != 0)
status = camqp_create_exchange(conf);
if (status != 0)
- return (camqp_setup_queue(conf));
- return (0);
+ return camqp_setup_queue(conf);
+ return 0;
} /* }}} int camqp_connect */
static int camqp_shutdown(void) /* {{{ */
} /* }}} int camqp_connect */
static int camqp_shutdown(void) /* {{{ */
DEBUG("amqp plugin: All subscriber threads exited.");
DEBUG("amqp plugin: All subscriber threads exited.");
} /* }}} int camqp_shutdown */
/*
} /* }}} int camqp_shutdown */
/*
ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
}
if (frame.frame_type != AMQP_FRAME_BODY) {
NOTICE("amqp plugin: Unexpected frame type: %#" PRIx8, frame.frame_type);
}
if (frame.frame_type != AMQP_FRAME_BODY) {
NOTICE("amqp plugin: Unexpected frame type: %#" PRIx8, frame.frame_type);
}
if ((body_size - received) < frame.payload.body_fragment.len) {
WARNING("amqp plugin: Body is larger than indicated by header.");
}
if ((body_size - received) < frame.payload.body_fragment.len) {
WARNING("amqp plugin: Body is larger than indicated by header.");
}
memcpy(body_ptr, frame.payload.body_fragment.bytes,
}
memcpy(body_ptr, frame.payload.body_fragment.bytes,
status = cmd_handle_putval(stderr, body);
if (status != 0)
ERROR("amqp plugin: cmd_handle_putval failed with status %i.", status);
status = cmd_handle_putval(stderr, body);
if (status != 0)
ERROR("amqp plugin: cmd_handle_putval failed with status %i.", status);
} else if (strcasecmp("application/json", content_type) == 0) {
ERROR("amqp plugin: camqp_read_body: Parsing JSON data has not "
"been implemented yet. FIXME!");
} else if (strcasecmp("application/json", content_type) == 0) {
ERROR("amqp plugin: camqp_read_body: Parsing JSON data has not "
"been implemented yet. FIXME!");
} else {
ERROR("amqp plugin: camqp_read_body: Unknown content type \"%s\".",
content_type);
} else {
ERROR("amqp plugin: camqp_read_body: Unknown content type \"%s\".",
content_type);
} /* }}} int camqp_read_body */
static int camqp_read_header(camqp_config_t *conf) /* {{{ */
} /* }}} int camqp_read_body */
static int camqp_read_header(camqp_config_t *conf) /* {{{ */
ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
ERROR("amqp plugin: amqp_simple_wait_frame failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
camqp_close_connection(conf);
}
if (frame.frame_type != AMQP_FRAME_HEADER) {
NOTICE("amqp plugin: Unexpected frame type: %#" PRIx8, frame.frame_type);
}
if (frame.frame_type != AMQP_FRAME_HEADER) {
NOTICE("amqp plugin: Unexpected frame type: %#" PRIx8, frame.frame_type);
}
properties = frame.payload.properties.decoded;
content_type = camqp_bytes_cstring(&properties->content_type);
if (content_type == NULL) {
ERROR("amqp plugin: Unable to determine content type.");
}
properties = frame.payload.properties.decoded;
content_type = camqp_bytes_cstring(&properties->content_type);
if (content_type == NULL) {
ERROR("amqp plugin: Unable to determine content type.");
}
status = camqp_read_body(conf, (size_t)frame.payload.properties.body_size,
content_type);
sfree(content_type);
}
status = camqp_read_body(conf, (size_t)frame.payload.properties.body_size,
content_type);
sfree(content_type);
} /* }}} int camqp_read_header */
static void *camqp_subscribe_thread(void *user_data) /* {{{ */
} /* }}} int camqp_read_header */
static void *camqp_subscribe_thread(void *user_data) /* {{{ */
camqp_config_free(conf);
pthread_exit(NULL);
camqp_config_free(conf);
pthread_exit(NULL);
} /* }}} void *camqp_subscribe_thread */
static int camqp_subscribe_init(camqp_config_t *conf) /* {{{ */
} /* }}} void *camqp_subscribe_thread */
static int camqp_subscribe_init(camqp_config_t *conf) /* {{{ */
if (tmp == NULL) {
ERROR("amqp plugin: realloc failed.");
sfree(subscriber_threads);
if (tmp == NULL) {
ERROR("amqp plugin: realloc failed.");
sfree(subscriber_threads);
}
subscriber_threads = tmp;
tmp = subscriber_threads + subscriber_threads_num;
}
subscriber_threads = tmp;
tmp = subscriber_threads + subscriber_threads_num;
char errbuf[1024];
ERROR("amqp plugin: pthread_create failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("amqp plugin: pthread_create failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
}
subscriber_threads_num++;
}
subscriber_threads_num++;
} /* }}} int camqp_subscribe_init */
/*
} /* }}} int camqp_subscribe_init */
/*
status = camqp_connect(conf);
if (status != 0)
status = camqp_connect(conf);
if (status != 0)
amqp_basic_properties_t props = {._flags = AMQP_BASIC_CONTENT_TYPE_FLAG |
AMQP_BASIC_DELIVERY_MODE_FLAG |
amqp_basic_properties_t props = {._flags = AMQP_BASIC_CONTENT_TYPE_FLAG |
AMQP_BASIC_DELIVERY_MODE_FLAG |
camqp_close_connection(conf);
}
camqp_close_connection(conf);
}
} /* }}} int camqp_write_locked */
static int camqp_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
} /* }}} int camqp_write_locked */
static int camqp_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
int status;
if ((ds == NULL) || (vl == NULL) || (conf == NULL))
int status;
if ((ds == NULL) || (vl == NULL) || (conf == NULL))
if (conf->routing_key != NULL) {
sstrncpy(routing_key, conf->routing_key, sizeof(routing_key));
if (conf->routing_key != NULL) {
sstrncpy(routing_key, conf->routing_key, sizeof(routing_key));
status = cmd_create_putval(buffer, sizeof(buffer), ds, vl);
if (status != 0) {
ERROR("amqp plugin: cmd_create_putval failed with status %i.", status);
status = cmd_create_putval(buffer, sizeof(buffer), ds, vl);
if (status != 0) {
ERROR("amqp plugin: cmd_create_putval failed with status %i.", status);
}
} else if (conf->format == CAMQP_FORMAT_JSON) {
size_t bfree = sizeof(buffer);
}
} else if (conf->format == CAMQP_FORMAT_JSON) {
size_t bfree = sizeof(buffer);
conf->postfix, conf->escape_char, conf->graphite_flags);
if (status != 0) {
ERROR("amqp plugin: format_graphite failed with status %i.", status);
conf->postfix, conf->escape_char, conf->graphite_flags);
if (status != 0) {
ERROR("amqp plugin: format_graphite failed with status %i.", status);
}
} else {
ERROR("amqp plugin: Invalid format (%i).", conf->format);
}
} else {
ERROR("amqp plugin: Invalid format (%i).", conf->format);
}
pthread_mutex_lock(&conf->lock);
status = camqp_write_locked(conf, buffer, routing_key);
pthread_mutex_unlock(&conf->lock);
}
pthread_mutex_lock(&conf->lock);
status = camqp_write_locked(conf, buffer, routing_key);
pthread_mutex_unlock(&conf->lock);
} /* }}} int camqp_write */
/*
} /* }}} int camqp_write */
/*
string = NULL;
status = cf_util_get_string(ci, &string);
if (status != 0)
string = NULL;
status = cf_util_get_string(ci, &string);
if (status != 0)
assert(string != NULL);
if (strcasecmp("Command", string) == 0)
assert(string != NULL);
if (strcasecmp("Command", string) == 0)
} /* }}} int config_set_string */
static int camqp_config_connection(oconfig_item_t *ci, /* {{{ */
} /* }}} int config_set_string */
static int camqp_config_connection(oconfig_item_t *ci, /* {{{ */
conf = calloc(1, sizeof(*conf));
if (conf == NULL) {
ERROR("amqp plugin: calloc failed.");
conf = calloc(1, sizeof(*conf));
if (conf == NULL) {
ERROR("amqp plugin: calloc failed.");
}
/* Initialize "conf" {{{ */
}
/* Initialize "conf" {{{ */
status = cf_util_get_string(ci, &conf->name);
if (status != 0) {
sfree(conf);
status = cf_util_get_string(ci, &conf->name);
if (status != 0) {
sfree(conf);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
if (status != 0) {
camqp_config_free(conf);
if (status != 0) {
camqp_config_free(conf);
}
if (conf->exchange != NULL) {
}
if (conf->exchange != NULL) {
});
if (status != 0) {
camqp_config_free(conf);
});
if (status != 0) {
camqp_config_free(conf);
}
} else {
status = camqp_subscribe_init(conf);
if (status != 0) {
camqp_config_free(conf);
}
} else {
status = camqp_subscribe_init(conf);
if (status != 0) {
camqp_config_free(conf);
} /* }}} int camqp_config_connection */
static int camqp_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int camqp_config_connection */
static int camqp_config(oconfig_item_t *ci) /* {{{ */
child->key);
} /* for (ci->children_num) */
child->key);
} /* for (ci->children_num) */
} /* }}} int camqp_config */
void module_register(void) {
} /* }}} int camqp_config */
void module_register(void) {
if (st == NULL) {
ERROR("apache plugin: apache_curl_callback: "
"user_data pointer is NULL.");
if (st == NULL) {
ERROR("apache plugin: apache_curl_callback: "
"user_data pointer is NULL.");
if ((st->apache_buffer_fill + len) >= st->apache_buffer_size) {
char *temp;
if ((st->apache_buffer_fill + len) >= st->apache_buffer_size) {
char *temp;
temp = realloc(st->apache_buffer, st->apache_buffer_fill + len + 1);
if (temp == NULL) {
ERROR("apache plugin: realloc failed.");
temp = realloc(st->apache_buffer, st->apache_buffer_fill + len + 1);
if (temp == NULL) {
ERROR("apache plugin: realloc failed.");
}
st->apache_buffer = temp;
st->apache_buffer_size = st->apache_buffer_fill + len + 1;
}
st->apache_buffer = temp;
st->apache_buffer_size = st->apache_buffer_fill + len + 1;
st->apache_buffer_fill += len;
st->apache_buffer[st->apache_buffer_fill] = 0;
st->apache_buffer_fill += len;
st->apache_buffer[st->apache_buffer_fill] = 0;
} /* int apache_curl_callback */
static size_t apache_header_callback(void *buf, size_t size, size_t nmemb,
} /* int apache_curl_callback */
static size_t apache_header_callback(void *buf, size_t size, size_t nmemb,
if (st == NULL) {
ERROR("apache plugin: apache_header_callback: "
"user_data pointer is NULL.");
if (st == NULL) {
ERROR("apache plugin: apache_header_callback: "
"user_data pointer is NULL.");
/* look for the Server header */
if (strncasecmp(buf, "Server: ", strlen("Server: ")) != 0)
/* look for the Server header */
if (strncasecmp(buf, "Server: ", strlen("Server: ")) != 0)
if (strstr(buf, "Apache") != NULL)
st->server_type = APACHE;
if (strstr(buf, "Apache") != NULL)
st->server_type = APACHE;
NOTICE("apache plugin: Unknown server software: %s", hdr);
}
NOTICE("apache plugin: Unknown server software: %s", hdr);
}
} /* apache_header_callback */
/* Configuration handling functiions
} /* apache_header_callback */
/* Configuration handling functiions
st = calloc(1, sizeof(*st));
if (st == NULL) {
ERROR("apache plugin: calloc failed.");
st = calloc(1, sizeof(*st));
if (st == NULL) {
ERROR("apache plugin: calloc failed.");
status = cf_util_get_string(ci, &st->name);
if (status != 0) {
sfree(st);
status = cf_util_get_string(ci, &st->name);
if (status != 0) {
sfree(st);
}
assert(st->name != NULL);
}
assert(st->name != NULL);
if (status != 0) {
apache_free(st);
if (status != 0) {
apache_free(st);
} /* int config_add */
static int config(oconfig_item_t *ci) {
} /* int config_add */
static int config(oconfig_item_t *ci) {
child->key);
} /* for (ci->children) */
child->key);
} /* for (ci->children) */
} /* int config */
/* initialize curl for each host */
} /* int config */
/* initialize curl for each host */
if ((st->curl = curl_easy_init()) == NULL) {
ERROR("apache plugin: init_host: `curl_easy_init' failed.");
if ((st->curl = curl_easy_init()) == NULL) {
ERROR("apache plugin: init_host: `curl_easy_init' failed.");
}
curl_easy_setopt(st->curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(st->curl, CURLOPT_NOSIGNAL, 1L);
"truncated.");
curl_easy_cleanup(st->curl);
st->curl = NULL;
"truncated.");
curl_easy_cleanup(st->curl);
st->curl = NULL;
}
curl_easy_setopt(st->curl, CURLOPT_USERPWD, credentials);
}
curl_easy_setopt(st->curl, CURLOPT_USERPWD, credentials);
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
} /* }}} int init_host */
static void submit_value(const char *type, const char *type_instance,
} /* }}} int init_host */
static void submit_value(const char *type, const char *type_instance,
if (st->curl == NULL) {
status = init_host(st);
if (status != 0)
if (st->curl == NULL) {
status = init_host(st);
if (status != 0)
}
assert(st->curl != NULL);
st->apache_buffer_fill = 0;
if (curl_easy_perform(st->curl) != CURLE_OK) {
ERROR("apache: curl_easy_perform failed: %s", st->apache_curl_error);
}
assert(st->curl != NULL);
st->apache_buffer_fill = 0;
if (curl_easy_perform(st->curl) != CURLE_OK) {
ERROR("apache: curl_easy_perform failed: %s", st->apache_curl_error);
}
/* fallback - server_type to apache if not set at this time */
}
/* fallback - server_type to apache if not set at this time */
st->apache_buffer_fill = 0;
st->apache_buffer_fill = 0;
} /* }}} int apache_read_host */
static int apache_init(void) /* {{{ */
} /* }}} int apache_read_host */
static int apache_init(void) /* {{{ */
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
} /* }}} int apache_init */
void module_register(void) {
} /* }}} int apache_init */
void module_register(void) {
uint16_t packet_size = 0;
if ((fd == NULL) || (*fd < 0))
uint16_t packet_size = 0;
if ((fd == NULL) || (*fd < 0))
(void)swrite(*fd, (void *)&packet_size, sizeof(packet_size));
close(*fd);
*fd = -1;
(void)swrite(*fd, (void *)&packet_size, sizeof(packet_size));
close(*fd);
*fd = -1;
} /* int net_shutdown */
/* Close the network connection */
static int apcups_shutdown(void) {
if (global_sockfd < 0)
} /* int net_shutdown */
/* Close the network connection */
static int apcups_shutdown(void) {
if (global_sockfd < 0)
net_shutdown(&global_sockfd);
net_shutdown(&global_sockfd);
} /* int apcups_shutdown */
/*
} /* int apcups_shutdown */
/*
INFO("apcups plugin: getaddrinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
INFO("apcups plugin: getaddrinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
if (sd < 0) {
DEBUG("apcups plugin: Unable to open a socket");
freeaddrinfo(ai_return);
if (sd < 0) {
DEBUG("apcups plugin: Unable to open a socket");
freeaddrinfo(ai_return);
}
status = connect(sd, ai_list->ai_addr, ai_list->ai_addrlen);
}
status = connect(sd, ai_list->ai_addr, ai_list->ai_addrlen);
INFO("apcups plugin: connect failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sd);
INFO("apcups plugin: connect failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sd);
}
DEBUG("apcups plugin: Done opening a socket %i", sd);
}
DEBUG("apcups plugin: Done opening a socket %i", sd);
if (sread(*sockfd, (void *)&packet_size, sizeof(packet_size)) != 0) {
close(*sockfd);
*sockfd = -1;
if (sread(*sockfd, (void *)&packet_size, sizeof(packet_size)) != 0) {
close(*sockfd);
*sockfd = -1;
}
packet_size = ntohs(packet_size);
}
packet_size = ntohs(packet_size);
packet_size, buflen);
close(*sockfd);
*sockfd = -1;
packet_size, buflen);
close(*sockfd);
*sockfd = -1;
/* now read the actual data */
if (sread(*sockfd, (void *)buf, packet_size) != 0) {
close(*sockfd);
*sockfd = -1;
/* now read the actual data */
if (sread(*sockfd, (void *)buf, packet_size) != 0) {
close(*sockfd);
*sockfd = -1;
- return ((int)packet_size);
+ return (int)packet_size;
} /* static int net_recv (int *sockfd, char *buf, int buflen) */
/*
} /* static int net_recv (int *sockfd, char *buf, int buflen) */
/*
if (swrite(*sockfd, (void *)&packet_size, sizeof(packet_size)) != 0) {
close(*sockfd);
*sockfd = -1;
if (swrite(*sockfd, (void *)&packet_size, sizeof(packet_size)) != 0) {
close(*sockfd);
*sockfd = -1;
}
/* send data packet */
if (swrite(*sockfd, (void *)buff, len) != 0) {
close(*sockfd);
*sockfd = -1;
}
/* send data packet */
if (swrite(*sockfd, (void *)buff, len) != 0) {
close(*sockfd);
*sockfd = -1;
}
/* Get and print status from apcupsd NIS server */
}
/* Get and print status from apcupsd NIS server */
if (global_sockfd < 0) {
ERROR("apcups plugin: Connecting to the "
"apcupsd failed.");
if (global_sockfd < 0) {
ERROR("apcups plugin: Connecting to the "
"apcupsd failed.");
}
ERROR("apcups plugin: Writing to the socket failed.");
}
ERROR("apcups plugin: Writing to the socket failed.");
char errbuf[1024];
ERROR("apcups plugin: Reading from socket failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("apcups plugin: Reading from socket failed: %s",
sstrerror(status, errbuf, sizeof(errbuf)));
}
static int apcups_config(oconfig_item_t *ci) {
}
static int apcups_config(oconfig_item_t *ci) {
} /* int apcups_config */
static void apc_submit_generic(const char *type, const char *type_inst,
} /* int apcups_config */
static void apc_submit_generic(const char *type, const char *type_inst,
DEBUG("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d",
conf_node == NULL ? APCUPS_DEFAULT_NODE : conf_node, conf_service,
status);
DEBUG("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d",
conf_node == NULL ? APCUPS_DEFAULT_NODE : conf_node, conf_service,
status);
}
apc_submit(&apcups_detail);
}
apc_submit(&apcups_detail);
} /* apcups_read */
void module_register(void) {
} /* apcups_read */
void module_register(void) {
if (status != kIOReturnSuccess) {
ERROR("IOMasterPort failed: %s", mach_error_string(status));
io_master_port = MACH_PORT_NULL;
if (status != kIOReturnSuccess) {
ERROR("IOMasterPort failed: %s", mach_error_string(status));
io_master_port = MACH_PORT_NULL;
}
static void as_submit(const char *type, const char *type_instance, double val) {
}
static void as_submit(const char *type, const char *type_instance, double val) {
int value_int;
double value_double;
if (!io_master_port || (io_master_port == MACH_PORT_NULL))
int value_int;
double value_double;
if (!io_master_port || (io_master_port == MACH_PORT_NULL))
status = IOServiceGetMatchingServices(
io_master_port, IOServiceNameMatching("IOHWSensor"), &iterator);
if (status != kIOReturnSuccess) {
ERROR("IOServiceGetMatchingServices failed: %s", mach_error_string(status));
status = IOServiceGetMatchingServices(
io_master_port, IOServiceNameMatching("IOHWSensor"), &iterator);
if (status != kIOReturnSuccess) {
ERROR("IOServiceGetMatchingServices failed: %s", mach_error_string(status));
}
while ((io_obj = IOIteratorNext(iterator))) {
}
while ((io_obj = IOIteratorNext(iterator))) {
IOObjectRelease(iterator);
IOObjectRelease(iterator);
} /* int as_read */
void module_register(void) {
} /* int as_read */
void module_register(void) {
}
static int aquaero_shutdown(void) {
libaquaero5_exit();
}
static int aquaero_shutdown(void) {
libaquaero5_exit();
} /* int aquaero_shutdown */
static void aquaero_submit(const char *type, const char *type_instance,
} /* int aquaero_shutdown */
static void aquaero_submit(const char *type, const char *type_instance,
ERROR("aquaero plugin: Failed to poll device \"%s\": %s (%s)",
conf_device ? conf_device : "default", err_msg,
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("aquaero plugin: Failed to poll device \"%s\": %s (%s)",
conf_device ? conf_device : "default", err_msg,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (libaquaero5_getsettings(conf_device, &aq_sett, &err_msg) < 0) {
}
if (libaquaero5_getsettings(conf_device, &aq_sett, &err_msg) < 0) {
"for device \"%s\": %s (%s)",
conf_device ? conf_device : "default", err_msg,
sstrerror(errno, errbuf, sizeof(errbuf)));
"for device \"%s\": %s (%s)",
conf_device ? conf_device : "default", err_msg,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* CPU Temperature sensor */
}
/* CPU Temperature sensor */
/* Liquid level */
aquaero_submit_array("percent", "waterlevel", aq_data.level, AQ5_NUM_LEVEL);
/* Liquid level */
aquaero_submit_array("percent", "waterlevel", aq_data.level, AQ5_NUM_LEVEL);
}
void module_register(void) {
}
void module_register(void) {
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
plugin_dispatch_values(&vl);
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
plugin_dispatch_values(&vl);
} /* }}} int ascent_submit_gauge */
static size_t ascent_curl_callback(void *buf, size_t size,
} /* }}} int ascent_submit_gauge */
static size_t ascent_curl_callback(void *buf, size_t size,
size_t len = size * nmemb;
if (len == 0)
size_t len = size * nmemb;
if (len == 0)
if ((ascent_buffer_fill + len) >= ascent_buffer_size) {
char *temp;
if ((ascent_buffer_fill + len) >= ascent_buffer_size) {
char *temp;
temp = realloc(ascent_buffer, ascent_buffer_fill + len + 1);
if (temp == NULL) {
ERROR("ascent plugin: realloc failed.");
temp = realloc(ascent_buffer, ascent_buffer_fill + len + 1);
if (temp == NULL) {
ERROR("ascent plugin: realloc failed.");
}
ascent_buffer = temp;
ascent_buffer_size = ascent_buffer_fill + len + 1;
}
ascent_buffer = temp;
ascent_buffer_size = ascent_buffer_fill + len + 1;
ascent_buffer_fill += len;
ascent_buffer[ascent_buffer_fill] = 0;
ascent_buffer_fill += len;
ascent_buffer[ascent_buffer_fill] = 0;
} /* }}} size_t ascent_curl_callback */
static int ascent_submit_players(player_stats_t *ps) /* {{{ */
} /* }}} size_t ascent_curl_callback */
static int ascent_submit_players(player_stats_t *ps) /* {{{ */
value = ((double)ps->latency_sum) / (1000.0 * ((double)ps->latency_num));
ascent_submit_gauge(NULL, "latency", "average", value);
value = ((double)ps->latency_sum) / (1000.0 * ((double)ps->latency_num));
ascent_submit_gauge(NULL, "latency", "average", value);
} /* }}} int ascent_submit_players */
static int ascent_account_player(player_stats_t *ps, /* {{{ */
} /* }}} int ascent_submit_players */
static int ascent_account_player(player_stats_t *ps, /* {{{ */
} /* }}} int ascent_account_player */
static int ascent_xml_submit_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
} /* }}} int ascent_account_player */
static int ascent_xml_submit_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
if (str_ptr == NULL) {
ERROR(
"ascent plugin: ascent_xml_submit_gauge: xmlNodeListGetString failed.");
if (str_ptr == NULL) {
ERROR(
"ascent plugin: ascent_xml_submit_gauge: xmlNodeListGetString failed.");
}
if (strcasecmp("N/A", str_ptr) == 0)
}
if (strcasecmp("N/A", str_ptr) == 0)
if (str_ptr == end_ptr) {
xmlFree(str_ptr);
ERROR("ascent plugin: ascent_xml_submit_gauge: strtod failed.");
if (str_ptr == end_ptr) {
xmlFree(str_ptr);
ERROR("ascent plugin: ascent_xml_submit_gauge: strtod failed.");
- return (ascent_submit_gauge(plugin_instance, type, type_instance, value));
+ return ascent_submit_gauge(plugin_instance, type, type_instance, value);
} /* }}} int ascent_xml_submit_gauge */
static int ascent_xml_read_int(xmlDoc *doc, xmlNode *node, /* {{{ */
} /* }}} int ascent_xml_submit_gauge */
static int ascent_xml_read_int(xmlDoc *doc, xmlNode *node, /* {{{ */
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("ascent plugin: ascent_xml_read_int: xmlNodeListGetString failed.");
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("ascent plugin: ascent_xml_read_int: xmlNodeListGetString failed.");
}
if (strcasecmp("N/A", str_ptr) == 0)
}
if (strcasecmp("N/A", str_ptr) == 0)
if (str_ptr == end_ptr) {
xmlFree(str_ptr);
ERROR("ascent plugin: ascent_xml_read_int: strtol failed.");
if (str_ptr == end_ptr) {
xmlFree(str_ptr);
ERROR("ascent plugin: ascent_xml_read_int: strtol failed.");
}
}
xmlFree(str_ptr);
*ret_value = value;
}
}
xmlFree(str_ptr);
*ret_value = value;
} /* }}} int ascent_xml_read_int */
static int ascent_xml_sessions_plr(xmlDoc *doc, xmlNode *node, /* {{{ */
} /* }}} int ascent_xml_read_int */
static int ascent_xml_sessions_plr(xmlDoc *doc, xmlNode *node, /* {{{ */
} /* }}} int ascent_xml_sessions_plr */
static int ascent_xml_sessions(xmlDoc *doc, xmlNode *node) /* {{{ */
} /* }}} int ascent_xml_sessions_plr */
static int ascent_xml_sessions(xmlDoc *doc, xmlNode *node) /* {{{ */
ascent_submit_players(&ps);
ascent_submit_players(&ps);
} /* }}} int ascent_xml_sessions */
static int ascent_xml_status(xmlDoc *doc, xmlNode *node) /* {{{ */
} /* }}} int ascent_xml_sessions */
static int ascent_xml_status(xmlDoc *doc, xmlNode *node) /* {{{ */
} /* }}} int ascent_xml_status */
static int ascent_xml(const char *data) /* {{{ */
} /* }}} int ascent_xml_status */
static int ascent_xml(const char *data) /* {{{ */
#endif
if (doc == NULL) {
ERROR("ascent plugin: xmlParseMemory failed.");
#endif
if (doc == NULL) {
ERROR("ascent plugin: xmlParseMemory failed.");
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
ERROR("ascent plugin: XML document is empty.");
xmlFreeDoc(doc);
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
ERROR("ascent plugin: XML document is empty.");
xmlFreeDoc(doc);
}
if (xmlStrcmp((const xmlChar *)"serverpage", cur->name) != 0) {
ERROR("ascent plugin: XML root element is not \"serverpage\".");
xmlFreeDoc(doc);
}
if (xmlStrcmp((const xmlChar *)"serverpage", cur->name) != 0) {
ERROR("ascent plugin: XML root element is not \"serverpage\".");
xmlFreeDoc(doc);
}
for (xmlNode *child = cur->xmlChildrenNode; child != NULL;
}
for (xmlNode *child = cur->xmlChildrenNode; child != NULL;
} /* for (child) */
xmlFreeDoc(doc);
} /* for (child) */
xmlFreeDoc(doc);
} /* }}} int ascent_xml */
static int config_set(char **var, const char *value) /* {{{ */
} /* }}} int ascent_xml */
static int config_set(char **var, const char *value) /* {{{ */
}
if ((*var = strdup(value)) == NULL)
}
if ((*var = strdup(value)) == NULL)
} /* }}} int config_set */
static int ascent_config(const char *key, const char *value) /* {{{ */
{
if (strcasecmp(key, "URL") == 0)
} /* }}} int config_set */
static int ascent_config(const char *key, const char *value) /* {{{ */
{
if (strcasecmp(key, "URL") == 0)
- return (config_set(&url, value));
+ return config_set(&url, value);
else if (strcasecmp(key, "User") == 0)
else if (strcasecmp(key, "User") == 0)
- return (config_set(&user, value));
+ return config_set(&user, value);
else if (strcasecmp(key, "Password") == 0)
else if (strcasecmp(key, "Password") == 0)
- return (config_set(&pass, value));
+ return config_set(&pass, value);
else if (strcasecmp(key, "VerifyPeer") == 0)
else if (strcasecmp(key, "VerifyPeer") == 0)
- return (config_set(&verify_peer, value));
+ return config_set(&verify_peer, value);
else if (strcasecmp(key, "VerifyHost") == 0)
else if (strcasecmp(key, "VerifyHost") == 0)
- return (config_set(&verify_host, value));
+ return config_set(&verify_host, value);
else if (strcasecmp(key, "CACert") == 0)
else if (strcasecmp(key, "CACert") == 0)
- return (config_set(&cacert, value));
+ return config_set(&cacert, value);
else if (strcasecmp(key, "Timeout") == 0)
else if (strcasecmp(key, "Timeout") == 0)
- return (config_set(&timeout, value));
+ return config_set(&timeout, value);
} /* }}} int ascent_config */
static int ascent_init(void) /* {{{ */
} /* }}} int ascent_config */
static int ascent_init(void) /* {{{ */
if (url == NULL) {
WARNING("ascent plugin: ascent_init: No URL configured, "
"returning an error.");
if (url == NULL) {
WARNING("ascent plugin: ascent_init: No URL configured, "
"returning an error.");
if ((curl = curl_easy_init()) == NULL) {
ERROR("ascent plugin: ascent_init: curl_easy_init failed.");
if ((curl = curl_easy_init()) == NULL) {
ERROR("ascent plugin: ascent_init: curl_easy_init failed.");
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("ascent plugin: ascent_init: Returning an error because the "
"credentials have been truncated.");
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("ascent plugin: ascent_init: Returning an error because the "
"credentials have been truncated.");
}
curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
}
curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
} /* }}} int ascent_init */
static int ascent_read(void) /* {{{ */
} /* }}} int ascent_init */
static int ascent_read(void) /* {{{ */
if (curl == NULL) {
ERROR("ascent plugin: I don't have a CURL object.");
if (curl == NULL) {
ERROR("ascent plugin: I don't have a CURL object.");
}
if (url == NULL) {
ERROR("ascent plugin: No URL has been configured.");
}
if (url == NULL) {
ERROR("ascent plugin: No URL has been configured.");
}
ascent_buffer_fill = 0;
if (curl_easy_perform(curl) != CURLE_OK) {
ERROR("ascent plugin: curl_easy_perform failed: %s", ascent_curl_error);
}
ascent_buffer_fill = 0;
if (curl_easy_perform(curl) != CURLE_OK) {
ERROR("ascent plugin: curl_easy_perform failed: %s", ascent_curl_error);
}
status = ascent_xml(ascent_buffer);
if (status != 0)
}
status = ascent_xml(ascent_buffer);
if (status != 0)
} /* }}} int ascent_read */
void module_register(void) {
} /* }}} int ascent_read */
void module_register(void) {
kCFStringEncodingASCII);
if (key_obj == NULL) {
DEBUG("CFStringCreateWithCString (%s) failed.\n", key_string);
kCFStringEncodingASCII);
if (key_obj == NULL) {
DEBUG("CFStringCreateWithCString (%s) failed.\n", key_string);
}
if ((val_obj = CFDictionaryGetValue(dict, key_obj)) == NULL) {
DEBUG("CFDictionaryGetValue (%s) failed.", key_string);
CFRelease(key_obj);
}
if ((val_obj = CFDictionaryGetValue(dict, key_obj)) == NULL) {
DEBUG("CFDictionaryGetValue (%s) failed.", key_string);
CFRelease(key_obj);
}
} else {
DEBUG("CFGetTypeID (val_obj) = %i", (int)CFGetTypeID(val_obj));
}
} else {
DEBUG("CFGetTypeID (val_obj) = %i", (int)CFGetTypeID(val_obj));
} /* }}} double dict_get_double */
#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
} /* }}} double dict_get_double */
#if HAVE_IOKIT_PS_IOPOWERSOURCES_H
if (!isnan(voltage))
battery_submit("0", "voltage", voltage);
if (!isnan(voltage))
battery_submit("0", "voltage", voltage);
} /* }}} int battery_read */
/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
} /* }}} int battery_read */
/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */
status =
sysfs_file_to_buffer(dir, power_supply, basename, buffer, sizeof(buffer));
if (status != 0)
status =
sysfs_file_to_buffer(dir, power_supply, basename, buffer, sizeof(buffer));
if (status != 0)
- return (strtogauge(buffer, ret_value));
+ return strtogauge(buffer, ret_value);
} /* }}} sysfs_file_to_gauge */
static int read_sysfs_capacity(char const *dir, /* {{{ */
} /* }}} sysfs_file_to_gauge */
static int read_sysfs_capacity(char const *dir, /* {{{ */
status =
sysfs_file_to_gauge(dir, power_supply, "energy_now", &capacity_charged);
if (status != 0)
status =
sysfs_file_to_gauge(dir, power_supply, "energy_now", &capacity_charged);
if (status != 0)
status =
sysfs_file_to_gauge(dir, power_supply, "energy_full", &capacity_full);
if (status != 0)
status =
sysfs_file_to_gauge(dir, power_supply, "energy_full", &capacity_full);
if (status != 0)
status = sysfs_file_to_gauge(dir, power_supply, "energy_full_design",
&capacity_design);
if (status != 0)
status = sysfs_file_to_gauge(dir, power_supply, "energy_full_design",
&capacity_design);
if (status != 0)
submit_capacity(plugin_instance, capacity_charged * SYSFS_FACTOR,
capacity_full * SYSFS_FACTOR, capacity_design * SYSFS_FACTOR);
submit_capacity(plugin_instance, capacity_charged * SYSFS_FACTOR,
capacity_full * SYSFS_FACTOR, capacity_design * SYSFS_FACTOR);
} /* }}} int read_sysfs_capacity */
static int read_sysfs_callback(char const *dir, /* {{{ */
} /* }}} int read_sysfs_capacity */
static int read_sysfs_callback(char const *dir, /* {{{ */
status =
sysfs_file_to_buffer(dir, power_supply, "type", buffer, sizeof(buffer));
if (status != 0)
status =
sysfs_file_to_buffer(dir, power_supply, "type", buffer, sizeof(buffer));
if (status != 0)
if (strcasecmp("Battery", buffer) != 0)
if (strcasecmp("Battery", buffer) != 0)
(void)sysfs_file_to_buffer(dir, power_supply, "status", buffer,
sizeof(buffer));
(void)sysfs_file_to_buffer(dir, power_supply, "status", buffer,
sizeof(buffer));
if (sysfs_file_to_gauge(dir, power_supply, "voltage_now", &v) == 0)
battery_submit(plugin_instance, "voltage", v * SYSFS_FACTOR);
if (sysfs_file_to_gauge(dir, power_supply, "voltage_now", &v) == 0)
battery_submit(plugin_instance, "voltage", v * SYSFS_FACTOR);
} /* }}} int read_sysfs_callback */
static int read_sysfs(void) /* {{{ */
} /* }}} int read_sysfs_callback */
static int read_sysfs(void) /* {{{ */
int battery_counter = 0;
if (access(SYSFS_PATH, R_OK) != 0)
int battery_counter = 0;
if (access(SYSFS_PATH, R_OK) != 0)
status = walk_directory(SYSFS_PATH, read_sysfs_callback,
/* user_data = */ &battery_counter,
/* include hidden */ 0);
status = walk_directory(SYSFS_PATH, read_sysfs_callback,
/* user_data = */ &battery_counter,
/* include hidden */ 0);
} /* }}} int read_sysfs */
static int read_acpi_full_capacity(char const *dir, /* {{{ */
} /* }}} int read_sysfs */
static int read_acpi_full_capacity(char const *dir, /* {{{ */
ssnprintf(filename, sizeof(filename), "%s/%s/info", dir, power_supply);
fh = fopen(filename, "r");
if (fh == NULL)
ssnprintf(filename, sizeof(filename), "%s/%s/info", dir, power_supply);
fh = fopen(filename, "r");
if (fh == NULL)
/* last full capacity: 40090 mWh */
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
/* last full capacity: 40090 mWh */
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
} /* }}} int read_acpi_full_capacity */
static int read_acpi_callback(char const *dir, /* {{{ */
} /* }}} int read_acpi_full_capacity */
static int read_acpi_callback(char const *dir, /* {{{ */
fh = fopen(filename, "r");
if (fh == NULL) {
if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
fh = fopen(filename, "r");
if (fh == NULL) {
if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
int battery_counter = 0;
if (access(PROC_ACPI_PATH, R_OK) != 0)
int battery_counter = 0;
if (access(PROC_ACPI_PATH, R_OK) != 0)
status = walk_directory(PROC_ACPI_PATH, read_acpi_callback,
/* user_data = */ &battery_counter,
/* include hidden */ 0);
status = walk_directory(PROC_ACPI_PATH, read_acpi_callback,
/* user_data = */ &battery_counter,
/* include hidden */ 0);
} /* }}} int read_acpi */
static int read_pmu(void) /* {{{ */
} /* }}} int read_acpi */
static int read_pmu(void) /* {{{ */
else if ((errno == EAGAIN) || (errno == EINTR))
continue;
else
else if ((errno == EAGAIN) || (errno == EINTR))
continue;
else
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
- return (ENOENT);
- return (0);
+ return ENOENT;
+ return 0;
} /* }}} int read_pmu */
static int battery_read(void) /* {{{ */
} /* }}} int read_pmu */
static int battery_read(void) /* {{{ */
DEBUG("battery plugin: Trying sysfs ...");
status = read_sysfs();
if (status == 0)
DEBUG("battery plugin: Trying sysfs ...");
status = read_sysfs();
if (status == 0)
DEBUG("battery plugin: Trying acpi ...");
status = read_acpi();
if (status == 0)
DEBUG("battery plugin: Trying acpi ...");
status = read_acpi();
if (status == 0)
DEBUG("battery plugin: Trying pmu ...");
status = read_pmu();
if (status == 0)
DEBUG("battery plugin: Trying pmu ...");
status = read_pmu();
if (status == 0)
ERROR("battery plugin: All available input methods failed.");
ERROR("battery plugin: All available input methods failed.");
} /* }}} int battery_read */
#endif /* KERNEL_LINUX */
} /* }}} int battery_read */
#endif /* KERNEL_LINUX */
} /* }}} int battery_config */
void module_register(void) {
} /* }}} int battery_config */
void module_register(void) {
if (success == 0) {
ERROR("battery plugin: statefs backend: none of the statistics are "
"available");
if (success == 0) {
ERROR("battery plugin: statefs backend: none of the statistics are "
"available");
size_t len = size * nmemb;
if (len == 0)
size_t len = size * nmemb;
if (len == 0)
if ((bind_buffer_fill + len) >= bind_buffer_size) {
char *temp;
if ((bind_buffer_fill + len) >= bind_buffer_size) {
char *temp;
temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
if (temp == NULL) {
ERROR("bind plugin: realloc failed.");
temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
if (temp == NULL) {
ERROR("bind plugin: realloc failed.");
}
bind_buffer = temp;
bind_buffer_size = bind_buffer_fill + len + 1;
}
bind_buffer = temp;
bind_buffer_size = bind_buffer_fill + len + 1;
bind_buffer_fill += len;
bind_buffer[bind_buffer_fill] = 0;
bind_buffer_fill += len;
bind_buffer[bind_buffer_fill] = 0;
} /* }}} size_t bind_curl_callback */
/*
} /* }}} size_t bind_curl_callback */
/*
translation_table_ptr_t *table = (translation_table_ptr_t *)user_data;
if (table == NULL)
translation_table_ptr_t *table = (translation_table_ptr_t *)user_data;
if (table == NULL)
for (size_t i = 0; i < table->table_length; i++) {
if (strcmp(table->table[i].xml_name, name) != 0)
for (size_t i = 0; i < table->table_length; i++) {
if (strcmp(table->table[i].xml_name, name) != 0)
} /* }}} int bind_xml_table_callback */
/*
} /* }}} int bind_xml_table_callback */
/*
list_info_ptr_t *list_info = (list_info_ptr_t *)user_data;
if (list_info == NULL)
list_info_ptr_t *list_info = (list_info_ptr_t *)user_data;
if (list_info == NULL)
submit(current_time, list_info->plugin_instance, list_info->type,
/* type instance = */ name, value);
submit(current_time, list_info->plugin_instance, list_info->type,
/* type instance = */ name, value);
} /* }}} int bind_xml_list_callback */
static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */
} /* }}} int bind_xml_list_callback */
static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed.");
}
status = parse_value(str_ptr, &value, DS_TYPE_DERIVE);
}
status = parse_value(str_ptr, &value, DS_TYPE_DERIVE);
ERROR("bind plugin: Parsing string \"%s\" to derive value failed.",
str_ptr);
xmlFree(str_ptr);
ERROR("bind plugin: Parsing string \"%s\" to derive value failed.",
str_ptr);
xmlFree(str_ptr);
}
xmlFree(str_ptr);
*ret_value = value.derive;
}
xmlFree(str_ptr);
*ret_value = value.derive;
} /* }}} int bind_xml_read_derive */
static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
} /* }}} int bind_xml_read_derive */
static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed.");
ERROR("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
else
ERROR("bind plugin: bind_xml_read_gauge: strtod failed.");
ERROR("bind plugin: bind_xml_read_gauge: strtod failed with overflow.");
else
ERROR("bind plugin: bind_xml_read_gauge: strtod failed.");
}
*ret_value = (gauge_t)value;
}
*ret_value = (gauge_t)value;
} /* }}} int bind_xml_read_gauge */
static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */
} /* }}} int bind_xml_read_gauge */
static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
}
if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1)) {
xmlXPathFreeObject(xpathObj);
}
if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1)) {
xmlXPathFreeObject(xpathObj);
}
if (xpathObj->nodesetval->nodeNr != 1) {
}
if (xpathObj->nodesetval->nodeNr != 1) {
ERROR("bind plugin: bind_xml_read_timestamp: "
"node->xmlChildrenNode == NULL");
xmlXPathFreeObject(xpathObj);
ERROR("bind plugin: bind_xml_read_timestamp: "
"node->xmlChildrenNode == NULL");
xmlXPathFreeObject(xpathObj);
}
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
xmlXPathFreeObject(xpathObj);
}
str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
if (str_ptr == NULL) {
ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed.");
xmlXPathFreeObject(xpathObj);
}
tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm);
}
tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm);
if (tmp == NULL) {
ERROR("bind plugin: bind_xml_read_timestamp: strptime failed.");
xmlXPathFreeObject(xpathObj);
if (tmp == NULL) {
ERROR("bind plugin: bind_xml_read_timestamp: strptime failed.");
xmlXPathFreeObject(xpathObj);
char errbuf[1024];
ERROR("bind plugin: timegm() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("bind plugin: timegm() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("bind plugin: mktime() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("bind plugin: mktime() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* mktime assumes that tm is local time. Luckily, it also sets timezone to
* the offset used for the conversion, and we undo the conversion to convert
}
/* mktime assumes that tm is local time. Luckily, it also sets timezone to
* the offset used for the conversion, and we undo the conversion to convert
#endif
xmlXPathFreeObject(xpathObj);
#endif
xmlXPathFreeObject(xpathObj);
} /* }}} int bind_xml_read_timestamp */
/*
} /* }}} int bind_xml_read_timestamp */
/*
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
xmlXPathFreeObject(xpathObj);
xmlXPathFreeObject(xpathObj);
} /* }}} int bind_parse_generic_name_value */
/*
} /* }}} int bind_parse_generic_name_value */
/*
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
xmlXPathFreeObject(xpathObj);
xmlXPathFreeObject(xpathObj);
} /* }}} int bind_parse_generic_value_list */
/*
} /* }}} int bind_parse_generic_value_list */
/*
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
if (xpathObj == NULL) {
ERROR("bind plugin: Unable to evaluate XPath expression `%s'.",
xpath_expression);
xmlXPathFreeObject(xpathObj);
xmlXPathFreeObject(xpathObj);
} /* }}} int bind_parse_generic_name_attr_value_list */
static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
} /* }}} int bind_parse_generic_name_attr_value_list */
static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
if (path_obj == NULL) {
ERROR("bind plugin: xmlXPathEvalExpression failed.");
path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
if (path_obj == NULL) {
ERROR("bind plugin: xmlXPathEvalExpression failed.");
}
for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
}
for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
if (zone_name == NULL) {
ERROR("bind plugin: Could not determine zone name.");
if (zone_name == NULL) {
ERROR("bind plugin: Could not determine zone name.");
}
for (j = 0; j < view->zones_num; j++) {
}
for (j = 0; j < view->zones_num; j++) {
zone_name = NULL;
if (j >= view->zones_num)
zone_name = NULL;
if (j >= view->zones_num)
zone_name = view->zones[j];
zone_name = view->zones[j];
} /* }}} int bind_xml_stats_handle_zone */
static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
} /* }}} int bind_xml_stats_handle_zone */
static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */
zone_path_context = xmlXPathNewContext(doc);
if (zone_path_context == NULL) {
ERROR("bind plugin: xmlXPathNewContext failed.");
zone_path_context = xmlXPathNewContext(doc);
if (zone_path_context == NULL) {
ERROR("bind plugin: xmlXPathNewContext failed.");
}
zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
if (zone_nodes == NULL) {
ERROR("bind plugin: Cannot find any <view> tags.");
xmlXPathFreeContext(zone_path_context);
}
zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx);
if (zone_nodes == NULL) {
ERROR("bind plugin: Cannot find any <view> tags.");
xmlXPathFreeContext(zone_path_context);
}
for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
}
for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) {
xmlXPathFreeObject(zone_nodes);
xmlXPathFreeContext(zone_path_context);
xmlXPathFreeObject(zone_nodes);
xmlXPathFreeContext(zone_path_context);
} /* }}} int bind_xml_stats_search_zones */
static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
} /* }}} int bind_xml_stats_search_zones */
static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
if (view_name == NULL) {
ERROR("bind plugin: Could not determine view name.");
if (view_name == NULL) {
ERROR("bind plugin: Could not determine view name.");
}
for (j = 0; j < views_num; j++) {
}
for (j = 0; j < views_num; j++) {
path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
if (path_obj == NULL) {
ERROR("bind plugin: xmlXPathEvalExpression failed.");
path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx);
if (path_obj == NULL) {
ERROR("bind plugin: xmlXPathEvalExpression failed.");
}
for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
}
for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr);
if (view_name == NULL) {
ERROR("bind plugin: Could not determine view name.");
xmlXPathFreeObject(path_obj);
if (view_name == NULL) {
ERROR("bind plugin: Could not determine view name.");
xmlXPathFreeObject(path_obj);
}
for (j = 0; j < views_num; j++) {
}
for (j = 0; j < views_num; j++) {
bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
current_time);
bind_xml_stats_search_zones(version, doc, path_ctx, node, view,
current_time);
} /* }}} int bind_xml_stats_handle_view */
static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
} /* }}} int bind_xml_stats_handle_view */
static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */
view_path_context = xmlXPathNewContext(doc);
if (view_path_context == NULL) {
ERROR("bind plugin: xmlXPathNewContext failed.");
view_path_context = xmlXPathNewContext(doc);
if (view_path_context == NULL) {
ERROR("bind plugin: xmlXPathNewContext failed.");
}
view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
if (view_nodes == NULL) {
ERROR("bind plugin: Cannot find any <view> tags.");
xmlXPathFreeContext(view_path_context);
}
view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx);
if (view_nodes == NULL) {
ERROR("bind plugin: Cannot find any <view> tags.");
xmlXPathFreeContext(view_path_context);
}
for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
}
for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) {
xmlXPathFreeObject(view_nodes);
xmlXPathFreeContext(view_path_context);
xmlXPathFreeObject(view_nodes);
xmlXPathFreeContext(view_path_context);
} /* }}} int bind_xml_stats_search_views */
static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
} /* }}} int bind_xml_stats_search_views */
static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */
¤t_time);
if (status != 0) {
ERROR("bind plugin: Reading `server/current-time' failed.");
¤t_time);
if (status != 0) {
ERROR("bind plugin: Reading `server/current-time' failed.");
}
DEBUG("bind plugin: Current server time is %i.", (int)current_time);
}
DEBUG("bind plugin: Current server time is %i.", (int)current_time);
doc = xmlParseMemory(data, strlen(data));
if (doc == NULL) {
ERROR("bind plugin: xmlParseMemory failed.");
doc = xmlParseMemory(data, strlen(data));
if (doc == NULL) {
ERROR("bind plugin: xmlParseMemory failed.");
}
xpathCtx = xmlXPathNewContext(doc);
if (xpathCtx == NULL) {
ERROR("bind plugin: xmlXPathNewContext failed.");
xmlFreeDoc(doc);
}
xpathCtx = xmlXPathNewContext(doc);
if (xpathCtx == NULL) {
ERROR("bind plugin: xmlXPathNewContext failed.");
xmlFreeDoc(doc);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
ERROR("bind plugin: Cannot find the <statistics> tag.");
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
ERROR("bind plugin: Cannot find the <statistics> tag.");
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
} else if (xpathObj->nodesetval == NULL) {
ERROR("bind plugin: xmlXPathEvalExpression failed.");
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
} else if (xpathObj->nodesetval == NULL) {
ERROR("bind plugin: xmlXPathEvalExpression failed.");
xmlXPathFreeObject(xpathObj);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
}
for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
}
for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
xmlXPathFreeContext(xpathCtx);
xmlFreeDoc(doc);
} /* }}} int bind_xml */
static int bind_config_set_bool(const char *name, int *var, /* {{{ */
} /* }}} int bind_xml */
static int bind_config_set_bool(const char *name, int *var, /* {{{ */
WARNING("bind plugin: The `%s' option needs "
"exactly one boolean argument.",
name);
WARNING("bind plugin: The `%s' option needs "
"exactly one boolean argument.",
name);
}
if (ci->values[0].value.boolean)
}
if (ci->values[0].value.boolean)
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("bind plugin: The `Zone' option needs "
"exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("bind plugin: The `Zone' option needs "
"exactly one string argument.");
}
tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
if (tmp == NULL) {
ERROR("bind plugin: realloc failed.");
}
tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1));
if (tmp == NULL) {
ERROR("bind plugin: realloc failed.");
}
view->zones = tmp;
view->zones[view->zones_num] = strdup(ci->values[0].value.string);
if (view->zones[view->zones_num] == NULL) {
ERROR("bind plugin: strdup failed.");
}
view->zones = tmp;
view->zones[view->zones_num] = strdup(ci->values[0].value.string);
if (view->zones[view->zones_num] == NULL) {
ERROR("bind plugin: strdup failed.");
} /* }}} int bind_config_add_view_zone */
static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
} /* }}} int bind_config_add_view_zone */
static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("bind plugin: `View' blocks need exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("bind plugin: `View' blocks need exactly one string argument.");
}
tmp = realloc(views, sizeof(*views) * (views_num + 1));
if (tmp == NULL) {
ERROR("bind plugin: realloc failed.");
}
tmp = realloc(views, sizeof(*views) * (views_num + 1));
if (tmp == NULL) {
ERROR("bind plugin: realloc failed.");
}
views = tmp;
tmp = views + views_num;
}
views = tmp;
tmp = views + views_num;
if (tmp->name == NULL) {
ERROR("bind plugin: strdup failed.");
sfree(views);
if (tmp->name == NULL) {
ERROR("bind plugin: strdup failed.");
sfree(views);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
} /* for (i = 0; i < ci->children_num; i++) */
views_num++;
} /* for (i = 0; i < ci->children_num; i++) */
views_num++;
} /* }}} int bind_config_add_view */
static int bind_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int bind_config_add_view */
static int bind_config(oconfig_item_t *ci) /* {{{ */
(child->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("bind plugin: The `Url' option needs "
"exactly one string argument.");
(child->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("bind plugin: The `Url' option needs "
"exactly one string argument.");
} /* }}} int bind_config */
static int bind_init(void) /* {{{ */
{
if (curl != NULL)
} /* }}} int bind_config */
static int bind_init(void) /* {{{ */
{
if (curl != NULL)
curl = curl_easy_init();
if (curl == NULL) {
ERROR("bind plugin: bind_init: curl_easy_init failed.");
curl = curl_easy_init();
if (curl == NULL) {
ERROR("bind plugin: bind_init: curl_easy_init failed.");
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
plugin_get_interval()));
#endif
plugin_get_interval()));
#endif
} /* }}} int bind_init */
static int bind_read(void) /* {{{ */
} /* }}} int bind_init */
static int bind_read(void) /* {{{ */
if (curl == NULL) {
ERROR("bind plugin: I don't have a CURL object.");
if (curl == NULL) {
ERROR("bind plugin: I don't have a CURL object.");
}
bind_buffer_fill = 0;
if (curl_easy_perform(curl) != CURLE_OK) {
ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
}
bind_buffer_fill = 0;
if (curl_easy_perform(curl) != CURLE_OK) {
ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
}
status = bind_xml(bind_buffer);
if (status != 0)
}
status = bind_xml(bind_buffer);
if (status != 0)
} /* }}} int bind_read */
static int bind_shutdown(void) /* {{{ */
} /* }}} int bind_read */
static int bind_shutdown(void) /* {{{ */
} /* }}} int bind_shutdown */
void module_register(void) {
} /* }}} int bind_shutdown */
void module_register(void) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("ceph plugin: `Daemon' blocks need exactly one string "
"argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("ceph plugin: `Daemon' blocks need exactly one string "
"argument.");
}
ret = cc_handle_str(ci, cd.name, DATA_MAX_NAME_LEN);
}
ret = cc_handle_str(ci, cd.name, DATA_MAX_NAME_LEN);
FILE *fh;
if (ignorelist_match(il_cgroup, cgroup_name))
FILE *fh;
if (ignorelist_match(il_cgroup, cgroup_name))
ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, cgroup_name);
status = lstat(abs_path, &statbuf);
if (status != 0) {
ERROR("cgroups plugin: stat (\"%s\") failed.", abs_path);
ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, cgroup_name);
status = lstat(abs_path, &statbuf);
if (status != 0) {
ERROR("cgroups plugin: stat (\"%s\") failed.", abs_path);
}
/* We are only interested in directories, so skip everything else. */
if (!S_ISDIR(statbuf.st_mode))
}
/* We are only interested in directories, so skip everything else. */
if (!S_ISDIR(statbuf.st_mode))
ssnprintf(abs_path, sizeof(abs_path), "%s/%s/cpuacct.stat", dirname,
cgroup_name);
ssnprintf(abs_path, sizeof(abs_path), "%s/%s/cpuacct.stat", dirname,
cgroup_name);
char errbuf[1024];
ERROR("cgroups plugin: fopen (\"%s\") failed: %s", abs_path,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("cgroups plugin: fopen (\"%s\") failed: %s", abs_path,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buf, sizeof(buf), fh) != NULL) {
}
while (fgets(buf, sizeof(buf), fh) != NULL) {
} /* int read_cpuacct_procs */
/*
} /* int read_cpuacct_procs */
/*
status = lstat(abs_path, &statbuf);
if (status != 0) {
ERROR("cgroups plugin: stat (%s) failed.", abs_path);
status = lstat(abs_path, &statbuf);
if (status != 0) {
ERROR("cgroups plugin: stat (%s) failed.", abs_path);
}
if (S_ISDIR(statbuf.st_mode)) {
status = walk_directory(abs_path, read_cpuacct_procs,
/* user_data = */ NULL,
/* include_hidden = */ 0);
}
if (S_ISDIR(statbuf.st_mode)) {
status = walk_directory(abs_path, read_cpuacct_procs,
/* user_data = */ NULL,
/* include_hidden = */ 0);
}
static int cgroups_init(void) {
if (il_cgroup == NULL)
il_cgroup = ignorelist_create(1);
}
static int cgroups_init(void) {
if (il_cgroup == NULL)
il_cgroup = ignorelist_create(1);
}
static int cgroups_config(const char *key, const char *value) {
}
static int cgroups_config(const char *key, const char *value) {
if (strcasecmp(key, "CGroup") == 0) {
if (ignorelist_add(il_cgroup, value))
if (strcasecmp(key, "CGroup") == 0) {
if (ignorelist_add(il_cgroup, value))
- return (1);
- return (0);
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
if (IS_TRUE(value))
ignorelist_set_invert(il_cgroup, 0);
else
ignorelist_set_invert(il_cgroup, 1);
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
if (IS_TRUE(value))
ignorelist_set_invert(il_cgroup, 0);
else
ignorelist_set_invert(il_cgroup, 1);
}
static int cgroups_read(void) {
}
static int cgroups_read(void) {
if (cu_mount_getlist(&mnt_list) == NULL) {
ERROR("cgroups plugin: cu_mount_getlist failed.");
if (cu_mount_getlist(&mnt_list) == NULL) {
ERROR("cgroups plugin: cu_mount_getlist failed.");
}
for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL;
}
for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL;
if (!cgroup_found) {
WARNING("cgroups plugin: Unable to find cgroup "
"mount-point with the \"cpuacct\" option.");
if (!cgroup_found) {
WARNING("cgroups plugin: Unable to find cgroup "
"mount-point with the \"cpuacct\" option.");
} /* int cgroup_read */
void module_register(void) {
} /* int cgroup_read */
void module_register(void) {
ret = (char *)malloc(strsize);
if (ret != NULL)
memcpy(ret, str, strsize);
ret = (char *)malloc(strsize);
if (ret != NULL)
memcpy(ret, str, strsize);
} /* }}} char *cn_strdup */
static int filter_ds(size_t *values_num, double **values,
} /* }}} char *cn_strdup */
static int filter_ds(size_t *values_num, double **values,
char **new_names;
if (match_ds_g == NULL)
char **new_names;
if (match_ds_g == NULL)
new_values = (gauge_t *)calloc(match_ds_num_g, sizeof(*new_values));
if (new_values == NULL) {
fprintf(stderr, "calloc failed: %s\n", strerror(errno));
new_values = (gauge_t *)calloc(match_ds_num_g, sizeof(*new_values));
if (new_values == NULL) {
fprintf(stderr, "calloc failed: %s\n", strerror(errno));
}
new_names = (char **)calloc(match_ds_num_g, sizeof(*new_names));
if (new_names == NULL) {
fprintf(stderr, "calloc failed: %s\n", strerror(errno));
free(new_values);
}
new_names = (char **)calloc(match_ds_num_g, sizeof(*new_names));
if (new_names == NULL) {
fprintf(stderr, "calloc failed: %s\n", strerror(errno));
free(new_values);
}
for (size_t i = 0; i < match_ds_num_g; i++) {
}
for (size_t i = 0; i < match_ds_num_g; i++) {
for (j = 0; j < i; j++)
free(new_names[j]);
free(new_names);
for (j = 0; j < i; j++)
free(new_names[j]);
free(new_names);
}
for (j = 0; j < *values_num; j++)
}
for (j = 0; j < *values_num; j++)
for (j = 0; j <= i; j++)
free(new_names[j]);
free(new_names);
for (j = 0; j <= i; j++)
free(new_names[j]);
free(new_names);
}
new_values[i] = (*values)[j];
}
new_values[i] = (*values)[j];
*values = new_values;
*values_names = new_names;
*values_num = match_ds_num_g;
*values = new_values;
*values_names = new_names;
*values_num = match_ds_num_g;
} /* int filter_ds */
static void parse_range(char *string, range_t *range) {
} /* int filter_ds */
static void parse_range(char *string, range_t *range) {
if (!isnan(range->max) && (range->max < value))
ret = 1;
if (!isnan(range->max) && (range->max < value))
ret = 1;
- return (((ret - range->invert) == 0) ? 0 : 1);
+ return ((ret - range->invert) == 0) ? 0 : 1;
} /* int match_range */
__attribute__((noreturn)) static void usage(const char *name) {
} /* int match_range */
__attribute__((noreturn)) static void usage(const char *name) {
printf("UNKNOWN: %s\n", lcc_strerror(connection));
if (ret_ident != NULL)
free(ret_ident);
printf("UNKNOWN: %s\n", lcc_strerror(connection));
if (ret_ident != NULL)
free(ret_ident);
}
status = lcc_sort_identifiers(connection, ret_ident, ret_ident_num);
}
status = lcc_sort_identifiers(connection, ret_ident, ret_ident_num);
printf("UNKNOWN: %s\n", lcc_strerror(connection));
if (ret_ident != NULL)
free(ret_ident);
printf("UNKNOWN: %s\n", lcc_strerror(connection));
if (ret_ident != NULL)
free(ret_ident);
}
for (size_t i = 0; i < ret_ident_num; ++i) {
}
for (size_t i = 0; i < ret_ident_num; ++i) {
free(ret_ident);
free(hostname);
free(ret_ident);
free(hostname);
} /* int do_listval */
static int do_check_con_none(size_t values_num, double *values,
} /* int do_listval */
static int do_check_con_none(size_t values_num, double *values,
if ((num_critical == 0) && (num_warning == 0) && (num_okay == 0)) {
printf("WARNING: No defined values found\n");
if ((num_critical == 0) && (num_warning == 0) && (num_okay == 0)) {
printf("WARNING: No defined values found\n");
} else if ((num_critical == 0) && (num_warning == 0)) {
status_str = "OKAY";
status_code = RET_OKAY;
} else if ((num_critical == 0) && (num_warning == 0)) {
status_str = "OKAY";
status_code = RET_OKAY;
} /* int do_check_con_none */
static int do_check_con_average(size_t values_num, double *values,
} /* int do_check_con_none */
static int do_check_con_average(size_t values_num, double *values,
continue;
printf("CRITICAL: Data source \"%s\" is NaN\n", values_names[i]);
continue;
printf("CRITICAL: Data source \"%s\" is NaN\n", values_names[i]);
if (total_num == 0) {
printf("WARNING: No defined values found\n");
if (total_num == 0) {
printf("WARNING: No defined values found\n");
}
average = total / total_num;
}
average = total / total_num;
printf(" %s=%f;;;;", values_names[i], values[i]);
printf("\n");
printf(" %s=%f;;;;", values_names[i], values[i]);
printf("\n");
} /* int do_check_con_average */
static int do_check_con_sum(size_t values_num, double *values,
} /* int do_check_con_average */
static int do_check_con_sum(size_t values_num, double *values,
continue;
printf("CRITICAL: Data source \"%s\" is NaN\n", values_names[i]);
continue;
printf("CRITICAL: Data source \"%s\" is NaN\n", values_names[i]);
if (total_num == 0) {
printf("WARNING: No defined values found\n");
if (total_num == 0) {
printf("WARNING: No defined values found\n");
}
if (match_range(&range_critical_g, total) != 0) {
}
if (match_range(&range_critical_g, total) != 0) {
printf(" %s=%f;;;;", values_names[i], values[i]);
printf("\n");
printf(" %s=%f;;;;", values_names[i], values[i]);
printf("\n");
} /* int do_check_con_sum */
static int do_check_con_percentage(size_t values_num, double *values,
} /* int do_check_con_sum */
static int do_check_con_percentage(size_t values_num, double *values,
if ((values_num < 1) || (isnan(values[0]))) {
printf("WARNING: The first value is not defined\n");
if ((values_num < 1) || (isnan(values[0]))) {
printf("WARNING: The first value is not defined\n");
}
for (size_t i = 0; i < values_num; i++) {
}
for (size_t i = 0; i < values_num; i++) {
continue;
printf("CRITICAL: Data source \"%s\" is NaN\n", values_names[i]);
continue;
printf("CRITICAL: Data source \"%s\" is NaN\n", values_names[i]);
if (sum == 0.0) {
printf("WARNING: Values sum up to zero\n");
if (sum == 0.0) {
printf("WARNING: Values sum up to zero\n");
}
percentage = 100.0 * values[0] / sum;
}
percentage = 100.0 * values[0] / sum;
printf("%s: %lf percent |", status_str, percentage);
for (size_t i = 0; i < values_num; i++)
printf(" %s=%lf;;;;", values_names[i], values[i]);
printf("%s: %lf percent |", status_str, percentage);
for (size_t i = 0; i < values_num; i++)
printf(" %s=%lf;;;;", values_names[i], values[i]);
} /* int do_check_con_percentage */
static int do_check(lcc_connection_t *connection) {
} /* int do_check_con_percentage */
static int do_check(lcc_connection_t *connection) {
printf("ERROR: Creating an identifier failed: %s.\n",
lcc_strerror(connection));
LCC_DESTROY(connection);
printf("ERROR: Creating an identifier failed: %s.\n",
lcc_strerror(connection));
LCC_DESTROY(connection);
}
status = lcc_getval(connection, &ident, &values_num, &values, &values_names);
}
status = lcc_getval(connection, &ident, &values_num, &values, &values_names);
printf("ERROR: Retrieving values from the daemon failed: %s.\n",
lcc_strerror(connection));
LCC_DESTROY(connection);
printf("ERROR: Retrieving values from the daemon failed: %s.\n",
lcc_strerror(connection));
LCC_DESTROY(connection);
}
LCC_DESTROY(connection);
status = filter_ds(&values_num, &values, &values_names);
if (status != RET_OKAY)
}
LCC_DESTROY(connection);
status = filter_ds(&values_num, &values, &values_names);
if (status != RET_OKAY)
status = RET_UNKNOWN;
if (consolitation_g == CON_NONE)
status = RET_UNKNOWN;
if (consolitation_g == CON_NONE)
free(values_names[i]);
free(values_names);
free(values_names[i]);
free(values_names);
} /* int do_check */
int main(int argc, char **argv) {
} /* int do_check */
int main(int argc, char **argv) {
tmp = realloc(match_ds_g, (match_ds_num_g + 1) * sizeof(char *));
if (tmp == NULL) {
fprintf(stderr, "realloc failed: %s\n", strerror(errno));
tmp = realloc(match_ds_g, (match_ds_num_g + 1) * sizeof(char *));
if (tmp == NULL) {
fprintf(stderr, "realloc failed: %s\n", strerror(errno));
}
match_ds_g = tmp;
match_ds_g[match_ds_num_g] = cn_strdup(optarg);
if (match_ds_g[match_ds_num_g] == NULL) {
fprintf(stderr, "cn_strdup failed: %s\n", strerror(errno));
}
match_ds_g = tmp;
match_ds_g[match_ds_num_g] = cn_strdup(optarg);
if (match_ds_g[match_ds_num_g] == NULL) {
fprintf(stderr, "cn_strdup failed: %s\n", strerror(errno));
}
match_ds_num_g++;
break;
}
match_ds_num_g++;
break;
status = lcc_connect(address, &connection);
if (status != 0) {
printf("ERROR: Connecting to daemon at %s failed.\n", socket_file_g);
status = lcc_connect(address, &connection);
if (status != 0) {
printf("ERROR: Connecting to daemon at %s failed.\n", socket_file_g);
}
if (0 == strcasecmp(value_string_g, "LIST"))
}
if (0 == strcasecmp(value_string_g, "LIST"))
- return (do_listval(connection));
+ return do_listval(connection);
- return (do_check(connection));
+ return do_check(connection);
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
perror("clock_gettime");
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
perror("clock_gettime");
- return ((double)ts.tv_sec) + (((double)ts.tv_nsec) / 1e9);
+ return (double)ts.tv_sec + (double)ts.tv_nsec / 1e9;
} /* }}} double dtime */
#else
/* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */
} /* }}} double dtime */
#else
/* Work around for Mac OS X which doesn't have clock_gettime(2). *sigh* */
if (gettimeofday(&tv, /* timezone = */ NULL) != 0)
perror("gettimeofday");
if (gettimeofday(&tv, /* timezone = */ NULL) != 0)
perror("gettimeofday");
- return ((double)tv.tv_sec) + (((double)tv.tv_usec) / 1e6);
+ return (double)tv.tv_sec + ((double)tv.tv_usec) / 1e6;
} /* }}} double dtime */
#endif
} /* }}} double dtime */
#endif
const lcc_value_list_t *vl1 = v1;
if (vl0->time < vl1->time)
const lcc_value_list_t *vl1 = v1;
if (vl0->time < vl1->time)
else if (vl0->time > vl1->time)
else if (vl0->time > vl1->time)
} /* }}} int compare_time */
static int get_boundet_random(int min, int max) /* {{{ */
} /* }}} int compare_time */
static int get_boundet_random(int min, int max) /* {{{ */
int range;
if (min >= max)
int range;
if (min >= max)
- return (min + ((int)(((double)range) * ((double)random()) /
- (((double)RAND_MAX) + 1.0))));
+ return min + ((int)(((double)range) * ((double)random()) / (((double)RAND_MAX) + 1.0)));
} /* }}} int get_boundet_random */
static lcc_value_list_t *create_value_list(void) /* {{{ */
} /* }}} int get_boundet_random */
static lcc_value_list_t *create_value_list(void) /* {{{ */
vl = calloc(1, sizeof(*vl));
if (vl == NULL) {
fprintf(stderr, "calloc failed.\n");
vl = calloc(1, sizeof(*vl));
if (vl == NULL) {
fprintf(stderr, "calloc failed.\n");
}
vl->values = calloc(/* nmemb = */ 1, sizeof(*vl->values));
if (vl->values == NULL) {
fprintf(stderr, "calloc failed.\n");
free(vl);
}
vl->values = calloc(/* nmemb = */ 1, sizeof(*vl->values));
if (vl->values == NULL) {
fprintf(stderr, "calloc failed.\n");
free(vl);
}
vl->values_types = calloc(/* nmemb = */ 1, sizeof(*vl->values_types));
}
vl->values_types = calloc(/* nmemb = */ 1, sizeof(*vl->values_types));
fprintf(stderr, "calloc failed.\n");
free(vl->values);
free(vl);
fprintf(stderr, "calloc failed.\n");
free(vl->values);
free(vl);
snprintf(vl->identifier.type_instance, sizeof(vl->identifier.type_instance),
"ti%li", random());
snprintf(vl->identifier.type_instance, sizeof(vl->identifier.type_instance),
"ti%li", random());
} /* }}} int create_value_list */
static void destroy_value_list(lcc_value_list_t *vl) /* {{{ */
} /* }}} int create_value_list */
static void destroy_value_list(lcc_value_list_t *vl) /* {{{ */
vl->time += vl->interval;
vl->time += vl->interval;
} /* }}} int send_value */
static int get_integer_opt(const char *str, int *ret_value) /* {{{ */
} /* }}} int send_value */
static int get_integer_opt(const char *str, int *ret_value) /* {{{ */
} /* }}} int get_integer_opt */
static int get_double_opt(const char *str, double *ret_value) /* {{{ */
} /* }}} int get_integer_opt */
static int get_double_opt(const char *str, double *ret_value) /* {{{ */
} /* }}} int get_double_opt */
static int read_options(int argc, char **argv) /* {{{ */
} /* }}} int get_double_opt */
static int read_options(int argc, char **argv) /* {{{ */
} /* switch (opt) */
} /* while (getopt) */
} /* switch (opt) */
} /* while (getopt) */
} /* }}} int read_options */
int main(int argc, char **argv) /* {{{ */
} /* }}} int read_options */
int main(int argc, char **argv) /* {{{ */
tmp = realloc(*array, (*array_len + 1) * elem_size);
if (tmp == NULL) {
fprintf(stderr, "ERROR: Failed to allocate memory.\n");
tmp = realloc(*array, (*array_len + 1) * elem_size);
if (tmp == NULL) {
fprintf(stderr, "ERROR: Failed to allocate memory.\n");
}
*array = tmp;
++(*array_len);
}
*array = tmp;
++(*array_len);
} /* array_grow */
static int parse_identifier(lcc_connection_t *c, const char *value,
} /* array_grow */
static int parse_identifier(lcc_connection_t *c, const char *value,
if (gethostname(hostname, sizeof(hostname)) != 0) {
fprintf(stderr, "ERROR: Failed to get local hostname: %s",
strerror(errno));
if (gethostname(hostname, sizeof(hostname)) != 0) {
fprintf(stderr, "ERROR: Failed to get local hostname: %s",
strerror(errno));
}
hostname[sizeof(hostname) - 1] = '\0';
}
hostname[sizeof(hostname) - 1] = '\0';
if (status != 0) {
fprintf(stderr, "ERROR: Failed to parse identifier ``%s'': %s.\n",
ident_str, lcc_strerror(c));
if (status != 0) {
fprintf(stderr, "ERROR: Failed to parse identifier ``%s'': %s.\n",
ident_str, lcc_strerror(c));
} /* parse_identifier */
static int getval(lcc_connection_t *c, int argc, char **argv) {
} /* parse_identifier */
static int getval(lcc_connection_t *c, int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "ERROR: getval: Missing identifier.\n");
if (argc != 2) {
fprintf(stderr, "ERROR: getval: Missing identifier.\n");
}
status = parse_identifier(c, argv[1], &ident);
if (status != 0)
}
status = parse_identifier(c, argv[1], &ident);
if (status != 0)
#define BAIL_OUT(s) \
do { \
#define BAIL_OUT(s) \
do { \
free(ret_values_names); \
} \
ret_values_num = 0; \
free(ret_values_names); \
} \
ret_values_num = 0; \
if (plugins != NULL) \
free(plugins); \
plugins_num = 0; \
if (plugins != NULL) \
free(plugins); \
plugins_num = 0; \
} while (0)
for (int i = 1; i < argc; ++i) {
} while (0)
for (int i = 1; i < argc; ++i) {
if (argc != 1) {
fprintf(stderr, "ERROR: listval: Does not accept any arguments.\n");
if (argc != 1) {
fprintf(stderr, "ERROR: listval: Does not accept any arguments.\n");
if (ret_ident != NULL) \
free(ret_ident); \
ret_ident_num = 0; \
if (ret_ident != NULL) \
free(ret_ident); \
ret_ident_num = 0; \
} while (0)
status = lcc_listval(c, &ret_ident, &ret_ident_num);
} while (0)
status = lcc_listval(c, &ret_ident, &ret_ident_num);
if (argc < 3) {
fprintf(stderr, "ERROR: putval: Missing identifier "
"and/or value list.\n");
if (argc < 3) {
fprintf(stderr, "ERROR: putval: Missing identifier "
"and/or value list.\n");
status = parse_identifier(c, argv[1], &vl.identifier);
if (status != 0)
status = parse_identifier(c, argv[1], &vl.identifier);
if (status != 0)
for (int i = 2; i < argc; ++i) {
char *tmp;
for (int i = 2; i < argc; ++i) {
char *tmp;
if (endptr == value) {
fprintf(stderr, "ERROR: Failed to parse interval as number: %s.\n",
value);
if (endptr == value) {
fprintf(stderr, "ERROR: Failed to parse interval as number: %s.\n",
value);
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "WARNING: Ignoring trailing garbage after "
"interval: %s.\n",
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "WARNING: Ignoring trailing garbage after "
"interval: %s.\n",
}
} else {
fprintf(stderr, "ERROR: putval: Unknown option `%s'.\n", key);
}
} else {
fprintf(stderr, "ERROR: putval: Unknown option `%s'.\n", key);
}
} else { /* value list */
char *value;
}
} else { /* value list */
char *value;
if (tmp == NULL) {
fprintf(stderr, "ERROR: putval: Invalid value list: %s.\n", argv[i]);
if (tmp == NULL) {
fprintf(stderr, "ERROR: putval: Invalid value list: %s.\n", argv[i]);
if (endptr == argv[i]) {
fprintf(stderr, "ERROR: Failed to parse time as number: %s.\n",
argv[i]);
if (endptr == argv[i]) {
fprintf(stderr, "ERROR: Failed to parse time as number: %s.\n",
argv[i]);
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "ERROR: Garbage after time: %s.\n", endptr);
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "ERROR: Garbage after time: %s.\n", endptr);
if (endptr == value) {
fprintf(stderr, "ERROR: Failed to parse value as number: %s.\n",
argv[i]);
if (endptr == value) {
fprintf(stderr, "ERROR: Failed to parse value as number: %s.\n",
argv[i]);
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "ERROR: Garbage after value: %s.\n", endptr);
} else if ((endptr != NULL) && (*endptr != '\0')) {
fprintf(stderr, "ERROR: Garbage after value: %s.\n", endptr);
status = lcc_putval(c, &vl);
if (status != 0) {
fprintf(stderr, "ERROR: %s\n", lcc_strerror(c));
status = lcc_putval(c, &vl);
if (status != 0) {
fprintf(stderr, "ERROR: %s\n", lcc_strerror(c));
}
}
}
if (values_len == 0) {
fprintf(stderr, "ERROR: putval: Missing value list(s).\n");
}
}
}
if (values_len == 0) {
fprintf(stderr, "ERROR: putval: Missing value list(s).\n");
} /* putval */
int main(int argc, char **argv) {
} /* putval */
int main(int argc, char **argv) {
if (status != 0) {
fprintf(stderr, "ERROR: Failed to connect to daemon at %s: %s.\n", address,
strerror(errno));
if (status != 0) {
fprintf(stderr, "ERROR: Failed to connect to daemon at %s: %s.\n", address,
strerror(errno));
}
if (strcasecmp(argv[optind], "getval") == 0)
}
if (strcasecmp(argv[optind], "getval") == 0)
status = putval(c, argc - optind, argv + optind);
else {
fprintf(stderr, "%s: invalid command: %s\n", argv[0], argv[optind]);
status = putval(c, argc - optind, argv + optind);
else {
fprintf(stderr, "%s: invalid command: %s\n", argv[0], argv[optind]);
}
LCC_DESTROY(c);
if (status != 0)
}
LCC_DESTROY(c);
if (status != 0)
- return (status);
- return (0);
+ return status;
+ return 0;
char const *path = old_files ? CONNTRACK_FILE_OLD : CONNTRACK_FILE;
if (parse_value_file(path, &conntrack, DS_TYPE_GAUGE) != 0) {
ERROR("conntrack plugin: Reading \"%s\" failed.", path);
char const *path = old_files ? CONNTRACK_FILE_OLD : CONNTRACK_FILE;
if (parse_value_file(path, &conntrack, DS_TYPE_GAUGE) != 0) {
ERROR("conntrack plugin: Reading \"%s\" failed.", path);
}
path = old_files ? CONNTRACK_MAX_FILE_OLD : CONNTRACK_MAX_FILE;
if (parse_value_file(path, &conntrack_max, DS_TYPE_GAUGE) != 0) {
ERROR("conntrack plugin: Reading \"%s\" failed.", path);
}
path = old_files ? CONNTRACK_MAX_FILE_OLD : CONNTRACK_MAX_FILE;
if (parse_value_file(path, &conntrack_max, DS_TYPE_GAUGE) != 0) {
ERROR("conntrack plugin: Reading \"%s\" failed.", path);
}
conntrack_pct.gauge = (conntrack.gauge / conntrack_max.gauge) * 100;
}
conntrack_pct.gauge = (conntrack.gauge / conntrack_max.gauge) * 100;
conntrack_submit("conntrack", "max", conntrack_max);
conntrack_submit("percent", "used", conntrack_pct);
conntrack_submit("conntrack", "max", conntrack_max);
conntrack_submit("percent", "used", conntrack_pct);
} /* static int conntrack_read */
void module_register(void) {
} /* static int conntrack_read */
void module_register(void) {
if (status != 0) {
ERROR("contextswitch plugin: sysctlbyname "
"(vm.stats.sys.v_swtch) failed");
if (status != 0) {
ERROR("contextswitch plugin: sysctlbyname "
"(vm.stats.sys.v_swtch) failed");
if (fh == NULL) {
ERROR("contextswitch plugin: unable to open /proc/stat: %s",
sstrerror(errno, buffer, sizeof(buffer)));
if (fh == NULL) {
ERROR("contextswitch plugin: unable to open /proc/stat: %s",
sstrerror(errno, buffer, sizeof(buffer)));
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
char errbuf[1024];
ERROR("contextswitch plugin: perfstat_cpu_total: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("contextswitch plugin: perfstat_cpu_total: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
cs_submit(perfcputotal.pswitch);
}
cs_submit(perfcputotal.pswitch);
else if (strcasecmp(key, "ReportNumCpu") == 0)
report_num_cpu = IS_TRUE(value) ? 1 : 0;
else
else if (strcasecmp(key, "ReportNumCpu") == 0)
report_num_cpu = IS_TRUE(value) ? 1 : 0;
else
} /* }}} int cpu_config */
static int init(void) {
} /* }}} int cpu_config */
static int init(void) {
"load information. "
"<https://collectd.org/bugs/22>");
cpu_list_len = 0;
"load information. "
"<https://collectd.org/bugs/22>");
cpu_list_len = 0;
}
if (status != KERN_SUCCESS) {
ERROR("cpu plugin: host_processors() failed with status %d.", (int)status);
cpu_list_len = 0;
}
if (status != KERN_SUCCESS) {
ERROR("cpu plugin: host_processors() failed with status %d.", (int)status);
cpu_list_len = 0;
}
INFO("cpu plugin: Found %i processor%s.", (int)cpu_list_len,
}
INFO("cpu plugin: Found %i processor%s.", (int)cpu_list_len,
numcpu = 0;
if (kc == NULL)
numcpu = 0;
if (kc == NULL)
/* Solaris doesn't count linear.. *sigh* */
for (numcpu = 0, ksp_chain = kc->kc_chain;
/* Solaris doesn't count linear.. *sigh* */
for (numcpu = 0, ksp_chain = kc->kc_chain;
if (status == -1) {
char errbuf[1024];
WARNING("cpu plugin: sysctl: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if (status == -1) {
char errbuf[1024];
WARNING("cpu plugin: sysctl: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* #endif CAN_USE_SYSCTL */
}
/* #endif CAN_USE_SYSCTL */
char errbuf[1024];
WARNING("cpu plugin: sysctlbyname(hw.ncpu): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("cpu plugin: sysctlbyname(hw.ncpu): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
#ifdef HAVE_SYSCTL_KERN_CP_TIMES
}
#ifdef HAVE_SYSCTL_KERN_CP_TIMES
char errbuf[1024];
WARNING("cpu plugin: sysctlbyname(kern.smp.maxcpus): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("cpu plugin: sysctlbyname(kern.smp.maxcpus): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
/* nothing to initialize */
#endif /* HAVE_PERFSTAT */
/* nothing to initialize */
#endif /* HAVE_PERFSTAT */
} /* int init */
static void submit_value(int cpu_num, int cpu_state, const char *type,
} /* int init */
static void submit_value(int cpu_num, int cpu_state, const char *type,
tmp = realloc(cpu_states, sz * sizeof(*cpu_states));
if (tmp == NULL) {
ERROR("cpu plugin: realloc failed.");
tmp = realloc(cpu_states, sz * sizeof(*cpu_states));
if (tmp == NULL) {
ERROR("cpu plugin: realloc failed.");
}
cpu_states = tmp;
tmp = cpu_states + cpu_states_num;
}
cpu_states = tmp;
tmp = cpu_states + cpu_states_num;
size_t index = ((cpu_num * COLLECTD_CPU_STATE_MAX) + state);
if (index >= cpu_states_num)
size_t index = ((cpu_num * COLLECTD_CPU_STATE_MAX) + state);
if (index >= cpu_states_num)
- return (&cpu_states[index]);
+ return &cpu_states[index];
} /* }}} cpu_state_t *get_cpu_state */
#if defined(HAVE_PERFSTAT) /* {{{ */
} /* }}} cpu_state_t *get_cpu_state */
#if defined(HAVE_PERFSTAT) /* {{{ */
int status =
value_to_rate(&rate, (value_t){.derive = d}, DS_TYPE_DERIVE, now, conv);
if (status != 0)
int status =
value_to_rate(&rate, (value_t){.derive = d}, DS_TYPE_DERIVE, now, conv);
if (status != 0)
sum_by_state[state] = rate;
if (state != COLLECTD_CPU_STATE_IDLE)
RATE_ADD(sum_by_state[COLLECTD_CPU_STATE_ACTIVE], sum_by_state[state]);
sum_by_state[state] = rate;
if (state != COLLECTD_CPU_STATE_IDLE)
RATE_ADD(sum_by_state[COLLECTD_CPU_STATE_ACTIVE], sum_by_state[state]);
}
#endif /* }}} HAVE_PERFSTAT */
}
#endif /* }}} HAVE_PERFSTAT */
value_t val = {.derive = d};
if (state >= COLLECTD_CPU_STATE_ACTIVE)
value_t val = {.derive = d};
if (state >= COLLECTD_CPU_STATE_ACTIVE)
status = cpu_states_alloc(cpu_num);
if (status != 0)
status = cpu_states_alloc(cpu_num);
if (status != 0)
if (global_cpu_num <= cpu_num)
global_cpu_num = cpu_num + 1;
if (global_cpu_num <= cpu_num)
global_cpu_num = cpu_num + 1;
status = value_to_rate(&rate, val, DS_TYPE_DERIVE, now, &s->conv);
if (status != 0)
status = value_to_rate(&rate, val, DS_TYPE_DERIVE, now, &s->conv);
if (status != 0)
s->rate = rate;
s->has_value = 1;
s->rate = rate;
s->has_value = 1;
} /* }}} int cpu_stage */
static int cpu_read(void) {
} /* }}} int cpu_stage */
static int cpu_read(void) {
char errbuf[1024];
ERROR("cpu plugin: fopen (/proc/stat) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("cpu plugin: fopen (/proc/stat) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buf, 1024, fh) != NULL) {
}
while (fgets(buf, 1024, fh) != NULL) {
static cpu_stat_t cs;
if (kc == NULL)
static cpu_stat_t cs;
if (kc == NULL)
for (int cpu = 0; cpu < numcpu; cpu++) {
if (kstat_read(kc, ksp[cpu], &cs) == -1)
for (int cpu = 0; cpu < numcpu; cpu++) {
if (kstat_read(kc, ksp[cpu], &cs) == -1)
if (numcpu < 1) {
ERROR("cpu plugin: Could not determine number of "
"installed CPUs using sysctl(3).");
if (numcpu < 1) {
ERROR("cpu plugin: Could not determine number of "
"installed CPUs using sysctl(3).");
}
memset(cpuinfo, 0, sizeof(cpuinfo));
}
memset(cpuinfo, 0, sizeof(cpuinfo));
char errbuf[1024];
ERROR("cpu plugin: sysctl failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("cpu plugin: sysctl failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("cpu plugin: sysctl failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("cpu plugin: sysctl failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
for (int i = 0; i < CPUSTATES; i++) {
}
for (int i = 0; i < CPUSTATES; i++) {
char errbuf[1024];
ERROR("cpu plugin: sysctlbyname failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("cpu plugin: sysctlbyname failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
for (int i = 0; i < numcpu; i++) {
}
for (int i = 0; i < numcpu; i++) {
char errbuf[1024];
ERROR("cpu plugin: sysctlbyname failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("cpu plugin: sysctlbyname failed: %s.",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
cpu_stage(0, COLLECTD_CPU_STATE_USER, (derive_t)cpuinfo[CP_USER], now);
}
cpu_stage(0, COLLECTD_CPU_STATE_USER, (derive_t)cpuinfo[CP_USER], now);
if (cs == NULL) {
ERROR("cpu plugin: sg_get_cpu_stats failed.");
if (cs == NULL) {
ERROR("cpu plugin: sg_get_cpu_stats failed.");
}
cpu_state(0, COLLECTD_CPU_STATE_IDLE, (derive_t)cs->idle);
}
cpu_state(0, COLLECTD_CPU_STATE_IDLE, (derive_t)cs->idle);
char errbuf[1024];
WARNING("cpu plugin: perfstat_cpu: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("cpu plugin: perfstat_cpu: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (pnumcpu != numcpu || perfcpu == NULL) {
}
if (pnumcpu != numcpu || perfcpu == NULL) {
char errbuf[1024];
WARNING("cpu plugin: perfstat_cpu: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("cpu plugin: perfstat_cpu: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
for (int i = 0; i < cpus; i++) {
}
for (int i = 0; i < cpus; i++) {
cpu_commit();
cpu_reset();
cpu_commit();
cpu_reset();
}
void module_register(void) {
}
void module_register(void) {
if (num_cpu == 0)
plugin_unregister_read("cpufreq");
if (num_cpu == 0)
plugin_unregister_read("cpufreq");
} /* int cpufreq_init */
static void cpufreq_submit(int cpu_num, value_t value) {
} /* int cpufreq_init */
static void cpufreq_submit(int cpu_num, value_t value) {
} /* int cpufreq_read */
void module_register(void) {
} /* int cpufreq_read */
void module_register(void) {
struct timespec b, m;
if (clock_gettime(CLOCK_BOOTTIME, &b) < 0) {
ERROR("cpusleep plugin: clock_boottime failed");
struct timespec b, m;
if (clock_gettime(CLOCK_BOOTTIME, &b) < 0) {
ERROR("cpusleep plugin: clock_boottime failed");
}
if (clock_gettime(CLOCK_MONOTONIC, &m) < 0) {
ERROR("cpusleep plugin: clock_monotonic failed");
}
if (clock_gettime(CLOCK_MONOTONIC, &m) < 0) {
ERROR("cpusleep plugin: clock_monotonic failed");
}
// to avoid false positives in counter overflow due to reboot,
}
// to avoid false positives in counter overflow due to reboot,
}
void module_register(void) {
}
void module_register(void) {
status = ssnprintf(buffer, buffer_len, "%.3f", CDTIME_T_TO_DOUBLE(vl->time));
if ((status < 1) || (status >= buffer_len))
status = ssnprintf(buffer, buffer_len, "%.3f", CDTIME_T_TO_DOUBLE(vl->time));
if ((status < 1) || (status >= buffer_len))
offset = status;
for (size_t i = 0; i < ds->ds_num; i++) {
offset = status;
for (size_t i = 0; i < ds->ds_num; i++) {
(ds->ds[i].type != DS_TYPE_DERIVE) &&
(ds->ds[i].type != DS_TYPE_ABSOLUTE)) {
sfree(rates);
(ds->ds[i].type != DS_TYPE_DERIVE) &&
(ds->ds[i].type != DS_TYPE_ABSOLUTE)) {
sfree(rates);
}
if (ds->ds[i].type == DS_TYPE_GAUGE) {
}
if (ds->ds[i].type == DS_TYPE_GAUGE) {
if (rates == NULL) {
WARNING("csv plugin: "
"uc_get_rate failed.");
if (rates == NULL) {
WARNING("csv plugin: "
"uc_get_rate failed.");
}
status =
ssnprintf(buffer + offset, buffer_len - offset, ",%lf", rates[i]);
}
status =
ssnprintf(buffer + offset, buffer_len - offset, ",%lf", rates[i]);
if ((status < 1) || (status >= (buffer_len - offset))) {
sfree(rates);
if ((status < 1) || (status >= (buffer_len - offset))) {
sfree(rates);
}
offset += status;
} /* for ds->ds_num */
sfree(rates);
}
offset += status;
} /* for ds->ds_num */
sfree(rates);
} /* int value_list_to_string */
static int value_list_to_filename(char *buffer, size_t buffer_size,
} /* int value_list_to_string */
static int value_list_to_filename(char *buffer, size_t buffer_size,
size_t len = strlen(datadir) + 1;
if (len >= ptr_size)
size_t len = strlen(datadir) + 1;
if (len >= ptr_size)
memcpy(ptr, datadir, len);
ptr[len - 1] = '/';
memcpy(ptr, datadir, len);
ptr[len - 1] = '/';
status = FORMAT_VL(ptr, ptr_size, vl);
if (status != 0)
status = FORMAT_VL(ptr, ptr_size, vl);
if (status != 0)
/* Skip all the time formatting stuff when printing to STDOUT or
* STDERR. */
if (use_stdio)
/* Skip all the time formatting stuff when printing to STDOUT or
* STDERR. */
if (use_stdio)
ptr_size -= strlen(ptr);
ptr += strlen(ptr);
ptr_size -= strlen(ptr);
ptr += strlen(ptr);
/* "-2013-07-12" => 11 bytes */
if (ptr_size < 12) {
ERROR("csv plugin: Buffer too small.");
/* "-2013-07-12" => 11 bytes */
if (ptr_size < 12) {
ERROR("csv plugin: Buffer too small.");
}
/* TODO: Find a way to minimize the calls to `localtime_r',
}
/* TODO: Find a way to minimize the calls to `localtime_r',
now = time(NULL);
if (localtime_r(&now, &struct_tm) == NULL) {
ERROR("csv plugin: localtime_r failed");
now = time(NULL);
if (localtime_r(&now, &struct_tm) == NULL) {
ERROR("csv plugin: localtime_r failed");
}
status = strftime(ptr, ptr_size, "-%Y-%m-%d", &struct_tm);
if (status == 0) /* yep, it returns zero on error. */
{
ERROR("csv plugin: strftime failed");
}
status = strftime(ptr, ptr_size, "-%Y-%m-%d", &struct_tm);
if (status == 0) /* yep, it returns zero on error. */
{
ERROR("csv plugin: strftime failed");
} /* int value_list_to_filename */
static int csv_create_file(const char *filename, const data_set_t *ds) {
FILE *csv;
if (check_create_dir(filename))
} /* int value_list_to_filename */
static int csv_create_file(const char *filename, const data_set_t *ds) {
FILE *csv;
if (check_create_dir(filename))
csv = fopen(filename, "w");
if (csv == NULL) {
char errbuf[1024];
ERROR("csv plugin: fopen (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
csv = fopen(filename, "w");
if (csv == NULL) {
char errbuf[1024];
ERROR("csv plugin: fopen (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (strcasecmp("stdout", value) == 0) {
use_stdio = 1;
}
if (strcasecmp("stdout", value) == 0) {
use_stdio = 1;
} else if (strcasecmp("stderr", value) == 0) {
use_stdio = 2;
} else if (strcasecmp("stderr", value) == 0) {
use_stdio = 2;
}
datadir = strdup(value);
if (datadir != NULL) {
}
datadir = strdup(value);
if (datadir != NULL) {
else
store_rates = 0;
} else {
else
store_rates = 0;
} else {
} /* int csv_config */
static int csv_write(const data_set_t *ds, const value_list_t *vl,
} /* int csv_config */
static int csv_write(const data_set_t *ds, const value_list_t *vl,
status = value_list_to_filename(filename, sizeof(filename), vl);
if (status != 0)
status = value_list_to_filename(filename, sizeof(filename), vl);
if (status != 0)
DEBUG("csv plugin: csv_write: filename = %s;", filename);
if (value_list_to_string(values, sizeof(values), ds, vl) != 0)
DEBUG("csv plugin: csv_write: filename = %s;", filename);
if (value_list_to_string(values, sizeof(values), ds, vl) != 0)
if (use_stdio) {
escape_string(filename, sizeof(filename));
if (use_stdio) {
escape_string(filename, sizeof(filename));
fprintf(use_stdio == 1 ? stdout : stderr, "PUTVAL %s interval=%.3f %s\n",
filename, CDTIME_T_TO_DOUBLE(vl->interval), values);
fprintf(use_stdio == 1 ? stdout : stderr, "PUTVAL %s interval=%.3f %s\n",
filename, CDTIME_T_TO_DOUBLE(vl->interval), values);
}
if (stat(filename, &statbuf) == -1) {
if (errno == ENOENT) {
if (csv_create_file(filename, ds))
}
if (stat(filename, &statbuf) == -1) {
if (errno == ENOENT) {
if (csv_create_file(filename, ds))
} else {
char errbuf[1024];
ERROR("stat(%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
} else {
char errbuf[1024];
ERROR("stat(%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
} else if (!S_ISREG(statbuf.st_mode)) {
ERROR("stat(%s): Not a regular file!", filename);
}
} else if (!S_ISREG(statbuf.st_mode)) {
ERROR("stat(%s): Not a regular file!", filename);
}
csv = fopen(filename, "a");
}
csv = fopen(filename, "a");
char errbuf[1024];
ERROR("csv plugin: fopen (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("csv plugin: fopen (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("csv plugin: flock (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(csv);
ERROR("csv plugin: flock (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(csv);
}
fprintf(csv, "%s\n", values);
}
fprintf(csv, "%s\n", values);
* because the `FILE *' may need to flush a cache first */
fclose(csv);
* because the `FILE *' may need to flush a cache first */
fclose(csv);
} /* int csv_write */
void module_register(void) {
} /* int csv_write */
void module_register(void) {
len = size * nmemb;
if (len == 0)
len = size * nmemb;
if (len == 0)
wp = user_data;
if (wp == NULL)
wp = user_data;
if (wp == NULL)
if ((wp->buffer_fill + len) >= wp->buffer_size) {
char *temp;
if ((wp->buffer_fill + len) >= wp->buffer_size) {
char *temp;
temp = realloc(wp->buffer, temp_size);
if (temp == NULL) {
ERROR("curl plugin: realloc failed.");
temp = realloc(wp->buffer, temp_size);
if (temp == NULL) {
ERROR("curl plugin: realloc failed.");
}
wp->buffer = temp;
wp->buffer_size = temp_size;
}
wp->buffer = temp;
wp->buffer_size = temp_size;
wp->buffer_fill += len;
wp->buffer[wp->buffer_fill] = 0;
wp->buffer_fill += len;
wp->buffer[wp->buffer_fill] = 0;
} /* }}} size_t cc_curl_callback */
static void cc_web_match_free(web_match_t *wm) /* {{{ */
} /* }}} size_t cc_curl_callback */
static void cc_web_match_free(web_match_t *wm) /* {{{ */
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl plugin: `%s' needs exactly one string argument.", name);
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl plugin: `%s' needs exactly one string argument.", name);
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
} /* }}} int cc_config_append_string */
static int cc_config_add_match_dstype(int *dstype_ret, /* {{{ */
} /* }}} int cc_config_append_string */
static int cc_config_add_match_dstype(int *dstype_ret, /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl plugin: `DSType' needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl plugin: `DSType' needs exactly one string argument.");
}
if (strncasecmp("Gauge", ci->values[0].value.string, strlen("Gauge")) == 0) {
}
if (strncasecmp("Gauge", ci->values[0].value.string, strlen("Gauge")) == 0) {
if (dstype == 0) {
WARNING("curl plugin: `%s' is not a valid argument to `DSType'.",
ci->values[0].value.string);
if (dstype == 0) {
WARNING("curl plugin: `%s' is not a valid argument to `DSType'.",
ci->values[0].value.string);
} /* }}} int cc_config_add_match_dstype */
static int cc_config_add_match(web_page_t *page, /* {{{ */
} /* }}} int cc_config_add_match_dstype */
static int cc_config_add_match(web_page_t *page, /* {{{ */
match = calloc(1, sizeof(*match));
if (match == NULL) {
ERROR("curl plugin: calloc failed.");
match = calloc(1, sizeof(*match));
if (match == NULL) {
ERROR("curl plugin: calloc failed.");
if (status != 0) {
cc_web_match_free(match);
if (status != 0) {
cc_web_match_free(match);
if (match->match == NULL) {
ERROR("curl plugin: match_create_simple failed.");
cc_web_match_free(match);
if (match->match == NULL) {
ERROR("curl plugin: match_create_simple failed.");
cc_web_match_free(match);
} else {
web_match_t *prev;
} else {
web_match_t *prev;
} /* }}} int cc_config_add_match */
static int cc_page_init_curl(web_page_t *wp) /* {{{ */
} /* }}} int cc_config_add_match */
static int cc_page_init_curl(web_page_t *wp) /* {{{ */
wp->curl = curl_easy_init();
if (wp->curl == NULL) {
ERROR("curl plugin: curl_easy_init failed.");
wp->curl = curl_easy_init();
if (wp->curl == NULL) {
ERROR("curl plugin: curl_easy_init failed.");
}
curl_easy_setopt(wp->curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(wp->curl, CURLOPT_NOSIGNAL, 1L);
wp->credentials = malloc(credentials_size);
if (wp->credentials == NULL) {
ERROR("curl plugin: malloc failed.");
wp->credentials = malloc(credentials_size);
if (wp->credentials == NULL) {
ERROR("curl plugin: malloc failed.");
}
ssnprintf(wp->credentials, credentials_size, "%s:%s", wp->user,
}
ssnprintf(wp->credentials, credentials_size, "%s:%s", wp->user,
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
} /* }}} int cc_page_init_curl */
static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */
} /* }}} int cc_page_init_curl */
static int cc_config_add_page(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl plugin: `Page' blocks need exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl plugin: `Page' blocks need exactly one string argument.");
}
page = calloc(1, sizeof(*page));
if (page == NULL) {
ERROR("curl plugin: calloc failed.");
}
page = calloc(1, sizeof(*page));
if (page == NULL) {
ERROR("curl plugin: calloc failed.");
}
page->url = NULL;
page->user = NULL;
}
page->url = NULL;
page->user = NULL;
if (page->instance == NULL) {
ERROR("curl plugin: strdup failed.");
sfree(page);
if (page->instance == NULL) {
ERROR("curl plugin: strdup failed.");
sfree(page);
}
/* Process all children */
}
/* Process all children */
if (status != 0) {
cc_web_page_free(page);
if (status != 0) {
cc_web_page_free(page);
}
/* Add the new page to the linked list */
}
/* Add the new page to the linked list */
} /* }}} int cc_config_add_page */
static int cc_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int cc_config_add_page */
static int cc_config(oconfig_item_t *ci) /* {{{ */
if ((success == 0) && (errors > 0)) {
ERROR("curl plugin: All statements failed.");
if ((success == 0) && (errors > 0)) {
ERROR("curl plugin: All statements failed.");
} /* }}} int cc_config */
static int cc_init(void) /* {{{ */
{
if (pages_g == NULL) {
INFO("curl plugin: No pages have been defined.");
} /* }}} int cc_config */
static int cc_init(void) /* {{{ */
{
if (pages_g == NULL) {
INFO("curl plugin: No pages have been defined.");
}
curl_global_init(CURL_GLOBAL_SSL);
}
curl_global_init(CURL_GLOBAL_SSL);
} /* }}} int cc_init */
static void cc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */
} /* }}} int cc_init */
static void cc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */
if (status != CURLE_OK) {
ERROR("curl plugin: curl_easy_perform failed with status %i: %s", status,
wp->curl_errbuf);
if (status != CURLE_OK) {
ERROR("curl plugin: curl_easy_perform failed with status %i: %s", status,
wp->curl_errbuf);
match_value_reset(mv);
} /* for (wm = wp->matches; wm != NULL; wm = wm->next) */
match_value_reset(mv);
} /* for (wm = wp->matches; wm != NULL; wm = wm->next) */
} /* }}} int cc_read_page */
static int cc_read(void) /* {{{ */
} /* }}} int cc_read_page */
static int cc_read(void) /* {{{ */
for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next)
cc_read_page(wp);
for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next)
cc_read_page(wp);
} /* }}} int cc_read */
static int cc_shutdown(void) /* {{{ */
} /* }}} int cc_read */
static int cc_shutdown(void) /* {{{ */
cc_web_page_free(pages_g);
pages_g = NULL;
cc_web_page_free(pages_g);
pages_g = NULL;
} /* }}} int cc_shutdown */
void module_register(void) {
} /* }}} int cc_shutdown */
void module_register(void) {
len = size * nmemb;
if (len == 0)
len = size * nmemb;
if (len == 0)
db = user_data;
if (db == NULL)
db = user_data;
if (db == NULL)
status = yajl_parse(db->yajl, (unsigned char *)buf, len);
if (status == yajl_status_ok)
status = yajl_parse(db->yajl, (unsigned char *)buf, len);
if (status == yajl_status_ok)
#if !HAVE_YAJL_V2
else if (status == yajl_status_insufficient_data)
#if !HAVE_YAJL_V2
else if (status == yajl_status_insufficient_data)
#endif
unsigned char *msg =
#endif
unsigned char *msg =
/* jsonText = */ (unsigned char *)buf, (unsigned int)len);
ERROR("curl_json plugin: yajl_parse failed: %s", msg);
yajl_free_error(db->yajl, msg);
/* jsonText = */ (unsigned char *)buf, (unsigned int)len);
ERROR("curl_json plugin: yajl_parse failed: %s", msg);
yajl_free_error(db->yajl, msg);
- return (0); /* abort write callback */
+ return 0; /* abort write callback */
} /* }}} size_t cj_curl_callback */
static int cj_get_type(cj_key_t *key) {
} /* }}} size_t cj_curl_callback */
static int cj_get_type(cj_key_t *key) {
static int cj_cb_boolean(void *ctx, int boolVal) {
cj_cb_inc_array_index(ctx, /* update_key = */ 0);
static int cj_cb_boolean(void *ctx, int boolVal) {
cj_cb_inc_array_index(ctx, /* update_key = */ 0);
- return (CJ_CB_CONTINUE);
}
static int cj_cb_null(void *ctx) {
cj_cb_inc_array_index(ctx, /* update_key = */ 0);
}
static int cj_cb_null(void *ctx) {
cj_cb_inc_array_index(ctx, /* update_key = */ 0);
- return (CJ_CB_CONTINUE);
}
static int cj_cb_number(void *ctx, const char *number, yajl_len_t number_len) {
}
static int cj_cb_number(void *ctx, const char *number, yajl_len_t number_len) {
NOTICE("curl_json plugin: Found \"%s\", but the configuration expects"
" a map.",
buffer);
NOTICE("curl_json plugin: Found \"%s\", but the configuration expects"
" a map.",
buffer);
- return (CJ_CB_CONTINUE);
}
cj_cb_inc_array_index(ctx, /* update_key = */ 1);
key = db->state[db->depth].key;
if ((key == NULL) || !CJ_IS_KEY(key)) {
}
cj_cb_inc_array_index(ctx, /* update_key = */ 1);
key = db->state[db->depth].key;
if ((key == NULL) || !CJ_IS_KEY(key)) {
- return (CJ_CB_CONTINUE);
}
} else {
cj_cb_inc_array_index(ctx, /* update_key = */ 1);
}
} else {
cj_cb_inc_array_index(ctx, /* update_key = */ 1);
status = parse_value(buffer, &vt, type);
if (status != 0) {
NOTICE("curl_json plugin: Unable to parse number: \"%s\"", buffer);
status = parse_value(buffer, &vt, type);
if (status != 0) {
NOTICE("curl_json plugin: Unable to parse number: \"%s\"", buffer);
- return (CJ_CB_CONTINUE);
}
cj_submit(db, key, &vt);
}
cj_submit(db, key, &vt);
- return (CJ_CB_CONTINUE);
} /* int cj_cb_number */
/* Queries the key-tree of the parent context for "in_name" and, if found,
} /* int cj_cb_number */
/* Queries the key-tree of the parent context for "in_name" and, if found,
db->state[db->depth].key = NULL;
}
db->state[db->depth].key = NULL;
}
- return (CJ_CB_CONTINUE);
}
static int cj_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) {
/* Handle the string as if it was a number. */
}
static int cj_cb_string(void *ctx, const unsigned char *val, yajl_len_t len) {
/* Handle the string as if it was a number. */
- return (cj_cb_number(ctx, (const char *)val, len));
+ return cj_cb_number(ctx, (const char *)val, len);
} /* int cj_cb_string */
static int cj_cb_start(void *ctx) {
} /* int cj_cb_string */
static int cj_cb_start(void *ctx) {
if (++db->depth >= YAJL_MAX_DEPTH) {
ERROR("curl_json plugin: %s depth exceeds max, aborting.",
db->url ? db->url : db->sock);
if (++db->depth >= YAJL_MAX_DEPTH) {
ERROR("curl_json plugin: %s depth exceeds max, aborting.",
db->url ? db->url : db->sock);
- return (CJ_CB_CONTINUE);
}
static int cj_cb_end(void *ctx) {
cj_t *db = (cj_t *)ctx;
db->state[db->depth].tree = NULL;
--db->depth;
}
static int cj_cb_end(void *ctx) {
cj_t *db = (cj_t *)ctx;
db->state[db->depth].tree = NULL;
--db->depth;
- return (CJ_CB_CONTINUE);
}
static int cj_cb_start_map(void *ctx) {
}
static int cj_cb_start_map(void *ctx) {
/* Configuration handling functions {{{ */
static c_avl_tree_t *cj_avl_create(void) {
/* Configuration handling functions {{{ */
static c_avl_tree_t *cj_avl_create(void) {
- return c_avl_create((int (*)(const void *, const void *))strcmp);
+ return c_avl_create((int(*)(const void *, const void *))strcmp);
}
static int cj_config_append_string(const char *name,
}
static int cj_config_append_string(const char *name,
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_json plugin: `%s' needs exactly one string argument.", name);
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_json plugin: `%s' needs exactly one string argument.", name);
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
} /* }}} int cj_config_append_string */
static int cj_config_add_key(cj_t *db, /* {{{ */
} /* }}} int cj_config_append_string */
static int cj_config_add_key(cj_t *db, /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_json plugin: The `Key' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_json plugin: The `Key' block "
"needs exactly one string argument.");
}
key = calloc(1, sizeof(*key));
if (key == NULL) {
ERROR("curl_json plugin: calloc failed.");
}
key = calloc(1, sizeof(*key));
if (key == NULL) {
ERROR("curl_json plugin: calloc failed.");
}
key->magic = CJ_KEY_MAGIC;
}
key->magic = CJ_KEY_MAGIC;
status = cf_util_get_string(ci, &key->path);
if (status != 0) {
sfree(key);
status = cf_util_get_string(ci, &key->path);
if (status != 0) {
sfree(key);
}
} else {
ERROR("curl_json plugin: cj_config: "
"Invalid key: %s",
ci->key);
cj_key_free(key);
}
} else {
ERROR("curl_json plugin: cj_config: "
"Invalid key: %s",
ci->key);
cj_key_free(key);
if (status != 0) {
cj_key_free(key);
if (status != 0) {
cj_key_free(key);
}
if (key->type == NULL) {
WARNING("curl_json plugin: `Type' missing in `Key' block.");
cj_key_free(key);
}
if (key->type == NULL) {
WARNING("curl_json plugin: `Type' missing in `Key' block.");
cj_key_free(key);
}
/* store path in a tree that will match the json map structure, example:
}
/* store path in a tree that will match the json map structure, example:
if (strlen(name) == 0) {
ERROR("curl_json plugin: invalid key: %s", key->path);
cj_key_free(key);
if (strlen(name) == 0) {
ERROR("curl_json plugin: invalid key: %s", key->path);
cj_key_free(key);
}
c_avl_insert(tree, strdup(name), key);
}
c_avl_insert(tree, strdup(name), key);
} /* }}} int cj_config_add_key */
static int cj_init_curl(cj_t *db) /* {{{ */
} /* }}} int cj_config_add_key */
static int cj_init_curl(cj_t *db) /* {{{ */
db->curl = curl_easy_init();
if (db->curl == NULL) {
ERROR("curl_json plugin: curl_easy_init failed.");
db->curl = curl_easy_init();
if (db->curl == NULL) {
ERROR("curl_json plugin: curl_easy_init failed.");
}
curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
db->credentials = malloc(credentials_size);
if (db->credentials == NULL) {
ERROR("curl_json plugin: malloc failed.");
db->credentials = malloc(credentials_size);
if (db->credentials == NULL) {
ERROR("curl_json plugin: malloc failed.");
}
ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
}
ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
} /* }}} int cj_init_curl */
static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */
} /* }}} int cj_init_curl */
static int cj_config_add_url(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_json plugin: The `URL' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_json plugin: The `URL' block "
"needs exactly one string argument.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("curl_json plugin: calloc failed.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("curl_json plugin: calloc failed.");
"Invalid key: %s",
ci->key);
cj_free(db);
"Invalid key: %s",
ci->key);
cj_free(db);
}
if (status != 0) {
sfree(db);
}
if (status != 0) {
sfree(db);
}
/* Fill the `cj_t' structure.. */
}
/* Fill the `cj_t' structure.. */
sfree(cb_name);
} else {
cj_free(db);
sfree(cb_name);
} else {
cj_free(db);
}
/* }}} int cj_config_add_database */
}
/* }}} int cj_config_add_database */
if ((success == 0) && (errors > 0)) {
ERROR("curl_json plugin: All statements failed.");
if ((success == 0) && (errors > 0)) {
ERROR("curl_json plugin: All statements failed.");
} /* }}} int cj_config */
/* }}} End of configuration handling functions */
} /* }}} int cj_config */
/* }}} End of configuration handling functions */
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
if (connect(fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0) {
ERROR("curl_json plugin: connect(%s) failed: %s",
(db->sock != NULL) ? db->sock : "<null>",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
if (connect(fd, (struct sockaddr *)&sa_unix, sizeof(sa_unix)) < 0) {
ERROR("curl_json plugin: connect(%s) failed: %s",
(db->sock != NULL) ? db->sock : "<null>",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
(db->sock != NULL) ? db->sock : "<null>",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
(db->sock != NULL) ? db->sock : "<null>",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
}
if (!cj_curl_callback(buffer, red, 1, db))
break;
} while (red > 0);
close(fd);
}
if (!cj_curl_callback(buffer, red, 1, db))
break;
} while (red > 0);
close(fd);
} /* }}} int cj_sock_perform */
static int cj_curl_perform(cj_t *db) /* {{{ */
} /* }}} int cj_sock_perform */
static int cj_curl_perform(cj_t *db) /* {{{ */
if (status != CURLE_OK) {
ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
status, db->curl_errbuf, url);
if (status != CURLE_OK) {
ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
status, db->curl_errbuf, url);
}
if (db->stats != NULL)
curl_stats_dispatch(db->stats, db->curl, cj_host(db), "curl_json",
}
if (db->stats != NULL)
curl_stats_dispatch(db->stats, db->curl, cj_host(db), "curl_json",
ERROR("curl_json plugin: curl_easy_perform failed with "
"response code %ld (%s)",
rc, url);
ERROR("curl_json plugin: curl_easy_perform failed with "
"response code %ld (%s)",
rc, url);
} /* }}} int cj_curl_perform */
static int cj_perform(cj_t *db) /* {{{ */
} /* }}} int cj_curl_perform */
static int cj_perform(cj_t *db) /* {{{ */
if (db->yajl == NULL) {
ERROR("curl_json plugin: yajl_alloc failed.");
db->yajl = yprev;
if (db->yajl == NULL) {
ERROR("curl_json plugin: yajl_alloc failed.");
db->yajl = yprev;
if (status < 0) {
yajl_free(db->yajl);
db->yajl = yprev;
if (status < 0) {
yajl_free(db->yajl);
db->yajl = yprev;
yajl_free_error(db->yajl, errmsg);
yajl_free(db->yajl);
db->yajl = yprev;
yajl_free_error(db->yajl, errmsg);
yajl_free(db->yajl);
db->yajl = yprev;
}
yajl_free(db->yajl);
db->yajl = yprev;
}
yajl_free(db->yajl);
db->yajl = yprev;
} /* }}} int cj_perform */
static int cj_read(user_data_t *ud) /* {{{ */
} /* }}} int cj_perform */
static int cj_read(user_data_t *ud) /* {{{ */
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("curl_json plugin: cj_read: Invalid user data.");
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("curl_json plugin: cj_read: Invalid user data.");
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
} /* }}} int cj_init */
void module_register(void) {
} /* }}} int cj_init */
void module_register(void) {
if (db == NULL) {
ERROR("curl_xml plugin: cx_curl_callback: "
"user_data pointer is NULL.");
if (db == NULL) {
ERROR("curl_xml plugin: cx_curl_callback: "
"user_data pointer is NULL.");
if ((db->buffer_fill + len) >= db->buffer_size) {
char *temp;
if ((db->buffer_fill + len) >= db->buffer_size) {
char *temp;
temp = realloc(db->buffer, db->buffer_fill + len + 1);
if (temp == NULL) {
ERROR("curl_xml plugin: realloc failed.");
temp = realloc(db->buffer, db->buffer_fill + len + 1);
if (temp == NULL) {
ERROR("curl_xml plugin: realloc failed.");
}
db->buffer = temp;
db->buffer_size = db->buffer_fill + len + 1;
}
db->buffer = temp;
db->buffer_size = db->buffer_fill + len + 1;
db->buffer_fill += len;
db->buffer[db->buffer_fill] = 0;
db->buffer_fill += len;
db->buffer[db->buffer_fill] = 0;
} /* }}} size_t cx_curl_callback */
static void cx_xpath_free(cx_xpath_t *xpath) /* {{{ */
} /* }}} size_t cx_curl_callback */
static void cx_xpath_free(cx_xpath_t *xpath) /* {{{ */
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_xml plugin: `%s' needs exactly one string argument.", name);
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_xml plugin: `%s' needs exactly one string argument.", name);
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
} /* }}} int cx_config_append_string */
static int cx_check_type(const data_set_t *ds, cx_xpath_t *xpath) /* {{{ */
{
if (!ds) {
WARNING("curl_xml plugin: DataSet `%s' not defined.", xpath->type);
} /* }}} int cx_config_append_string */
static int cx_check_type(const data_set_t *ds, cx_xpath_t *xpath) /* {{{ */
{
if (!ds) {
WARNING("curl_xml plugin: DataSet `%s' not defined.", xpath->type);
}
if (ds->ds_num != xpath->values_len) {
WARNING("curl_xml plugin: DataSet `%s' requires %zu values, but config "
"talks about %zu",
xpath->type, ds->ds_num, xpath->values_len);
}
if (ds->ds_num != xpath->values_len) {
WARNING("curl_xml plugin: DataSet `%s' requires %zu values, but config "
"talks about %zu",
xpath->type, ds->ds_num, xpath->values_len);
} /* }}} cx_check_type */
static xmlXPathObjectPtr
} /* }}} cx_check_type */
static xmlXPathObjectPtr
{
if (node->type == XML_TEXT_NODE || node->type == XML_ATTRIBUTE_NODE ||
node->type == XML_ELEMENT_NODE)
{
if (node->type == XML_TEXT_NODE || node->type == XML_ATTRIBUTE_NODE ||
node->type == XML_ELEMENT_NODE)
WARNING("curl_xml plugin: "
"Node \"%s\" doesn't seem to be a text node. Skipping...",
WARNING("curl_xml plugin: "
"Node \"%s\" doesn't seem to be a text node. Skipping...",
values_node_obj =
cx_evaluate_xpath(xpath_ctx, BAD_CAST xpath->values[index].path);
if (values_node_obj == NULL)
values_node_obj =
cx_evaluate_xpath(xpath_ctx, BAD_CAST xpath->values[index].path);
if (values_node_obj == NULL)
- return (-1); /* Error already logged. */
+ return -1; /* Error already logged. */
values_node = values_node_obj->nodesetval;
tmp_size = (values_node) ? values_node->nodeNr : 0;
values_node = values_node_obj->nodesetval;
tmp_size = (values_node) ? values_node->nodeNr : 0;
"Skipping...",
xpath->values[index].path);
xmlXPathFreeObject(values_node_obj);
"Skipping...",
xpath->values[index].path);
xmlXPathFreeObject(values_node_obj);
"only one node. Skipping...",
xpath->values[index].path);
xmlXPathFreeObject(values_node_obj);
"only one node. Skipping...",
xpath->values[index].path);
xmlXPathFreeObject(values_node_obj);
}
/* ignoring the element if other than textnode/attribute*/
}
/* ignoring the element if other than textnode/attribute*/
"only text/attribute node which is not the case. Skipping...",
xpath->values[index].path);
xmlXPathFreeObject(values_node_obj);
"only text/attribute node which is not the case. Skipping...",
xpath->values[index].path);
xmlXPathFreeObject(values_node_obj);
}
node_value = (char *)xmlNodeGetContent(values_node->nodeTab[0]);
}
node_value = (char *)xmlNodeGetContent(values_node->nodeTab[0]);
/* We have reached here which means that
* we have got something to work */
/* We have reached here which means that
* we have got something to work */
} /* }}} int cx_handle_single_value_xpath */
static int cx_handle_all_value_xpaths(xmlXPathContextPtr xpath_ctx, /* {{{ */
} /* }}} int cx_handle_single_value_xpath */
static int cx_handle_all_value_xpaths(xmlXPathContextPtr xpath_ctx, /* {{{ */
for (size_t i = 0; i < xpath->values_len; i++) {
status = cx_handle_single_value_xpath(xpath_ctx, xpath, ds, vl, i);
if (status != 0)
for (size_t i = 0; i < xpath->values_len; i++) {
status = cx_handle_single_value_xpath(xpath_ctx, xpath, ds, vl, i);
if (status != 0)
- return (-1); /* An error has been printed. */
+ return -1; /* An error has been printed. */
} /* for (i = 0; i < xpath->values_len; i++) */
plugin_dispatch_values(vl);
vl->values = NULL;
} /* for (i = 0; i < xpath->values_len; i++) */
plugin_dispatch_values(vl);
vl->values = NULL;
} /* }}} int cx_handle_all_value_xpaths */
static int cx_handle_instance_xpath(xmlXPathContextPtr xpath_ctx, /* {{{ */
} /* }}} int cx_handle_all_value_xpaths */
static int cx_handle_instance_xpath(xmlXPathContextPtr xpath_ctx, /* {{{ */
"Base-XPath %s is a table (more than one result was returned), "
"but no instance-XPath has been defined.",
xpath->path);
"Base-XPath %s is a table (more than one result was returned), "
"but no instance-XPath has been defined.",
xpath->path);
}
/* instance has to be an xpath expression */
}
/* instance has to be an xpath expression */
instance_node_obj = cx_evaluate_xpath(xpath_ctx, BAD_CAST xpath->instance);
if (instance_node_obj == NULL)
instance_node_obj = cx_evaluate_xpath(xpath_ctx, BAD_CAST xpath->instance);
if (instance_node_obj == NULL)
- return (-1); /* error is logged already */
+ return -1; /* error is logged already */
instance_node = instance_node_obj->nodesetval;
tmp_size = (instance_node) ? instance_node->nodeNr : 0;
instance_node = instance_node_obj->nodesetval;
tmp_size = (instance_node) ? instance_node->nodeNr : 0;
"any of the nodes. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
"any of the nodes. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
"to return only one text node. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
"to return only one text node. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
}
/* ignoring the element if other than textnode/attribute */
}
/* ignoring the element if other than textnode/attribute */
"which is not the case. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
"which is not the case. Skipping the node.",
xpath->instance);
xmlXPathFreeObject(instance_node_obj);
}
} /* if (xpath->instance != NULL) */
}
} /* if (xpath->instance != NULL) */
* somewhere inside this structure. */
xmlXPathFreeObject(instance_node_obj);
* somewhere inside this structure. */
xmlXPathFreeObject(instance_node_obj);
} /* }}} int cx_handle_instance_xpath */
static int cx_handle_base_xpath(char const *plugin_instance, /* {{{ */
} /* }}} int cx_handle_instance_xpath */
static int cx_handle_base_xpath(char const *plugin_instance, /* {{{ */
/* free up the allocated memory */
xmlXPathFreeObject(base_node_obj);
/* free up the allocated memory */
xmlXPathFreeObject(base_node_obj);
} /* }}} cx_handle_base_xpath */
static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */
} /* }}} cx_handle_base_xpath */
static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */
doc = xmlParseDoc(xml);
if (doc == NULL) {
ERROR("curl_xml plugin: Failed to parse the xml document - %s", xml);
doc = xmlParseDoc(xml);
if (doc == NULL) {
ERROR("curl_xml plugin: Failed to parse the xml document - %s", xml);
}
xpath_ctx = xmlXPathNewContext(doc);
if (xpath_ctx == NULL) {
ERROR("curl_xml plugin: Failed to create the xml context");
xmlFreeDoc(doc);
}
xpath_ctx = xmlXPathNewContext(doc);
if (xpath_ctx == NULL) {
ERROR("curl_xml plugin: Failed to create the xml context");
xmlFreeDoc(doc);
}
for (size_t i = 0; i < db->namespaces_num; i++) {
}
for (size_t i = 0; i < db->namespaces_num; i++) {
ns->prefix, ns->url);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(doc);
ns->prefix, ns->url);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(doc);
if (status != CURLE_OK) {
ERROR("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
status, db->curl_errbuf, url);
if (status != CURLE_OK) {
ERROR("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
status, db->curl_errbuf, url);
}
if (db->stats != NULL)
curl_stats_dispatch(db->stats, db->curl, cx_host(db), "curl_xml",
}
if (db->stats != NULL)
curl_stats_dispatch(db->stats, db->curl, cx_host(db), "curl_xml",
ERROR(
"curl_xml plugin: curl_easy_perform failed with response code %ld (%s)",
rc, url);
ERROR(
"curl_xml plugin: curl_easy_perform failed with response code %ld (%s)",
rc, url);
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("curl_xml plugin: cx_read: Invalid user data.");
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("curl_xml plugin: cx_read: Invalid user data.");
oconfig_item_t *ci) {
if (ci->values_num < 1) {
WARNING("curl_xml plugin: `ValuesFrom' needs at least one argument.");
oconfig_item_t *ci) {
if (ci->values_num < 1) {
WARNING("curl_xml plugin: `ValuesFrom' needs at least one argument.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("curl_xml plugin: `ValuesFrom' needs only string argument.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("curl_xml plugin: `ValuesFrom' needs only string argument.");
xpath->values_len = 0;
xpath->values = malloc(sizeof(cx_values_t) * ci->values_num);
if (xpath->values == NULL)
xpath->values_len = 0;
xpath->values = malloc(sizeof(cx_values_t) * ci->values_num);
if (xpath->values == NULL)
xpath->values_len = (size_t)ci->values_num;
/* populate cx_values_t structure */
xpath->values_len = (size_t)ci->values_num;
/* populate cx_values_t structure */
sizeof(xpath->values[i].path));
}
sizeof(xpath->values[i].path));
}
} /* }}} cx_config_add_values */
static int cx_config_add_xpath(cx_t *db, oconfig_item_t *ci) /* {{{ */
} /* }}} cx_config_add_values */
static int cx_config_add_xpath(cx_t *db, oconfig_item_t *ci) /* {{{ */
xpath = calloc(1, sizeof(*xpath));
if (xpath == NULL) {
ERROR("curl_xml plugin: calloc failed.");
xpath = calloc(1, sizeof(*xpath));
if (xpath == NULL) {
ERROR("curl_xml plugin: calloc failed.");
}
status = cf_util_get_string(ci, &xpath->path);
if (status != 0) {
cx_xpath_free(xpath);
}
status = cf_util_get_string(ci, &xpath->path);
if (status != 0) {
cx_xpath_free(xpath);
}
/* error out if xpath->path is an empty string */
}
/* error out if xpath->path is an empty string */
ERROR("curl_xml plugin: invalid xpath. "
"xpath value can't be an empty string");
cx_xpath_free(xpath);
ERROR("curl_xml plugin: invalid xpath. "
"xpath value can't be an empty string");
cx_xpath_free(xpath);
if (db->list == NULL) {
ERROR("curl_xml plugin: list creation failed.");
cx_xpath_free(xpath);
if (db->list == NULL) {
ERROR("curl_xml plugin: list creation failed.");
cx_xpath_free(xpath);
if (name == NULL) {
ERROR("curl_xml plugin: strdup failed.");
cx_xpath_free(xpath);
if (name == NULL) {
ERROR("curl_xml plugin: strdup failed.");
cx_xpath_free(xpath);
}
le = llentry_create(name, xpath);
}
le = llentry_create(name, xpath);
ERROR("curl_xml plugin: llentry_create failed.");
cx_xpath_free(xpath);
sfree(name);
ERROR("curl_xml plugin: llentry_create failed.");
cx_xpath_free(xpath);
sfree(name);
}
llist_append(db->list, le);
}
llist_append(db->list, le);
} /* }}} int cx_config_add_xpath */
static int cx_config_add_namespace(cx_t *db, /* {{{ */
} /* }}} int cx_config_add_xpath */
static int cx_config_add_namespace(cx_t *db, /* {{{ */
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_xml plugin: The `Namespace' option "
"needs exactly two string arguments.");
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_xml plugin: The `Namespace' option "
"needs exactly two string arguments.");
}
ns = realloc(db->namespaces,
sizeof(*db->namespaces) * (db->namespaces_num + 1));
if (ns == NULL) {
ERROR("curl_xml plugin: realloc failed.");
}
ns = realloc(db->namespaces,
sizeof(*db->namespaces) * (db->namespaces_num + 1));
if (ns == NULL) {
ERROR("curl_xml plugin: realloc failed.");
}
db->namespaces = ns;
ns = db->namespaces + db->namespaces_num;
}
db->namespaces = ns;
ns = db->namespaces + db->namespaces_num;
sfree(ns->prefix);
sfree(ns->url);
ERROR("curl_xml plugin: strdup failed.");
sfree(ns->prefix);
sfree(ns->url);
ERROR("curl_xml plugin: strdup failed.");
} /* }}} int cx_config_add_namespace */
/* Initialize db->curl */
} /* }}} int cx_config_add_namespace */
/* Initialize db->curl */
db->curl = curl_easy_init();
if (db->curl == NULL) {
ERROR("curl_xml plugin: curl_easy_init failed.");
db->curl = curl_easy_init();
if (db->curl == NULL) {
ERROR("curl_xml plugin: curl_easy_init failed.");
}
curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(db->curl, CURLOPT_NOSIGNAL, 1L);
db->credentials = malloc(credentials_size);
if (db->credentials == NULL) {
ERROR("curl_xml plugin: malloc failed.");
db->credentials = malloc(credentials_size);
if (db->credentials == NULL) {
ERROR("curl_xml plugin: malloc failed.");
}
ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
}
ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
(long)CDTIME_T_TO_MS(plugin_get_interval()));
#endif
} /* }}} int cx_init_curl */
static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */
} /* }}} int cx_init_curl */
static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_xml plugin: The `URL' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("curl_xml plugin: The `URL' block "
"needs exactly one string argument.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("curl_xml plugin: calloc failed.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("curl_xml plugin: calloc failed.");
status = cf_util_get_string(ci, &db->url);
if (status != 0) {
sfree(db);
status = cf_util_get_string(ci, &db->url);
if (status != 0) {
sfree(db);
}
} else {
ERROR("curl_xml plugin: cx_config: "
"Invalid key: %s",
ci->key);
cx_free(db);
}
} else {
ERROR("curl_xml plugin: cx_config: "
"Invalid key: %s",
ci->key);
cx_free(db);
}
/* Fill the `cx_t' structure.. */
}
/* Fill the `cx_t' structure.. */
sfree(cb_name);
} else {
cx_free(db);
sfree(cb_name);
} else {
cx_free(db);
} /* }}} int cx_config_add_url */
/* }}} End of configuration handling functions */
} /* }}} int cx_config_add_url */
/* }}} End of configuration handling functions */
if ((success == 0) && (errors > 0)) {
ERROR("curl_xml plugin: All statements failed.");
if ((success == 0) && (errors > 0)) {
ERROR("curl_xml plugin: All statements failed.");
} /* }}} int cx_config */
static int cx_init(void) /* {{{ */
} /* }}} int cx_config */
static int cx_init(void) /* {{{ */
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
} /* }}} int cx_init */
void module_register(void) {
} /* }}} int cx_init */
void module_register(void) {
str = global_option_get("Hostname");
if ((str != NULL) && (str[0] != 0)) {
sstrncpy(hostname_g, str, sizeof(hostname_g));
str = global_option_get("Hostname");
if ((str != NULL) && (str[0] != 0)) {
sstrncpy(hostname_g, str, sizeof(hostname_g));
}
if (gethostname(hostname_g, sizeof(hostname_g)) != 0) {
fprintf(stderr, "`gethostname' failed and no "
"hostname was configured.\n");
}
if (gethostname(hostname_g, sizeof(hostname_g)) != 0) {
fprintf(stderr, "`gethostname' failed and no "
"hostname was configured.\n");
}
str = global_option_get("FQDNLookup");
if (IS_FALSE(str))
}
str = global_option_get("FQDNLookup");
if (IS_FALSE(str))
struct addrinfo ai_hints = {.ai_flags = AI_CANONNAME};
struct addrinfo ai_hints = {.ai_flags = AI_CANONNAME};
"name. Please fix the network "
"configuration.",
hostname_g);
"name. Please fix the network "
"configuration.",
hostname_g);
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
} /* int init_hostname */
static int init_global_variables(void) {
} /* int init_hostname */
static int init_global_variables(void) {
if (timeout_g <= 1) {
fprintf(stderr, "Cannot set the timeout to a correct value.\n"
"Please check your settings.\n");
if (timeout_g <= 1) {
fprintf(stderr, "Cannot set the timeout to a correct value.\n"
"Please check your settings.\n");
}
DEBUG("timeout_g = %i;", timeout_g);
if (init_hostname() != 0)
}
DEBUG("timeout_g = %i;", timeout_g);
if (init_hostname() != 0)
DEBUG("hostname_g = %s;", hostname_g);
DEBUG("hostname_g = %s;", hostname_g);
} /* int init_global_variables */
static int change_basedir(const char *orig_dir) {
} /* int init_global_variables */
static int change_basedir(const char *orig_dir) {
if (dir == NULL) {
char errbuf[1024];
ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if (dir == NULL) {
char errbuf[1024];
ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if (dirlen == 0) {
free(dir);
if (dirlen == 0) {
free(dir);
}
status = chdir(dir);
if (status == 0) {
free(dir);
}
status = chdir(dir);
if (status == 0) {
free(dir);
} else if (errno != ENOENT) {
char errbuf[1024];
ERROR("change_basedir: chdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(dir);
} else if (errno != ENOENT) {
char errbuf[1024];
ERROR("change_basedir: chdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(dir);
}
status = mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
}
status = mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
ERROR("change_basedir: mkdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(dir);
ERROR("change_basedir: mkdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(dir);
ERROR("change_basedir: chdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(dir);
ERROR("change_basedir: chdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(dir);
} /* static int change_basedir (char *dir) */
#if HAVE_LIBKSTAT
} /* static int change_basedir (char *dir) */
#if HAVE_LIBKSTAT
#endif
)) {
ERROR("sg_init: %s", sg_str_error(sg_get_error()));
#endif
)) {
ERROR("sg_init: %s", sg_str_error(sg_get_error()));
}
if (sg_drop_privileges()) {
ERROR("sg_drop_privileges: %s", sg_str_error(sg_get_error()));
}
if (sg_drop_privileges()) {
ERROR("sg_drop_privileges: %s", sg_str_error(sg_get_error()));
if (errno != EINTR) {
char errbuf[1024];
ERROR("nanosleep failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if (errno != EINTR) {
char errbuf[1024];
ERROR("nanosleep failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
}
} /* while (loop == 0) */
}
}
} /* while (loop == 0) */
} /* int do_loop */
static int do_shutdown(void) {
} /* int do_loop */
static int do_shutdown(void) {
if ((fh = fopen(file, "w")) == NULL) {
char errbuf[1024];
ERROR("fopen (%s): %s", file, sstrerror(errno, errbuf, sizeof(errbuf)));
if ((fh = fopen(file, "w")) == NULL) {
char errbuf[1024];
ERROR("fopen (%s): %s", file, sstrerror(errno, errbuf, sizeof(errbuf)));
}
fprintf(fh, "%i\n", (int)getpid());
fclose(fh);
}
fprintf(fh, "%i\n", (int)getpid());
fclose(fh);
} /* static int pidfile_create (const char *file) */
static int pidfile_remove(void) {
} /* static int pidfile_create (const char *file) */
static int pidfile_remove(void) {
if (file == NULL)
return 0;
if (file == NULL)
return 0;
} /* static int pidfile_remove (const char *file) */
#endif /* COLLECT_DAEMON */
} /* static int pidfile_remove (const char *file) */
#endif /* COLLECT_DAEMON */
if (cf_read(configfile)) {
fprintf(stderr, "Error: Reading the config file failed!\n"
"Read the logs for details.\n");
if (cf_read(configfile)) {
fprintf(stderr, "Error: Reading the config file failed!\n"
"Read the logs for details.\n");
if ((basedir = global_option_get("BaseDir")) == NULL) {
fprintf(stderr,
"Don't have a basedir to use. This should not happen. Ever.");
if ((basedir = global_option_get("BaseDir")) == NULL) {
fprintf(stderr,
"Don't have a basedir to use. This should not happen. Ever.");
} else if (change_basedir(basedir)) {
fprintf(stderr, "Error: Unable to change to directory `%s'.\n", basedir);
} else if (change_basedir(basedir)) {
fprintf(stderr, "Error: Unable to change to directory `%s'.\n", basedir);
exit(EXIT_FAILURE);
if (test_config)
exit(EXIT_FAILURE);
if (test_config)
/* error */
char errbuf[1024];
fprintf(stderr, "fork: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
/* error */
char errbuf[1024];
fprintf(stderr, "fork: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
} else if (pid != 0) {
/* parent */
/* printf ("Running (PID %i)\n", pid); */
} else if (pid != 0) {
/* parent */
/* printf ("Running (PID %i)\n", pid); */
}
/* Detach from session */
}
/* Detach from session */
if (status != 0) {
ERROR("Error: Could not connect `STDIN' to `/dev/null' (status %d)",
status);
if (status != 0) {
ERROR("Error: Could not connect `STDIN' to `/dev/null' (status %d)",
status);
}
status = dup(0);
if (status != 1) {
ERROR("Error: Could not connect `STDOUT' to `/dev/null' (status %d)",
status);
}
status = dup(0);
if (status != 1) {
ERROR("Error: Could not connect `STDOUT' to `/dev/null' (status %d)",
status);
}
status = dup(0);
if (status != 2) {
ERROR("Error: Could not connect `STDERR' to `/dev/null', (status %d)",
status);
}
status = dup(0);
if (status != 2) {
ERROR("Error: Could not connect `STDERR' to `/dev/null', (status %d)",
status);
}
} /* if (daemonize) */
#endif /* COLLECT_DAEMON */
}
} /* if (daemonize) */
#endif /* COLLECT_DAEMON */
char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal INT: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal INT: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
struct sigaction sig_term_action = {.sa_handler = sig_term_handler};
}
struct sigaction sig_term_action = {.sa_handler = sig_term_handler};
char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal TERM: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal TERM: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
struct sigaction sig_usr1_action = {.sa_handler = sig_usr1_handler};
}
struct sigaction sig_usr1_action = {.sa_handler = sig_usr1_handler};
char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal USR1: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("Error: Failed to install a signal handler for signal USR1: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
pidfile_remove();
#endif /* COLLECT_DAEMON */
pidfile_remove();
#endif /* COLLECT_DAEMON */
/* Only enable __attribute__() for compilers known to support it. */
#if !defined(__clang__) && !defined(__GNUC__)
/* Only enable __attribute__() for compilers known to support it. */
#if !defined(__clang__) && !defined(__GNUC__)
-#if !defined(__attribute__)
#define __attribute__(x) /**/
#endif
#define __attribute__(x) /**/
#endif
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
#undef strcpy
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
#undef strcpy
strncpy(dest, src, n);
dest[n - 1] = '\0';
strncpy(dest, src, n);
dest[n - 1] = '\0';
} /* char *sstrncpy */
int ssnprintf(char *dest, size_t n, const char *format, ...) {
} /* char *sstrncpy */
int ssnprintf(char *dest, size_t n, const char *format, ...) {
dest[n - 1] = '\0';
va_end(ap);
dest[n - 1] = '\0';
va_end(ap);
} /* int ssnprintf */
char *ssnprintf_alloc(char const *format, ...) /* {{{ */
} /* int ssnprintf */
char *ssnprintf_alloc(char const *format, ...) /* {{{ */
status = vsnprintf(static_buffer, sizeof(static_buffer), format, ap);
va_end(ap);
if (status < 0)
status = vsnprintf(static_buffer, sizeof(static_buffer), format, ap);
va_end(ap);
if (status < 0)
/* "status" does not include the null byte. */
alloc_buffer_size = (size_t)(status + 1);
if (alloc_buffer_size <= sizeof(static_buffer))
/* "status" does not include the null byte. */
alloc_buffer_size = (size_t)(status + 1);
if (alloc_buffer_size <= sizeof(static_buffer))
- return (strdup(static_buffer));
+ return strdup(static_buffer);
/* Allocate a buffer large enough to hold the string. */
alloc_buffer = calloc(1, alloc_buffer_size);
if (alloc_buffer == NULL)
/* Allocate a buffer large enough to hold the string. */
alloc_buffer = calloc(1, alloc_buffer_size);
if (alloc_buffer == NULL)
/* Print again into this new buffer. */
va_start(ap, format);
/* Print again into this new buffer. */
va_start(ap, format);
va_end(ap);
if (status < 0) {
sfree(alloc_buffer);
va_end(ap);
if (status < 0) {
sfree(alloc_buffer);
} /* }}} char *ssnprintf_alloc */
char *sstrdup(const char *s) {
} /* }}} char *ssnprintf_alloc */
char *sstrdup(const char *s) {
size_t sz;
if (s == NULL)
size_t sz;
if (s == NULL)
/* Do not use `strdup' here, because it's not specified in POSIX. It's
* ``only'' an XSI extension. */
/* Do not use `strdup' here, because it's not specified in POSIX. It's
* ``only'' an XSI extension. */
} /* char *sstrdup */
/* Even though Posix requires "strerror_r" to return an "int",
} /* char *sstrdup */
/* Even though Posix requires "strerror_r" to return an "int",
}
#endif /* STRERROR_R_CHAR_P */
}
#endif /* STRERROR_R_CHAR_P */
} /* char *sstrerror */
void *smalloc(size_t size) {
} /* char *sstrerror */
void *smalloc(size_t size) {
} /* void *smalloc */
#if 0
} /* void *smalloc */
#if 0
continue;
if (status < 0)
continue;
if (status < 0)
if (status == 0) {
DEBUG("Received EOF from fd %i. "
"Closing fd and returning error.",
fd);
close(fd);
if (status == 0) {
DEBUG("Received EOF from fd %i. "
"Closing fd and returning error.",
fd);
close(fd);
}
assert((0 > status) || (nleft >= (size_t)status));
}
assert((0 > status) || (nleft >= (size_t)status));
ptr = ptr + ((size_t)status);
}
ptr = ptr + ((size_t)status);
}
}
ssize_t swrite(int fd, const void *buf, size_t count) {
}
ssize_t swrite(int fd, const void *buf, size_t count) {
ptr = ptr + ((size_t)status);
}
ptr = ptr + ((size_t)status);
}
}
int strsplit(char *string, char **fields, size_t size) {
}
int strsplit(char *string, char **fields, size_t size) {
}
int strjoin(char *buffer, size_t buffer_size, char **fields, size_t fields_num,
}
int strjoin(char *buffer, size_t buffer_size, char **fields, size_t fields_num,
if (((fields_num != 0) && (fields == NULL)) ||
((buffer_size != 0) && (buffer == NULL)))
if (((fields_num != 0) && (fields == NULL)) ||
((buffer_size != 0) && (buffer == NULL)))
if (buffer != NULL)
buffer[0] = 0;
if (buffer != NULL)
buffer[0] = 0;
/* Check if we need to escape at all first */
temp = strpbrk(buffer, " \t\"\\");
if (temp == NULL)
/* Check if we need to escape at all first */
temp = strpbrk(buffer, " \t\"\\");
if (temp == NULL)
temp = calloc(1, buffer_size);
if (temp == NULL)
temp = calloc(1, buffer_size);
if (temp == NULL)
sstrncpy(buffer, temp, buffer_size);
sfree(temp);
sstrncpy(buffer, temp, buffer_size);
sfree(temp);
} /* int escape_string */
int strunescape(char *buf, size_t buf_len) {
} /* int escape_string */
int strunescape(char *buf, size_t buf_len) {
ERROR("string unescape: backslash found at end of string.");
/* Ensure null-byte at the end of the buffer. */
buf[i] = 0;
ERROR("string unescape: backslash found at end of string.");
/* Ensure null-byte at the end of the buffer. */
buf[i] = 0;
memmove(buf + i + 1, buf + i + 2, buf_len - i - 2);
buf[buf_len - 1] = 0;
}
memmove(buf + i + 1, buf + i + 2, buf_len - i - 2);
buf[buf_len - 1] = 0;
}
} /* int strunescape */
size_t strstripnewline(char *buffer) {
} /* int strunescape */
size_t strstripnewline(char *buffer) {
buffer[buffer_len] = 0;
}
buffer[buffer_len] = 0;
}
} /* size_t strstripnewline */
int escape_slashes(char *buffer, size_t buffer_size) {
} /* size_t strstripnewline */
int escape_slashes(char *buffer, size_t buffer_size) {
if (buffer_len <= 1) {
if (strcmp("/", buffer) == 0) {
if (buffer_size < 5)
if (buffer_len <= 1) {
if (strcmp("/", buffer) == 0) {
if (buffer_size < 5)
sstrncpy(buffer, "root", buffer_size);
}
sstrncpy(buffer, "root", buffer_size);
}
}
/* Move one to the left */
}
/* Move one to the left */
} /* int escape_slashes */
void replace_special(char *buffer, size_t buffer_size) {
} /* int escape_slashes */
void replace_special(char *buffer, size_t buffer_size) {
delta->tv_sec = 0;
delta->tv_usec = 0;
}
delta->tv_sec = 0;
delta->tv_usec = 0;
}
}
if ((tv0.tv_sec < tv1.tv_sec) ||
}
if ((tv0.tv_sec < tv1.tv_sec) ||
assert((delta == NULL) ||
((0 <= delta->tv_usec) && (delta->tv_usec < 1000000)));
assert((delta == NULL) ||
((0 <= delta->tv_usec) && (delta->tv_usec < 1000000)));
} /* int timeval_cmp */
int check_create_dir(const char *file_orig) {
} /* int timeval_cmp */
int check_create_dir(const char *file_orig) {
* Sanity checks first
*/
if (file_orig == NULL)
* Sanity checks first
*/
if (file_orig == NULL)
if ((len = strlen(file_orig)) < 1)
if ((len = strlen(file_orig)) < 1)
else if (len >= sizeof(file_copy))
else if (len >= sizeof(file_copy))
/*
* If `file_orig' ends in a slash the last component is a directory,
/*
* If `file_orig' ends in a slash the last component is a directory,
ERROR("Cowardly refusing to create a directory that "
"begins with a `.' (dot): `%s'",
file_orig);
ERROR("Cowardly refusing to create a directory that "
"begins with a `.' (dot): `%s'",
file_orig);
if (strjoin(dir + path_is_absolute, (size_t)(dir_len - path_is_absolute),
fields, (size_t)(i + 1), "/") < 0) {
ERROR("strjoin failed: `%s', component #%i", file_orig, i);
if (strjoin(dir + path_is_absolute, (size_t)(dir_len - path_is_absolute),
fields, (size_t)(i + 1), "/") < 0) {
ERROR("strjoin failed: `%s', component #%i", file_orig, i);
char errbuf[1024];
ERROR("check_create_dir: mkdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("check_create_dir: mkdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
} else {
char errbuf[1024];
ERROR("check_create_dir: stat (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
} else {
char errbuf[1024];
ERROR("check_create_dir: stat (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
} else if (!S_ISDIR(statbuf.st_mode)) {
ERROR("check_create_dir: `%s' exists but is not "
"a directory!",
dir);
}
} else if (!S_ISDIR(statbuf.st_mode)) {
ERROR("check_create_dir: `%s' exists but is not "
"a directory!",
dir);
} /* check_create_dir */
#ifdef HAVE_LIBKSTAT
} /* check_create_dir */
#ifdef HAVE_LIBKSTAT
*ksp_ptr = NULL;
if (kc == NULL)
*ksp_ptr = NULL;
if (kc == NULL)
ssnprintf(ident, sizeof(ident), "%s,%i,%s", module, instance, name);
*ksp_ptr = kstat_lookup(kc, module, instance, name);
if (*ksp_ptr == NULL) {
ERROR("get_kstat: Cound not find kstat %s", ident);
ssnprintf(ident, sizeof(ident), "%s,%i,%s", module, instance, name);
*ksp_ptr = kstat_lookup(kc, module, instance, name);
if (*ksp_ptr == NULL) {
ERROR("get_kstat: Cound not find kstat %s", ident);
}
if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) {
ERROR("get_kstat: kstat %s has wrong type", ident);
*ksp_ptr = NULL;
}
if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) {
ERROR("get_kstat: kstat %s has wrong type", ident);
*ksp_ptr = NULL;
if (kstat_read(kc, *ksp_ptr, NULL) == -1) {
ERROR("get_kstat: kstat %s could not be read", ident);
if (kstat_read(kc, *ksp_ptr, NULL) == -1) {
ERROR("get_kstat: kstat %s could not be read", ident);
}
if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) {
ERROR("get_kstat: kstat %s has wrong type", ident);
}
if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED) {
ERROR("get_kstat: kstat %s has wrong type", ident);
}
long long get_kstat_value(kstat_t *ksp, char *name) {
}
long long get_kstat_value(kstat_t *ksp, char *name) {
if (ksp == NULL) {
ERROR("get_kstat_value (\"%s\"): ksp is NULL.", name);
if (ksp == NULL) {
ERROR("get_kstat_value (\"%s\"): ksp is NULL.", name);
} else if (ksp->ks_type != KSTAT_TYPE_NAMED) {
ERROR("get_kstat_value (\"%s\"): ksp->ks_type (%#x) "
"is not KSTAT_TYPE_NAMED (%#x).",
name, (unsigned int)ksp->ks_type, (unsigned int)KSTAT_TYPE_NAMED);
} else if (ksp->ks_type != KSTAT_TYPE_NAMED) {
ERROR("get_kstat_value (\"%s\"): ksp->ks_type (%#x) "
"is not KSTAT_TYPE_NAMED (%#x).",
name, (unsigned int)ksp->ks_type, (unsigned int)KSTAT_TYPE_NAMED);
}
if ((kn = (kstat_named_t *)kstat_data_lookup(ksp, name)) == NULL)
}
if ((kn = (kstat_named_t *)kstat_data_lookup(ksp, name)) == NULL)
if (kn->data_type == KSTAT_DATA_INT32)
retval = (long long)kn->value.i32;
if (kn->data_type == KSTAT_DATA_INT32)
retval = (long long)kn->value.i32;
else
WARNING("get_kstat_value: Not a numeric value: %s", name);
else
WARNING("get_kstat_value: Not a numeric value: %s", name);
}
#endif /* HAVE_LIBKSTAT */
#ifndef HAVE_HTONLL
unsigned long long ntohll(unsigned long long n) {
#if BYTE_ORDER == BIG_ENDIAN
}
#endif /* HAVE_LIBKSTAT */
#ifndef HAVE_HTONLL
unsigned long long ntohll(unsigned long long n) {
#if BYTE_ORDER == BIG_ENDIAN
#else
return (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32);
#endif
#else
return (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32);
#endif
unsigned long long htonll(unsigned long long n) {
#if BYTE_ORDER == BIG_ENDIAN
unsigned long long htonll(unsigned long long n) {
#if BYTE_ORDER == BIG_ENDIAN
#else
return (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32);
#endif
#else
return (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32);
#endif
if ((ret.byte[0] == 0x00) && (ret.byte[1] == 0x00) && (ret.byte[2] == 0x00) &&
(ret.byte[3] == 0x00) && (ret.byte[4] == 0x00) && (ret.byte[5] == 0x00) &&
(ret.byte[6] == 0xf8) && (ret.byte[7] == 0x7f)) {
if ((ret.byte[0] == 0x00) && (ret.byte[1] == 0x00) && (ret.byte[2] == 0x00) &&
(ret.byte[3] == 0x00) && (ret.byte[4] == 0x00) && (ret.byte[5] == 0x00) &&
(ret.byte[6] == 0xf8) && (ret.byte[7] == 0x7f)) {
} else {
uint64_t tmp;
tmp = ret.integer;
ret.integer = FP_CONVERT(tmp);
} else {
uint64_t tmp;
tmp = ret.integer;
ret.integer = FP_CONVERT(tmp);
ret.byte[4] = ret.byte[5] = 0x00;
ret.byte[6] = 0xf8;
ret.byte[7] = 0x7f;
ret.byte[4] = ret.byte[5] = 0x00;
ret.byte[6] = 0xf8;
ret.byte[7] = 0x7f;
} else {
uint64_t tmp;
ret.floating = d;
tmp = FP_CONVERT(ret.integer);
ret.integer = tmp;
} else {
uint64_t tmp;
ret.floating = d;
tmp = FP_CONVERT(ret.integer);
ret.integer = tmp;
}
} /* double htond */
#endif /* FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP */
}
} /* double htond */
#endif /* FP_LAYOUT_NEED_ENDIANFLIP || FP_LAYOUT_NEED_INTSWAP */
do { \
size_t l = strlen(str); \
if (l >= buffer_size) \
do { \
size_t l = strlen(str); \
if (l >= buffer_size) \
memcpy(buffer, (str), l); \
buffer += l; \
buffer_size -= l; \
memcpy(buffer, (str), l); \
buffer += l; \
buffer_size -= l; \
buffer[0] = 0;
#undef APPEND
buffer[0] = 0;
#undef APPEND
} /* int format_name */
int format_values(char *ret, size_t ret_len, /* {{{ */
} /* int format_name */
int format_values(char *ret, size_t ret_len, /* {{{ */
status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__); \
if (status < 1) { \
sfree(rates); \
status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__); \
if (status < 1) { \
sfree(rates); \
} else if (((size_t)status) >= (ret_len - offset)) { \
sfree(rates); \
} else if (((size_t)status) >= (ret_len - offset)) { \
sfree(rates); \
} else \
offset += ((size_t)status); \
} while (0)
} else \
offset += ((size_t)status); \
} while (0)
rates = uc_get_rate(ds, vl);
if (rates == NULL) {
WARNING("format_values: uc_get_rate failed.");
rates = uc_get_rate(ds, vl);
if (rates == NULL) {
WARNING("format_values: uc_get_rate failed.");
}
BUFFER_ADD(":" GAUGE_FORMAT, rates[i]);
} else if (ds->ds[i].type == DS_TYPE_COUNTER)
}
BUFFER_ADD(":" GAUGE_FORMAT, rates[i]);
} else if (ds->ds[i].type == DS_TYPE_COUNTER)
else {
ERROR("format_values: Unknown data source type: %i", ds->ds[i].type);
sfree(rates);
else {
ERROR("format_values: Unknown data source type: %i", ds->ds[i].type);
sfree(rates);
}
} /* for ds->ds_num */
#undef BUFFER_ADD
sfree(rates);
}
} /* for ds->ds_num */
#undef BUFFER_ADD
sfree(rates);
} /* }}} int format_values */
int parse_identifier(char *str, char **ret_host, char **ret_plugin,
} /* }}} int format_values */
int parse_identifier(char *str, char **ret_host, char **ret_plugin,
hostname = str;
if (hostname == NULL)
hostname = str;
if (hostname == NULL)
plugin = strchr(hostname, '/');
if (plugin == NULL)
plugin = strchr(hostname, '/');
if (plugin == NULL)
*plugin = '\0';
plugin++;
type = strchr(plugin, '/');
if (type == NULL) {
if (default_host == NULL)
*plugin = '\0';
plugin++;
type = strchr(plugin, '/');
if (type == NULL) {
if (default_host == NULL)
/* else: no host specified; use default */
type = plugin;
plugin = hostname;
/* else: no host specified; use default */
type = plugin;
plugin = hostname;
*ret_plugin_instance = plugin_instance;
*ret_type = type;
*ret_type_instance = type_instance;
*ret_plugin_instance = plugin_instance;
*ret_type = type;
*ret_type_instance = type_instance;
} /* int parse_identifier */
int parse_identifier_vl(const char *str, value_list_t *vl) /* {{{ */
} /* int parse_identifier */
int parse_identifier_vl(const char *str, value_list_t *vl) /* {{{ */
int status;
if ((str == NULL) || (vl == NULL))
int status;
if ((str == NULL) || (vl == NULL))
sstrncpy(str_copy, str, sizeof(str_copy));
sstrncpy(str_copy, str, sizeof(str_copy));
&type_instance,
/* default_host = */ NULL);
if (status != 0)
&type_instance,
/* default_host = */ NULL);
if (status != 0)
sstrncpy(vl->host, host, sizeof(vl->host));
sstrncpy(vl->plugin, plugin, sizeof(vl->plugin));
sstrncpy(vl->host, host, sizeof(vl->host));
sstrncpy(vl->plugin, plugin, sizeof(vl->plugin));
sstrncpy(vl->type_instance, (type_instance != NULL) ? type_instance : "",
sizeof(vl->type_instance));
sstrncpy(vl->type_instance, (type_instance != NULL) ? type_instance : "",
sizeof(vl->type_instance));
} /* }}} int parse_identifier_vl */
int parse_value(const char *value_orig, value_t *ret_value, int ds_type) {
} /* }}} int parse_identifier_vl */
int parse_value(const char *value_orig, value_t *ret_value, int ds_type) {
size_t value_len;
if (value_orig == NULL)
size_t value_len;
if (value_orig == NULL)
value = strdup(value_orig);
if (value == NULL)
value = strdup(value_orig);
if (value == NULL)
value_len = strlen(value);
while ((value_len > 0) && isspace((int)value[value_len - 1])) {
value_len = strlen(value);
while ((value_len > 0) && isspace((int)value[value_len - 1])) {
|| (endptr == ptr) /* Invalid string */
|| (endptr == NULL) /* This should not happen */
|| (*endptr != 0)) /* Trailing chars */
|| (endptr == ptr) /* Invalid string */
|| (endptr == NULL) /* This should not happen */
|| (*endptr != 0)) /* Trailing chars */
vl->time = DOUBLE_TO_CDTIME_T(tmp);
}
vl->time = DOUBLE_TO_CDTIME_T(tmp);
}
} /* while (strtok_r) */
if ((ptr != NULL) || (i == 0))
} /* while (strtok_r) */
if ((ptr != NULL) || (i == 0))
- return (-1);
- return (0);
} /* int parse_values */
int parse_value_file(char const *path, value_t *ret_value, int ds_type) {
} /* int parse_values */
int parse_value_file(char const *path, value_t *ret_value, int ds_type) {
fh = fopen(path, "r");
if (fh == NULL)
fh = fopen(path, "r");
if (fh == NULL)
if (fgets(buffer, sizeof(buffer), fh) == NULL) {
fclose(fh);
if (fgets(buffer, sizeof(buffer), fh) == NULL) {
fclose(fh);
pthread_mutex_unlock(&getpwnam_r_lock);
pthread_mutex_unlock(&getpwnam_r_lock);
} /* int getpwnam_r */
#endif /* !HAVE_GETPWNAM_R */
} /* int getpwnam_r */
#endif /* !HAVE_GETPWNAM_R */
if (type_instance != NULL)
sstrncpy(n->type_instance, type_instance, sizeof(n->type_instance));
if (type_instance != NULL)
sstrncpy(n->type_instance, type_instance, sizeof(n->type_instance));
} /* int notification_init */
int walk_directory(const char *dir, dirwalk_callback_f callback,
} /* int notification_init */
int walk_directory(const char *dir, dirwalk_callback_f callback,
closedir(dh);
if ((success == 0) && (failure > 0))
closedir(dh);
if ((success == 0) && (failure > 0))
- return (-1);
- return (0);
}
ssize_t read_file_contents(const char *filename, char *buf, size_t bufsize) {
}
ssize_t read_file_contents(const char *filename, char *buf, size_t bufsize) {
fh = fopen(filename, "r");
if (fh == NULL)
fh = fopen(filename, "r");
if (fh == NULL)
ret = (ssize_t)fread(buf, 1, bufsize, fh);
if ((ret == 0) && (ferror(fh) != 0)) {
ret = (ssize_t)fread(buf, 1, bufsize, fh);
if ((ret == 0) && (ferror(fh) != 0)) {
}
counter_t counter_diff(counter_t old_value, counter_t new_value) {
}
counter_t counter_diff(counter_t old_value, counter_t new_value) {
diff = new_value - old_value;
}
diff = new_value - old_value;
}
} /* counter_t counter_diff */
int rate_to_value(value_t *ret_value, gauge_t rate, /* {{{ */
} /* counter_t counter_diff */
int rate_to_value(value_t *ret_value, gauge_t rate, /* {{{ */
state->last_time = t;
*ret_value = state->last_value;
state->last_time = t;
*ret_value = state->last_value;
}
/* Counter and absolute can't handle negative rates. Reset "last time"
}
/* Counter and absolute can't handle negative rates. Reset "last time"
if ((rate < 0.0) &&
((ds_type == DS_TYPE_COUNTER) || (ds_type == DS_TYPE_ABSOLUTE))) {
memset(state, 0, sizeof(*state));
if ((rate < 0.0) &&
((ds_type == DS_TYPE_COUNTER) || (ds_type == DS_TYPE_ABSOLUTE))) {
memset(state, 0, sizeof(*state));
}
/* Another invalid state: The time is not increasing. */
if (t <= state->last_time) {
memset(state, 0, sizeof(*state));
}
/* Another invalid state: The time is not increasing. */
if (t <= state->last_time) {
memset(state, 0, sizeof(*state));
}
delta_t = t - state->last_time;
}
delta_t = t - state->last_time;
} /* }}} */
if (ds_type == DS_TYPE_DERIVE) {
} /* }}} */
if (ds_type == DS_TYPE_DERIVE) {
state->last_time = t;
*ret_value = state->last_value;
state->last_time = t;
*ret_value = state->last_value;
} /* }}} value_t rate_to_value */
int value_to_rate(gauge_t *ret_rate, /* {{{ */
} /* }}} value_t rate_to_value */
int value_to_rate(gauge_t *ret_rate, /* {{{ */
/* Another invalid state: The time is not increasing. */
if (t <= state->last_time) {
memset(state, 0, sizeof(*state));
/* Another invalid state: The time is not increasing. */
if (t <= state->last_time) {
memset(state, 0, sizeof(*state));
}
interval = CDTIME_T_TO_DOUBLE(t - state->last_time);
}
interval = CDTIME_T_TO_DOUBLE(t - state->last_time);
if (state->last_time == 0) {
state->last_value = value;
state->last_time = t;
if (state->last_time == 0) {
state->last_value = value;
state->last_time = t;
state->last_value = value;
state->last_time = t;
state->last_value = value;
state->last_time = t;
} /* }}} value_t rate_to_value */
int service_name_to_port_number(const char *service_name) {
} /* }}} value_t rate_to_value */
int service_name_to_port_number(const char *service_name) {
int service_number;
if (service_name == NULL)
int service_number;
if (service_name == NULL)
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC};
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC};
if (status != 0) {
ERROR("service_name_to_port_number: getaddrinfo failed: %s",
gai_strerror(status));
if (status != 0) {
ERROR("service_name_to_port_number: getaddrinfo failed: %s",
gai_strerror(status));
freeaddrinfo(ai_list);
if ((service_number > 0) && (service_number <= 65535))
freeaddrinfo(ai_list);
if ((service_number > 0) && (service_number <= 65535))
- return (service_number);
- return (-1);
+ return service_number;
+ return -1;
} /* int service_name_to_port_number */
void set_sock_opts(int sockfd) /* {{{ */
} /* int service_name_to_port_number */
void set_sock_opts(int sockfd) /* {{{ */
char *endptr;
if ((string == NULL) || (ret_value == NULL))
char *endptr;
if ((string == NULL) || (ret_value == NULL))
errno = 0;
endptr = NULL;
tmp = (derive_t)strtoll(string, &endptr, /* base = */ 0);
if ((endptr == string) || (errno != 0))
errno = 0;
endptr = NULL;
tmp = (derive_t)strtoll(string, &endptr, /* base = */ 0);
if ((endptr == string) || (errno != 0))
} /* }}} int strtoderive */
int strtogauge(const char *string, gauge_t *ret_value) /* {{{ */
} /* }}} int strtoderive */
int strtogauge(const char *string, gauge_t *ret_value) /* {{{ */
char *endptr = NULL;
if ((string == NULL) || (ret_value == NULL))
char *endptr = NULL;
if ((string == NULL) || (ret_value == NULL))
errno = 0;
endptr = NULL;
tmp = (gauge_t)strtod(string, &endptr);
if (errno != 0)
errno = 0;
endptr = NULL;
tmp = (gauge_t)strtod(string, &endptr);
if (errno != 0)
else if ((endptr == NULL) || (*endptr != 0))
else if ((endptr == NULL) || (*endptr != 0))
} /* }}} int strtogauge */
int strarray_add(char ***ret_array, size_t *ret_array_len,
} /* }}} int strtogauge */
int strarray_add(char ***ret_array, size_t *ret_array_len,
size_t array_len = *ret_array_len;
if (str == NULL)
size_t array_len = *ret_array_len;
if (str == NULL)
array = realloc(*ret_array, (array_len + 1) * sizeof(*array));
if (array == NULL)
array = realloc(*ret_array, (array_len + 1) * sizeof(*array));
if (array == NULL)
*ret_array = array;
array[array_len] = strdup(str);
if (array[array_len] == NULL)
*ret_array = array;
array[array_len] = strdup(str);
if (array[array_len] == NULL)
array_len++;
*ret_array_len = array_len;
array_len++;
*ret_array_len = array_len;
} /* }}} int strarray_add */
void strarray_free(char **array, size_t array_len) /* {{{ */
} /* }}} int strarray_add */
void strarray_free(char **array, size_t array_len) /* {{{ */
cap_flag_value_t cap_flag_value;
if (!CAP_IS_SUPPORTED(cap_value))
cap_flag_value_t cap_flag_value;
if (!CAP_IS_SUPPORTED(cap_value))
if (!(cap = cap_get_proc())) {
ERROR("check_capability: cap_get_proc failed.");
if (!(cap = cap_get_proc())) {
ERROR("check_capability: cap_get_proc failed.");
}
if (cap_get_flag(cap, cap_value, CAP_EFFECTIVE, &cap_flag_value) < 0) {
ERROR("check_capability: cap_get_flag failed.");
cap_free(cap);
}
if (cap_get_flag(cap, cap_value, CAP_EFFECTIVE, &cap_flag_value) < 0) {
ERROR("check_capability: cap_get_flag failed.");
cap_free(cap);
- return (cap_flag_value != CAP_SET);
+ return cap_flag_value != CAP_SET;
} /* }}} int check_capability */
#else
int check_capability(__attribute__((unused)) int arg) /* {{{ */
{
WARNING("check_capability: unsupported capability implementation. "
"Some plugin(s) may require elevated privileges to work properly.");
} /* }}} int check_capability */
#else
int check_capability(__attribute__((unused)) int arg) /* {{{ */
{
WARNING("check_capability: unsupported capability implementation. "
"Some plugin(s) may require elevated privileges to work properly.");
} /* }}} int check_capability */
#endif /* HAVE_CAPABILITY */
} /* }}} int check_capability */
#endif /* HAVE_CAPABILITY */
EXPECT_EQ_STR("collect", ptr);
OK(buffer[3] == buffer[12]);
EXPECT_EQ_STR("collect", ptr);
OK(buffer[3] == buffer[12]);
EXPECT_EQ_STR("collect", ptr);
OK(buffer[3] == buffer[12]);
EXPECT_EQ_STR("collect", ptr);
OK(buffer[3] == buffer[12]);
ptr = sstrdup(NULL);
OK(ptr == NULL);
ptr = sstrdup(NULL);
OK(ptr == NULL);
status = strsplit(buffer, fields, 8);
OK(status == 0);
status = strsplit(buffer, fields, 8);
OK(status == 0);
/* use (NULL, 0) to determine required buffer size. */
EXPECT_EQ_INT(3, strjoin(NULL, 0, (char *[]){"a", "b"}, 2, "-"));
/* use (NULL, 0) to determine required buffer size. */
EXPECT_EQ_INT(3, strjoin(NULL, 0, (char *[]){"a", "b"}, 2, "-"));
}
DEF_TEST(escape_slashes) {
}
DEF_TEST(escape_slashes) {
status = strunescape(buffer, sizeof(buffer));
OK(status != 0);
EXPECT_EQ_STR("\tbackslash end", buffer);
status = strunescape(buffer, sizeof(buffer));
OK(status != 0);
EXPECT_EQ_STR("\tbackslash end", buffer);
/* Backslash at buffer end */
strncpy(buffer, "\\t3\\56", sizeof(buffer));
/* Backslash at buffer end */
strncpy(buffer, "\\t3\\56", sizeof(buffer));
OK(buffer[5] == '6');
OK(buffer[6] == '7');
OK(buffer[5] == '6');
OK(buffer[6] == '7');
}
DEF_TEST(parse_values) {
}
DEF_TEST(parse_values) {
EXPECT_EQ_DOUBLE(cases[i].value, vl.values[0].gauge);
}
EXPECT_EQ_DOUBLE(cases[i].value, vl.values[0].gauge);
}
}
DEF_TEST(value_to_rate) {
}
DEF_TEST(value_to_rate) {
cf_callback_t *cf_cb;
if (type == NULL)
cf_callback_t *cf_cb;
if (type == NULL)
for (cf_cb = first_callback; cf_cb != NULL; cf_cb = cf_cb->next)
if (strcasecmp(cf_cb->type, type) == 0)
break;
for (cf_cb = first_callback; cf_cb != NULL; cf_cb = cf_cb->next)
if (strcasecmp(cf_cb->type, type) == 0)
break;
}
static int cf_dispatch(const char *type, const char *orig_key,
}
static int cf_dispatch(const char *type, const char *orig_key,
int i = 0;
if (orig_key == NULL)
int i = 0;
if (orig_key == NULL)
DEBUG("type = %s, key = %s, value = %s", ESCAPE_NULL(type), orig_key,
ESCAPE_NULL(orig_value));
DEBUG("type = %s, key = %s, value = %s", ESCAPE_NULL(type), orig_key,
ESCAPE_NULL(orig_value));
"the plugin isn't loaded or didn't register "
"a configuration callback.",
type);
"the plugin isn't loaded or didn't register "
"a configuration callback.",
type);
}
if ((key = strdup(orig_key)) == NULL)
}
if ((key = strdup(orig_key)) == NULL)
if ((value = strdup(orig_value)) == NULL) {
free(key);
if ((value = strdup(orig_value)) == NULL) {
free(key);
} /* int cf_dispatch */
static int dispatch_global_option(const oconfig_item_t *ci) {
if (ci->values_num != 1)
} /* int cf_dispatch */
static int dispatch_global_option(const oconfig_item_t *ci) {
if (ci->values_num != 1)
if (ci->values[0].type == OCONFIG_TYPE_STRING)
if (ci->values[0].type == OCONFIG_TYPE_STRING)
- return (global_option_set(ci->key, ci->values[0].value.string, 0));
+ return global_option_set(ci->key, ci->values[0].value.string, 0);
else if (ci->values[0].type == OCONFIG_TYPE_NUMBER) {
char tmp[128];
ssnprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number);
else if (ci->values[0].type == OCONFIG_TYPE_NUMBER) {
char tmp[128];
ssnprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number);
- return (global_option_set(ci->key, tmp, 0));
+ return global_option_set(ci->key, tmp, 0);
} else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN) {
if (ci->values[0].value.boolean)
} else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN) {
if (ci->values[0].value.boolean)
- return (global_option_set(ci->key, "true", 0));
+ return global_option_set(ci->key, "true", 0);
- return (global_option_set(ci->key, "false", 0));
+ return global_option_set(ci->key, "false", 0);
} /* int dispatch_global_option */
static int dispatch_value_typesdb(oconfig_item_t *ci) {
} /* int dispatch_global_option */
static int dispatch_value_typesdb(oconfig_item_t *ci) {
if (ci->values_num < 1) {
ERROR("configfile: `TypesDB' needs at least one argument.");
if (ci->values_num < 1) {
ERROR("configfile: `TypesDB' needs at least one argument.");
}
for (int i = 0; i < ci->values_num; ++i) {
}
for (int i = 0; i < ci->values_num; ++i) {
read_types_list(ci->values[i].value.string);
}
read_types_list(ci->values[i].value.string);
}
} /* int dispatch_value_typesdb */
static int dispatch_value_plugindir(oconfig_item_t *ci) {
assert(strcasecmp(ci->key, "PluginDir") == 0);
if (ci->values_num != 1)
} /* int dispatch_value_typesdb */
static int dispatch_value_plugindir(oconfig_item_t *ci) {
assert(strcasecmp(ci->key, "PluginDir") == 0);
if (ci->values_num != 1)
if (ci->values[0].type != OCONFIG_TYPE_STRING)
if (ci->values[0].type != OCONFIG_TYPE_STRING)
plugin_set_dir(ci->values[0].value.string);
plugin_set_dir(ci->values[0].value.string);
}
static int dispatch_loadplugin(oconfig_item_t *ci) {
}
static int dispatch_loadplugin(oconfig_item_t *ci) {
assert(strcasecmp(ci->key, "LoadPlugin") == 0);
if (ci->values_num != 1)
assert(strcasecmp(ci->key, "LoadPlugin") == 0);
if (ci->values_num != 1)
if (ci->values[0].type != OCONFIG_TYPE_STRING)
if (ci->values[0].type != OCONFIG_TYPE_STRING)
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0)
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0)
/* reset to the "global" context */
plugin_set_ctx(old_ctx);
/* reset to the "global" context */
plugin_set_ctx(old_ctx);
} /* int dispatch_value_loadplugin */
static int dispatch_value_plugin(const char *plugin, oconfig_item_t *ci) {
} /* int dispatch_value_loadplugin */
static int dispatch_value_plugin(const char *plugin, oconfig_item_t *ci) {
ci->values[i].value.boolean ? "true" : "false");
if ((status < 0) || (status >= buffer_free))
ci->values[i].value.boolean ? "true" : "false");
if ((status < 0) || (status >= buffer_free))
buffer_free -= status;
buffer_ptr += status;
}
/* skip the initial space */
buffer_ptr = buffer + 1;
buffer_free -= status;
buffer_ptr += status;
}
/* skip the initial space */
buffer_ptr = buffer + 1;
- return (cf_dispatch(plugin, ci->key, buffer_ptr));
+ return cf_dispatch(plugin, ci->key, buffer_ptr);
} /* int dispatch_value_plugin */
static int dispatch_value(oconfig_item_t *ci) {
} /* int dispatch_value_plugin */
static int dispatch_value(oconfig_item_t *ci) {
} /* int dispatch_value */
static int dispatch_block_plugin(oconfig_item_t *ci) {
const char *name;
if (strcasecmp(ci->key, "Plugin") != 0)
} /* int dispatch_value */
static int dispatch_block_plugin(oconfig_item_t *ci) {
const char *name;
if (strcasecmp(ci->key, "Plugin") != 0)
if (ci->values[0].type != OCONFIG_TYPE_STRING)
if (ci->values[0].type != OCONFIG_TYPE_STRING)
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0) {
name = ci->values[0].value.string;
if (strcmp("libvirt", name) == 0) {
ERROR("Automatically loading plugin \"%s\" failed "
"with status %i.",
name, status);
ERROR("Automatically loading plugin \"%s\" failed "
"with status %i.",
name, status);
old_ctx = plugin_set_ctx(cb->ctx);
ret_val = (cb->callback(ci));
plugin_set_ctx(old_ctx);
old_ctx = plugin_set_ctx(cb->ctx);
ret_val = (cb->callback(ci));
plugin_set_ctx(old_ctx);
}
static int dispatch_block(oconfig_item_t *ci) {
if (strcasecmp(ci->key, "LoadPlugin") == 0)
}
static int dispatch_block(oconfig_item_t *ci) {
if (strcasecmp(ci->key, "LoadPlugin") == 0)
- return (dispatch_loadplugin(ci));
+ return dispatch_loadplugin(ci);
else if (strcasecmp(ci->key, "Plugin") == 0)
else if (strcasecmp(ci->key, "Plugin") == 0)
- return (dispatch_block_plugin(ci));
+ return dispatch_block_plugin(ci);
else if (strcasecmp(ci->key, "Chain") == 0)
else if (strcasecmp(ci->key, "Chain") == 0)
- return (fc_configure(ci));
+ return fc_configure(ci);
}
static int cf_ci_replace_child(oconfig_item_t *dst, oconfig_item_t *src,
}
static int cf_ci_replace_child(oconfig_item_t *dst, oconfig_item_t *src,
* all children. */
if (dst->children_num + src->children_num - 1 == 0) {
dst->children_num = 0;
* all children. */
if (dst->children_num + src->children_num - 1 == 0) {
dst->children_num = 0;
(dst->children_num + src->children_num - 1));
if (temp == NULL) {
ERROR("configfile: realloc failed.");
(dst->children_num + src->children_num - 1));
if (temp == NULL) {
ERROR("configfile: realloc failed.");
/* Update the number of children. */
dst->children_num += (src->children_num - 1);
/* Update the number of children. */
dst->children_num += (src->children_num - 1);
} /* int cf_ci_replace_child */
static int cf_ci_append_children(oconfig_item_t *dst, oconfig_item_t *src) {
oconfig_item_t *temp;
if ((src == NULL) || (src->children_num == 0))
} /* int cf_ci_replace_child */
static int cf_ci_append_children(oconfig_item_t *dst, oconfig_item_t *src) {
oconfig_item_t *temp;
if ((src == NULL) || (src->children_num == 0))
temp = realloc(dst->children, sizeof(oconfig_item_t) *
(dst->children_num + src->children_num));
if (temp == NULL) {
ERROR("configfile: realloc failed.");
temp = realloc(dst->children, sizeof(oconfig_item_t) *
(dst->children_num + src->children_num));
if (temp == NULL) {
ERROR("configfile: realloc failed.");
sizeof(oconfig_item_t) * src->children_num);
dst->children_num += src->children_num;
sizeof(oconfig_item_t) * src->children_num);
dst->children_num += src->children_num;
} /* int cf_ci_append_children */
#define CF_MAX_DEPTH 8
} /* int cf_ci_append_children */
#define CF_MAX_DEPTH 8
sfree(pattern);
if (new == NULL)
sfree(pattern);
if (new == NULL)
/* Now replace the i'th child in `root' with `new'. */
if (cf_ci_replace_child(root, new, i) < 0) {
sfree(new->values);
sfree(new);
/* Now replace the i'th child in `root' with `new'. */
if (cf_ci_replace_child(root, new, i) < 0) {
sfree(new->values);
sfree(new);
}
/* ... and go back to the new i'th child. */
}
/* ... and go back to the new i'th child. */
sfree(new);
} /* for (i = 0; i < root->children_num; i++) */
sfree(new);
} /* for (i = 0; i < root->children_num; i++) */
} /* int cf_include_all */
static oconfig_item_t *cf_read_file(const char *file, const char *pattern,
} /* int cf_include_all */
static oconfig_item_t *cf_read_file(const char *file, const char *pattern,
"does not match pattern `%s'.",
filename, pattern);
free(tmp);
"does not match pattern `%s'.",
filename, pattern);
free(tmp);
root = oconfig_parse_file(file);
if (root == NULL) {
ERROR("configfile: Cannot read file `%s'.", file);
root = oconfig_parse_file(file);
if (root == NULL) {
ERROR("configfile: Cannot read file `%s'.", file);
}
status = cf_include_all(root, depth);
if (status != 0) {
oconfig_free(root);
}
status = cf_include_all(root, depth);
if (status != 0) {
oconfig_free(root);
} /* oconfig_item_t *cf_read_file */
static int cf_compare_string(const void *p1, const void *p2) {
} /* oconfig_item_t *cf_read_file */
static int cf_compare_string(const void *p1, const void *p2) {
char errbuf[1024];
ERROR("configfile: opendir failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("configfile: opendir failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
closedir(dh);
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
closedir(dh);
}
while ((de = readdir(dh)) != NULL) {
}
while ((de = readdir(dh)) != NULL) {
free(filenames[i]);
free(filenames);
free(root);
free(filenames[i]);
free(filenames);
free(root);
free(filenames[i]);
free(filenames);
free(root);
free(filenames[i]);
free(filenames);
free(root);
if (filenames == NULL) {
closedir(dh);
if (filenames == NULL) {
closedir(dh);
}
qsort((void *)filenames, filenames_num, sizeof(*filenames),
}
qsort((void *)filenames, filenames_num, sizeof(*filenames),
closedir(dh);
free(filenames);
closedir(dh);
free(filenames);
} /* oconfig_item_t *cf_read_dir */
/*
} /* oconfig_item_t *cf_read_dir */
/*
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
}
status = wordexp(path, &we, WRDE_NOCMD);
if (status != 0) {
ERROR("configfile: wordexp (%s) failed.", path);
}
status = wordexp(path, &we, WRDE_NOCMD);
if (status != 0) {
ERROR("configfile: wordexp (%s) failed.", path);
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
}
root = calloc(1, sizeof(*root));
if (root == NULL) {
ERROR("configfile: calloc failed.");
}
/* wordexp() might return a sorted list already. That's not
}
/* wordexp() might return a sorted list already. That's not
if (temp == NULL) {
oconfig_free(root);
if (temp == NULL) {
oconfig_free(root);
}
cf_ci_append_children(root, temp);
}
cf_ci_append_children(root, temp);
} /* oconfig_item_t *cf_read_generic */
/* #endif HAVE_WORDEXP_H */
} /* oconfig_item_t *cf_read_generic */
/* #endif HAVE_WORDEXP_H */
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
ERROR("configfile: Not including `%s' because the maximum "
"nesting depth has been reached.",
path);
}
status = stat(path, &statbuf);
}
status = stat(path, &statbuf);
char errbuf[1024];
ERROR("configfile: stat (%s) failed: %s", path,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("configfile: stat (%s) failed: %s", path,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (S_ISREG(statbuf.st_mode))
}
if (S_ISREG(statbuf.st_mode))
- return (cf_read_file(path, pattern, depth));
+ return cf_read_file(path, pattern, depth);
else if (S_ISDIR(statbuf.st_mode))
else if (S_ISDIR(statbuf.st_mode))
- return (cf_read_dir(path, pattern, depth));
+ return cf_read_dir(path, pattern, depth);
ERROR("configfile: %s is neither a file nor a directory.", path);
ERROR("configfile: %s is neither a file nor a directory.", path);
} /* oconfig_item_t *cf_read_generic */
#endif /* !HAVE_WORDEXP_H */
} /* oconfig_item_t *cf_read_generic */
#endif /* !HAVE_WORDEXP_H */
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot set unknown global option `%s'.", option);
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot set unknown global option `%s'.", option);
}
if (cf_global_options[i].from_cli && (!from_cli)) {
DEBUG("configfile: Ignoring %s `%s' option because "
"it was overriden by a command-line option.",
option, value);
}
if (cf_global_options[i].from_cli && (!from_cli)) {
DEBUG("configfile: Ignoring %s `%s' option because "
"it was overriden by a command-line option.",
option, value);
}
sfree(cf_global_options[i].value);
}
sfree(cf_global_options[i].value);
cf_global_options[i].from_cli = from_cli;
cf_global_options[i].from_cli = from_cli;
}
const char *global_option_get(const char *option) {
}
const char *global_option_get(const char *option) {
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot get unknown global option `%s'.", option);
if (i >= cf_global_options_num) {
ERROR("configfile: Cannot get unknown global option `%s'.", option);
- return ((cf_global_options[i].value != NULL) ? cf_global_options[i].value
- : cf_global_options[i].def);
+ return (cf_global_options[i].value != NULL) ? cf_global_options[i].value : cf_global_options[i].def;
} /* char *global_option_get */
long global_option_get_long(const char *option, long default_value) {
} /* char *global_option_get */
long global_option_get_long(const char *option, long default_value) {
str = global_option_get(option);
if (NULL == str)
str = global_option_get(option);
if (NULL == str)
- return (default_value);
errno = 0;
value = strtol(str, /* endptr = */ NULL, /* base = */ 0);
if (errno != 0)
errno = 0;
value = strtol(str, /* endptr = */ NULL, /* base = */ 0);
if (errno != 0)
- return (default_value);
} /* char *global_option_get_long */
cdtime_t global_option_get_time(const char *name, cdtime_t def) /* {{{ */
} /* char *global_option_get_long */
cdtime_t global_option_get_time(const char *name, cdtime_t def) /* {{{ */
optstr = global_option_get(name);
if (optstr == NULL)
optstr = global_option_get(name);
if (optstr == NULL)
errno = 0;
v = strtod(optstr, &endptr);
if ((endptr == NULL) || (*endptr != 0) || (errno != 0))
errno = 0;
v = strtod(optstr, &endptr);
if ((endptr == NULL) || (*endptr != 0) || (errno != 0))
- return (DOUBLE_TO_CDTIME_T(v));
+ return DOUBLE_TO_CDTIME_T(v);
} /* }}} cdtime_t global_option_get_time */
cdtime_t cf_get_default_interval(void) {
} /* }}} cdtime_t global_option_get_time */
cdtime_t cf_get_default_interval(void) {
- return (global_option_get_time(
- "Interval", DOUBLE_TO_CDTIME_T(COLLECTD_DEFAULT_INTERVAL)));
+ return global_option_get_time("Interval",
+ DOUBLE_TO_CDTIME_T(COLLECTD_DEFAULT_INTERVAL));
}
void cf_unregister(const char *type) {
}
void cf_unregister(const char *type) {
new = malloc(sizeof(*new));
if (new == NULL)
new = malloc(sizeof(*new));
if (new == NULL)
new->type = strdup(type);
if (new->type == NULL) {
sfree(new);
new->type = strdup(type);
if (new->type == NULL) {
sfree(new);
}
new->callback = callback;
}
new->callback = callback;
} /* int cf_register_complex */
int cf_read(const char *filename) {
} /* int cf_register_complex */
int cf_read(const char *filename) {
conf = cf_read_generic(filename, /* pattern = */ NULL, /* depth = */ 0);
if (conf == NULL) {
ERROR("Unable to read config file %s.", filename);
conf = cf_read_generic(filename, /* pattern = */ NULL, /* depth = */ 0);
if (conf == NULL) {
ERROR("Unable to read config file %s.", filename);
} else if (conf->children_num == 0) {
ERROR("Configuration file %s is empty.", filename);
oconfig_free(conf);
} else if (conf->children_num == 0) {
ERROR("Configuration file %s is empty.", filename);
oconfig_free(conf);
}
for (int i = 0; i < conf->children_num; i++) {
}
for (int i = 0; i < conf->children_num; i++) {
ERROR("cf_util_get_string: The %s option requires "
"exactly one string argument.",
ci->key);
ERROR("cf_util_get_string: The %s option requires "
"exactly one string argument.",
ci->key);
}
string = strdup(ci->values[0].value.string);
if (string == NULL)
}
string = strdup(ci->values[0].value.string);
if (string == NULL)
if (*ret_string != NULL)
sfree(*ret_string);
*ret_string = string;
if (*ret_string != NULL)
sfree(*ret_string);
*ret_string = string;
} /* }}} int cf_util_get_string */
/* Assures the config option is a string and copies it to the provided buffer.
} /* }}} int cf_util_get_string */
/* Assures the config option is a string and copies it to the provided buffer.
int cf_util_get_string_buffer(const oconfig_item_t *ci, char *buffer, /* {{{ */
size_t buffer_size) {
if ((ci == NULL) || (buffer == NULL) || (buffer_size < 1))
int cf_util_get_string_buffer(const oconfig_item_t *ci, char *buffer, /* {{{ */
size_t buffer_size) {
if ((ci == NULL) || (buffer == NULL) || (buffer_size < 1))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("cf_util_get_string_buffer: The %s option requires "
"exactly one string argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("cf_util_get_string_buffer: The %s option requires "
"exactly one string argument.",
ci->key);
}
strncpy(buffer, ci->values[0].value.string, buffer_size);
buffer[buffer_size - 1] = 0;
}
strncpy(buffer, ci->values[0].value.string, buffer_size);
buffer[buffer_size - 1] = 0;
} /* }}} int cf_util_get_string_buffer */
/* Assures the config option is a number and returns it as an int. */
int cf_util_get_int(const oconfig_item_t *ci, int *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
} /* }}} int cf_util_get_string_buffer */
/* Assures the config option is a number and returns it as an int. */
int cf_util_get_int(const oconfig_item_t *ci, int *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_int: The %s option requires "
"exactly one numeric argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_int: The %s option requires "
"exactly one numeric argument.",
ci->key);
}
*ret_value = (int)ci->values[0].value.number;
}
*ret_value = (int)ci->values[0].value.number;
} /* }}} int cf_util_get_int */
int cf_util_get_double(const oconfig_item_t *ci, double *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
} /* }}} int cf_util_get_int */
int cf_util_get_double(const oconfig_item_t *ci, double *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_double: The %s option requires "
"exactly one numeric argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_double: The %s option requires "
"exactly one numeric argument.",
ci->key);
}
*ret_value = ci->values[0].value.number;
}
*ret_value = ci->values[0].value.number;
} /* }}} int cf_util_get_double */
int cf_util_get_boolean(const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */
{
if ((ci == NULL) || (ret_bool == NULL))
} /* }}} int cf_util_get_double */
int cf_util_get_boolean(const oconfig_item_t *ci, _Bool *ret_bool) /* {{{ */
{
if ((ci == NULL) || (ret_bool == NULL))
if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) &&
(ci->values[0].type != OCONFIG_TYPE_STRING))) {
ERROR("cf_util_get_boolean: The %s option requires "
"exactly one boolean argument.",
ci->key);
if ((ci->values_num != 1) || ((ci->values[0].type != OCONFIG_TYPE_BOOLEAN) &&
(ci->values[0].type != OCONFIG_TYPE_STRING))) {
ERROR("cf_util_get_boolean: The %s option requires "
"exactly one boolean argument.",
ci->key);
}
switch (ci->values[0].type) {
}
switch (ci->values[0].type) {
ERROR("cf_util_get_boolean: Cannot parse string value `%s' of the `%s' "
"option as a boolean value.",
ci->values[0].value.string, ci->key);
ERROR("cf_util_get_boolean: Cannot parse string value `%s' of the `%s' "
"option as a boolean value.",
ci->values[0].value.string, ci->key);
} /* }}} int cf_util_get_boolean */
int cf_util_get_flag(const oconfig_item_t *ci, /* {{{ */
} /* }}} int cf_util_get_boolean */
int cf_util_get_flag(const oconfig_item_t *ci, /* {{{ */
_Bool b;
if (ret_value == NULL)
_Bool b;
if (ret_value == NULL)
b = 0;
status = cf_util_get_boolean(ci, &b);
if (status != 0)
b = 0;
status = cf_util_get_boolean(ci, &b);
if (status != 0)
if (b) {
*ret_value |= flag;
if (b) {
*ret_value |= flag;
} /* }}} int cf_util_get_flag */
/* Assures that the config option is a string or a number if the correct range
} /* }}} int cf_util_get_flag */
/* Assures that the config option is a string or a number if the correct range
ERROR("cf_util_get_port_number: The \"%s\" option requires "
"exactly one string argument.",
ci->key);
ERROR("cf_util_get_port_number: The \"%s\" option requires "
"exactly one string argument.",
ci->key);
}
if (ci->values[0].type == OCONFIG_TYPE_STRING)
}
if (ci->values[0].type == OCONFIG_TYPE_STRING)
- return (service_name_to_port_number(ci->values[0].value.string));
+ return service_name_to_port_number(ci->values[0].value.string);
assert(ci->values[0].type == OCONFIG_TYPE_NUMBER);
tmp = (int)(ci->values[0].value.number + 0.5);
assert(ci->values[0].type == OCONFIG_TYPE_NUMBER);
tmp = (int)(ci->values[0].value.number + 0.5);
"you specified, %i, is not in the valid "
"range of 1-65535.",
ci->key, tmp);
"you specified, %i, is not in the valid "
"range of 1-65535.",
ci->key, tmp);
} /* }}} int cf_util_get_port_number */
int cf_util_get_service(const oconfig_item_t *ci, char **ret_string) /* {{{ */
} /* }}} int cf_util_get_port_number */
int cf_util_get_service(const oconfig_item_t *ci, char **ret_string) /* {{{ */
ERROR("cf_util_get_service: The %s option requires exactly "
"one argument.",
ci->key);
ERROR("cf_util_get_service: The %s option requires exactly "
"one argument.",
ci->key);
}
if (ci->values[0].type == OCONFIG_TYPE_STRING)
}
if (ci->values[0].type == OCONFIG_TYPE_STRING)
- return (cf_util_get_string(ci, ret_string));
+ return cf_util_get_string(ci, ret_string);
if (ci->values[0].type != OCONFIG_TYPE_NUMBER) {
ERROR("cf_util_get_service: The %s option requires "
"exactly one string or numeric argument.",
if (ci->values[0].type != OCONFIG_TYPE_NUMBER) {
ERROR("cf_util_get_service: The %s option requires "
"exactly one string or numeric argument.",
port = 0;
status = cf_util_get_int(ci, &port);
if (status != 0)
port = 0;
status = cf_util_get_int(ci, &port);
if (status != 0)
else if ((port < 1) || (port > 65535)) {
ERROR("cf_util_get_service: The port number given "
"for the %s option is out of "
"range (%i).",
ci->key, port);
else if ((port < 1) || (port > 65535)) {
ERROR("cf_util_get_service: The port number given "
"for the %s option is out of "
"range (%i).",
ci->key, port);
}
service = malloc(6);
if (service == NULL) {
ERROR("cf_util_get_service: Out of memory.");
}
service = malloc(6);
if (service == NULL) {
ERROR("cf_util_get_service: Out of memory.");
}
ssnprintf(service, 6, "%i", port);
sfree(*ret_string);
*ret_string = service;
}
ssnprintf(service, 6, "%i", port);
sfree(*ret_string);
*ret_string = service;
} /* }}} int cf_util_get_service */
int cf_util_get_cdtime(const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
} /* }}} int cf_util_get_service */
int cf_util_get_cdtime(const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
{
if ((ci == NULL) || (ret_value == NULL))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_cdtime: The %s option requires "
"exactly one numeric argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("cf_util_get_cdtime: The %s option requires "
"exactly one numeric argument.",
ci->key);
}
if (ci->values[0].value.number < 0.0) {
ERROR("cf_util_get_cdtime: The numeric argument of the %s "
"option must not be negative.",
ci->key);
}
if (ci->values[0].value.number < 0.0) {
ERROR("cf_util_get_cdtime: The numeric argument of the %s "
"option must not be negative.",
ci->key);
}
*ret_value = DOUBLE_TO_CDTIME_T(ci->values[0].value.number);
}
*ret_value = DOUBLE_TO_CDTIME_T(ci->values[0].value.number);
} /* }}} int cf_util_get_cdtime */
} /* }}} int cf_util_get_cdtime */
char *dest;
if (orig == NULL)
char *dest;
if (orig == NULL)
sz = strlen(orig) + 1;
dest = malloc(sz);
if (dest == NULL)
sz = strlen(orig) + 1;
dest = malloc(sz);
if (dest == NULL)
} /* }}} char *fc_strdup */
/*
} /* }}} char *fc_strdup */
/*
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Match' blocks require "
"exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Match' blocks require "
"exactly one string argument.");
WARNING("Filter subsystem: Cannot find a \"%s\" match. "
"Did you load the appropriate plugin?",
ci->values[0].value.string);
WARNING("Filter subsystem: Cannot find a \"%s\" match. "
"Did you load the appropriate plugin?",
ci->values[0].value.string);
}
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("fc_config_add_match: calloc failed.");
}
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("fc_config_add_match: calloc failed.");
}
sstrncpy(m->name, ptr->name, sizeof(m->name));
}
sstrncpy(m->name, ptr->name, sizeof(m->name));
if (status != 0) {
WARNING("Filter subsystem: Failed to create a %s match.", m->name);
fc_free_matches(m);
if (status != 0) {
WARNING("Filter subsystem: Failed to create a %s match.", m->name);
fc_free_matches(m);
} /* }}} int fc_config_add_match */
static int fc_config_add_target(fc_target_t **targets_head, /* {{{ */
} /* }}} int fc_config_add_match */
static int fc_config_add_target(fc_target_t **targets_head, /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Target' blocks require "
"exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Target' blocks require "
"exactly one string argument.");
}
ptr = target_list_head;
}
ptr = target_list_head;
WARNING("Filter subsystem: Cannot find a \"%s\" target. "
"Did you load the appropriate plugin?",
ci->values[0].value.string);
WARNING("Filter subsystem: Cannot find a \"%s\" target. "
"Did you load the appropriate plugin?",
ci->values[0].value.string);
}
t = calloc(1, sizeof(*t));
if (t == NULL) {
ERROR("fc_config_add_target: calloc failed.");
}
t = calloc(1, sizeof(*t));
if (t == NULL) {
ERROR("fc_config_add_target: calloc failed.");
}
sstrncpy(t->name, ptr->name, sizeof(t->name));
}
sstrncpy(t->name, ptr->name, sizeof(t->name));
if (status != 0) {
WARNING("Filter subsystem: Failed to create a %s target.", t->name);
fc_free_targets(t);
if (status != 0) {
WARNING("Filter subsystem: Failed to create a %s target.", t->name);
fc_free_targets(t);
}
} else {
t->user_data = NULL;
}
} else {
t->user_data = NULL;
} /* }}} int fc_config_add_target */
static int fc_config_add_rule(fc_chain_t *chain, /* {{{ */
} /* }}} int fc_config_add_target */
static int fc_config_add_rule(fc_chain_t *chain, /* {{{ */
if (ci->values_num > 1) {
WARNING("Filter subsystem: `Rule' blocks have at most one argument.");
if (ci->values_num > 1) {
WARNING("Filter subsystem: `Rule' blocks have at most one argument.");
} else if ((ci->values_num == 1) &&
(ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Rule' blocks expect one string argument "
"or no argument at all.");
} else if ((ci->values_num == 1) &&
(ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: `Rule' blocks expect one string argument "
"or no argument at all.");
}
rule = calloc(1, sizeof(*rule));
if (rule == NULL) {
ERROR("fc_config_add_rule: calloc failed.");
}
rule = calloc(1, sizeof(*rule));
if (rule == NULL) {
ERROR("fc_config_add_rule: calloc failed.");
}
if (ci->values_num == 1) {
}
if (ci->values_num == 1) {
if (status != 0) {
fc_free_rules(rule);
if (status != 0) {
fc_free_rules(rule);
}
if (chain->rules != NULL) {
}
if (chain->rules != NULL) {
} /* }}} int fc_config_add_rule */
static int fc_config_add_chain(const oconfig_item_t *ci) /* {{{ */
} /* }}} int fc_config_add_rule */
static int fc_config_add_chain(const oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: <Chain> blocks require exactly one "
"string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("Filter subsystem: <Chain> blocks require exactly one "
"string argument.");
}
if (chain_list_head != NULL) {
}
if (chain_list_head != NULL) {
chain = calloc(1, sizeof(*chain));
if (chain == NULL) {
ERROR("fc_config_add_chain: calloc failed.");
chain = calloc(1, sizeof(*chain));
if (chain == NULL) {
ERROR("fc_config_add_chain: calloc failed.");
}
sstrncpy(chain->name, ci->values[0].value.string, sizeof(chain->name));
}
}
sstrncpy(chain->name, ci->values[0].value.string, sizeof(chain->name));
}
if (status != 0) {
fc_free_chains(chain);
if (status != 0) {
fc_free_chains(chain);
}
if (chain_list_head != NULL) {
if (!new_chain)
}
if (chain_list_head != NULL) {
if (!new_chain)
chain_list_head = chain;
}
chain_list_head = chain;
}
} /* }}} int fc_config_add_chain */
/*
} /* }}} int fc_config_add_chain */
/*
if (ci->children_num != 1) {
ERROR("Filter subsystem: The built-in target `jump' needs exactly "
"one `Chain' argument!");
if (ci->children_num != 1) {
ERROR("Filter subsystem: The built-in target `jump' needs exactly "
"one `Chain' argument!");
}
ci_chain = ci->children;
}
ci_chain = ci->children;
ERROR("Filter subsystem: The built-in target `jump' does not "
"support the configuration option `%s'.",
ci_chain->key);
ERROR("Filter subsystem: The built-in target `jump' does not "
"support the configuration option `%s'.",
ci_chain->key);
}
if ((ci_chain->values_num != 1) ||
(ci_chain->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("Filter subsystem: Built-in target `jump': The `Chain' option "
"needs exactly one string argument.");
}
if ((ci_chain->values_num != 1) ||
(ci_chain->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("Filter subsystem: Built-in target `jump': The `Chain' option "
"needs exactly one string argument.");
}
*user_data = fc_strdup(ci_chain->values[0].value.string);
if (*user_data == NULL) {
ERROR("fc_bit_jump_create: fc_strdup failed.");
}
*user_data = fc_strdup(ci_chain->values[0].value.string);
if (*user_data == NULL) {
ERROR("fc_bit_jump_create: fc_strdup failed.");
} /* }}} int fc_bit_jump_create */
static int fc_bit_jump_destroy(void **user_data) /* {{{ */
} /* }}} int fc_bit_jump_create */
static int fc_bit_jump_destroy(void **user_data) /* {{{ */
} /* }}} int fc_bit_jump_destroy */
static int fc_bit_jump_invoke(const data_set_t *ds, /* {{{ */
} /* }}} int fc_bit_jump_destroy */
static int fc_bit_jump_invoke(const data_set_t *ds, /* {{{ */
ERROR("Filter subsystem: Built-in target `jump': There is no chain "
"named `%s'.",
chain_name);
ERROR("Filter subsystem: Built-in target `jump': There is no chain "
"named `%s'.",
chain_name);
}
status = fc_process_chain(ds, vl, chain);
if (status < 0)
}
status = fc_process_chain(ds, vl, chain);
if (status < 0)
else if (status == FC_TARGET_STOP)
else if (status == FC_TARGET_STOP)
- return (FC_TARGET_STOP);
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int fc_bit_jump_invoke */
static int
} /* }}} int fc_bit_jump_invoke */
static int
value_list_t __attribute__((unused)) * vl,
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
value_list_t __attribute__((unused)) * vl,
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
- return (FC_TARGET_STOP);
} /* }}} int fc_bit_stop_invoke */
static int
} /* }}} int fc_bit_stop_invoke */
static int
value_list_t __attribute__((unused)) * vl,
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
value_list_t __attribute__((unused)) * vl,
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
- return (FC_TARGET_RETURN);
+ return FC_TARGET_RETURN;
} /* }}} int fc_bit_return_invoke */
static int fc_bit_write_create(const oconfig_item_t *ci, /* {{{ */
} /* }}} int fc_bit_return_invoke */
static int fc_bit_write_create(const oconfig_item_t *ci, /* {{{ */
*user_data = plugin_list;
*user_data = plugin_list;
} /* }}} int fc_bit_write_create */
static int fc_bit_write_destroy(void **user_data) /* {{{ */
} /* }}} int fc_bit_write_create */
static int fc_bit_write_destroy(void **user_data) /* {{{ */
fc_writer_t *plugin_list;
if ((user_data == NULL) || (*user_data == NULL))
fc_writer_t *plugin_list;
if ((user_data == NULL) || (*user_data == NULL))
plugin_list = *user_data;
plugin_list = *user_data;
free(plugin_list[i].plugin);
free(plugin_list);
free(plugin_list[i].plugin);
free(plugin_list);
} /* }}} int fc_bit_write_destroy */
static int fc_bit_write_invoke(const data_set_t *ds, /* {{{ */
} /* }}} int fc_bit_write_destroy */
static int fc_bit_write_invoke(const data_set_t *ds, /* {{{ */
} /* for (i = 0; plugin_list[i] != NULL; i++) */
}
} /* for (i = 0; plugin_list[i] != NULL; i++) */
}
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int fc_bit_write_invoke */
static int fc_init_once(void) /* {{{ */
} /* }}} int fc_bit_write_invoke */
static int fc_init_once(void) /* {{{ */
target_proc_t tproc = {0};
if (done != 0)
target_proc_t tproc = {0};
if (done != 0)
tproc.create = fc_bit_jump_create;
tproc.destroy = fc_bit_jump_destroy;
tproc.create = fc_bit_jump_create;
tproc.destroy = fc_bit_jump_destroy;
fc_register_target("write", tproc);
done++;
fc_register_target("write", tproc);
done++;
} /* }}} int fc_init_once */
/*
} /* }}} int fc_init_once */
/*
m = calloc(1, sizeof(*m));
if (m == NULL)
m = calloc(1, sizeof(*m));
if (m == NULL)
sstrncpy(m->name, name, sizeof(m->name));
memcpy(&m->proc, &proc, sizeof(m->proc));
sstrncpy(m->name, name, sizeof(m->name));
memcpy(&m->proc, &proc, sizeof(m->proc));
} /* }}} int fc_register_match */
/* Add a target to list of available targets. */
} /* }}} int fc_register_match */
/* Add a target to list of available targets. */
t = calloc(1, sizeof(*t));
if (t == NULL)
t = calloc(1, sizeof(*t));
if (t == NULL)
sstrncpy(t->name, name, sizeof(t->name));
memcpy(&t->proc, &proc, sizeof(t->proc));
sstrncpy(t->name, name, sizeof(t->name));
memcpy(&t->proc, &proc, sizeof(t->proc));
} /* }}} int fc_register_target */
fc_chain_t *fc_chain_get_by_name(const char *chain_name) /* {{{ */
{
if (chain_name == NULL)
} /* }}} int fc_register_target */
fc_chain_t *fc_chain_get_by_name(const char *chain_name) /* {{{ */
{
if (chain_name == NULL)
for (fc_chain_t *chain = chain_list_head; chain != NULL; chain = chain->next)
if (strcasecmp(chain_name, chain->name) == 0)
for (fc_chain_t *chain = chain_list_head; chain != NULL; chain = chain->next)
if (strcasecmp(chain_name, chain->name) == 0)
} /* }}} int fc_chain_get_by_name */
int fc_process_chain(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int fc_chain_get_by_name */
int fc_process_chain(const data_set_t *ds, value_list_t *vl, /* {{{ */
int status = FC_TARGET_CONTINUE;
if (chain == NULL)
int status = FC_TARGET_CONTINUE;
if (chain == NULL)
DEBUG("fc_process_chain (chain = %s);", chain->name);
DEBUG("fc_process_chain (chain = %s);", chain->name);
} /* for (rule) */
if ((status == FC_TARGET_STOP) || (status == FC_TARGET_RETURN))
} /* for (rule) */
if ((status == FC_TARGET_STOP) || (status == FC_TARGET_RETURN))
DEBUG("fc_process_chain (%s): Executing the default targets.", chain->name);
DEBUG("fc_process_chain (%s): Executing the default targets.", chain->name);
chain->name, target->name,
(status == FC_TARGET_STOP) ? "stop" : "return");
if (status == FC_TARGET_STOP)
chain->name, target->name,
(status == FC_TARGET_STOP) ? "stop" : "return");
if (status == FC_TARGET_STOP)
- return (FC_TARGET_STOP);
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
}
DEBUG("fc_process_chain (%s): Signaling `continue' at end of chain.",
chain->name);
}
DEBUG("fc_process_chain (%s): Signaling `continue' at end of chain.",
chain->name);
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int fc_process_chain */
/* Iterate over all rules in the chain and execute all targets for which all
} /* }}} int fc_process_chain */
/* Iterate over all rules in the chain and execute all targets for which all
int fc_default_action(const data_set_t *ds, value_list_t *vl) /* {{{ */
{
/* FIXME: Pass the meta-data to match targets here (when implemented). */
int fc_default_action(const data_set_t *ds, value_list_t *vl) /* {{{ */
{
/* FIXME: Pass the meta-data to match targets here (when implemented). */
- return (fc_bit_write_invoke(ds, vl,
- /* meta = */ NULL, /* user_data = */ NULL));
+ return fc_bit_write_invoke(ds, vl, NULL, NULL);
} /* }}} int fc_default_action */
int fc_configure(const oconfig_item_t *ci) /* {{{ */
} /* }}} int fc_default_action */
int fc_configure(const oconfig_item_t *ci) /* {{{ */
fc_init_once();
if (ci == NULL)
fc_init_once();
if (ci == NULL)
if (strcasecmp("Chain", ci->key) == 0)
if (strcasecmp("Chain", ci->key) == 0)
- return (fc_config_add_chain(ci));
+ return fc_config_add_chain(ci);
WARNING("Filter subsystem: Unknown top level config option `%s'.", ci->key);
WARNING("Filter subsystem: Unknown top level config option `%s'.", ci->key);
} /* }}} int fc_configure */
} /* }}} int fc_configure */
char *dest;
if (orig == NULL)
char *dest;
if (orig == NULL)
sz = strlen(orig) + 1;
dest = malloc(sz);
if (dest == NULL)
sz = strlen(orig) + 1;
dest = malloc(sz);
if (dest == NULL)
} /* }}} char *md_strdup */
static meta_entry_t *md_entry_alloc(const char *key) /* {{{ */
} /* }}} char *md_strdup */
static meta_entry_t *md_entry_alloc(const char *key) /* {{{ */
e = calloc(1, sizeof(*e));
if (e == NULL) {
ERROR("md_entry_alloc: calloc failed.");
e = calloc(1, sizeof(*e));
if (e == NULL) {
ERROR("md_entry_alloc: calloc failed.");
}
e->key = md_strdup(key);
if (e->key == NULL) {
free(e);
ERROR("md_entry_alloc: md_strdup failed.");
}
e->key = md_strdup(key);
if (e->key == NULL) {
free(e);
ERROR("md_entry_alloc: md_strdup failed.");
}
e->type = 0;
e->next = NULL;
}
e->type = 0;
e->next = NULL;
} /* }}} meta_entry_t *md_entry_alloc */
/* XXX: The lock on md must be held while calling this function! */
} /* }}} meta_entry_t *md_entry_alloc */
/* XXX: The lock on md must be held while calling this function! */
copy = md_entry_alloc(orig->key);
if (copy == NULL)
copy = md_entry_alloc(orig->key);
if (copy == NULL)
copy->type = orig->type;
if (copy->type == MD_TYPE_STRING)
copy->value.mv_string = strdup(orig->value.mv_string);
else
copy->value = orig->value;
copy->type = orig->type;
if (copy->type == MD_TYPE_STRING)
copy->value.mv_string = strdup(orig->value.mv_string);
else
copy->value = orig->value;
} /* }}} meta_entry_t *md_entry_clone_contents */
static meta_entry_t *md_entry_clone(const meta_entry_t *orig) /* {{{ */
} /* }}} meta_entry_t *md_entry_clone_contents */
static meta_entry_t *md_entry_clone(const meta_entry_t *orig) /* {{{ */
meta_entry_t *copy;
if (orig == NULL)
meta_entry_t *copy;
if (orig == NULL)
copy = md_entry_clone_contents(orig);
copy->next = md_entry_clone(orig->next);
copy = md_entry_clone_contents(orig);
copy->next = md_entry_clone(orig->next);
} /* }}} meta_entry_t *md_entry_clone */
static void md_entry_free(meta_entry_t *e) /* {{{ */
} /* }}} meta_entry_t *md_entry_clone */
static void md_entry_free(meta_entry_t *e) /* {{{ */
meta_entry_t *prev;
if ((md == NULL) || (e == NULL))
meta_entry_t *prev;
if ((md == NULL) || (e == NULL))
pthread_mutex_lock(&md->lock);
pthread_mutex_lock(&md->lock);
} /* }}} int md_entry_insert */
/* XXX: The lock on md must be held while calling this function! */
} /* }}} int md_entry_insert */
/* XXX: The lock on md must be held while calling this function! */
} /* }}} int md_entry_insert_clone */
/* XXX: The lock on md must be held while calling this function! */
} /* }}} int md_entry_insert_clone */
/* XXX: The lock on md must be held while calling this function! */
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
for (e = md->head; e != NULL; e = e->next)
if (strcasecmp(key, e->key) == 0)
break;
for (e = md->head; e != NULL; e = e->next)
if (strcasecmp(key, e->key) == 0)
break;
} /* }}} meta_entry_t *md_entry_lookup */
/*
} /* }}} meta_entry_t *md_entry_lookup */
/*
md = calloc(1, sizeof(*md));
if (md == NULL) {
ERROR("meta_data_create: calloc failed.");
md = calloc(1, sizeof(*md));
if (md == NULL) {
ERROR("meta_data_create: calloc failed.");
}
pthread_mutex_init(&md->lock, /* attr = */ NULL);
}
pthread_mutex_init(&md->lock, /* attr = */ NULL);
} /* }}} meta_data_t *meta_data_create */
meta_data_t *meta_data_clone(meta_data_t *orig) /* {{{ */
} /* }}} meta_data_t *meta_data_create */
meta_data_t *meta_data_clone(meta_data_t *orig) /* {{{ */
meta_data_t *copy;
if (orig == NULL)
meta_data_t *copy;
if (orig == NULL)
copy = meta_data_create();
if (copy == NULL)
copy = meta_data_create();
if (copy == NULL)
pthread_mutex_lock(&orig->lock);
copy->head = md_entry_clone(orig->head);
pthread_mutex_unlock(&orig->lock);
pthread_mutex_lock(&orig->lock);
copy->head = md_entry_clone(orig->head);
pthread_mutex_unlock(&orig->lock);
} /* }}} meta_data_t *meta_data_clone */
int meta_data_clone_merge(meta_data_t **dest, meta_data_t *orig) /* {{{ */
{
if (orig == NULL)
} /* }}} meta_data_t *meta_data_clone */
int meta_data_clone_merge(meta_data_t **dest, meta_data_t *orig) /* {{{ */
{
if (orig == NULL)
if (*dest == NULL) {
*dest = meta_data_clone(orig);
if (*dest == NULL) {
*dest = meta_data_clone(orig);
}
pthread_mutex_lock(&orig->lock);
}
pthread_mutex_lock(&orig->lock);
}
pthread_mutex_unlock(&orig->lock);
}
pthread_mutex_unlock(&orig->lock);
} /* }}} int meta_data_clone_merge */
void meta_data_destroy(meta_data_t *md) /* {{{ */
} /* }}} int meta_data_clone_merge */
void meta_data_destroy(meta_data_t *md) /* {{{ */
int meta_data_exists(meta_data_t *md, const char *key) /* {{{ */
{
if ((md == NULL) || (key == NULL))
int meta_data_exists(meta_data_t *md, const char *key) /* {{{ */
{
if ((md == NULL) || (key == NULL))
pthread_mutex_lock(&md->lock);
for (meta_entry_t *e = md->head; e != NULL; e = e->next) {
if (strcasecmp(key, e->key) == 0) {
pthread_mutex_unlock(&md->lock);
pthread_mutex_lock(&md->lock);
for (meta_entry_t *e = md->head; e != NULL; e = e->next) {
if (strcasecmp(key, e->key) == 0) {
pthread_mutex_unlock(&md->lock);
}
}
pthread_mutex_unlock(&md->lock);
}
}
pthread_mutex_unlock(&md->lock);
} /* }}} int meta_data_exists */
int meta_data_type(meta_data_t *md, const char *key) /* {{{ */
} /* }}} int meta_data_exists */
int meta_data_type(meta_data_t *md, const char *key) /* {{{ */
if (count == 0) {
pthread_mutex_unlock(&md->lock);
if (count == 0) {
pthread_mutex_unlock(&md->lock);
}
*toc = calloc(count, sizeof(**toc));
}
*toc = calloc(count, sizeof(**toc));
meta_entry_t *prev;
if ((md == NULL) || (key == NULL))
meta_entry_t *prev;
if ((md == NULL) || (key == NULL))
pthread_mutex_lock(&md->lock);
pthread_mutex_lock(&md->lock);
if (this == NULL) {
pthread_mutex_unlock(&md->lock);
if (this == NULL) {
pthread_mutex_unlock(&md->lock);
this->next = NULL;
md_entry_free(this);
this->next = NULL;
md_entry_free(this);
} /* }}} int meta_data_delete */
/*
} /* }}} int meta_data_delete */
/*
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
e = md_entry_alloc(key);
if (e == NULL)
e = md_entry_alloc(key);
if (e == NULL)
e->value.mv_string = md_strdup(value);
if (e->value.mv_string == NULL) {
ERROR("meta_data_add_string: md_strdup failed.");
md_entry_free(e);
e->value.mv_string = md_strdup(value);
if (e->value.mv_string == NULL) {
ERROR("meta_data_add_string: md_strdup failed.");
md_entry_free(e);
}
e->type = MD_TYPE_STRING;
}
e->type = MD_TYPE_STRING;
- return (md_entry_insert(md, e));
+ return md_entry_insert(md, e);
} /* }}} int meta_data_add_string */
int meta_data_add_signed_int(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_add_string */
int meta_data_add_signed_int(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
e = md_entry_alloc(key);
if (e == NULL)
e = md_entry_alloc(key);
if (e == NULL)
e->value.mv_signed_int = value;
e->type = MD_TYPE_SIGNED_INT;
e->value.mv_signed_int = value;
e->type = MD_TYPE_SIGNED_INT;
- return (md_entry_insert(md, e));
+ return md_entry_insert(md, e);
} /* }}} int meta_data_add_signed_int */
int meta_data_add_unsigned_int(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_add_signed_int */
int meta_data_add_unsigned_int(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
e = md_entry_alloc(key);
if (e == NULL)
e = md_entry_alloc(key);
if (e == NULL)
e->value.mv_unsigned_int = value;
e->type = MD_TYPE_UNSIGNED_INT;
e->value.mv_unsigned_int = value;
e->type = MD_TYPE_UNSIGNED_INT;
- return (md_entry_insert(md, e));
+ return md_entry_insert(md, e);
} /* }}} int meta_data_add_unsigned_int */
int meta_data_add_double(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_add_unsigned_int */
int meta_data_add_double(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
e = md_entry_alloc(key);
if (e == NULL)
e = md_entry_alloc(key);
if (e == NULL)
e->value.mv_double = value;
e->type = MD_TYPE_DOUBLE;
e->value.mv_double = value;
e->type = MD_TYPE_DOUBLE;
- return (md_entry_insert(md, e));
+ return md_entry_insert(md, e);
} /* }}} int meta_data_add_double */
int meta_data_add_boolean(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_add_double */
int meta_data_add_boolean(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL))
e = md_entry_alloc(key);
if (e == NULL)
e = md_entry_alloc(key);
if (e == NULL)
e->value.mv_boolean = value;
e->type = MD_TYPE_BOOLEAN;
e->value.mv_boolean = value;
e->type = MD_TYPE_BOOLEAN;
- return (md_entry_insert(md, e));
+ return md_entry_insert(md, e);
} /* }}} int meta_data_add_boolean */
/*
} /* }}} int meta_data_add_boolean */
/*
char *temp;
if ((md == NULL) || (key == NULL) || (value == NULL))
char *temp;
if ((md == NULL) || (key == NULL) || (value == NULL))
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_STRING) {
ERROR("meta_data_get_string: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_STRING) {
ERROR("meta_data_get_string: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
temp = md_strdup(e->value.mv_string);
if (temp == NULL) {
pthread_mutex_unlock(&md->lock);
ERROR("meta_data_get_string: md_strdup failed.");
}
temp = md_strdup(e->value.mv_string);
if (temp == NULL) {
pthread_mutex_unlock(&md->lock);
ERROR("meta_data_get_string: md_strdup failed.");
}
pthread_mutex_unlock(&md->lock);
*value = temp;
}
pthread_mutex_unlock(&md->lock);
*value = temp;
} /* }}} int meta_data_get_string */
int meta_data_get_signed_int(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_get_string */
int meta_data_get_signed_int(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_SIGNED_INT) {
ERROR("meta_data_get_signed_int: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_SIGNED_INT) {
ERROR("meta_data_get_signed_int: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_signed_int;
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_signed_int;
pthread_mutex_unlock(&md->lock);
} /* }}} int meta_data_get_signed_int */
int meta_data_get_unsigned_int(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_get_signed_int */
int meta_data_get_unsigned_int(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_UNSIGNED_INT) {
ERROR("meta_data_get_unsigned_int: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_UNSIGNED_INT) {
ERROR("meta_data_get_unsigned_int: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_unsigned_int;
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_unsigned_int;
pthread_mutex_unlock(&md->lock);
} /* }}} int meta_data_get_unsigned_int */
int meta_data_get_double(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_get_unsigned_int */
int meta_data_get_double(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_DOUBLE) {
ERROR("meta_data_get_double: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_DOUBLE) {
ERROR("meta_data_get_double: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_double;
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_double;
pthread_mutex_unlock(&md->lock);
} /* }}} int meta_data_get_double */
int meta_data_get_boolean(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_get_double */
int meta_data_get_boolean(meta_data_t *md, /* {{{ */
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
meta_entry_t *e;
if ((md == NULL) || (key == NULL) || (value == NULL))
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_BOOLEAN) {
ERROR("meta_data_get_boolean: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
if (e->type != MD_TYPE_BOOLEAN) {
ERROR("meta_data_get_boolean: Type mismatch for key `%s'", e->key);
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_boolean;
pthread_mutex_unlock(&md->lock);
}
*value = e->value.mv_boolean;
pthread_mutex_unlock(&md->lock);
} /* }}} int meta_data_get_boolean */
int meta_data_as_string(meta_data_t *md, /* {{{ */
} /* }}} int meta_data_get_boolean */
int meta_data_as_string(meta_data_t *md, /* {{{ */
int type;
if ((md == NULL) || (key == NULL) || (value == NULL))
int type;
if ((md == NULL) || (key == NULL) || (value == NULL))
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
pthread_mutex_lock(&md->lock);
e = md_entry_lookup(md, key);
if (e == NULL) {
pthread_mutex_unlock(&md->lock);
default:
pthread_mutex_unlock(&md->lock);
ERROR("meta_data_as_string: unknown type %d for key `%s'", type, key);
default:
pthread_mutex_unlock(&md->lock);
ERROR("meta_data_as_string: unknown type %d for key `%s'", type, key);
}
pthread_mutex_unlock(&md->lock);
}
pthread_mutex_unlock(&md->lock);
if (temp == NULL) {
pthread_mutex_unlock(&md->lock);
ERROR("meta_data_as_string: md_strdup failed for key `%s'.", key);
if (temp == NULL) {
pthread_mutex_unlock(&md->lock);
ERROR("meta_data_as_string: md_strdup failed for key `%s'.", key);
} /* }}} int meta_data_as_string */
} /* }}} int meta_data_as_string */
static const char *plugin_get_dir(void) {
if (plugindir == NULL)
static const char *plugin_get_dir(void) {
if (plugindir == NULL)
}
static int plugin_update_internal_statistics(void) { /* {{{ */
}
static int plugin_update_internal_statistics(void) { /* {{{ */
ERROR("plugin: register_callback: "
"llist_create failed.");
destroy_callback(cf);
ERROR("plugin: register_callback: "
"llist_create failed.");
destroy_callback(cf);
if (key == NULL) {
ERROR("plugin: register_callback: strdup failed.");
destroy_callback(cf);
if (key == NULL) {
ERROR("plugin: register_callback: strdup failed.");
destroy_callback(cf);
}
le = llist_search(*list, name);
}
le = llist_search(*list, name);
"llentry_create failed.");
sfree(key);
destroy_callback(cf);
"llentry_create failed.");
sfree(key);
destroy_callback(cf);
}
llist_append(*list, le);
}
llist_append(*list, le);
} /* }}} int register_callback */
static void log_list_callbacks(llist_t **list, /* {{{ */
} /* }}} int register_callback */
static void log_list_callbacks(llist_t **list, /* {{{ */
cf = calloc(1, sizeof(*cf));
if (cf == NULL) {
ERROR("plugin: create_register_callback: calloc failed.");
cf = calloc(1, sizeof(*cf));
if (cf == NULL) {
ERROR("plugin: create_register_callback: calloc failed.");
}
cf->cf_callback = callback;
}
cf->cf_callback = callback;
cf->cf_ctx = plugin_get_ctx();
cf->cf_ctx = plugin_get_ctx();
- return (register_callback(list, name, cf));
+ return register_callback(list, name, cf);
} /* }}} int create_register_callback */
static int plugin_unregister(llist_t *list, const char *name) /* {{{ */
} /* }}} int create_register_callback */
static int plugin_unregister(llist_t *list, const char *name) /* {{{ */
llentry_t *e;
if (list == NULL)
llentry_t *e;
if (list == NULL)
e = llist_search(list, name);
if (e == NULL)
e = llist_search(list, name);
if (e == NULL)
} /* }}} int plugin_unregister */
/*
} /* }}} int plugin_unregister */
/*
if (list_log != NULL)
fprintf(stderr, "ERROR: %s\n", errbuf);
if (list_log != NULL)
fprintf(stderr, "ERROR: %s\n", errbuf);
}
reg_handle = (void (*)(void))dlsym(dlh, "module_register");
}
reg_handle = (void (*)(void))dlsym(dlh, "module_register");
WARNING("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
dlerror());
dlclose(dlh);
WARNING("Couldn't find symbol \"module_register\" in \"%s\": %s\n", file,
dlerror());
dlclose(dlh);
}
static void *plugin_read_thread(void __attribute__((unused)) * args) {
}
static void *plugin_read_thread(void __attribute__((unused)) * args) {
} /* while (read_loop) */
pthread_exit(NULL);
} /* while (read_loop) */
pthread_exit(NULL);
} /* void *plugin_read_thread */
#ifdef PTHREAD_MAX_NAMELEN_NP
} /* void *plugin_read_thread */
#ifdef PTHREAD_MAX_NAMELEN_NP
value_list_t *vl;
if (vl_orig == NULL)
value_list_t *vl;
if (vl_orig == NULL)
vl = malloc(sizeof(*vl));
if (vl == NULL)
vl = malloc(sizeof(*vl));
if (vl == NULL)
memcpy(vl, vl_orig, sizeof(*vl));
if (vl->host[0] == 0)
memcpy(vl, vl_orig, sizeof(*vl));
if (vl->host[0] == 0)
vl->values = calloc(vl_orig->values_len, sizeof(*vl->values));
if (vl->values == NULL) {
plugin_value_list_free(vl);
vl->values = calloc(vl_orig->values_len, sizeof(*vl->values));
if (vl->values == NULL) {
plugin_value_list_free(vl);
}
memcpy(vl->values, vl_orig->values,
vl_orig->values_len * sizeof(*vl->values));
}
memcpy(vl->values, vl_orig->values,
vl_orig->values_len * sizeof(*vl->values));
vl->meta = meta_data_clone(vl->meta);
if ((vl_orig->meta != NULL) && (vl->meta == NULL)) {
plugin_value_list_free(vl);
vl->meta = meta_data_clone(vl->meta);
if ((vl_orig->meta != NULL) && (vl->meta == NULL)) {
plugin_value_list_free(vl);
} /* }}} value_list_t *plugin_value_list_clone */
static int plugin_write_enqueue(value_list_t const *vl) /* {{{ */
} /* }}} value_list_t *plugin_value_list_clone */
static int plugin_write_enqueue(value_list_t const *vl) /* {{{ */
q = malloc(sizeof(*q));
if (q == NULL)
q = malloc(sizeof(*q));
if (q == NULL)
q->next = NULL;
q->vl = plugin_value_list_clone(vl);
if (q->vl == NULL) {
sfree(q);
q->next = NULL;
q->vl = plugin_value_list_clone(vl);
if (q->vl == NULL) {
sfree(q);
}
/* Store context of caller (read plugin); otherwise, it would not be
}
/* Store context of caller (read plugin); otherwise, it would not be
pthread_cond_signal(&write_cond);
pthread_mutex_unlock(&write_lock);
pthread_cond_signal(&write_cond);
pthread_mutex_unlock(&write_lock);
} /* }}} int plugin_write_enqueue */
static value_list_t *plugin_write_dequeue(void) /* {{{ */
} /* }}} int plugin_write_enqueue */
static value_list_t *plugin_write_dequeue(void) /* {{{ */
if (write_queue_head == NULL) {
pthread_mutex_unlock(&write_lock);
if (write_queue_head == NULL) {
pthread_mutex_unlock(&write_lock);
} /* }}} value_list_t *plugin_write_dequeue */
static void *plugin_write_thread(void __attribute__((unused)) * args) /* {{{ */
} /* }}} value_list_t *plugin_write_dequeue */
static void *plugin_write_thread(void __attribute__((unused)) * args) /* {{{ */
} /* }}} void *plugin_write_thread */
static void start_write_threads(size_t num) /* {{{ */
} /* }}} void *plugin_write_thread */
static void start_write_threads(size_t num) /* {{{ */
assert(plugins_loaded != NULL);
status = c_avl_get(plugins_loaded, name, /* ret_value = */ NULL);
assert(plugins_loaded != NULL);
status = c_avl_get(plugins_loaded, name, /* ret_value = */ NULL);
}
static int plugin_mark_loaded(char const *name) {
}
static int plugin_mark_loaded(char const *name) {
name_copy = strdup(name);
if (name_copy == NULL)
name_copy = strdup(name);
if (name_copy == NULL)
status = c_avl_insert(plugins_loaded,
/* key = */ name_copy, /* value = */ NULL);
status = c_avl_insert(plugins_loaded,
/* key = */ name_copy, /* value = */ NULL);
}
static void plugin_free_loaded(void) {
}
static void plugin_free_loaded(void) {
int status;
if (plugin_name == NULL)
int status;
if (plugin_name == NULL)
/* Check if plugin is already loaded and don't do anything in this
* case. */
if (plugin_is_loaded(plugin_name))
/* Check if plugin is already loaded and don't do anything in this
* case. */
if (plugin_is_loaded(plugin_name))
dir = plugin_get_dir();
ret = 1;
dir = plugin_get_dir();
ret = 1;
status = ssnprintf(typename, sizeof(typename), "%s.so", plugin_name);
if ((status < 0) || ((size_t)status >= sizeof(typename))) {
WARNING("plugin_load: Filename too long: \"%s.so\"", plugin_name);
status = ssnprintf(typename, sizeof(typename), "%s.so", plugin_name);
if ((status < 0) || ((size_t)status >= sizeof(typename))) {
WARNING("plugin_load: Filename too long: \"%s.so\"", plugin_name);
}
if ((dh = opendir(dir)) == NULL) {
char errbuf[1024];
ERROR("plugin_load: opendir (%s) failed: %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if ((dh = opendir(dir)) == NULL) {
char errbuf[1024];
ERROR("plugin_load: opendir (%s) failed: %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while ((de = readdir(dh)) != NULL) {
}
while ((de = readdir(dh)) != NULL) {
if (filename[0] == 0)
ERROR("plugin_load: Could not find plugin \"%s\" in %s", plugin_name, dir);
if (filename[0] == 0)
ERROR("plugin_load: Could not find plugin \"%s\" in %s", plugin_name, dir);
int (*callback)(const char *key, const char *val),
const char **keys, int keys_num) {
cf_register(name, callback, keys, keys_num);
int (*callback)(const char *key, const char *val),
const char **keys, int keys_num) {
cf_register(name, callback, keys, keys_num);
} /* int plugin_register_config */
int plugin_register_complex_config(const char *type,
int (*callback)(oconfig_item_t *)) {
} /* int plugin_register_config */
int plugin_register_complex_config(const char *type,
int (*callback)(oconfig_item_t *)) {
- return (cf_register_complex(type, callback));
+ return cf_register_complex(type, callback);
} /* int plugin_register_complex_config */
int plugin_register_init(const char *name, int (*callback)(void)) {
} /* int plugin_register_complex_config */
int plugin_register_init(const char *name, int (*callback)(void)) {
- return (create_register_callback(&list_init, name, (void *)callback,
- /* user_data = */ NULL));
+ return create_register_callback(&list_init, name, (void *)callback, NULL);
} /* plugin_register_init */
static int plugin_compare_read_func(const void *arg0, const void *arg1) {
} /* plugin_register_init */
static int plugin_compare_read_func(const void *arg0, const void *arg1) {
rf1 = arg1;
if (rf0->rf_next_read < rf1->rf_next_read)
rf1 = arg1;
if (rf0->rf_next_read < rf1->rf_next_read)
else if (rf0->rf_next_read > rf1->rf_next_read)
else if (rf0->rf_next_read > rf1->rf_next_read)
} /* int plugin_compare_read_func */
/* Add a read function to both, the heap and a linked list. The linked list if
} /* int plugin_compare_read_func */
/* Add a read function to both, the heap and a linked list. The linked list if
if (read_list == NULL) {
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: read_list failed.");
if (read_list == NULL) {
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: read_list failed.");
if (read_heap == NULL) {
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: c_heap_create failed.");
if (read_heap == NULL) {
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: c_heap_create failed.");
"Check for duplicate \"LoadPlugin\" lines "
"in your configuration!",
rf->rf_name);
"Check for duplicate \"LoadPlugin\" lines "
"in your configuration!",
rf->rf_name);
}
le = llentry_create(rf->rf_name, rf);
if (le == NULL) {
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: llentry_create failed.");
}
le = llentry_create(rf->rf_name, rf);
if (le == NULL) {
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: llentry_create failed.");
}
status = c_heap_insert(read_heap, rf);
}
status = c_heap_insert(read_heap, rf);
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: c_heap_insert failed.");
llentry_destroy(le);
pthread_mutex_unlock(&read_lock);
ERROR("plugin_insert_read: c_heap_insert failed.");
llentry_destroy(le);
}
/* This does not fail. */
}
/* This does not fail. */
/* Wake up all the read threads. */
pthread_cond_broadcast(&read_cond);
pthread_mutex_unlock(&read_lock);
/* Wake up all the read threads. */
pthread_cond_broadcast(&read_cond);
pthread_mutex_unlock(&read_lock);
} /* int plugin_insert_read */
int plugin_register_read(const char *name, int (*callback)(void)) {
} /* int plugin_insert_read */
int plugin_register_read(const char *name, int (*callback)(void)) {
rf = calloc(1, sizeof(*rf));
if (rf == NULL) {
ERROR("plugin_register_read: calloc failed.");
rf = calloc(1, sizeof(*rf));
if (rf == NULL) {
ERROR("plugin_register_read: calloc failed.");
}
rf->rf_callback = (void *)callback;
}
rf->rf_callback = (void *)callback;
} /* int plugin_register_read */
int plugin_register_complex_read(const char *group, const char *name,
} /* int plugin_register_read */
int plugin_register_complex_read(const char *group, const char *name,
rf = calloc(1, sizeof(*rf));
if (rf == NULL) {
ERROR("plugin_register_complex_read: calloc failed.");
rf = calloc(1, sizeof(*rf));
if (rf == NULL) {
ERROR("plugin_register_complex_read: calloc failed.");
}
rf->rf_callback = (void *)callback;
}
rf->rf_callback = (void *)callback;
} /* int plugin_register_complex_read */
int plugin_register_write(const char *name, plugin_write_cb callback,
user_data_t const *ud) {
} /* int plugin_register_complex_read */
int plugin_register_write(const char *name, plugin_write_cb callback,
user_data_t const *ud) {
- return (create_register_callback(&list_write, name, (void *)callback, ud));
+ return create_register_callback(&list_write, name, (void *)callback, ud);
} /* int plugin_register_write */
static int plugin_flush_timeout_callback(user_data_t *ud) {
flush_callback_t *cb = ud->data;
} /* int plugin_register_write */
static int plugin_flush_timeout_callback(user_data_t *ud) {
flush_callback_t *cb = ud->data;
- return plugin_flush(cb->name, cb->timeout, /* identifier = */ NULL);
+ return plugin_flush(cb->name, cb->timeout, NULL);
} /* static int plugin_flush_callback */
static void plugin_flush_timeout_callback_free(void *data) {
} /* static int plugin_flush_callback */
static void plugin_flush_timeout_callback_free(void *data) {
flush_name = malloc(name_size + prefix_size + 1);
if (flush_name == NULL) {
ERROR("plugin_flush_callback_name: malloc failed.");
flush_name = malloc(name_size + prefix_size + 1);
if (flush_name == NULL) {
ERROR("plugin_flush_callback_name: malloc failed.");
}
sstrncpy(flush_name, flush_prefix, prefix_size + 1);
}
sstrncpy(flush_name, flush_prefix, prefix_size + 1);
flush_name = plugin_flush_callback_name(name);
if (flush_name == NULL)
flush_name = plugin_flush_callback_name(name);
if (flush_name == NULL)
cb = malloc(sizeof(*cb));
if (cb == NULL) {
ERROR("plugin_register_flush: malloc failed.");
sfree(flush_name);
cb = malloc(sizeof(*cb));
if (cb == NULL) {
ERROR("plugin_register_flush: malloc failed.");
sfree(flush_name);
}
cb->name = strdup(name);
}
cb->name = strdup(name);
ERROR("plugin_register_flush: strdup failed.");
sfree(cb);
sfree(flush_name);
ERROR("plugin_register_flush: strdup failed.");
sfree(cb);
sfree(flush_name);
}
cb->timeout = ctx.flush_timeout;
}
cb->timeout = ctx.flush_timeout;
int plugin_register_missing(const char *name, plugin_missing_cb callback,
user_data_t const *ud) {
int plugin_register_missing(const char *name, plugin_missing_cb callback,
user_data_t const *ud) {
- return (create_register_callback(&list_missing, name, (void *)callback, ud));
+ return create_register_callback(&list_missing, name, (void *)callback, ud);
} /* int plugin_register_missing */
int plugin_register_shutdown(const char *name, int (*callback)(void)) {
} /* int plugin_register_missing */
int plugin_register_shutdown(const char *name, int (*callback)(void)) {
- return (create_register_callback(&list_shutdown, name, (void *)callback,
- /* user_data = */ NULL));
+ return create_register_callback(&list_shutdown, name, (void *)callback,
+ NULL);
} /* int plugin_register_shutdown */
static void plugin_free_data_sets(void) {
} /* int plugin_register_shutdown */
static void plugin_free_data_sets(void) {
} else if (data_sets == NULL) {
data_sets = c_avl_create((int (*)(const void *, const void *))strcmp);
if (data_sets == NULL)
} else if (data_sets == NULL) {
data_sets = c_avl_create((int (*)(const void *, const void *))strcmp);
if (data_sets == NULL)
}
ds_copy = malloc(sizeof(*ds_copy));
if (ds_copy == NULL)
}
ds_copy = malloc(sizeof(*ds_copy));
if (ds_copy == NULL)
memcpy(ds_copy, ds, sizeof(data_set_t));
ds_copy->ds = malloc(sizeof(*ds_copy->ds) * ds->ds_num);
if (ds_copy->ds == NULL) {
sfree(ds_copy);
memcpy(ds_copy, ds, sizeof(data_set_t));
ds_copy->ds = malloc(sizeof(*ds_copy->ds) * ds->ds_num);
if (ds_copy->ds == NULL) {
sfree(ds_copy);
}
for (size_t i = 0; i < ds->ds_num; i++)
memcpy(ds_copy->ds + i, ds->ds + i, sizeof(data_source_t));
}
for (size_t i = 0; i < ds->ds_num; i++)
memcpy(ds_copy->ds + i, ds->ds + i, sizeof(data_source_t));
- return (c_avl_insert(data_sets, (void *)ds_copy->type, (void *)ds_copy));
+ return c_avl_insert(data_sets, (void *)ds_copy->type, (void *)ds_copy);
} /* int plugin_register_data_set */
int plugin_register_log(const char *name, plugin_log_cb callback,
user_data_t const *ud) {
} /* int plugin_register_data_set */
int plugin_register_log(const char *name, plugin_log_cb callback,
user_data_t const *ud) {
- return (create_register_callback(&list_log, name, (void *)callback, ud));
+ return create_register_callback(&list_log, name, (void *)callback, ud);
} /* int plugin_register_log */
int plugin_register_notification(const char *name,
plugin_notification_cb callback,
user_data_t const *ud) {
} /* int plugin_register_log */
int plugin_register_notification(const char *name,
plugin_notification_cb callback,
user_data_t const *ud) {
- return (
- create_register_callback(&list_notification, name, (void *)callback, ud));
+ return create_register_callback(&list_notification, name, (void *)callback,
+ ud);
} /* int plugin_register_log */
int plugin_unregister_config(const char *name) {
cf_unregister(name);
} /* int plugin_register_log */
int plugin_unregister_config(const char *name) {
cf_unregister(name);
} /* int plugin_unregister_config */
int plugin_unregister_complex_config(const char *name) {
cf_unregister_complex(name);
} /* int plugin_unregister_config */
int plugin_unregister_complex_config(const char *name) {
cf_unregister_complex(name);
} /* int plugin_unregister_complex_config */
int plugin_unregister_init(const char *name) {
} /* int plugin_unregister_complex_config */
int plugin_unregister_init(const char *name) {
- return (plugin_unregister(list_init, name));
+ return plugin_unregister(list_init, name);
}
int plugin_unregister_read(const char *name) /* {{{ */
}
int plugin_unregister_read(const char *name) /* {{{ */
read_func_t *rf;
if (name == NULL)
read_func_t *rf;
if (name == NULL)
pthread_mutex_lock(&read_lock);
if (read_list == NULL) {
pthread_mutex_unlock(&read_lock);
pthread_mutex_lock(&read_lock);
if (read_list == NULL) {
pthread_mutex_unlock(&read_lock);
}
le = llist_search(read_list, name);
if (le == NULL) {
pthread_mutex_unlock(&read_lock);
WARNING("plugin_unregister_read: No such read function: %s", name);
}
le = llist_search(read_list, name);
if (le == NULL) {
pthread_mutex_unlock(&read_lock);
WARNING("plugin_unregister_read: No such read function: %s", name);
}
llist_remove(read_list, le);
}
llist_remove(read_list, le);
DEBUG("plugin_unregister_read: Marked `%s' for removal.", name);
DEBUG("plugin_unregister_read: Marked `%s' for removal.", name);
} /* }}} int plugin_unregister_read */
void plugin_log_available_writers(void) {
} /* }}} int plugin_unregister_read */
void plugin_log_available_writers(void) {
int found = 0;
if (group == NULL)
int found = 0;
if (group == NULL)
pthread_mutex_lock(&read_lock);
if (read_list == NULL) {
pthread_mutex_unlock(&read_lock);
pthread_mutex_lock(&read_lock);
if (read_list == NULL) {
pthread_mutex_unlock(&read_lock);
WARNING("plugin_unregister_read_group: No such "
"group of read function: %s",
group);
WARNING("plugin_unregister_read_group: No such "
"group of read function: %s",
group);
} /* }}} int plugin_unregister_read_group */
int plugin_unregister_write(const char *name) {
} /* }}} int plugin_unregister_read_group */
int plugin_unregister_write(const char *name) {
- return (plugin_unregister(list_write, name));
+ return plugin_unregister(list_write, name);
}
int plugin_unregister_flush(const char *name) {
}
int plugin_unregister_flush(const char *name) {
}
int plugin_unregister_missing(const char *name) {
}
int plugin_unregister_missing(const char *name) {
- return (plugin_unregister(list_missing, name));
+ return plugin_unregister(list_missing, name);
}
int plugin_unregister_shutdown(const char *name) {
}
int plugin_unregister_shutdown(const char *name) {
- return (plugin_unregister(list_shutdown, name));
+ return plugin_unregister(list_shutdown, name);
}
int plugin_unregister_data_set(const char *name) {
data_set_t *ds;
if (data_sets == NULL)
}
int plugin_unregister_data_set(const char *name) {
data_set_t *ds;
if (data_sets == NULL)
if (c_avl_remove(data_sets, name, NULL, (void *)&ds) != 0)
if (c_avl_remove(data_sets, name, NULL, (void *)&ds) != 0)
sfree(ds->ds);
sfree(ds);
sfree(ds->ds);
sfree(ds);
} /* int plugin_unregister_data_set */
int plugin_unregister_log(const char *name) {
} /* int plugin_unregister_data_set */
int plugin_unregister_log(const char *name) {
- return (plugin_unregister(list_log, name));
+ return plugin_unregister(list_log, name);
}
int plugin_unregister_notification(const char *name) {
}
int plugin_unregister_notification(const char *name) {
- return (plugin_unregister(list_notification, name));
+ return plugin_unregister(list_notification, name);
}
int plugin_init_all(void) {
}
int plugin_init_all(void) {
if (read_heap == NULL) {
NOTICE("No read-functions are registered.");
if (read_heap == NULL) {
NOTICE("No read-functions are registered.");
destroy_callback((void *)rf);
}
destroy_callback((void *)rf);
}
- return (return_status);
} /* int plugin_read_all_once */
int plugin_write(const char *plugin, /* {{{ */
} /* int plugin_read_all_once */
int plugin_write(const char *plugin, /* {{{ */
int status;
if (vl == NULL)
int status;
if (vl == NULL)
if (ds == NULL) {
ds = plugin_get_ds(vl->type);
if (ds == NULL) {
ERROR("plugin_write: Unable to lookup type `%s'.", vl->type);
if (ds == NULL) {
ds = plugin_get_ds(vl->type);
if (ds == NULL) {
ERROR("plugin_write: Unable to lookup type `%s'.", vl->type);
status = (*callback)(ds, vl, &cf->cf_udata);
}
status = (*callback)(ds, vl, &cf->cf_udata);
}
} /* }}} int plugin_write */
int plugin_flush(const char *plugin, cdtime_t timeout, const char *identifier) {
llentry_t *le;
if (list_flush == NULL)
} /* }}} int plugin_write */
int plugin_flush(const char *plugin, cdtime_t timeout, const char *identifier) {
llentry_t *le;
if (list_flush == NULL)
le = llist_head(list_flush);
while (le != NULL) {
le = llist_head(list_flush);
while (le != NULL) {
} /* int plugin_flush */
int plugin_shutdown_all(void) {
} /* int plugin_flush */
int plugin_shutdown_all(void) {
plugin_free_loaded();
plugin_free_data_sets();
plugin_free_loaded();
plugin_free_data_sets();
} /* void plugin_shutdown_all */
int plugin_dispatch_missing(const value_list_t *vl) /* {{{ */
} /* void plugin_shutdown_all */
int plugin_dispatch_missing(const value_list_t *vl) /* {{{ */
llentry_t *le;
if (list_missing == NULL)
llentry_t *le;
if (list_missing == NULL)
le = llist_head(list_missing);
while (le != NULL) {
le = llist_head(list_missing);
while (le != NULL) {
ERROR("plugin_dispatch_missing: Callback function \"%s\" "
"failed with status %i.",
le->key, status);
ERROR("plugin_dispatch_missing: Callback function \"%s\" "
"failed with status %i.",
le->key, status);
} /* int }}} plugin_dispatch_missing */
static int plugin_dispatch_values_internal(value_list_t *vl) {
} /* int }}} plugin_dispatch_missing */
static int plugin_dispatch_values_internal(value_list_t *vl) {
ERROR("plugin_dispatch_values: Invalid value list "
"from plugin %s.",
vl->plugin);
ERROR("plugin_dispatch_values: Invalid value list "
"from plugin %s.",
vl->plugin);
}
/* Free meta data only if the calling function didn't specify any. In
}
/* Free meta data only if the calling function didn't specify any. In
ERROR("plugin_dispatch_values: No data sets registered. "
"Could the types database be read? Check "
"your `TypesDB' setting!");
ERROR("plugin_dispatch_values: No data sets registered. "
"Could the types database be read? Check "
"your `TypesDB' setting!");
}
if (c_avl_get(data_sets, vl->type, (void *)&ds) != 0) {
}
if (c_avl_get(data_sets, vl->type, (void *)&ds) != 0) {
INFO("plugin_dispatch_values: Dataset not found: %s "
"(from \"%s\"), check your types.db!",
vl->type, ident);
INFO("plugin_dispatch_values: Dataset not found: %s "
"(from \"%s\"), check your types.db!",
vl->type, ident);
}
DEBUG("plugin_dispatch_values: time = %.3f; interval = %.3f; "
}
DEBUG("plugin_dispatch_values: time = %.3f; interval = %.3f; "
"(ds->ds_num = %zu) != "
"(vl->values_len = %zu)",
ds->type, ds->ds_num, vl->values_len);
"(ds->ds_num = %zu) != "
"(vl->values_len = %zu)",
ds->type, ds->ds_num, vl->values_len);
"status %i (%#x).",
status, status);
} else if (status == FC_TARGET_STOP)
"status %i (%#x).",
status, status);
} else if (status == FC_TARGET_STOP)
}
/* Update the value cache */
}
/* Update the value cache */
} /* int plugin_dispatch_values_internal */
static double get_drop_probability(void) /* {{{ */
} /* int plugin_dispatch_values_internal */
static double get_drop_probability(void) /* {{{ */
pthread_mutex_unlock(&write_lock);
if (wql < write_limit_low)
pthread_mutex_unlock(&write_lock);
if (wql < write_limit_low)
if (wql >= write_limit_high)
if (wql >= write_limit_high)
pos = 1 + wql - write_limit_low;
size = 1 + write_limit_high - write_limit_low;
pos = 1 + wql - write_limit_low;
size = 1 + write_limit_high - write_limit_low;
- return (((double)pos) / ((double)size));
+ return (double)pos / (double)size;
} /* }}} double get_drop_probability */
static _Bool check_drop_value(void) /* {{{ */
} /* }}} double get_drop_probability */
static _Bool check_drop_value(void) /* {{{ */
int status;
if (write_limit_high == 0)
int status;
if (write_limit_high == 0)
p = get_drop_probability();
if (p == 0.0)
p = get_drop_probability();
if (p == 0.0)
status = pthread_mutex_trylock(&last_message_lock);
if (status == 0) {
status = pthread_mutex_trylock(&last_message_lock);
if (status == 0) {
q = cdrand_d();
if (q > p)
q = cdrand_d();
if (q > p)
} /* }}} _Bool check_drop_value */
int plugin_dispatch_values(value_list_t const *vl) {
} /* }}} _Bool check_drop_value */
int plugin_dispatch_values(value_list_t const *vl) {
stats_values_dropped++;
pthread_mutex_unlock(&statistics_lock);
}
stats_values_dropped++;
pthread_mutex_unlock(&statistics_lock);
}
}
status = plugin_write_enqueue(vl);
}
status = plugin_write_enqueue(vl);
ERROR("plugin_dispatch_values: plugin_write_enqueue failed "
"with status %i (%s).",
status, sstrerror(status, errbuf, sizeof(errbuf)));
ERROR("plugin_dispatch_values: plugin_write_enqueue failed "
"with status %i (%s).",
status, sstrerror(status, errbuf, sizeof(errbuf)));
}
__attribute__((sentinel)) int
}
__attribute__((sentinel)) int
va_end(ap);
plugin_value_list_free(vl);
va_end(ap);
plugin_value_list_free(vl);
} /* }}} int plugin_dispatch_multivalue */
int plugin_dispatch_notification(const notification_t *notif) {
} /* }}} int plugin_dispatch_multivalue */
int plugin_dispatch_notification(const notification_t *notif) {
/* Nobody cares for notifications */
if (list_notification == NULL)
/* Nobody cares for notifications */
if (list_notification == NULL)
le = llist_head(list_notification);
while (le != NULL) {
le = llist_head(list_notification);
while (le != NULL) {
} /* int plugin_dispatch_notification */
void plugin_log(int level, const char *format, ...) {
} /* int plugin_dispatch_notification */
void plugin_log(int level, const char *format, ...) {
log_level = LOG_DEBUG;
#endif /* COLLECT_DEBUG */
log_level = LOG_DEBUG;
#endif /* COLLECT_DEBUG */
} /* int parse_log_severity */
int parse_notif_severity(const char *severity) {
} /* int parse_log_severity */
int parse_notif_severity(const char *severity) {
(strcmp(severity, "WARN") == 0))
notif_severity = NOTIF_WARNING;
(strcmp(severity, "WARN") == 0))
notif_severity = NOTIF_WARNING;
- return (notif_severity);
} /* int parse_notif_severity */
const data_set_t *plugin_get_ds(const char *name) {
} /* int parse_notif_severity */
const data_set_t *plugin_get_ds(const char *name) {
if (data_sets == NULL) {
ERROR("plugin_get_ds: No data sets are defined yet.");
if (data_sets == NULL) {
ERROR("plugin_get_ds: No data sets are defined yet.");
}
if (c_avl_get(data_sets, name, (void *)&ds) != 0) {
DEBUG("No such dataset registered: %s", name);
}
if (c_avl_get(data_sets, name, (void *)&ds) != 0) {
DEBUG("No such dataset registered: %s", name);
} /* data_set_t *plugin_get_ds */
static int plugin_notification_meta_add(notification_t *n, const char *name,
} /* data_set_t *plugin_get_ds */
static int plugin_notification_meta_add(notification_t *n, const char *name,
if ((n == NULL) || (name == NULL) || (value == NULL)) {
ERROR("plugin_notification_meta_add: A pointer is NULL!");
if ((n == NULL) || (name == NULL) || (value == NULL)) {
ERROR("plugin_notification_meta_add: A pointer is NULL!");
}
meta = calloc(1, sizeof(*meta));
if (meta == NULL) {
ERROR("plugin_notification_meta_add: calloc failed.");
}
meta = calloc(1, sizeof(*meta));
if (meta == NULL) {
ERROR("plugin_notification_meta_add: calloc failed.");
}
sstrncpy(meta->name, name, sizeof(meta->name));
}
sstrncpy(meta->name, name, sizeof(meta->name));
if (meta->nm_value.nm_string == NULL) {
ERROR("plugin_notification_meta_add: strdup failed.");
sfree(meta);
if (meta->nm_value.nm_string == NULL) {
ERROR("plugin_notification_meta_add: strdup failed.");
sfree(meta);
default: {
ERROR("plugin_notification_meta_add: Unknown type: %i", type);
sfree(meta);
default: {
ERROR("plugin_notification_meta_add: Unknown type: %i", type);
sfree(meta);
} /* int plugin_notification_meta_add */
int plugin_notification_meta_add_string(notification_t *n, const char *name,
const char *value) {
} /* int plugin_notification_meta_add */
int plugin_notification_meta_add_string(notification_t *n, const char *name,
const char *value) {
- return (plugin_notification_meta_add(n, name, NM_TYPE_STRING, value));
+ return plugin_notification_meta_add(n, name, NM_TYPE_STRING, value);
}
int plugin_notification_meta_add_signed_int(notification_t *n, const char *name,
int64_t value) {
}
int plugin_notification_meta_add_signed_int(notification_t *n, const char *name,
int64_t value) {
- return (plugin_notification_meta_add(n, name, NM_TYPE_SIGNED_INT, &value));
+ return plugin_notification_meta_add(n, name, NM_TYPE_SIGNED_INT, &value);
}
int plugin_notification_meta_add_unsigned_int(notification_t *n,
const char *name,
uint64_t value) {
}
int plugin_notification_meta_add_unsigned_int(notification_t *n,
const char *name,
uint64_t value) {
- return (plugin_notification_meta_add(n, name, NM_TYPE_UNSIGNED_INT, &value));
+ return plugin_notification_meta_add(n, name, NM_TYPE_UNSIGNED_INT, &value);
}
int plugin_notification_meta_add_double(notification_t *n, const char *name,
double value) {
}
int plugin_notification_meta_add_double(notification_t *n, const char *name,
double value) {
- return (plugin_notification_meta_add(n, name, NM_TYPE_DOUBLE, &value));
+ return plugin_notification_meta_add(n, name, NM_TYPE_DOUBLE, &value);
}
int plugin_notification_meta_add_boolean(notification_t *n, const char *name,
_Bool value) {
}
int plugin_notification_meta_add_boolean(notification_t *n, const char *name,
_Bool value) {
- return (plugin_notification_meta_add(n, name, NM_TYPE_BOOLEAN, &value));
+ return plugin_notification_meta_add(n, name, NM_TYPE_BOOLEAN, &value);
}
int plugin_notification_meta_copy(notification_t *dst,
}
int plugin_notification_meta_copy(notification_t *dst,
meta->nm_value.nm_boolean);
}
meta->nm_value.nm_boolean);
}
} /* int plugin_notification_meta_copy */
int plugin_notification_meta_free(notification_meta_t *n) {
} /* int plugin_notification_meta_copy */
int plugin_notification_meta_free(notification_meta_t *n) {
if (n == NULL) {
ERROR("plugin_notification_meta_free: n == NULL!");
if (n == NULL) {
ERROR("plugin_notification_meta_free: n == NULL!");
} /* int plugin_notification_meta_free */
static void plugin_ctx_destructor(void *ctx) {
} /* int plugin_notification_meta_free */
static void plugin_ctx_destructor(void *ctx) {
assert(plugin_ctx_key_initialized);
pthread_setspecific(plugin_ctx_key, ctx);
DEBUG("Created new plugin context.");
assert(plugin_ctx_key_initialized);
pthread_setspecific(plugin_ctx_key, ctx);
DEBUG("Created new plugin context.");
} /* int plugin_ctx_create */
void plugin_init_ctx(void) {
} /* int plugin_ctx_create */
void plugin_init_ctx(void) {
} /* plugin_ctx_t plugin_get_ctx */
plugin_ctx_t plugin_set_ctx(plugin_ctx_t ctx) {
} /* plugin_ctx_t plugin_get_ctx */
plugin_ctx_t plugin_set_ctx(plugin_ctx_t ctx) {
} /* void plugin_set_ctx */
cdtime_t plugin_get_interval(void) {
} /* void plugin_set_ctx */
cdtime_t plugin_get_interval(void) {
if (buf_len < 11) {
ERROR("parse_ds: (buf_len = %zu) < 11", buf_len);
if (buf_len < 11) {
ERROR("parse_ds: (buf_len = %zu) < 11", buf_len);
}
if (buf[buf_len - 1] == ',') {
}
if (buf[buf_len - 1] == ',') {
if (fields_num != 4) {
ERROR("parse_ds: (fields_num = %i) != 4", fields_num);
if (fields_num != 4) {
ERROR("parse_ds: (fields_num = %i) != 4", fields_num);
}
sstrncpy(dsrc->name, fields[0], sizeof(dsrc->name));
}
sstrncpy(dsrc->name, fields[0], sizeof(dsrc->name));
else {
ERROR("(fields[1] = %s) != (GAUGE || COUNTER || DERIVE || ABSOLUTE)",
fields[1]);
else {
ERROR("(fields[1] = %s) != (GAUGE || COUNTER || DERIVE || ABSOLUTE)",
fields[1]);
}
if (strcasecmp(fields[2], "U") == 0)
}
if (strcasecmp(fields[2], "U") == 0)
else
dsrc->max = atof(fields[3]);
else
dsrc->max = atof(fields[3]);
} /* int parse_ds */
static void parse_line(char *buf) {
} /* int parse_ds */
static void parse_line(char *buf) {
FILE *fh;
if (file == NULL)
FILE *fh;
if (file == NULL)
fh = fopen(file, "r");
if (fh == NULL) {
fh = fopen(file, "r");
if (fh == NULL) {
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("Failed to open types database `%s': %s", file,
sstrerror(errno, errbuf, sizeof(errbuf)));
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("Failed to open types database `%s': %s", file,
sstrerror(errno, errbuf, sizeof(errbuf)));
DEBUG("Done parsing `%s'", file);
DEBUG("Done parsing `%s'", file);
} /* int read_types_list */
} /* int read_types_list */
int height_right;
if (n == NULL)
int height_right;
if (n == NULL)
height_left = (n->left == NULL) ? 0 : n->left->height;
height_right = (n->right == NULL) ? 0 : n->right->height;
height_left = (n->left == NULL) ? 0 : n->left->height;
height_right = (n->right == NULL) ? 0 : n->right->height;
- return (((height_left > height_right) ? height_left : height_right) + 1);
+ return ((height_left > height_right) ? height_left : height_right) + 1;
} /* int calc_height */
static c_avl_node_t *search(c_avl_tree_t *t, const void *key) {
} /* int calc_height */
static c_avl_node_t *search(c_avl_tree_t *t, const void *key) {
while (n != NULL) {
cmp = t->compare(key, n->key);
if (cmp == 0)
while (n != NULL) {
cmp = t->compare(key, n->key);
if (cmp == 0)
else if (cmp < 0)
n = n->left;
else
n = n->right;
}
else if (cmp < 0)
n = n->left;
else
n = n->right;
}
x->height = calc_height(x);
y->height = calc_height(y);
x->height = calc_height(x);
y->height = calc_height(y);
} /* void rotate_right */
/*
} /* void rotate_right */
/*
x->height = calc_height(x);
y->height = calc_height(y);
x->height = calc_height(x);
y->height = calc_height(y);
} /* void rotate_left */
static c_avl_node_t *rotate_left_right(c_avl_tree_t *t, c_avl_node_t *x) {
rotate_left(t, x->left);
} /* void rotate_left */
static c_avl_node_t *rotate_left_right(c_avl_tree_t *t, c_avl_node_t *x) {
rotate_left(t, x->left);
- return (rotate_right(t, x));
+ return rotate_right(t, x);
} /* void rotate_left_right */
static c_avl_node_t *rotate_right_left(c_avl_tree_t *t, c_avl_node_t *x) {
rotate_right(t, x->right);
} /* void rotate_left_right */
static c_avl_node_t *rotate_right_left(c_avl_tree_t *t, c_avl_node_t *x) {
rotate_right(t, x->right);
- return (rotate_left(t, x));
+ return rotate_left(t, x);
} /* void rotate_right_left */
static void rebalance(c_avl_tree_t *t, c_avl_node_t *n) {
} /* void rotate_right_left */
static void rebalance(c_avl_tree_t *t, c_avl_node_t *n) {
c_avl_node_t *r; /* return node */
if (n == NULL) {
c_avl_node_t *r; /* return node */
if (n == NULL) {
}
/* If we can't descent any further, we have to backtrack to the first
}
/* If we can't descent any further, we have to backtrack to the first
* r->left != n => r->right = n => r->parent == NULL */
if ((r == NULL) || (r->left != n)) {
assert((r == NULL) || (r->parent == NULL));
* r->left != n => r->right = n => r->parent == NULL */
if ((r == NULL) || (r->left != n)) {
assert((r == NULL) || (r->parent == NULL));
} else {
assert(r->left == n);
} else {
assert(r->left == n);
} /* c_avl_node_t *c_avl_node_next */
static c_avl_node_t *c_avl_node_prev(c_avl_node_t *n) {
c_avl_node_t *r; /* return node */
if (n == NULL) {
} /* c_avl_node_t *c_avl_node_next */
static c_avl_node_t *c_avl_node_prev(c_avl_node_t *n) {
c_avl_node_t *r; /* return node */
if (n == NULL) {
}
/* If we can't descent any further, we have to backtrack to the first
}
/* If we can't descent any further, we have to backtrack to the first
* r->right != n => r->left = n => r->parent == NULL */
if ((r == NULL) || (r->right != n)) {
assert((r == NULL) || (r->parent == NULL));
* r->right != n => r->left = n => r->parent == NULL */
if ((r == NULL) || (r->right != n)) {
assert((r == NULL) || (r->parent == NULL));
} else {
assert(r->right == n);
} else {
assert(r->right == n);
} /* c_avl_node_t *c_avl_node_prev */
static int _remove(c_avl_tree_t *t, c_avl_node_t *n) {
} /* c_avl_node_t *c_avl_node_prev */
static int _remove(c_avl_tree_t *t, c_avl_node_t *n) {
c_avl_tree_t *t;
if (compare == NULL)
c_avl_tree_t *t;
if (compare == NULL)
if ((t = malloc(sizeof(*t))) == NULL)
if ((t = malloc(sizeof(*t))) == NULL)
t->root = NULL;
t->compare = compare;
t->size = 0;
t->root = NULL;
t->compare = compare;
t->size = 0;
}
void c_avl_destroy(c_avl_tree_t *t) {
}
void c_avl_destroy(c_avl_tree_t *t) {
int cmp;
if ((new = malloc(sizeof(*new))) == NULL)
int cmp;
if ((new = malloc(sizeof(*new))) == NULL)
new->key = key;
new->value = value;
new->key = key;
new->value = value;
new->parent = NULL;
t->root = new;
t->size = 1;
new->parent = NULL;
t->root = new;
t->size = 1;
cmp = t->compare(nptr->key, new->key);
if (cmp == 0) {
free_node(new);
cmp = t->compare(nptr->key, new->key);
if (cmp == 0) {
free_node(new);
} else if (cmp < 0) {
/* nptr < new */
if (nptr->right == NULL) {
} else if (cmp < 0) {
/* nptr < new */
if (nptr->right == NULL) {
verify_tree(t->root);
++t->size;
verify_tree(t->root);
++t->size;
} /* int c_avl_insert */
int c_avl_remove(c_avl_tree_t *t, const void *key, void **rkey, void **rvalue) {
} /* int c_avl_insert */
int c_avl_remove(c_avl_tree_t *t, const void *key, void **rkey, void **rvalue) {
n = search(t, key);
if (n == NULL)
n = search(t, key);
if (n == NULL)
if (rkey != NULL)
*rkey = n->key;
if (rkey != NULL)
*rkey = n->key;
status = _remove(t, n);
verify_tree(t->root);
--t->size;
status = _remove(t, n);
verify_tree(t->root);
--t->size;
} /* void *c_avl_remove */
int c_avl_get(c_avl_tree_t *t, const void *key, void **value) {
} /* void *c_avl_remove */
int c_avl_get(c_avl_tree_t *t, const void *key, void **value) {
n = search(t, key);
if (n == NULL)
n = search(t, key);
if (n == NULL)
if (value != NULL)
*value = n->value;
if (value != NULL)
*value = n->value;
}
int c_avl_pick(c_avl_tree_t *t, void **key, void **value) {
}
int c_avl_pick(c_avl_tree_t *t, void **key, void **value) {
c_avl_node_t *p;
if ((key == NULL) || (value == NULL))
c_avl_node_t *p;
if ((key == NULL) || (value == NULL))
n = t->root;
while ((n->left != NULL) || (n->right != NULL)) {
n = t->root;
while ((n->left != NULL) || (n->right != NULL)) {
--t->size;
rebalance(t, p);
--t->size;
rebalance(t, p);
} /* int c_avl_pick */
c_avl_iterator_t *c_avl_get_iterator(c_avl_tree_t *t) {
c_avl_iterator_t *iter;
if (t == NULL)
} /* int c_avl_pick */
c_avl_iterator_t *c_avl_get_iterator(c_avl_tree_t *t) {
c_avl_iterator_t *iter;
if (t == NULL)
iter = calloc(1, sizeof(*iter));
if (iter == NULL)
iter = calloc(1, sizeof(*iter));
if (iter == NULL)
} /* c_avl_iterator_t *c_avl_get_iterator */
int c_avl_iterator_next(c_avl_iterator_t *iter, void **key, void **value) {
c_avl_node_t *n;
if ((iter == NULL) || (key == NULL) || (value == NULL))
} /* c_avl_iterator_t *c_avl_get_iterator */
int c_avl_iterator_next(c_avl_iterator_t *iter, void **key, void **value) {
c_avl_node_t *n;
if ((iter == NULL) || (key == NULL) || (value == NULL))
if (iter->node == NULL) {
for (n = iter->tree->root; n != NULL; n = n->left)
if (iter->node == NULL) {
for (n = iter->tree->root; n != NULL; n = n->left)
iter->node = n;
*key = n->key;
*value = n->value;
iter->node = n;
*key = n->key;
*value = n->value;
} /* int c_avl_iterator_next */
int c_avl_iterator_prev(c_avl_iterator_t *iter, void **key, void **value) {
c_avl_node_t *n;
if ((iter == NULL) || (key == NULL) || (value == NULL))
} /* int c_avl_iterator_next */
int c_avl_iterator_prev(c_avl_iterator_t *iter, void **key, void **value) {
c_avl_node_t *n;
if ((iter == NULL) || (key == NULL) || (value == NULL))
if (iter->node == NULL) {
for (n = iter->tree->root; n != NULL; n = n->left)
if (iter->node == NULL) {
for (n = iter->tree->root; n != NULL; n = n->left)
iter->node = n;
*key = n->key;
*value = n->value;
iter->node = n;
*key = n->key;
*value = n->value;
} /* int c_avl_iterator_prev */
void c_avl_iterator_destroy(c_avl_iterator_t *iter) { free(iter); }
int c_avl_size(c_avl_tree_t *t) {
if (t == NULL)
} /* int c_avl_iterator_prev */
void c_avl_iterator_destroy(c_avl_iterator_t *iter) { free(iter); }
int c_avl_size(c_avl_tree_t *t) {
if (t == NULL)
- return (0);
- return (t->size);
+ return 0;
+ return t->size;
assert(v1 != NULL);
compare_total_count++;
assert(v1 != NULL);
compare_total_count++;
- return (strcmp(v0, v1));
#if COLLECT_DEBUG
assert((a != NULL) && (b != NULL));
#endif
#if COLLECT_DEBUG
assert((a != NULL) && (b != NULL));
#endif
- return (strcmp(a->name, b->name));
+ return strcmp(a->name, b->name);
} /* int cache_compare */
static cache_entry_t *cache_alloc(size_t values_num) {
} /* int cache_compare */
static cache_entry_t *cache_alloc(size_t values_num) {
ce = calloc(1, sizeof(*ce));
if (ce == NULL) {
ERROR("utils_cache: cache_alloc: calloc failed.");
ce = calloc(1, sizeof(*ce));
if (ce == NULL) {
ERROR("utils_cache: cache_alloc: calloc failed.");
}
ce->values_num = values_num;
}
ce->values_num = values_num;
sfree(ce->values_raw);
sfree(ce);
ERROR("utils_cache: cache_alloc: calloc failed.");
sfree(ce->values_raw);
sfree(ce);
ERROR("utils_cache: cache_alloc: calloc failed.");
}
ce->history = NULL;
ce->history_length = 0;
ce->meta = NULL;
}
ce->history = NULL;
ce->history_length = 0;
ce->meta = NULL;
} /* cache_entry_t *cache_alloc */
static void cache_free(cache_entry_t *ce) {
} /* cache_entry_t *cache_alloc */
static void cache_free(cache_entry_t *ce) {
key_copy = strdup(key);
if (key_copy == NULL) {
ERROR("uc_insert: strdup failed.");
key_copy = strdup(key);
if (key_copy == NULL) {
ERROR("uc_insert: strdup failed.");
}
ce = cache_alloc(ds->ds_num);
if (ce == NULL) {
sfree(key_copy);
ERROR("uc_insert: cache_alloc (%zu) failed.", ds->ds_num);
}
ce = cache_alloc(ds->ds_num);
if (ce == NULL) {
sfree(key_copy);
ERROR("uc_insert: cache_alloc (%zu) failed.", ds->ds_num);
}
sstrncpy(ce->name, key, sizeof(ce->name));
}
sstrncpy(ce->name, key, sizeof(ce->name));
ds->ds[i].type);
sfree(key_copy);
cache_free(ce);
ds->ds[i].type);
sfree(key_copy);
cache_free(ce);
} /* switch (ds->ds[i].type) */
} /* for (i) */
} /* switch (ds->ds[i].type) */
} /* for (i) */
if (c_avl_insert(cache_tree, key_copy, ce) != 0) {
sfree(key_copy);
ERROR("uc_insert: c_avl_insert failed.");
if (c_avl_insert(cache_tree, key_copy, ce) != 0) {
sfree(key_copy);
ERROR("uc_insert: c_avl_insert failed.");
}
DEBUG("uc_insert: Added %s to the cache.", key);
}
DEBUG("uc_insert: Added %s to the cache.", key);
} /* int uc_insert */
int uc_init(void) {
} /* int uc_insert */
int uc_init(void) {
cache_tree =
c_avl_create((int (*)(const void *, const void *))cache_compare);
cache_tree =
c_avl_create((int (*)(const void *, const void *))cache_compare);
} /* int uc_init */
int uc_check_timeout(void) {
} /* int uc_init */
int uc_check_timeout(void) {
if (expired_num == 0) {
sfree(expired);
if (expired_num == 0) {
sfree(expired);
}
/* Call the "missing" callback for each value. Do this before removing the
}
/* Call the "missing" callback for each value. Do this before removing the
pthread_mutex_unlock(&cache_lock);
sfree(expired);
pthread_mutex_unlock(&cache_lock);
sfree(expired);
} /* int uc_check_timeout */
int uc_update(const data_set_t *ds, const value_list_t *vl) {
} /* int uc_check_timeout */
int uc_update(const data_set_t *ds, const value_list_t *vl) {
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_update: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_update: FORMAT_VL failed.");
}
pthread_mutex_lock(&cache_lock);
}
pthread_mutex_lock(&cache_lock);
{
status = uc_insert(ds, vl, name);
pthread_mutex_unlock(&cache_lock);
{
status = uc_insert(ds, vl, name);
pthread_mutex_unlock(&cache_lock);
"last cache update = %.3f;",
name, CDTIME_T_TO_DOUBLE(vl->time),
CDTIME_T_TO_DOUBLE(ce->last_time));
"last cache update = %.3f;",
name, CDTIME_T_TO_DOUBLE(vl->time),
CDTIME_T_TO_DOUBLE(ce->last_time));
}
for (size_t i = 0; i < ds->ds_num; i++) {
}
for (size_t i = 0; i < ds->ds_num; i++) {
pthread_mutex_unlock(&cache_lock);
ERROR("uc_update: Don't know how to handle data source type %i.",
ds->ds[i].type);
pthread_mutex_unlock(&cache_lock);
ERROR("uc_update: Don't know how to handle data source type %i.",
ds->ds[i].type);
} /* switch (ds->ds[i].type) */
DEBUG("uc_update: %s: ds[%zu] = %lf", name, i, ce->values_gauge[i]);
} /* switch (ds->ds[i].type) */
DEBUG("uc_update: %s: ds[%zu] = %lf", name, i, ce->values_gauge[i]);
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int uc_update */
int uc_get_rate_by_name(const char *name, gauge_t **ret_values,
} /* int uc_update */
int uc_get_rate_by_name(const char *name, gauge_t **ret_values,
*ret_values_num = ret_num;
}
*ret_values_num = ret_num;
}
} /* gauge_t *uc_get_rate_by_name */
gauge_t *uc_get_rate(const data_set_t *ds, const value_list_t *vl) {
} /* gauge_t *uc_get_rate_by_name */
gauge_t *uc_get_rate(const data_set_t *ds, const value_list_t *vl) {
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("utils_cache: uc_get_rate: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("utils_cache: uc_get_rate: FORMAT_VL failed.");
}
status = uc_get_rate_by_name(name, &ret, &ret_num);
if (status != 0)
}
status = uc_get_rate_by_name(name, &ret, &ret_num);
if (status != 0)
/* This is important - the caller has no other way of knowing how many
* values are returned. */
/* This is important - the caller has no other way of knowing how many
* values are returned. */
"but uc_get_rate_by_name returned %zu.",
ds->type, ds->ds_num, ret_num);
sfree(ret);
"but uc_get_rate_by_name returned %zu.",
ds->type, ds->ds_num, ret_num);
sfree(ret);
} /* gauge_t *uc_get_rate */
size_t uc_get_size(void) {
} /* gauge_t *uc_get_rate */
size_t uc_get_size(void) {
size_arrays = (size_t)c_avl_size(cache_tree);
pthread_mutex_unlock(&cache_lock);
size_arrays = (size_t)c_avl_size(cache_tree);
pthread_mutex_unlock(&cache_lock);
}
int uc_get_names(char ***ret_names, cdtime_t **ret_times, size_t *ret_number) {
}
int uc_get_names(char ***ret_names, cdtime_t **ret_times, size_t *ret_number) {
int status = 0;
if ((ret_names == NULL) || (ret_number == NULL))
int status = 0;
if ((ret_names == NULL) || (ret_number == NULL))
pthread_mutex_lock(&cache_lock);
pthread_mutex_lock(&cache_lock);
/* Handle the "no values" case here, to avoid the error message when
* calloc() returns NULL. */
pthread_mutex_unlock(&cache_lock);
/* Handle the "no values" case here, to avoid the error message when
* calloc() returns NULL. */
pthread_mutex_unlock(&cache_lock);
}
names = calloc(size_arrays, sizeof(*names));
}
names = calloc(size_arrays, sizeof(*names));
sfree(names);
sfree(times);
pthread_mutex_unlock(&cache_lock);
sfree(names);
sfree(times);
pthread_mutex_unlock(&cache_lock);
}
iter = c_avl_get_iterator(cache_tree);
}
iter = c_avl_get_iterator(cache_tree);
sfree(names);
sfree(times);
sfree(names);
sfree(times);
sfree(times);
*ret_number = number;
sfree(times);
*ret_number = number;
} /* int uc_get_names */
int uc_get_state(const data_set_t *ds, const value_list_t *vl) {
} /* int uc_get_names */
int uc_get_state(const data_set_t *ds, const value_list_t *vl) {
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_get_state: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_get_state: FORMAT_VL failed.");
}
pthread_mutex_lock(&cache_lock);
}
pthread_mutex_lock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int uc_get_state */
int uc_set_state(const data_set_t *ds, const value_list_t *vl, int state) {
} /* int uc_get_state */
int uc_set_state(const data_set_t *ds, const value_list_t *vl, int state) {
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_set_state: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_set_state: FORMAT_VL failed.");
}
pthread_mutex_lock(&cache_lock);
}
pthread_mutex_lock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int uc_set_state */
int uc_get_history_by_name(const char *name, gauge_t *ret_history,
} /* int uc_set_state */
int uc_get_history_by_name(const char *name, gauge_t *ret_history,
status = c_avl_get(cache_tree, name, (void *)&ce);
if (status != 0) {
pthread_mutex_unlock(&cache_lock);
status = c_avl_get(cache_tree, name, (void *)&ce);
if (status != 0) {
pthread_mutex_unlock(&cache_lock);
}
if (((size_t)ce->values_num) != num_ds) {
pthread_mutex_unlock(&cache_lock);
}
if (((size_t)ce->values_num) != num_ds) {
pthread_mutex_unlock(&cache_lock);
}
/* Check if there are enough values available. If not, increase the buffer
}
/* Check if there are enough values available. If not, increase the buffer
realloc(ce->history, sizeof(*ce->history) * num_steps * ce->values_num);
if (tmp == NULL) {
pthread_mutex_unlock(&cache_lock);
realloc(ce->history, sizeof(*ce->history) * num_steps * ce->values_num);
if (tmp == NULL) {
pthread_mutex_unlock(&cache_lock);
}
for (size_t i = ce->history_length * ce->values_num;
}
for (size_t i = ce->history_length * ce->values_num;
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int uc_get_history_by_name */
int uc_get_history(const data_set_t *ds, const value_list_t *vl,
} /* int uc_get_history_by_name */
int uc_get_history(const data_set_t *ds, const value_list_t *vl,
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("utils_cache: uc_get_history: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("utils_cache: uc_get_history: FORMAT_VL failed.");
- return (uc_get_history_by_name(name, ret_history, num_steps, num_ds));
+ return uc_get_history_by_name(name, ret_history, num_steps, num_ds);
} /* int uc_get_history */
int uc_get_hits(const data_set_t *ds, const value_list_t *vl) {
} /* int uc_get_history */
int uc_get_hits(const data_set_t *ds, const value_list_t *vl) {
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_get_hits: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_get_hits: FORMAT_VL failed.");
}
pthread_mutex_lock(&cache_lock);
}
pthread_mutex_lock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int uc_get_hits */
int uc_set_hits(const data_set_t *ds, const value_list_t *vl, int hits) {
} /* int uc_get_hits */
int uc_set_hits(const data_set_t *ds, const value_list_t *vl, int hits) {
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_set_hits: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_set_hits: FORMAT_VL failed.");
}
pthread_mutex_lock(&cache_lock);
}
pthread_mutex_lock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int uc_set_hits */
int uc_inc_hits(const data_set_t *ds, const value_list_t *vl, int step) {
} /* int uc_set_hits */
int uc_inc_hits(const data_set_t *ds, const value_list_t *vl, int step) {
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_inc_hits: FORMAT_VL failed.");
if (FORMAT_VL(name, sizeof(name), vl) != 0) {
ERROR("uc_inc_hits: FORMAT_VL failed.");
}
pthread_mutex_lock(&cache_lock);
}
pthread_mutex_lock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int uc_inc_hits */
/*
} /* int uc_inc_hits */
/*
iter = (uc_iter_t *)calloc(1, sizeof(*iter));
if (iter == NULL)
iter = (uc_iter_t *)calloc(1, sizeof(*iter));
if (iter == NULL)
pthread_mutex_lock(&cache_lock);
iter->iter = c_avl_get_iterator(cache_tree);
if (iter->iter == NULL) {
free(iter);
pthread_mutex_lock(&cache_lock);
iter->iter = c_avl_get_iterator(cache_tree);
if (iter->iter == NULL) {
free(iter);
} /* uc_iter_t *uc_get_iterator */
int uc_iterator_next(uc_iter_t *iter, char **ret_name) {
int status;
if (iter == NULL)
} /* uc_iter_t *uc_get_iterator */
int uc_iterator_next(uc_iter_t *iter, char **ret_name) {
int status;
if (iter == NULL)
while ((status = c_avl_iterator_next(iter->iter, (void *)&iter->name,
(void *)&iter->entry)) == 0) {
while ((status = c_avl_iterator_next(iter->iter, (void *)&iter->name,
(void *)&iter->entry)) == 0) {
if (status != 0) {
iter->name = NULL;
iter->entry = NULL;
if (status != 0) {
iter->name = NULL;
iter->entry = NULL;
}
if (ret_name != NULL)
*ret_name = iter->name;
}
if (ret_name != NULL)
*ret_name = iter->name;
} /* int uc_iterator_next */
void uc_iterator_destroy(uc_iter_t *iter) {
} /* int uc_iterator_next */
void uc_iterator_destroy(uc_iter_t *iter) {
int uc_iterator_get_time(uc_iter_t *iter, cdtime_t *ret_time) {
if ((iter == NULL) || (iter->entry == NULL) || (ret_time == NULL))
int uc_iterator_get_time(uc_iter_t *iter, cdtime_t *ret_time) {
if ((iter == NULL) || (iter->entry == NULL) || (ret_time == NULL))
*ret_time = iter->entry->last_time;
*ret_time = iter->entry->last_time;
} /* int uc_iterator_get_name */
int uc_iterator_get_values(uc_iter_t *iter, value_t **ret_values,
size_t *ret_num) {
if ((iter == NULL) || (iter->entry == NULL) || (ret_values == NULL) ||
(ret_num == NULL))
} /* int uc_iterator_get_name */
int uc_iterator_get_values(uc_iter_t *iter, value_t **ret_values,
size_t *ret_num) {
if ((iter == NULL) || (iter->entry == NULL) || (ret_values == NULL) ||
(ret_num == NULL))
*ret_values =
calloc(iter->entry->values_num, sizeof(*iter->entry->values_raw));
if (*ret_values == NULL)
*ret_values =
calloc(iter->entry->values_num, sizeof(*iter->entry->values_raw));
if (*ret_values == NULL)
for (size_t i = 0; i < iter->entry->values_num; ++i)
*ret_values[i] = iter->entry->values_raw[i];
*ret_num = iter->entry->values_num;
for (size_t i = 0; i < iter->entry->values_num; ++i)
*ret_values[i] = iter->entry->values_raw[i];
*ret_num = iter->entry->values_num;
} /* int uc_iterator_get_values */
int uc_iterator_get_interval(uc_iter_t *iter, cdtime_t *ret_interval) {
if ((iter == NULL) || (iter->entry == NULL) || (ret_interval == NULL))
} /* int uc_iterator_get_values */
int uc_iterator_get_interval(uc_iter_t *iter, cdtime_t *ret_interval) {
if ((iter == NULL) || (iter->entry == NULL) || (ret_interval == NULL))
*ret_interval = iter->entry->interval;
*ret_interval = iter->entry->interval;
} /* int uc_iterator_get_name */
/*
} /* int uc_iterator_get_name */
/*
status = FORMAT_VL(name, sizeof(name), vl);
if (status != 0) {
ERROR("utils_cache: uc_get_meta: FORMAT_VL failed.");
status = FORMAT_VL(name, sizeof(name), vl);
if (status != 0) {
ERROR("utils_cache: uc_get_meta: FORMAT_VL failed.");
}
pthread_mutex_lock(&cache_lock);
}
pthread_mutex_lock(&cache_lock);
status = c_avl_get(cache_tree, name, (void *)&ce);
if (status != 0) {
pthread_mutex_unlock(&cache_lock);
status = c_avl_get(cache_tree, name, (void *)&ce);
if (status != 0) {
pthread_mutex_unlock(&cache_lock);
if (ce->meta == NULL)
pthread_mutex_unlock(&cache_lock);
if (ce->meta == NULL)
pthread_mutex_unlock(&cache_lock);
} /* }}} meta_data_t *uc_get_meta */
/* Sorry about this preprocessor magic, but it really makes this file much
} /* }}} meta_data_t *uc_get_meta */
/* Sorry about this preprocessor magic, but it really makes this file much
int status; \
meta = uc_get_meta(vl); \
if (meta == NULL) \
int status; \
meta = uc_get_meta(vl); \
if (meta == NULL) \
status = wrap_function(meta, key); \
pthread_mutex_unlock(&cache_lock); \
status = wrap_function(meta, key); \
pthread_mutex_unlock(&cache_lock); \
}
int uc_meta_data_exists(const value_list_t *vl,
const char *key) UC_WRAP(meta_data_exists)
}
int uc_meta_data_exists(const value_list_t *vl,
const char *key) UC_WRAP(meta_data_exists)
int status; \
meta = uc_get_meta(vl); \
if (meta == NULL) \
int status; \
meta = uc_get_meta(vl); \
if (meta == NULL) \
status = wrap_function(meta, key, value); \
pthread_mutex_unlock(&cache_lock); \
status = wrap_function(meta, key, value); \
pthread_mutex_unlock(&cache_lock); \
}
int uc_meta_data_add_string(const value_list_t *vl, const char *key,
const char *value)
}
int uc_meta_data_add_string(const value_list_t *vl, const char *key,
const char *value)
gauge_t *uc_get_rate(__attribute__((unused)) data_set_t const *ds,
__attribute__((unused)) value_list_t const *vl) {
errno = ENOTSUP;
gauge_t *uc_get_rate(__attribute__((unused)) data_set_t const *ds,
__attribute__((unused)) value_list_t const *vl) {
errno = ENOTSUP;
}
int uc_get_rate_by_name(const char *name, gauge_t **ret_values,
size_t *ret_values_num) {
}
int uc_get_rate_by_name(const char *name, gauge_t **ret_values,
size_t *ret_values_num) {
}
int uc_get_names(char ***ret_names, cdtime_t **ret_times, size_t *ret_number) {
}
int uc_get_names(char ***ret_names, cdtime_t **ret_times, size_t *ret_number) {
c_heap_t *h;
if (compare == NULL)
c_heap_t *h;
if (compare == NULL)
h = calloc(1, sizeof(*h));
if (h == NULL)
h = calloc(1, sizeof(*h));
if (h == NULL)
pthread_mutex_init(&h->lock, /* attr = */ NULL);
h->compare = compare;
pthread_mutex_init(&h->lock, /* attr = */ NULL);
h->compare = compare;
h->list_len = 0;
h->list_size = 0;
h->list_len = 0;
h->list_size = 0;
} /* c_heap_t *c_heap_create */
void c_heap_destroy(c_heap_t *h) {
} /* c_heap_t *c_heap_create */
void c_heap_destroy(c_heap_t *h) {
size_t index;
if ((h == NULL) || (ptr == NULL))
size_t index;
if ((h == NULL) || (ptr == NULL))
pthread_mutex_lock(&h->lock);
pthread_mutex_lock(&h->lock);
tmp = realloc(h->list, (h->list_size + 16) * sizeof(*h->list));
if (tmp == NULL) {
pthread_mutex_unlock(&h->lock);
tmp = realloc(h->list, (h->list_size + 16) * sizeof(*h->list));
if (tmp == NULL) {
pthread_mutex_unlock(&h->lock);
reheap(h, /* parent of this node = */ (index - 1) / 2, DIR_UP);
pthread_mutex_unlock(&h->lock);
reheap(h, /* parent of this node = */ (index - 1) / 2, DIR_UP);
pthread_mutex_unlock(&h->lock);
} /* int c_heap_insert */
void *c_heap_get_root(c_heap_t *h) {
void *ret = NULL;
if (h == NULL)
} /* int c_heap_insert */
void *c_heap_get_root(c_heap_t *h) {
void *ret = NULL;
if (h == NULL)
pthread_mutex_lock(&h->lock);
if (h->list_len == 0) {
pthread_mutex_unlock(&h->lock);
pthread_mutex_lock(&h->lock);
if (h->list_len == 0) {
pthread_mutex_unlock(&h->lock);
} else if (h->list_len == 1) {
ret = h->list[0];
h->list[0] = NULL;
} else if (h->list_len == 1) {
ret = h->list[0];
h->list[0] = NULL;
pthread_mutex_unlock(&h->lock);
pthread_mutex_unlock(&h->lock);
} /* void *c_heap_get_root */
} /* void *c_heap_get_root */
ret = calloc(1, sizeof(*ret));
if (ret == NULL)
ret = calloc(1, sizeof(*ret));
if (ret == NULL)
}
void llist_destroy(llist_t *l) {
}
void llist_destroy(llist_t *l) {
}
void llentry_destroy(llentry_t *e) { free(e); }
}
void llentry_destroy(llentry_t *e) { free(e); }
-int llist_size(llist_t *l) { return (l ? l->size : 0); }
+int llist_size(llist_t *l) { return l ? l->size : 0; }
static int llist_strcmp(llentry_t *e, void *ud) {
if ((e == NULL) || (ud == NULL))
static int llist_strcmp(llentry_t *e, void *ud) {
if ((e == NULL) || (ud == NULL))
- return (-1);
- return (strcmp(e->key, (const char *)ud));
+ return -1;
+ return strcmp(e->key, (const char *)ud);
}
llentry_t *llist_search(llist_t *l, const char *key) {
}
llentry_t *llist_search(llist_t *l, const char *key) {
- return (llist_search_custom(l, llist_strcmp, (void *)key));
+ return llist_search_custom(l, llist_strcmp, (void *)key);
}
llentry_t *llist_search_custom(llist_t *l, int (*compare)(llentry_t *, void *),
}
llentry_t *llist_search_custom(llist_t *l, int (*compare)(llentry_t *, void *),
llentry_t *e;
if (l == NULL)
llentry_t *e;
if (l == NULL)
e = l->head;
while (e != NULL) {
e = l->head;
while (e != NULL) {
}
llentry_t *llist_head(llist_t *l) {
if (l == NULL)
}
llentry_t *llist_head(llist_t *l) {
if (l == NULL)
- return (NULL);
- return (l->head);
+ return NULL;
+ return l->head;
}
llentry_t *llist_tail(llist_t *l) {
if (l == NULL)
}
llentry_t *llist_tail(llist_t *l) {
if (l == NULL)
- return (NULL);
- return (l->tail);
+ return NULL;
+ return l->tail;
r = erand48(seed);
pthread_mutex_unlock(&lock);
r = erand48(seed);
pthread_mutex_unlock(&lock);
}
uint32_t cdrand_u(void) {
}
uint32_t cdrand_u(void) {
r = (long)(0.5 + (cdrand_d() * range));
r += min;
r = (long)(0.5 + (cdrand_d() * range));
r += min;
if ((buf == NULL) || (string == NULL) || (needle == NULL) ||
(replacement == NULL))
if ((buf == NULL) || (string == NULL) || (needle == NULL) ||
(replacement == NULL))
needle_len = strlen(needle);
sstrncpy(buf, string, buflen);
needle_len = strlen(needle);
sstrncpy(buf, string, buflen);
i, string, needle, replacement);
}
i, string, needle, replacement);
}
} /* char *subst_string */
} /* char *subst_string */
name[sizeof(name) - 1] = '\0';
if (c_avl_get(threshold_tree, name, (void *)&th) == 0)
name[sizeof(name) - 1] = '\0';
if (c_avl_get(threshold_tree, name, (void *)&th) == 0)
} /* }}} threshold_t *threshold_get */
/*
} /* }}} threshold_t *threshold_get */
/*
if ((th = threshold_get(vl->host, vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance)) != NULL)
if ((th = threshold_get(vl->host, vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get(vl->host, vl->plugin, vl->plugin_instance,
vl->type, NULL)) != NULL)
else if ((th = threshold_get(vl->host, vl->plugin, vl->plugin_instance,
vl->type, NULL)) != NULL)
else if ((th = threshold_get(vl->host, vl->plugin, NULL, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get(vl->host, vl->plugin, NULL, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get(vl->host, vl->plugin, NULL, vl->type, NULL)) !=
NULL)
else if ((th = threshold_get(vl->host, vl->plugin, NULL, vl->type, NULL)) !=
NULL)
else if ((th = threshold_get(vl->host, "", NULL, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get(vl->host, "", NULL, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get(vl->host, "", NULL, vl->type, NULL)) != NULL)
else if ((th = threshold_get(vl->host, "", NULL, vl->type, NULL)) != NULL)
else if ((th = threshold_get("", vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get("", vl->plugin, vl->plugin_instance, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get("", vl->plugin, vl->plugin_instance, vl->type,
NULL)) != NULL)
else if ((th = threshold_get("", vl->plugin, vl->plugin_instance, vl->type,
NULL)) != NULL)
else if ((th = threshold_get("", vl->plugin, NULL, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get("", vl->plugin, NULL, vl->type,
vl->type_instance)) != NULL)
else if ((th = threshold_get("", vl->plugin, NULL, vl->type, NULL)) != NULL)
else if ((th = threshold_get("", vl->plugin, NULL, vl->type, NULL)) != NULL)
else if ((th = threshold_get("", "", NULL, vl->type, vl->type_instance)) !=
NULL)
else if ((th = threshold_get("", "", NULL, vl->type, vl->type_instance)) !=
NULL)
else if ((th = threshold_get("", "", NULL, vl->type, NULL)) != NULL)
else if ((th = threshold_get("", "", NULL, vl->type, NULL)) != NULL)
} /* }}} threshold_t *threshold_search */
int ut_search_threshold(const value_list_t *vl, /* {{{ */
} /* }}} threshold_t *threshold_search */
int ut_search_threshold(const value_list_t *vl, /* {{{ */
threshold_t *t;
if (vl == NULL)
threshold_t *t;
if (vl == NULL)
/* Is this lock really necessary? */
pthread_mutex_lock(&threshold_lock);
t = threshold_search(vl);
if (t == NULL) {
pthread_mutex_unlock(&threshold_lock);
/* Is this lock really necessary? */
pthread_mutex_lock(&threshold_lock);
t = threshold_search(vl);
if (t == NULL) {
pthread_mutex_unlock(&threshold_lock);
}
memcpy(ret_threshold, t, sizeof(*ret_threshold));
}
memcpy(ret_threshold, t, sizeof(*ret_threshold));
ret_threshold->next = NULL;
ret_threshold->next = NULL;
} /* }}} int ut_search_threshold */
} /* }}} int ut_search_threshold */
if (conn == NULL) {
sstrncpy(buffer, "connection is NULL", buffer_size);
if (conn == NULL) {
sstrncpy(buffer, "connection is NULL", buffer_size);
ssnprintf(buffer, buffer_size, "dbi_conn_error failed with status %i",
status);
ssnprintf(buffer, buffer_size, "dbi_conn_error failed with status %i",
status);
} /* }}} const char *cdbi_conn_error */
static int cdbi_result_get_field(dbi_result res, /* {{{ */
} /* }}} const char *cdbi_conn_error */
static int cdbi_result_get_field(dbi_result res, /* {{{ */
if (src_type == DBI_TYPE_ERROR) {
ERROR("dbi plugin: cdbi_result_get: "
"dbi_result_get_field_type_idx failed.");
if (src_type == DBI_TYPE_ERROR) {
ERROR("dbi plugin: cdbi_result_get: "
"dbi_result_get_field_type_idx failed.");
}
if (src_type == DBI_TYPE_INTEGER) {
}
if (src_type == DBI_TYPE_INTEGER) {
if (value == NULL)
sstrncpy(buffer, "", buffer_size);
else if (strcmp("ERROR", value) == 0)
if (value == NULL)
sstrncpy(buffer, "", buffer_size);
else if (strcmp("ERROR", value) == 0)
else
sstrncpy(buffer, value, buffer_size);
}
else
sstrncpy(buffer, value, buffer_size);
}
ERROR("dbi plugin: Column `%s': Don't know how to handle "
"source type %hu.",
field_name, src_type);
ERROR("dbi plugin: Column `%s': Don't know how to handle "
"source type %hu.",
field_name, src_type);
} /* }}} int cdbi_result_get_field */
static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
} /* }}} int cdbi_result_get_field */
static void cdbi_database_free(cdbi_database_t *db) /* {{{ */
(ci->values[1].type != OCONFIG_TYPE_NUMBER))) {
WARNING("dbi plugin: The `DriverOption' config option "
"needs exactly two arguments.");
(ci->values[1].type != OCONFIG_TYPE_NUMBER))) {
WARNING("dbi plugin: The `DriverOption' config option "
"needs exactly two arguments.");
}
option = realloc(db->driver_options,
sizeof(*option) * (db->driver_options_num + 1));
if (option == NULL) {
ERROR("dbi plugin: realloc failed");
}
option = realloc(db->driver_options,
sizeof(*option) * (db->driver_options_num + 1));
if (option == NULL) {
ERROR("dbi plugin: realloc failed");
}
db->driver_options = option;
}
db->driver_options = option;
option->key = strdup(ci->values[0].value.string);
if (option->key == NULL) {
ERROR("dbi plugin: strdup failed.");
option->key = strdup(ci->values[0].value.string);
if (option->key == NULL) {
ERROR("dbi plugin: strdup failed.");
}
if (ci->values[1].type == OCONFIG_TYPE_STRING) {
}
if (ci->values[1].type == OCONFIG_TYPE_STRING) {
if (option->value.string == NULL) {
ERROR("dbi plugin: strdup failed.");
sfree(option->key);
if (option->value.string == NULL) {
ERROR("dbi plugin: strdup failed.");
sfree(option->key);
}
} else {
assert(ci->values[1].type == OCONFIG_TYPE_NUMBER);
}
} else {
assert(ci->values[1].type == OCONFIG_TYPE_NUMBER);
}
db->driver_options_num++;
}
db->driver_options_num++;
} /* }}} int cdbi_config_add_database_driver_option */
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
} /* }}} int cdbi_config_add_database_driver_option */
static int cdbi_config_add_database(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("dbi plugin: The `Database' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("dbi plugin: The `Database' block "
"needs exactly one string argument.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("dbi plugin: calloc failed.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("dbi plugin: calloc failed.");
}
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
}
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
}
/* Fill the `cdbi_database_t' structure.. */
}
/* Fill the `cdbi_database_t' structure.. */
if (status != 0) {
cdbi_database_free(db);
if (status != 0) {
cdbi_database_free(db);
} /* }}} int cdbi_config_add_database */
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int cdbi_config_add_database */
static int cdbi_config(oconfig_item_t *ci) /* {{{ */
}
} /* for (ci->children) */
}
} /* for (ci->children) */
} /* }}} int cdbi_config */
/* }}} End of configuration handling functions */
} /* }}} int cdbi_config */
/* }}} End of configuration handling functions */
int status;
if (did_init != 0)
int status;
if (did_init != 0)
if (queries_num == 0) {
ERROR("dbi plugin: No <Query> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
if (queries_num == 0) {
ERROR("dbi plugin: No <Query> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
}
if (databases_num == 0) {
ERROR("dbi plugin: No <Database> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
}
if (databases_num == 0) {
ERROR("dbi plugin: No <Database> blocks have been found. Without them, "
"this plugin can't do anything useful, so we will return an error.");
}
status = dbi_initialize_r(/* driverdir = */ NULL, &dbi_instance);
if (status < 0) {
ERROR("dbi plugin: cdbi_init: dbi_initialize_r failed with status %i.",
status);
}
status = dbi_initialize_r(/* driverdir = */ NULL, &dbi_instance);
if (status < 0) {
ERROR("dbi plugin: cdbi_init: dbi_initialize_r failed with status %i.",
status);
} else if (status == 0) {
ERROR("dbi plugin: `dbi_initialize_r' could not load any drivers. Please "
"install at least one `DBD' or check your installation.");
} else if (status == 0) {
ERROR("dbi plugin: `dbi_initialize_r' could not load any drivers. Please "
"install at least one `DBD' or check your installation.");
}
DEBUG("dbi plugin: cdbi_init: dbi_initialize_r reports %i driver%s.", status,
(status == 1) ? "" : "s");
}
DEBUG("dbi plugin: cdbi_init: dbi_initialize_r reports %i driver%s.", status,
(status == 1) ? "" : "s");
} /* }}} int cdbi_init */
static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
} /* }}} int cdbi_init */
static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */
if (db->connection != NULL) {
status = dbi_conn_ping(db->connection);
if (status != 0) /* connection is alive */
if (db->connection != NULL) {
status = dbi_conn_ping(db->connection);
if (status != 0) /* connection is alive */
dbi_conn_close(db->connection);
db->connection = NULL;
dbi_conn_close(db->connection);
db->connection = NULL;
driver = dbi_driver_list_r(driver, dbi_instance)) {
INFO("dbi plugin: * %s", dbi_driver_get_name(driver));
}
driver = dbi_driver_list_r(driver, dbi_instance)) {
INFO("dbi plugin: * %s", dbi_driver_get_name(driver));
}
}
connection = dbi_conn_open(driver);
if (connection == NULL) {
ERROR("dbi plugin: cdbi_connect_database: dbi_conn_open (%s) failed.",
db->driver);
}
connection = dbi_conn_open(driver);
if (connection == NULL) {
ERROR("dbi plugin: cdbi_connect_database: dbi_conn_open (%s) failed.",
db->driver);
}
/* Set all the driver options. Because this is a very very very generic
}
/* Set all the driver options. Because this is a very very very generic
}
dbi_conn_close(connection);
}
dbi_conn_close(connection);
}
} /* for (i = 0; i < db->driver_options_num; i++) */
}
} /* for (i = 0; i < db->driver_options_num; i++) */
"dbi_conn_connect failed: %s",
db->name, cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
"dbi_conn_connect failed: %s",
db->name, cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
}
if (db->select_db != NULL) {
}
if (db->select_db != NULL) {
db->name, db->select_db,
cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
db->name, db->select_db,
cdbi_strerror(connection, errbuf, sizeof(errbuf)));
dbi_conn_close(connection);
}
}
db->connection = connection;
}
}
db->connection = connection;
} /* }}} int cdbi_connect_database */
static int cdbi_read_database(user_data_t *ud) /* {{{ */
} /* }}} int cdbi_connect_database */
static int cdbi_read_database(user_data_t *ud) /* {{{ */
status = cdbi_connect_database(db);
if (status != 0)
status = cdbi_connect_database(db);
if (status != 0)
assert(db->connection != NULL);
db_version = dbi_conn_get_engine_version(db->connection);
assert(db->connection != NULL);
db_version = dbi_conn_get_engine_version(db->connection);
if (success == 0) {
ERROR("dbi plugin: All queries failed for database `%s'.", db->name);
if (success == 0) {
ERROR("dbi plugin: All queries failed for database `%s'.", db->name);
} /* }}} int cdbi_read_database */
static int cdbi_shutdown(void) /* {{{ */
} /* }}} int cdbi_read_database */
static int cdbi_shutdown(void) /* {{{ */
queries = NULL;
queries_num = 0;
queries = NULL;
queries_num = 0;
} /* }}} int cdbi_shutdown */
void module_register(void) /* {{{ */
} /* }}} int cdbi_shutdown */
void module_register(void) /* {{{ */
if (il_fstype == NULL)
il_fstype = ignorelist_create(1);
if (il_fstype == NULL)
il_fstype = ignorelist_create(1);
}
static int df_config(const char *key, const char *value) {
}
static int df_config(const char *key, const char *value) {
if (strcasecmp(key, "Device") == 0) {
if (ignorelist_add(il_device, value))
if (strcasecmp(key, "Device") == 0) {
if (ignorelist_add(il_device, value))
- return (1);
- return (0);
} else if (strcasecmp(key, "MountPoint") == 0) {
if (ignorelist_add(il_mountpoint, value))
} else if (strcasecmp(key, "MountPoint") == 0) {
if (ignorelist_add(il_mountpoint, value))
- return (1);
- return (0);
} else if (strcasecmp(key, "FSType") == 0) {
if (ignorelist_add(il_fstype, value))
} else if (strcasecmp(key, "FSType") == 0) {
if (ignorelist_add(il_fstype, value))
- return (1);
- return (0);
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
if (IS_TRUE(value)) {
ignorelist_set_invert(il_device, 0);
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
if (IS_TRUE(value)) {
ignorelist_set_invert(il_device, 0);
ignorelist_set_invert(il_mountpoint, 1);
ignorelist_set_invert(il_fstype, 1);
}
ignorelist_set_invert(il_mountpoint, 1);
ignorelist_set_invert(il_fstype, 1);
}
} else if (strcasecmp(key, "ReportByDevice") == 0) {
if (IS_TRUE(value))
by_device = 1;
} else if (strcasecmp(key, "ReportByDevice") == 0) {
if (IS_TRUE(value))
by_device = 1;
} else if (strcasecmp(key, "ReportInodes") == 0) {
if (IS_TRUE(value))
report_inodes = 1;
else
report_inodes = 0;
} else if (strcasecmp(key, "ReportInodes") == 0) {
if (IS_TRUE(value))
report_inodes = 1;
else
report_inodes = 0;
} else if (strcasecmp(key, "ValuesAbsolute") == 0) {
if (IS_TRUE(value))
values_absolute = 1;
else
values_absolute = 0;
} else if (strcasecmp(key, "ValuesAbsolute") == 0) {
if (IS_TRUE(value))
values_absolute = 1;
else
values_absolute = 0;
} else if (strcasecmp(key, "ValuesPercentage") == 0) {
if (IS_TRUE(value))
values_percentage = 1;
else
values_percentage = 0;
} else if (strcasecmp(key, "ValuesPercentage") == 0) {
if (IS_TRUE(value))
values_percentage = 1;
else
values_percentage = 0;
}
__attribute__((nonnull(2))) static void df_submit_one(char *plugin_instance,
}
__attribute__((nonnull(2))) static void df_submit_one(char *plugin_instance,
mnt_list = NULL;
if (cu_mount_getlist(&mnt_list) == NULL) {
ERROR("df plugin: cu_mount_getlist failed.");
mnt_list = NULL;
if (cu_mount_getlist(&mnt_list) == NULL) {
ERROR("df plugin: cu_mount_getlist failed.");
}
for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL;
}
for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL;
df_submit_one(disk_name, "percent_bytes", "used",
(gauge_t)((float_t)(blk_used) / statbuf.f_blocks * 100));
} else
df_submit_one(disk_name, "percent_bytes", "used",
(gauge_t)((float_t)(blk_used) / statbuf.f_blocks * 100));
} else
disk_name, "percent_inodes", "used",
(gauge_t)((float_t)(inode_used) / statbuf.f_files * 100));
} else
disk_name, "percent_inodes", "used",
(gauge_t)((float_t)(inode_used) / statbuf.f_files * 100));
} else
}
if (values_absolute) {
df_submit_one(disk_name, "df_inodes", "free", (gauge_t)inode_free);
}
if (values_absolute) {
df_submit_one(disk_name, "df_inodes", "free", (gauge_t)inode_free);
cu_mount_freelist(mnt_list);
cu_mount_freelist(mnt_list);
} /* int df_read */
void module_register(void) {
} /* int df_read */
void module_register(void) {
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
if (strcasecmp("Disk", key) == 0) {
ignorelist_add(ignorelist, value);
if (strcasecmp("Disk", key) == 0) {
ignorelist_add(ignorelist, value);
conf_udev_name_attr = NULL;
}
if ((conf_udev_name_attr = strdup(value)) == NULL)
conf_udev_name_attr = NULL;
}
if ((conf_udev_name_attr = strdup(value)) == NULL)
#else
WARNING("disk plugin: The \"UdevNameAttr\" option is only supported "
"if collectd is built with libudev support");
#endif
} else {
#else
WARNING("disk plugin: The \"UdevNameAttr\" option is only supported "
"if collectd is built with libudev support");
#endif
} else {
} /* int disk_config */
static int disk_init(void) {
} /* int disk_config */
static int disk_init(void) {
if (status != kIOReturnSuccess) {
ERROR("IOMasterPort failed: %s", mach_error_string(status));
io_master_port = MACH_PORT_NULL;
if (status != kIOReturnSuccess) {
ERROR("IOMasterPort failed: %s", mach_error_string(status));
io_master_port = MACH_PORT_NULL;
}
/* #endif HAVE_IOKIT_IOKITLIB_H */
}
/* #endif HAVE_IOKIT_IOKITLIB_H */
handle_udev = udev_new();
if (handle_udev == NULL) {
ERROR("disk plugin: udev_new() failed!");
handle_udev = udev_new();
if (handle_udev == NULL) {
ERROR("disk plugin: udev_new() failed!");
}
}
#endif /* HAVE_UDEV_H */
}
}
#endif /* HAVE_UDEV_H */
rv = geom_gettree(&geom_tree);
if (rv != 0) {
ERROR("geom_gettree() failed, returned %d", rv);
rv = geom_gettree(&geom_tree);
if (rv != 0) {
ERROR("geom_gettree() failed, returned %d", rv);
}
rv = geom_stats_open();
if (rv != 0) {
ERROR("geom_stats_open() failed, returned %d", rv);
}
rv = geom_stats_open();
if (rv != 0) {
ERROR("geom_stats_open() failed, returned %d", rv);
}
/* #endif KERNEL_FREEBSD */
}
/* #endif KERNEL_FREEBSD */
numdisk = 0;
if (kc == NULL)
numdisk = 0;
if (kc == NULL)
for (numdisk = 0, ksp_chain = kc->kc_chain;
(numdisk < MAX_NUMDISK) && (ksp_chain != NULL);
for (numdisk = 0, ksp_chain = kc->kc_chain;
(numdisk < MAX_NUMDISK) && (ksp_chain != NULL);
}
#endif /* HAVE_LIBKSTAT */
}
#endif /* HAVE_LIBKSTAT */
} /* int disk_init */
static int disk_shutdown(void) {
} /* int disk_init */
static int disk_shutdown(void) {
udev_unref(handle_udev);
#endif /* HAVE_UDEV_H */
#endif /* KERNEL_LINUX */
udev_unref(handle_udev);
#endif /* HAVE_UDEV_H */
#endif /* KERNEL_LINUX */
} /* int disk_shutdown */
static void disk_submit(const char *plugin_instance, const char *type,
} /* int disk_shutdown */
static void disk_submit(const char *plugin_instance, const char *type,
double avg_time = ((double)delta_time) / ((double)delta_ops);
double avg_time_incr = interval * avg_time;
double avg_time = ((double)delta_time) / ((double)delta_ops);
double avg_time_incr = interval * avg_time;
- return ((counter_t)(avg_time_incr + .5));
+ return (counter_t)(avg_time_incr + .5);
kCFStringEncodingASCII);
if (key_obj == NULL) {
DEBUG("CFStringCreateWithCString (%s) failed.", key);
kCFStringEncodingASCII);
if (key_obj == NULL) {
DEBUG("CFStringCreateWithCString (%s) failed.", key);
}
/* get => we don't need to release (== free) the object */
}
/* get => we don't need to release (== free) the object */
if (val_obj == NULL) {
DEBUG("CFDictionaryGetValue (%s) failed.", key);
if (val_obj == NULL) {
DEBUG("CFDictionaryGetValue (%s) failed.", key);
}
if (!CFNumberGetValue(val_obj, kCFNumberSInt64Type, &val_int)) {
DEBUG("CFNumberGetValue (%s) failed.", key);
}
if (!CFNumberGetValue(val_obj, kCFNumberSInt64Type, &val_int)) {
DEBUG("CFNumberGetValue (%s) failed.", key);
}
#endif /* HAVE_IOKIT_IOKITLIB_H */
}
#endif /* HAVE_IOKIT_IOKITLIB_H */
/* Get the list of all disk objects. */
if (IOServiceGetMatchingServices(
/* Get the list of all disk objects. */
if (IOServiceGetMatchingServices(
- io_master_port, IOServiceMatching(kIOBlockStorageDriverClass),
- &disk_list) != kIOReturnSuccess) {
+ io_master_port, IOServiceMatching(kIOBlockStorageDriverClass),
+ &disk_list) != kIOReturnSuccess) {
ERROR("disk plugin: IOServiceGetMatchingServices failed.");
ERROR("disk plugin: IOServiceGetMatchingServices failed.");
}
while ((disk = IOIteratorNext(disk_list)) != 0) {
}
while ((disk = IOIteratorNext(disk_list)) != 0) {
snap = geom_stats_snapshot_get();
if (snap == NULL) {
ERROR("disk plugin: geom_stats_snapshot_get() failed.");
snap = geom_stats_snapshot_get();
if (snap == NULL) {
ERROR("disk plugin: geom_stats_snapshot_get() failed.");
}
/* Check if we have dirty read from this snapshot */
}
/* Check if we have dirty read from this snapshot */
if (geom_gettree(&geom_tree) != 0) {
ERROR("disk plugin: geom_gettree() failed");
geom_stats_snapshot_free(snap);
if (geom_gettree(&geom_tree) != 0) {
ERROR("disk plugin: geom_gettree() failed");
geom_stats_snapshot_free(snap);
}
geom_id = geom_lookupid(&geom_tree, snap_iter->id);
}
}
geom_id = geom_lookupid(&geom_tree, snap_iter->id);
}
fh = fopen("/proc/partitions", "r");
if (fh == NULL) {
ERROR("disk plugin: fopen (/proc/{diskstats,partitions}) failed.");
fh = fopen("/proc/partitions", "r");
if (fh == NULL) {
ERROR("disk plugin: fopen (/proc/{diskstats,partitions}) failed.");
static kstat_io_t kio;
if (kc == NULL)
static kstat_io_t kio;
if (kc == NULL)
for (int i = 0; i < numdisk; i++) {
if (kstat_read(kc, ksp[i], &kio) == -1)
for (int i = 0; i < numdisk; i++) {
if (kstat_read(kc, ksp[i], &kio) == -1)
char name[DATA_MAX_NAME_LEN];
if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
char name[DATA_MAX_NAME_LEN];
if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
for (int counter = 0; counter < disks; counter++) {
strncpy(name, ds->disk_name, sizeof(name));
for (int counter = 0; counter < disks; counter++) {
strncpy(name, ds->disk_name, sizeof(name));
char errbuf[1024];
WARNING("disk plugin: perfstat_disk: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("disk plugin: perfstat_disk: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (numdisk != pnumdisk || stat_disk == NULL) {
}
if (numdisk != pnumdisk || stat_disk == NULL) {
char errbuf[1024];
WARNING("disk plugin: perfstat_disk : %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("disk plugin: perfstat_disk : %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
for (int i = 0; i < rnumdisk; i++) {
}
for (int i = 0; i < rnumdisk; i++) {
}
#endif /* defined(HAVE_PERFSTAT) */
}
#endif /* defined(HAVE_PERFSTAT) */
} /* int disk_read */
void module_register(void) {
} /* int disk_read */
void module_register(void) {
if (entry->key == key)
break;
if (entry->key == key)
break;
}
static counter_list_t *counter_list_create(counter_list_t **list,
}
static counter_list_t *counter_list_create(counter_list_t **list,
entry = calloc(1, sizeof(*entry));
if (entry == NULL)
entry = calloc(1, sizeof(*entry));
if (entry == NULL)
entry->key = key;
entry->value = value;
entry->key = key;
entry->value = value;
}
static void counter_list_add(counter_list_t **list, unsigned int key,
}
static void counter_list_add(counter_list_t **list, unsigned int key,
if (pcap_device != NULL)
free(pcap_device);
if ((pcap_device = strdup(value)) == NULL)
if (pcap_device != NULL)
free(pcap_device);
if ((pcap_device = strdup(value)) == NULL)
} else if (strcasecmp(key, "IgnoreSource") == 0) {
if (value != NULL)
ignore_list_add_name(value);
} else if (strcasecmp(key, "IgnoreSource") == 0) {
if (value != NULL)
ignore_list_add_name(value);
else
select_numeric_qtype = 1;
} else {
else
select_numeric_qtype = 1;
} else {
}
static void dns_child_callback(const rfc1035_header_t *dns) {
}
static void dns_child_callback(const rfc1035_header_t *dns) {
ERROR("dns plugin: Opening interface `%s' "
"failed: %s",
(pcap_device != NULL) ? pcap_device : "any", pcap_error);
ERROR("dns plugin: Opening interface `%s' "
"failed: %s",
(pcap_device != NULL) ? pcap_device : "any", pcap_error);
}
status = pcap_compile(pcap_obj, &fp, "udp port 53", 1, 0);
if (status < 0) {
ERROR("dns plugin: pcap_compile failed: %s", pcap_statustostr(status));
}
status = pcap_compile(pcap_obj, &fp, "udp port 53", 1, 0);
if (status < 0) {
ERROR("dns plugin: pcap_compile failed: %s", pcap_statustostr(status));
}
status = pcap_setfilter(pcap_obj, &fp);
if (status < 0) {
ERROR("dns plugin: pcap_setfilter failed: %s", pcap_statustostr(status));
}
status = pcap_setfilter(pcap_obj, &fp);
if (status < 0) {
ERROR("dns plugin: pcap_setfilter failed: %s", pcap_statustostr(status));
}
DEBUG("dns plugin: PCAP object created.");
}
DEBUG("dns plugin: PCAP object created.");
status = PCAP_ERROR_IFACE_NOT_UP;
pcap_close(pcap_obj);
status = PCAP_ERROR_IFACE_NOT_UP;
pcap_close(pcap_obj);
} /* int dns_run_pcap_loop */
static int dns_sleep_one_interval(void) /* {{{ */
} /* int dns_run_pcap_loop */
static int dns_sleep_one_interval(void) /* {{{ */
if ((errno == EINTR) || (errno == EAGAIN))
continue;
if ((errno == EINTR) || (errno == EAGAIN))
continue;
} /* }}} int dns_sleep_one_interval */
static void *dns_child_loop(__attribute__((unused)) void *dummy) /* {{{ */
} /* }}} int dns_sleep_one_interval */
static void *dns_child_loop(__attribute__((unused)) void *dummy) /* {{{ */
ERROR("dns plugin: PCAP returned error %s.", pcap_statustostr(status));
listen_thread_init = 0;
ERROR("dns plugin: PCAP returned error %s.", pcap_statustostr(status));
listen_thread_init = 0;
} /* }}} void *dns_child_loop */
static int dns_init(void) {
} /* }}} void *dns_child_loop */
static int dns_init(void) {
pthread_mutex_unlock(&traffic_mutex);
if (listen_thread_init != 0)
pthread_mutex_unlock(&traffic_mutex);
if (listen_thread_init != 0)
status = plugin_thread_create(&listen_thread, NULL, dns_child_loop, (void *)0,
"dns listen");
status = plugin_thread_create(&listen_thread, NULL, dns_child_loop, (void *)0,
"dns listen");
char errbuf[1024];
ERROR("dns plugin: pthread_create failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("dns plugin: pthread_create failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
listen_thread_init = 1;
}
listen_thread_init = 1;
} /* int dns_init */
static void submit_derive(const char *type, const char *type_instance,
} /* int dns_init */
static void submit_derive(const char *type, const char *type_instance,
submit_derive("dns_rcode", rcode_str(keys[i]), values[i]);
}
submit_derive("dns_rcode", rcode_str(keys[i]), values[i]);
}
} /* int dns_read */
void module_register(void) {
} /* int dns_read */
void module_register(void) {
}
static int dpdk_stats_get_size(dpdk_helper_ctx_t *phc) {
}
static int dpdk_stats_get_size(dpdk_helper_ctx_t *phc) {
- return (dpdk_helper_data_size_get(phc) - sizeof(dpdk_stats_ctx_t));
+ return dpdk_helper_data_size_get(phc) - sizeof(dpdk_stats_ctx_t);
}
int dpdk_helper_command_handler(dpdk_helper_ctx_t *phc, enum DPDK_CMD cmd) {
}
int dpdk_helper_command_handler(dpdk_helper_ctx_t *phc, enum DPDK_CMD cmd) {
};
static size_t drbd_names_num = STATIC_ARRAY_SIZE(drbd_names);
};
static size_t drbd_names_num = STATIC_ARRAY_SIZE(drbd_names);
-static int drbd_init(void) { return (0); }
+static int drbd_init(void) { return 0; }
static int drbd_submit_fields(long int resource, char **fields,
size_t fields_num) {
static int drbd_submit_fields(long int resource, char **fields,
size_t fields_num) {
if (resource < 0) {
WARNING("drbd plugin: Unable to parse resource");
if (resource < 0) {
WARNING("drbd plugin: Unable to parse resource");
}
if (fields_num != drbd_names_num) {
WARNING("drbd plugin: Wrong number of fields for "
"r%ld statistics. Expected %zu, got %zu.",
resource, drbd_names_num, fields_num);
}
if (fields_num != drbd_names_num) {
WARNING("drbd plugin: Wrong number of fields for "
"r%ld statistics. Expected %zu, got %zu.",
resource, drbd_names_num, fields_num);
}
ssnprintf(plugin_instance, sizeof(plugin_instance), "r%ld", resource);
}
ssnprintf(plugin_instance, sizeof(plugin_instance), "r%ld", resource);
continue;
data = strchr(fields[i], ':');
if (data == NULL)
continue;
data = strchr(fields[i], ':');
if (data == NULL)
(void)parse_value(++data, &values[i], DS_TYPE_DERIVE);
}
(void)parse_value(++data, &values[i], DS_TYPE_DERIVE);
}
plugin_dispatch_values(&vl);
}
plugin_dispatch_values(&vl);
}
} /* drbd_submit_fields */
static int drbd_read(void) {
} /* drbd_submit_fields */
static int drbd_read(void) {
fh = fopen(drbd_stats, "r");
if (fh == NULL) {
WARNING("drbd plugin: Unable to open %s", drbd_stats);
fh = fopen(drbd_stats, "r");
if (fh == NULL) {
WARNING("drbd plugin: Unable to open %s", drbd_stats);
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
} /* while (fgets) */
fclose(fh);
} /* while (fgets) */
fclose(fh);
} /* void drbd_read */
void module_register(void) {
} /* void drbd_read */
void module_register(void) {
} /* while (1) */
pthread_exit((void *)0);
} /* while (1) */
pthread_exit((void *)0);
} /* static void *collect (void *) */
static void *open_connection(void __attribute__((unused)) * arg) {
} /* static void *collect (void *) */
static void *open_connection(void __attribute__((unused)) * arg) {
}
pthread_exit((void *)0);
}
pthread_exit((void *)0);
} /* static void *open_connection (void *) */
static int email_init(void) {
} /* static void *open_connection (void *) */
static int email_init(void) {
disabled = 1;
log_err("plugin_thread_create() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
disabled = 1;
log_err("plugin_thread_create() failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
} /* int email_init */
static void type_list_free(type_list_t *t) {
} /* int email_init */
static void type_list_free(type_list_t *t) {
sfree(sock_file);
sfree(sock_group);
sfree(sock_file);
sfree(sock_group);
} /* static void email_shutdown (void) */
static void email_submit(const char *type, const char *type_instance,
} /* static void email_shutdown (void) */
static void email_submit(const char *type, const char *type_instance,
int score_count_old;
if (disabled)
int score_count_old;
if (disabled)
/* email count */
pthread_mutex_lock(&count_mutex);
/* email count */
pthread_mutex_lock(&count_mutex);
for (type_t *ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next)
email_submit("spam_check", ptr->name, ptr->value);
for (type_t *ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next)
email_submit("spam_check", ptr->name, ptr->value);
} /* int email_read */
void module_register(void) {
} /* int email_read */
void module_register(void) {
value_t v;
if (parse_value_file(ENTROPY_FILE, &v, DS_TYPE_GAUGE) != 0) {
ERROR("entropy plugin: Reading \"" ENTROPY_FILE "\" failed.");
value_t v;
if (parse_value_file(ENTROPY_FILE, &v, DS_TYPE_GAUGE) != 0) {
ERROR("entropy plugin: Reading \"" ENTROPY_FILE "\" failed.");
}
void module_register(void) {
}
void module_register(void) {
tmp = realloc(interfaces, sizeof(*interfaces) * (interfaces_num + 1));
if (tmp == NULL)
tmp = realloc(interfaces, sizeof(*interfaces) * (interfaces_num + 1));
if (tmp == NULL)
interfaces = tmp;
interfaces[interfaces_num] = NULL;
status = cf_util_get_string(ci, interfaces + interfaces_num);
if (status != 0)
interfaces = tmp;
interfaces[interfaces_num] = NULL;
status = cf_util_get_string(ci, interfaces + interfaces_num);
if (status != 0)
interfaces_num++;
INFO("ethstat plugin: Registered interface %s",
interfaces[interfaces_num - 1]);
interfaces_num++;
INFO("ethstat plugin: Registered interface %s",
interfaces[interfaces_num - 1]);
} /* }}} int ethstat_add_interface */
static int ethstat_add_map(const oconfig_item_t *ci) /* {{{ */
} /* }}} int ethstat_add_interface */
static int ethstat_add_map(const oconfig_item_t *ci) /* {{{ */
ERROR("ethstat plugin: The %s option requires "
"two or three string arguments.",
ci->key);
ERROR("ethstat plugin: The %s option requires "
"two or three string arguments.",
ci->key);
}
key = strdup(ci->values[0].value.string);
if (key == NULL) {
ERROR("ethstat plugin: strdup(3) failed.");
}
key = strdup(ci->values[0].value.string);
if (key == NULL) {
ERROR("ethstat plugin: strdup(3) failed.");
}
map = calloc(1, sizeof(*map));
if (map == NULL) {
sfree(key);
ERROR("ethstat plugin: calloc failed.");
}
map = calloc(1, sizeof(*map));
if (map == NULL) {
sfree(key);
ERROR("ethstat plugin: calloc failed.");
}
sstrncpy(map->type, ci->values[1].value.string, sizeof(map->type));
}
sstrncpy(map->type, ci->values[1].value.string, sizeof(map->type));
sfree(map);
sfree(key);
ERROR("ethstat plugin: c_avl_create() failed.");
sfree(map);
sfree(key);
ERROR("ethstat plugin: c_avl_create() failed.");
} /* }}} int ethstat_add_map */
static int ethstat_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int ethstat_add_map */
static int ethstat_config(oconfig_item_t *ci) /* {{{ */
} /* }}} */
static void ethstat_submit_value(const char *device, const char *type_instance,
} /* }}} */
static void ethstat_submit_value(const char *device, const char *type_instance,
ERROR("ethstat plugin: Failed to get driver information "
"from %s: %s",
device, sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("ethstat plugin: Failed to get driver information "
"from %s: %s",
device, sstrerror(errno, errbuf, sizeof(errbuf)));
}
n_stats = (size_t)drvinfo.n_stats;
if (n_stats < 1) {
close(fd);
ERROR("ethstat plugin: No stats available for %s", device);
}
n_stats = (size_t)drvinfo.n_stats;
if (n_stats < 1) {
close(fd);
ERROR("ethstat plugin: No stats available for %s", device);
}
strings_size = sizeof(struct ethtool_gstrings) + (n_stats * ETH_GSTRING_LEN);
}
strings_size = sizeof(struct ethtool_gstrings) + (n_stats * ETH_GSTRING_LEN);
sfree(strings);
sfree(stats);
ERROR("ethstat plugin: malloc failed.");
sfree(strings);
sfree(stats);
ERROR("ethstat plugin: malloc failed.");
}
strings->cmd = ETHTOOL_GSTRINGS;
}
strings->cmd = ETHTOOL_GSTRINGS;
free(stats);
ERROR("ethstat plugin: Cannot get strings from %s: %s", device,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(stats);
ERROR("ethstat plugin: Cannot get strings from %s: %s", device,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
stats->cmd = ETHTOOL_GSTATS;
}
stats->cmd = ETHTOOL_GSTATS;
free(stats);
ERROR("ethstat plugin: Reading statistics from %s failed: %s", device,
sstrerror(errno, errbuf, sizeof(errbuf)));
free(stats);
ERROR("ethstat plugin: Reading statistics from %s failed: %s", device,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
for (size_t i = 0; i < n_stats; i++) {
}
for (size_t i = 0; i < n_stats; i++) {
sfree(strings);
sfree(stats);
sfree(strings);
sfree(stats);
} /* }}} ethstat_read_interface */
static int ethstat_read(void) {
} /* }}} ethstat_read_interface */
static int ethstat_read(void) {
void *value = NULL;
if (value_map == NULL)
void *value = NULL;
if (value_map == NULL)
while (c_avl_pick(value_map, &key, &value) == 0) {
sfree(key);
while (c_avl_pick(value_map, &key, &value) == 0) {
sfree(key);
c_avl_destroy(value_map);
value_map = NULL;
c_avl_destroy(value_map);
value_map = NULL;
}
void module_register(void) {
}
void module_register(void) {
if (ci->children_num != 0) {
WARNING("exec plugin: The config option `%s' may not be a block.", ci->key);
if (ci->children_num != 0) {
WARNING("exec plugin: The config option `%s' may not be a block.", ci->key);
}
if (ci->values_num < 2) {
WARNING("exec plugin: The config option `%s' needs at least two "
"arguments.",
ci->key);
}
if (ci->values_num < 2) {
WARNING("exec plugin: The config option `%s' needs at least two "
"arguments.",
ci->key);
}
if ((ci->values[0].type != OCONFIG_TYPE_STRING) ||
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
WARNING("exec plugin: The first two arguments to the `%s' option must "
"be string arguments.",
ci->key);
}
if ((ci->values[0].type != OCONFIG_TYPE_STRING) ||
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
WARNING("exec plugin: The first two arguments to the `%s' option must "
"be string arguments.",
ci->key);
}
pl = calloc(1, sizeof(*pl));
if (pl == NULL) {
ERROR("exec plugin: calloc failed.");
}
pl = calloc(1, sizeof(*pl));
if (pl == NULL) {
ERROR("exec plugin: calloc failed.");
}
if (strcasecmp("NotificationExec", ci->key) == 0)
}
if (strcasecmp("NotificationExec", ci->key) == 0)
if (pl->user == NULL) {
ERROR("exec plugin: strdup failed.");
sfree(pl);
if (pl->user == NULL) {
ERROR("exec plugin: strdup failed.");
sfree(pl);
}
pl->group = strchr(pl->user, ':');
}
pl->group = strchr(pl->user, ':');
ERROR("exec plugin: strdup failed.");
sfree(pl->user);
sfree(pl);
ERROR("exec plugin: strdup failed.");
sfree(pl->user);
sfree(pl);
}
pl->argv = calloc(ci->values_num, sizeof(*pl->argv));
}
pl->argv = calloc(ci->values_num, sizeof(*pl->argv));
sfree(pl->exec);
sfree(pl->user);
sfree(pl);
sfree(pl->exec);
sfree(pl->user);
sfree(pl);
sfree(pl->exec);
sfree(pl->user);
sfree(pl);
sfree(pl->exec);
sfree(pl->user);
sfree(pl);
}
for (i = 1; i < (ci->values_num - 1); i++) {
}
for (i = 1; i < (ci->values_num - 1); i++) {
sfree(pl->exec);
sfree(pl->user);
sfree(pl);
sfree(pl->exec);
sfree(pl->user);
sfree(pl);
}
for (i = 0; pl->argv[i] != NULL; i++) {
}
for (i = 0; pl->argv[i] != NULL; i++) {
pl->next = pl_head;
pl_head = pl;
pl->next = pl_head;
pl_head = pl;
} /* int exec_config_exec }}} */
static int exec_config(oconfig_item_t *ci) /* {{{ */
} /* int exec_config_exec }}} */
static int exec_config(oconfig_item_t *ci) /* {{{ */
} /* int exec_config }}} */
static void set_environment(void) /* {{{ */
} /* int exec_config }}} */
static void set_environment(void) /* {{{ */
if (status != 0) {
ERROR("exec plugin: pipe failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
if (status != 0) {
ERROR("exec plugin: pipe failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char nambuf[2048];
if (pl->pid != 0)
char nambuf[2048];
if (pl->pid != 0)
if ((create_pipe(fd_pipe_in) == -1) || (create_pipe(fd_pipe_out) == -1) ||
(create_pipe(fd_pipe_err) == -1))
if ((create_pipe(fd_pipe_in) == -1) || (create_pipe(fd_pipe_out) == -1) ||
(create_pipe(fd_pipe_err) == -1))
else
close(fd_pipe_err[0]);
else
close(fd_pipe_err[0]);
failed:
close_pipe(fd_pipe_in);
close_pipe(fd_pipe_out);
close_pipe(fd_pipe_err);
failed:
close_pipe(fd_pipe_in);
close_pipe(fd_pipe_out);
close_pipe(fd_pipe_err);
} /* int fork_child }}} */
static int parse_line(char *buffer) /* {{{ */
{
if (strncasecmp("PUTVAL", buffer, strlen("PUTVAL")) == 0)
} /* int fork_child }}} */
static int parse_line(char *buffer) /* {{{ */
{
if (strncasecmp("PUTVAL", buffer, strlen("PUTVAL")) == 0)
- return (cmd_handle_putval(stdout, buffer));
+ return cmd_handle_putval(stdout, buffer);
else if (strncasecmp("PUTNOTIF", buffer, strlen("PUTNOTIF")) == 0)
else if (strncasecmp("PUTNOTIF", buffer, strlen("PUTNOTIF")) == 0)
- return (handle_putnotif(stdout, buffer));
+ return handle_putnotif(stdout, buffer);
else {
ERROR("exec plugin: Unable to parse command, ignoring line: \"%s\"",
buffer);
else {
ERROR("exec plugin: Unable to parse command, ignoring line: \"%s\"",
buffer);
}
} /* int parse_line }}} */
}
} /* int parse_line }}} */
close(fd_err);
pthread_exit((void *)0);
close(fd_err);
pthread_exit((void *)0);
} /* void *exec_read_one }}} */
static void *exec_notification_one(void *arg) /* {{{ */
} /* void *exec_read_one }}} */
static void *exec_notification_one(void *arg) /* {{{ */
n->meta = NULL;
sfree(arg);
pthread_exit((void *)0);
n->meta = NULL;
sfree(arg);
pthread_exit((void *)0);
} /* void *exec_notification_one }}} */
static int exec_init(void) /* {{{ */
} /* void *exec_notification_one }}} */
static int exec_init(void) /* {{{ */
} /* int exec_init }}} */
static int exec_read(void) /* {{{ */
} /* int exec_init }}} */
static int exec_read(void) /* {{{ */
pthread_attr_destroy(&attr);
} /* for (pl) */
pthread_attr_destroy(&attr);
} /* for (pl) */
} /* int exec_read }}} */
static int exec_notification(const notification_t *n, /* {{{ */
} /* int exec_read }}} */
static int exec_notification(const notification_t *n, /* {{{ */
pthread_attr_destroy(&attr);
} /* for (pl) */
pthread_attr_destroy(&attr);
} /* for (pl) */
} /* }}} int exec_notification */
static int exec_shutdown(void) /* {{{ */
} /* }}} int exec_notification */
static int exec_shutdown(void) /* {{{ */
} /* while (pl) */
pl_head = NULL;
} /* while (pl) */
pl_head = NULL;
} /* int exec_shutdown }}} */
void module_register(void) {
} /* int exec_shutdown }}} */
void module_register(void) {
}
static void fhcount_submit(const char *type, const char *type_instance,
}
static void fhcount_submit(const char *type, const char *type_instance,
fp = fopen("/proc/sys/fs/file-nr", "r");
if (fp == NULL) {
ERROR("fhcount: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
fp = fopen("/proc/sys/fs/file-nr", "r");
if (fp == NULL) {
ERROR("fhcount: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (fgets(buffer, buffer_len, fp) == NULL) {
ERROR("fhcount: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(fp);
}
if (fgets(buffer, buffer_len, fp) == NULL) {
ERROR("fhcount: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(fp);
if (numfields != 3) {
ERROR("fhcount: Line doesn't contain 3 fields");
if (numfields != 3) {
ERROR("fhcount: Line doesn't contain 3 fields");
fhcount_submit("percent", "unused", (gauge_t)prc_unused);
}
fhcount_submit("percent", "unused", (gauge_t)prc_unused);
}
}
void module_register(void) {
}
void module_register(void) {
/* do nothing */;
if (*ptr == 0)
/* do nothing */;
if (*ptr == 0)
copy = strdup(ptr);
if (copy == NULL)
copy = strdup(ptr);
if (copy == NULL)
sfree(dir->instance);
dir->instance = copy;
sfree(dir->instance);
dir->instance = copy;
} /* int fc_config_set_instance */
static int fc_config_add_dir_instance(fc_directory_conf_t *dir,
} /* int fc_config_set_instance */
static int fc_config_add_dir_instance(fc_directory_conf_t *dir,
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("filecount plugin: The `Instance' config option needs exactly "
"one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("filecount plugin: The `Instance' config option needs exactly "
"one string argument.");
- return (fc_config_set_instance(dir, ci->values[0].value.string));
+ return fc_config_set_instance(dir, ci->values[0].value.string);
} /* int fc_config_add_dir_instance */
static int fc_config_add_dir_name(fc_directory_conf_t *dir,
} /* int fc_config_add_dir_instance */
static int fc_config_add_dir_name(fc_directory_conf_t *dir,
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("filecount plugin: The `Name' config option needs exactly one "
"string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("filecount plugin: The `Name' config option needs exactly one "
"string argument.");
}
temp = strdup(ci->values[0].value.string);
if (temp == NULL) {
ERROR("filecount plugin: strdup failed.");
}
temp = strdup(ci->values[0].value.string);
if (temp == NULL) {
ERROR("filecount plugin: strdup failed.");
}
sfree(dir->name);
dir->name = temp;
}
sfree(dir->name);
dir->name = temp;
} /* int fc_config_add_dir_name */
static int fc_config_add_dir_mtime(fc_directory_conf_t *dir,
} /* int fc_config_add_dir_name */
static int fc_config_add_dir_mtime(fc_directory_conf_t *dir,
(ci->values[0].type != OCONFIG_TYPE_NUMBER))) {
WARNING("filecount plugin: The `MTime' config option needs exactly one "
"string or numeric argument.");
(ci->values[0].type != OCONFIG_TYPE_NUMBER))) {
WARNING("filecount plugin: The `MTime' config option needs exactly one "
"string or numeric argument.");
}
if (ci->values[0].type == OCONFIG_TYPE_NUMBER) {
dir->mtime = (int64_t)ci->values[0].value.number;
}
if (ci->values[0].type == OCONFIG_TYPE_NUMBER) {
dir->mtime = (int64_t)ci->values[0].value.number;
(endptr == ci->values[0].value.string)) {
WARNING("filecount plugin: Converting `%s' to a number failed.",
ci->values[0].value.string);
(endptr == ci->values[0].value.string)) {
WARNING("filecount plugin: Converting `%s' to a number failed.",
ci->values[0].value.string);
default:
WARNING("filecount plugin: Invalid suffix for `MTime': `%c'", *endptr);
default:
WARNING("filecount plugin: Invalid suffix for `MTime': `%c'", *endptr);
} /* switch (*endptr) */
dir->mtime = (int64_t)temp;
} /* switch (*endptr) */
dir->mtime = (int64_t)temp;
} /* int fc_config_add_dir_mtime */
static int fc_config_add_dir_size(fc_directory_conf_t *dir,
} /* int fc_config_add_dir_mtime */
static int fc_config_add_dir_size(fc_directory_conf_t *dir,
(ci->values[0].type != OCONFIG_TYPE_NUMBER))) {
WARNING("filecount plugin: The `Size' config option needs exactly one "
"string or numeric argument.");
(ci->values[0].type != OCONFIG_TYPE_NUMBER))) {
WARNING("filecount plugin: The `Size' config option needs exactly one "
"string or numeric argument.");
}
if (ci->values[0].type == OCONFIG_TYPE_NUMBER) {
dir->size = (int64_t)ci->values[0].value.number;
}
if (ci->values[0].type == OCONFIG_TYPE_NUMBER) {
dir->size = (int64_t)ci->values[0].value.number;
(endptr == ci->values[0].value.string)) {
WARNING("filecount plugin: Converting `%s' to a number failed.",
ci->values[0].value.string);
(endptr == ci->values[0].value.string)) {
WARNING("filecount plugin: Converting `%s' to a number failed.",
ci->values[0].value.string);
default:
WARNING("filecount plugin: Invalid suffix for `Size': `%c'", *endptr);
default:
WARNING("filecount plugin: Invalid suffix for `Size': `%c'", *endptr);
} /* switch (*endptr) */
dir->size = (int64_t)temp;
} /* switch (*endptr) */
dir->size = (int64_t)temp;
} /* int fc_config_add_dir_size */
static int fc_config_add_dir_option(fc_directory_conf_t *dir,
} /* int fc_config_add_dir_size */
static int fc_config_add_dir_option(fc_directory_conf_t *dir,
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
WARNING("filecount plugin: The `Recursive' config options needs exactly "
"one boolean argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
WARNING("filecount plugin: The `Recursive' config options needs exactly "
"one boolean argument.");
}
if (ci->values[0].value.boolean)
}
if (ci->values[0].value.boolean)
else
dir->options &= ~bit;
else
dir->options &= ~bit;
} /* int fc_config_add_dir_option */
static int fc_config_add_dir(oconfig_item_t *ci) {
} /* int fc_config_add_dir_option */
static int fc_config_add_dir(oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("filecount plugin: `Directory' needs exactly one string "
"argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("filecount plugin: `Directory' needs exactly one string "
"argument.");
}
/* Initialize `dir' */
dir = calloc(1, sizeof(*dir));
if (dir == NULL) {
ERROR("filecount plugin: calloc failed.");
}
/* Initialize `dir' */
dir = calloc(1, sizeof(*dir));
if (dir == NULL) {
ERROR("filecount plugin: calloc failed.");
}
dir->path = strdup(ci->values[0].value.string);
if (dir->path == NULL) {
ERROR("filecount plugin: strdup failed.");
sfree(dir);
}
dir->path = strdup(ci->values[0].value.string);
if (dir->path == NULL) {
ERROR("filecount plugin: strdup failed.");
sfree(dir);
}
fc_config_set_instance(dir, dir->path);
}
fc_config_set_instance(dir, dir->path);
sfree(dir->instance);
sfree(dir->path);
sfree(dir);
sfree(dir->instance);
sfree(dir->path);
sfree(dir);
} /* int fc_config_add_dir */
static int fc_config(oconfig_item_t *ci) {
} /* int fc_config_add_dir */
static int fc_config(oconfig_item_t *ci) {
}
} /* for (ci->children) */
}
} /* for (ci->children) */
} /* int fc_config */
static int fc_init(void) {
if (directories_num < 1) {
WARNING("filecount plugin: No directories have been configured.");
} /* int fc_config */
static int fc_init(void) {
if (directories_num < 1) {
WARNING("filecount plugin: No directories have been configured.");
} /* int fc_init */
static int fc_read_dir_callback(const char *dirname, const char *filename,
} /* int fc_init */
static int fc_read_dir_callback(const char *dirname, const char *filename,
int status;
if (dir == NULL)
int status;
if (dir == NULL)
ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename);
status = lstat(abs_path, &statbuf);
if (status != 0) {
ERROR("filecount plugin: stat (%s) failed.", abs_path);
ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename);
status = lstat(abs_path, &statbuf);
if (status != 0) {
ERROR("filecount plugin: stat (%s) failed.", abs_path);
}
if (S_ISDIR(statbuf.st_mode) && (dir->options & FC_RECURSIVE)) {
status = walk_directory(
abs_path, fc_read_dir_callback, dir,
/* include hidden = */ (dir->options & FC_HIDDEN) ? 1 : 0);
}
if (S_ISDIR(statbuf.st_mode) && (dir->options & FC_RECURSIVE)) {
status = walk_directory(
abs_path, fc_read_dir_callback, dir,
/* include hidden = */ (dir->options & FC_HIDDEN) ? 1 : 0);
} else if (!S_ISREG(statbuf.st_mode)) {
} else if (!S_ISREG(statbuf.st_mode)) {
}
if (dir->name != NULL) {
status = fnmatch(dir->name, filename, /* flags = */ 0);
if (status != 0)
}
if (dir->name != NULL) {
status = fnmatch(dir->name, filename, /* flags = */ 0);
if (status != 0)
if (((dir->mtime < 0) && (statbuf.st_mtime < mtime)) ||
((dir->mtime > 0) && (statbuf.st_mtime > mtime)))
if (((dir->mtime < 0) && (statbuf.st_mtime < mtime)) ||
((dir->mtime > 0) && (statbuf.st_mtime > mtime)))
if (((dir->size < 0) && (statbuf.st_size > size)) ||
((dir->size > 0) && (statbuf.st_size < size)))
if (((dir->size < 0) && (statbuf.st_size > size)) ||
((dir->size > 0) && (statbuf.st_size < size)))
}
dir->files_num++;
dir->files_size += (uint64_t)statbuf.st_size;
}
dir->files_num++;
dir->files_size += (uint64_t)statbuf.st_size;
} /* int fc_read_dir_callback */
static int fc_read_dir(fc_directory_conf_t *dir) {
} /* int fc_read_dir_callback */
static int fc_read_dir(fc_directory_conf_t *dir) {
/* include hidden */ (dir->options & FC_HIDDEN) ? 1 : 0);
if (status != 0) {
WARNING("filecount plugin: walk_directory (%s) failed.", dir->path);
/* include hidden */ (dir->options & FC_HIDDEN) ? 1 : 0);
if (status != 0) {
WARNING("filecount plugin: walk_directory (%s) failed.", dir->path);
} /* int fc_read_dir */
static int fc_read(void) {
for (size_t i = 0; i < directories_num; i++)
fc_read_dir(directories[i]);
} /* int fc_read_dir */
static int fc_read(void) {
for (size_t i = 0; i < directories_num; i++)
fc_read_dir(directories[i]);
} /* int fc_read */
void module_register(void) {
} /* int fc_read */
void module_register(void) {
} else {
printf("cant open file\n");
} else {
printf("cant open file\n");
}
void module_register(void) {
}
void module_register(void) {
/* Look up the DS type and ds_index. */
if (map[i].ds_type < 0) /* {{{ */
/* Look up the DS type and ds_index. */
if (map[i].ds_type < 0) /* {{{ */
ds = plugin_get_ds(map[i].type);
if (ds == NULL) {
WARNING("gmond plugin: Type not defined: %s", map[i].type);
ds = plugin_get_ds(map[i].type);
if (ds == NULL) {
WARNING("gmond plugin: Type not defined: %s", map[i].type);
}
if ((map[i].ds_name == NULL) && (ds->ds_num != 1)) {
WARNING("gmond plugin: No data source name defined for metric %s, "
"but type %s has more than one data source.",
map[i].ganglia_name, map[i].type);
}
if ((map[i].ds_name == NULL) && (ds->ds_num != 1)) {
WARNING("gmond plugin: No data source name defined for metric %s, "
"but type %s has more than one data source.",
map[i].ganglia_name, map[i].type);
}
if (map[i].ds_name == NULL) {
}
if (map[i].ds_name == NULL) {
WARNING("gmond plugin: There is no data source "
"named `%s' in type `%s'.",
map[i].ds_name, ds->type);
WARNING("gmond plugin: There is no data source "
"named `%s' in type `%s'.",
map[i].ds_name, ds->type);
map[i].ds_type = ds->ds[map[i].ds_index].type;
} /* }}} if ((map[i].ds_type < 0) || (map[i].ds_index < 0)) */
map[i].ds_type = ds->ds[map[i].ds_index].type;
} /* }}} if ((map[i].ds_type < 0) || (map[i].ds_index < 0)) */
} /* }}} metric_map_t *metric_lookup */
static int create_sockets(socket_entry_t **ret_sockets, /* {{{ */
} /* }}} metric_map_t *metric_lookup */
static int create_sockets(socket_entry_t **ret_sockets, /* {{{ */
int status;
if (*ret_sockets != NULL)
int status;
if (*ret_sockets != NULL)
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG | AI_PASSIVE,
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG | AI_PASSIVE,
(service == NULL) ? "(null)" : service,
(ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(ai_return));
(service == NULL) ? "(null)" : service,
(ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(ai_return));
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
if (sockets_num == 0) {
sfree(sockets);
if (sockets_num == 0) {
sfree(sockets);
}
*ret_sockets = sockets;
*ret_sockets_num = sockets_num;
}
*ret_sockets = sockets;
*ret_sockets_num = sockets_num;
} /* }}} int create_sockets */
static int request_meta_data(const char *host, const char *name) /* {{{ */
} /* }}} int create_sockets */
static int request_meta_data(const char *host, const char *name) /* {{{ */
(msg.Ganglia_metadata_msg_u.grequest.metric_id.name == NULL)) {
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
(msg.Ganglia_metadata_msg_u.grequest.metric_id.name == NULL)) {
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
}
xdrmem_create(&xdr, buffer, sizeof(buffer), XDR_ENCODE);
}
xdrmem_create(&xdr, buffer, sizeof(buffer), XDR_ENCODE);
if (!xdr_Ganglia_metadata_msg(&xdr, &msg)) {
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
if (!xdr_Ganglia_metadata_msg(&xdr, &msg)) {
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
}
buffer_size = xdr_getpos(&xdr);
}
buffer_size = xdr_getpos(&xdr);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.host);
sfree(msg.Ganglia_metadata_msg_u.grequest.metric_id.name);
} /* }}} int request_meta_data */
static staging_entry_t *staging_entry_get(const char *host, /* {{{ */
} /* }}} int request_meta_data */
static staging_entry_t *staging_entry_get(const char *host, /* {{{ */
int status;
if (staging_tree == NULL)
int status;
if (staging_tree == NULL)
ssnprintf(key, sizeof(key), "%s/%s/%s", host, type,
(type_instance != NULL) ? type_instance : "");
ssnprintf(key, sizeof(key), "%s/%s/%s", host, type,
(type_instance != NULL) ? type_instance : "");
se = NULL;
status = c_avl_get(staging_tree, key, (void *)&se);
if (status == 0)
se = NULL;
status = c_avl_get(staging_tree, key, (void *)&se);
if (status == 0)
/* insert new entry */
se = calloc(1, sizeof(*se));
if (se == NULL)
/* insert new entry */
se = calloc(1, sizeof(*se));
if (se == NULL)
sstrncpy(se->key, key, sizeof(se->key));
se->flags = 0;
sstrncpy(se->key, key, sizeof(se->key));
se->flags = 0;
se->vl.values = (value_t *)calloc(values_len, sizeof(*se->vl.values));
if (se->vl.values == NULL) {
sfree(se);
se->vl.values = (value_t *)calloc(values_len, sizeof(*se->vl.values));
if (se->vl.values == NULL) {
sfree(se);
}
se->vl.values_len = values_len;
}
se->vl.values_len = values_len;
ERROR("gmond plugin: c_avl_insert failed.");
sfree(se->vl.values);
sfree(se);
ERROR("gmond plugin: c_avl_insert failed.");
sfree(se->vl.values);
sfree(se);
} /* }}} staging_entry_t *staging_entry_get */
static int staging_entry_update(const char *host, const char *name, /* {{{ */
} /* }}} staging_entry_t *staging_entry_get */
static int staging_entry_update(const char *host, const char *name, /* {{{ */
ds = plugin_get_ds(type);
if (ds == NULL) {
ERROR("gmond plugin: Looking up type %s failed.", type);
ds = plugin_get_ds(type);
if (ds == NULL) {
ERROR("gmond plugin: Looking up type %s failed.", type);
}
if (ds->ds_num <= ds_index) {
ERROR("gmond plugin: Invalid index %zu: %s has only %zu data source(s).",
ds_index, ds->type, ds->ds_num);
}
if (ds->ds_num <= ds_index) {
ERROR("gmond plugin: Invalid index %zu: %s has only %zu data source(s).",
ds_index, ds->type, ds->ds_num);
}
pthread_mutex_lock(&staging_lock);
}
pthread_mutex_lock(&staging_lock);
if (se == NULL) {
pthread_mutex_unlock(&staging_lock);
ERROR("gmond plugin: staging_entry_get failed.");
if (se == NULL) {
pthread_mutex_unlock(&staging_lock);
ERROR("gmond plugin: staging_entry_get failed.");
}
if (se->vl.values_len != ds->ds_num) {
pthread_mutex_unlock(&staging_lock);
}
if (se->vl.values_len != ds->ds_num) {
pthread_mutex_unlock(&staging_lock);
}
if (ds_type == DS_TYPE_COUNTER)
}
if (ds_type == DS_TYPE_COUNTER)
/* Check if all data sources have been set. If not, return here. */
if (se->flags != ((0x01 << se->vl.values_len) - 1)) {
pthread_mutex_unlock(&staging_lock);
/* Check if all data sources have been set. If not, return here. */
if (se->flags != ((0x01 << se->vl.values_len) - 1)) {
pthread_mutex_unlock(&staging_lock);
}
/* Check if the interval of this metric is known. If not, request meta data
}
/* Check if the interval of this metric is known. If not, request meta data
pthread_mutex_unlock(&staging_lock);
request_meta_data(host, name);
pthread_mutex_unlock(&staging_lock);
request_meta_data(host, name);
}
plugin_dispatch_values(&se->vl);
}
plugin_dispatch_values(&se->vl);
se->flags = 0;
pthread_mutex_unlock(&staging_lock);
se->flags = 0;
pthread_mutex_unlock(&staging_lock);
} /* }}} int staging_entry_update */
static int mc_handle_value_msg(Ganglia_value_msg *msg) /* {{{ */
} /* }}} int staging_entry_update */
static int mc_handle_value_msg(Ganglia_value_msg *msg) /* {{{ */
}
default:
DEBUG("gmond plugin: Value type not handled: %i", msg->id);
}
default:
DEBUG("gmond plugin: Value type not handled: %i", msg->id);
} /* }}} switch (msg->id) */
assert(host != NULL);
} /* }}} switch (msg->id) */
assert(host != NULL);
- return (staging_entry_update(host, name, map->type, map->type_instance,
- map->ds_index, map->ds_type, val_copy));
+ return staging_entry_update(host, name, map->type, map->type_instance,
+ map->ds_index, map->ds_type, val_copy);
}
DEBUG("gmond plugin: Cannot find a translation for %s.", name);
}
DEBUG("gmond plugin: Cannot find a translation for %s.", name);
} /* }}} int mc_handle_value_msg */
static int mc_handle_metadata_msg(Ganglia_metadata_msg *msg) /* {{{ */
} /* }}} int mc_handle_value_msg */
static int mc_handle_metadata_msg(Ganglia_metadata_msg *msg) /* {{{ */
msg_meta = msg->Ganglia_metadata_msg_u.gfull;
if (msg_meta.metric.tmax == 0)
msg_meta = msg->Ganglia_metadata_msg_u.gfull;
if (msg_meta.metric.tmax == 0)
map = metric_lookup(msg_meta.metric_id.name);
if (map == NULL) {
DEBUG("gmond plugin: Not handling meta data %s.",
msg_meta.metric_id.name);
map = metric_lookup(msg_meta.metric_id.name);
if (map == NULL) {
DEBUG("gmond plugin: Not handling meta data %s.",
msg_meta.metric_id.name);
}
ds = plugin_get_ds(map->type);
if (ds == NULL) {
WARNING("gmond plugin: Could not find data set %s.", map->type);
}
ds = plugin_get_ds(map->type);
if (ds == NULL) {
WARNING("gmond plugin: Could not find data set %s.", map->type);
}
DEBUG("gmond plugin: Received meta data for %s/%s.",
}
DEBUG("gmond plugin: Received meta data for %s/%s.",
if (se == NULL) {
ERROR("gmond plugin: staging_entry_get failed.");
if (se == NULL) {
ERROR("gmond plugin: staging_entry_get failed.");
- default: { return (-1); }
+ default: { return -1; }
} /* }}} int mc_handle_metadata_msg */
static int mc_handle_metric(void *buffer, size_t buffer_size) /* {{{ */
} /* }}} int mc_handle_metadata_msg */
static int mc_handle_metric(void *buffer, size_t buffer_size) /* {{{ */
default:
DEBUG("gmond plugin: Unknown format: %i", format);
default:
DEBUG("gmond plugin: Unknown format: %i", format);
} /* }}} int mc_handle_metric */
static int mc_handle_socket(struct pollfd *p) /* {{{ */
} /* }}} int mc_handle_metric */
static int mc_handle_socket(struct pollfd *p) /* {{{ */
if ((p->revents & (POLLIN | POLLPRI)) == 0) {
p->revents = 0;
if ((p->revents & (POLLIN | POLLPRI)) == 0) {
p->revents = 0;
}
buffer_size = recv(p->fd, buffer, sizeof(buffer), /* flags = */ 0);
}
buffer_size = recv(p->fd, buffer, sizeof(buffer), /* flags = */ 0);
ERROR("gmond plugin: recv failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
p->revents = 0;
ERROR("gmond plugin: recv failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
p->revents = 0;
}
mc_handle_metric(buffer, (size_t)buffer_size);
}
mc_handle_metric(buffer, (size_t)buffer_size);
} /* }}} int mc_handle_socket */
static void *mc_receive_thread(void *arg) /* {{{ */
} /* }}} int mc_handle_socket */
static void *mc_receive_thread(void *arg) /* {{{ */
/* listen = */ 1);
if (status != 0) {
ERROR("gmond plugin: create_sockets failed.");
/* listen = */ 1);
if (status != 0) {
ERROR("gmond plugin: create_sockets failed.");
}
mc_receive_sockets = (struct pollfd *)calloc(mc_receive_sockets_num,
}
mc_receive_sockets = (struct pollfd *)calloc(mc_receive_sockets_num,
free(mc_receive_socket_entries);
mc_receive_socket_entries = NULL;
mc_receive_sockets_num = 0;
free(mc_receive_socket_entries);
mc_receive_socket_entries = NULL;
mc_receive_sockets_num = 0;
}
for (size_t i = 0; i < mc_receive_sockets_num; i++) {
}
for (size_t i = 0; i < mc_receive_sockets_num; i++) {
} /* while (mc_receive_thread_loop != 0) */
free(mc_receive_socket_entries);
} /* while (mc_receive_thread_loop != 0) */
free(mc_receive_socket_entries);
} /* }}} void *mc_receive_thread */
static int mc_receive_thread_start(void) /* {{{ */
} /* }}} void *mc_receive_thread */
static int mc_receive_thread_start(void) /* {{{ */
int status;
if (mc_receive_thread_running != 0)
int status;
if (mc_receive_thread_running != 0)
mc_receive_thread_loop = 1;
mc_receive_thread_loop = 1;
if (status != 0) {
ERROR("gmond plugin: Starting receive thread failed.");
mc_receive_thread_loop = 0;
if (status != 0) {
ERROR("gmond plugin: Starting receive thread failed.");
mc_receive_thread_loop = 0;
}
mc_receive_thread_running = 1;
}
mc_receive_thread_running = 1;
} /* }}} int start_receive_thread */
static int mc_receive_thread_stop(void) /* {{{ */
{
if (mc_receive_thread_running == 0)
} /* }}} int start_receive_thread */
static int mc_receive_thread_stop(void) /* {{{ */
{
if (mc_receive_thread_running == 0)
mc_receive_thread_loop = 0;
mc_receive_thread_loop = 0;
mc_receive_thread_running = 0;
mc_receive_thread_running = 0;
} /* }}} int mc_receive_thread_stop */
/*
} /* }}} int mc_receive_thread_stop */
/*
WARNING("gmond plugin: The `%s' option needs "
"exactly one string argument.",
ci->key);
WARNING("gmond plugin: The `%s' option needs "
"exactly one string argument.",
ci->key);
}
tmp = strdup(ci->values[0].value.string);
if (tmp == NULL) {
ERROR("gmond plugin: strdup failed.");
}
tmp = strdup(ci->values[0].value.string);
if (tmp == NULL) {
ERROR("gmond plugin: strdup failed.");
}
sfree(*str);
*str = tmp;
}
sfree(*str);
*str = tmp;
} /* }}} int gmond_config_set_string */
static int gmond_config_add_metric(oconfig_item_t *ci) /* {{{ */
} /* }}} int gmond_config_set_string */
static int gmond_config_add_metric(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("gmond plugin: `Metric' blocks need "
"exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("gmond plugin: `Metric' blocks need "
"exactly one string argument.");
}
map = realloc(metric_map, (metric_map_len + 1) * sizeof(*metric_map));
if (map == NULL) {
ERROR("gmond plugin: realloc failed.");
}
map = realloc(metric_map, (metric_map_len + 1) * sizeof(*metric_map));
if (map == NULL) {
ERROR("gmond plugin: realloc failed.");
}
metric_map = map;
map = metric_map + metric_map_len;
}
metric_map = map;
map = metric_map + metric_map_len;
map->ganglia_name = strdup(ci->values[0].value.string);
if (map->ganglia_name == NULL) {
ERROR("gmond plugin: strdup failed.");
map->ganglia_name = strdup(ci->values[0].value.string);
if (map->ganglia_name == NULL) {
ERROR("gmond plugin: strdup failed.");
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
ERROR("gmond plugin: No type is set for metric %s.", map->ganglia_name);
sfree(map->ganglia_name);
sfree(map->type_instance);
ERROR("gmond plugin: No type is set for metric %s.", map->ganglia_name);
sfree(map->ganglia_name);
sfree(map->type_instance);
} /* }}} int gmond_config_add_metric */
static int gmond_config_set_address(oconfig_item_t *ci, /* {{{ */
} /* }}} int gmond_config_add_metric */
static int gmond_config_set_address(oconfig_item_t *ci, /* {{{ */
WARNING("gmond plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
WARNING("gmond plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
}
if ((ci->values[0].type != OCONFIG_TYPE_STRING) ||
((ci->values_num == 2) && (ci->values[1].type != OCONFIG_TYPE_STRING))) {
WARNING("gmond plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
}
if ((ci->values[0].type != OCONFIG_TYPE_STRING) ||
((ci->values_num == 2) && (ci->values[1].type != OCONFIG_TYPE_STRING))) {
WARNING("gmond plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
}
addr = strdup(ci->values[0].value.string);
}
addr = strdup(ci->values[0].value.string);
ERROR("gmond plugin: strdup failed.");
sfree(addr);
sfree(port);
ERROR("gmond plugin: strdup failed.");
sfree(addr);
sfree(port);
*ret_addr = addr;
*ret_port = port;
*ret_addr = addr;
*ret_port = port;
} /* }}} int gmond_config_set_address */
static int gmond_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int gmond_config_set_address */
static int gmond_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int gmond_config */
static int gmond_init(void) /* {{{ */
} /* }}} int gmond_config */
static int gmond_init(void) /* {{{ */
staging_tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (staging_tree == NULL) {
ERROR("gmond plugin: c_avl_create failed.");
staging_tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (staging_tree == NULL) {
ERROR("gmond plugin: c_avl_create failed.");
}
mc_receive_thread_start();
}
mc_receive_thread_start();
} /* }}} int gmond_init */
static int gmond_shutdown(void) /* {{{ */
} /* }}} int gmond_init */
static int gmond_shutdown(void) /* {{{ */
mc_send_sockets_num = 0;
pthread_mutex_unlock(&mc_send_sockets_lock);
mc_send_sockets_num = 0;
pthread_mutex_unlock(&mc_send_sockets_lock);
} /* }}} int gmond_shutdown */
void module_register(void) {
} /* }}} int gmond_shutdown */
void module_register(void) {
cgps_submit("satellites", data_copy.sats_used, "used");
cgps_submit("satellites", data_copy.sats_visible, "visible");
cgps_submit("satellites", data_copy.sats_used, "used");
cgps_submit("satellites", data_copy.sats_visible, "visible");
cgps_config_data.timeout = CGPS_DEFAULT_TIMEOUT;
}
cgps_config_data.timeout = CGPS_DEFAULT_TIMEOUT;
}
plugin_thread_create(&cgps_thread_id, NULL, cgps_thread, NULL, "gps");
if (status != 0) {
ERROR("gps plugin: pthread_create() failed.");
plugin_thread_create(&cgps_thread_id, NULL, cgps_thread, NULL, "gps");
if (status != 0) {
ERROR("gps plugin: pthread_create() failed.");
sfree(cgps_config_data.port);
sfree(cgps_config_data.host);
sfree(cgps_config_data.port);
sfree(cgps_config_data.host);
ERROR("hddtemp plugin: getaddrinfo (%s, %s): %s", host, port,
(ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(ai_return));
ERROR("hddtemp plugin: getaddrinfo (%s, %s): %s", host, port,
(ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(ai_return));
if (fd < 0) {
ERROR("hddtemp plugin: Could not connect to daemon.");
if (fd < 0) {
ERROR("hddtemp plugin: Could not connect to daemon.");
}
/* receive data from the hddtemp daemon */
}
/* receive data from the hddtemp daemon */
close(fd);
free(buffer);
ERROR("hddtemp plugin: Allocation failed.");
close(fd);
free(buffer);
ERROR("hddtemp plugin: Allocation failed.");
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
free(buffer);
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
free(buffer);
}
buffer_fill += status;
}
}
buffer_fill += status;
}
buffer);
close(fd);
free(buffer);
buffer);
close(fd);
free(buffer);
}
assert(buffer_fill < buffer_size);
buffer[buffer_fill] = '\0';
close(fd);
}
assert(buffer_fill < buffer_size);
buffer[buffer_fill] = '\0';
close(fd);
}
static int hddtemp_config(const char *key, const char *value) {
}
static int hddtemp_config(const char *key, const char *value) {
else
sstrncpy(hddtemp_port, value, sizeof(hddtemp_port));
} else {
else
sstrncpy(hddtemp_port, value, sizeof(hddtemp_port));
} else {
}
static void hddtemp_submit(char *type_instance, double value) {
}
static void hddtemp_submit(char *type_instance, double value) {
/* get data from daemon */
buf = hddtemp_query_daemon();
if (buf == NULL)
/* get data from daemon */
buf = hddtemp_query_daemon();
if (buf == NULL)
/* NB: strtok_r will eat up "||" and leading "|"'s */
ptr = buf;
/* NB: strtok_r will eat up "||" and leading "|"'s */
ptr = buf;
} /* int hddtemp_read */
/* module_register
} /* int hddtemp_read */
/* module_register
}
static void submit_hp(const struct entry_info *info) {
}
static void submit_hp(const struct entry_info *info) {
if (!(*s != '\0' && *endptr == '\0')) {
DEBUG(RDT_PLUGIN ": Error converting '%s' to unsigned number.", s);
if (!(*s != '\0' && *endptr == '\0')) {
DEBUG(RDT_PLUGIN ": Error converting '%s' to unsigned number.", s);
*p = '\0';
ret = strtouint64(token, &start);
if (ret < 0)
*p = '\0';
ret = strtouint64(token, &start);
if (ret < 0)
ret = strtouint64(p + 1, &end);
if (ret < 0)
ret = strtouint64(p + 1, &end);
if (ret < 0)
}
for (n = start; n <= end; n++) {
if (!(isdup(nums, index, n))) {
}
for (n = start; n <= end; n++) {
if (!(isdup(nums, index, n))) {
ret = strtouint64(token, &val);
if (ret < 0)
ret = strtouint64(token, &val);
if (ret < 0)
if (!(isdup(nums, index, val))) {
nums[index] = val;
if (!(isdup(nums, index, val))) {
nums[index] = val;
cg->cores = calloc(num_cores, sizeof(unsigned));
if (cg->cores == NULL) {
ERROR(RDT_PLUGIN ": Error allocating core group table");
cg->cores = calloc(num_cores, sizeof(unsigned));
if (cg->cores == NULL) {
ERROR(RDT_PLUGIN ": Error allocating core group table");
}
cg->num_cores = num_cores;
cg->desc = strdup(desc);
if (cg->desc == NULL) {
ERROR(RDT_PLUGIN ": Error allocating core group description");
sfree(cg->cores);
}
cg->num_cores = num_cores;
cg->desc = strdup(desc);
if (cg->desc == NULL) {
ERROR(RDT_PLUGIN ": Error allocating core group description");
sfree(cg->cores);
}
for (size_t i = 0; i < num_cores; i++)
}
for (size_t i = 0; i < num_cores; i++)
if (n == 0) {
ERROR(RDT_PLUGIN ": Error parsing core group (%s)",
item->values[j].value.string);
if (n == 0) {
ERROR(RDT_PLUGIN ": Error parsing core group (%s)",
item->values[j].value.string);
}
/* set core group info */
}
/* set core group info */
if (item == NULL) {
DEBUG(RDT_PLUGIN ": cgroups_config: Invalid argument.");
if (item == NULL) {
DEBUG(RDT_PLUGIN ": cgroups_config: Invalid argument.");
}
DEBUG(RDT_PLUGIN ": Core groups [%d]:", item->values_num);
for (int j = 0; j < item->values_num; j++) {
if (item->values[j].type != OCONFIG_TYPE_STRING) {
ERROR(RDT_PLUGIN ": given core group value is not a string [idx=%d]", j);
}
DEBUG(RDT_PLUGIN ": Core groups [%d]:", item->values_num);
for (int j = 0; j < item->values_num; j++) {
if (item->values[j].type != OCONFIG_TYPE_STRING) {
ERROR(RDT_PLUGIN ": given core group value is not a string [idx=%d]", j);
}
DEBUG(RDT_PLUGIN ": [%d]: %s", j, item->values[j].value.string);
}
}
DEBUG(RDT_PLUGIN ": [%d]: %s", j, item->values[j].value.string);
}
if (n < 0) {
rdt_free_cgroups();
ERROR(RDT_PLUGIN ": Error parsing core groups configuration.");
if (n < 0) {
rdt_free_cgroups();
ERROR(RDT_PLUGIN ": Error parsing core groups configuration.");
}
/* validate configured core id values */
}
/* validate configured core id values */
g_rdt->cgroups[group_idx].desc,
(int)g_rdt->cgroups[group_idx].cores[core_idx]);
rdt_free_cgroups();
g_rdt->cgroups[group_idx].desc,
(int)g_rdt->cgroups[group_idx].cores[core_idx]);
rdt_free_cgroups();
if (found != 0) {
rdt_free_cgroups();
ERROR(RDT_PLUGIN ": Cannot monitor same cores in different groups.");
if (found != 0) {
rdt_free_cgroups();
ERROR(RDT_PLUGIN ": Cannot monitor same cores in different groups.");
if (g_rdt->pgroups[i] == NULL) {
rdt_free_cgroups();
ERROR(RDT_PLUGIN ": Failed to allocate memory for monitoring data.");
if (g_rdt->pgroups[i] == NULL) {
rdt_free_cgroups();
ERROR(RDT_PLUGIN ": Failed to allocate memory for monitoring data.");
}
static void rdt_pqos_log(void *context, const size_t size, const char *msg) {
}
static void rdt_pqos_log(void *context, const size_t size, const char *msg) {
if (g_rdt != NULL) {
/* already initialized if config callback was called before init callback */
if (g_rdt != NULL) {
/* already initialized if config callback was called before init callback */
}
g_rdt = calloc(1, sizeof(*g_rdt));
if (g_rdt == NULL) {
ERROR(RDT_PLUGIN ": Failed to allocate memory for rdt context.");
}
g_rdt = calloc(1, sizeof(*g_rdt));
if (g_rdt == NULL) {
ERROR(RDT_PLUGIN ": Failed to allocate memory for rdt context.");
}
struct pqos_config pqos = {.fd_log = -1,
}
struct pqos_config pqos = {.fd_log = -1,
/* Reset pqos monitoring groups registers */
pqos_mon_reset();
/* Reset pqos monitoring groups registers */
pqos_mon_reset();
rdt_preinit_error2:
pqos_fini();
rdt_preinit_error2:
pqos_fini();
}
static int rdt_config(oconfig_item_t *ci) {
}
static int rdt_config(oconfig_item_t *ci) {
}
static void rdt_submit_derive(char *cgroup, char *type, char *type_instance,
}
static void rdt_submit_derive(char *cgroup, char *type, char *type_instance,
if (g_rdt == NULL) {
ERROR(RDT_PLUGIN ": rdt_read: plugin not initialized.");
if (g_rdt == NULL) {
ERROR(RDT_PLUGIN ": rdt_read: plugin not initialized.");
}
ret = pqos_mon_poll(&g_rdt->pgroups[0], (unsigned)g_rdt->num_groups);
if (ret != PQOS_RETVAL_OK) {
ERROR(RDT_PLUGIN ": Failed to poll monitoring data.");
}
ret = pqos_mon_poll(&g_rdt->pgroups[0], (unsigned)g_rdt->num_groups);
if (ret != PQOS_RETVAL_OK) {
ERROR(RDT_PLUGIN ": Failed to poll monitoring data.");
}
static int rdt_init(void) {
int ret;
if(g_state == CONFIGURATION_ERROR)
}
static int rdt_init(void) {
int ret;
if(g_state == CONFIGURATION_ERROR)
ret = rdt_preinit();
if (ret != 0)
ret = rdt_preinit();
if (ret != 0)
}
static int rdt_shutdown(void) {
}
static int rdt_shutdown(void) {
DEBUG(RDT_PLUGIN ": rdt_shutdown.");
if (g_rdt == NULL)
DEBUG(RDT_PLUGIN ": rdt_shutdown.");
if (g_rdt == NULL)
/* Stop monitoring */
for (int i = 0; i < g_rdt->num_groups; i++) {
/* Stop monitoring */
for (int i = 0; i < g_rdt->num_groups; i++) {
rdt_free_cgroups();
sfree(g_rdt);
rdt_free_cgroups();
sfree(g_rdt);
}
void module_register(void) {
}
void module_register(void) {
"Solaris.");
#endif /* HAVE_LIBKSTAT */
} else {
"Solaris.");
#endif /* HAVE_LIBKSTAT */
} else {
numif = 0;
if (kc == NULL)
numif = 0;
if (kc == NULL)
for (numif = 0, ksp_chain = kc->kc_chain;
(numif < MAX_NUMIF) && (ksp_chain != NULL);
for (numif = 0, ksp_chain = kc->kc_chain;
(numif < MAX_NUMIF) && (ksp_chain != NULL);
ksp[numif++] = ksp_chain;
}
ksp[numif++] = ksp_chain;
}
} /* int interface_init */
#endif /* HAVE_LIBKSTAT */
} /* int interface_init */
#endif /* HAVE_LIBKSTAT */
struct IFA_DATA *if_data;
if (getifaddrs(&if_list) != 0)
struct IFA_DATA *if_data;
if (getifaddrs(&if_list) != 0)
for (struct ifaddrs *if_ptr = if_list; if_ptr != NULL;
if_ptr = if_ptr->ifa_next) {
for (struct ifaddrs *if_ptr = if_list; if_ptr != NULL;
if_ptr = if_ptr->ifa_next) {
char errbuf[1024];
WARNING("interface plugin: fopen: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("interface plugin: fopen: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, 1024, fh) != NULL) {
}
while (fgets(buffer, 1024, fh) != NULL) {
char iname[DATA_MAX_NAME_LEN];
if (kc == NULL)
char iname[DATA_MAX_NAME_LEN];
if (kc == NULL)
for (int i = 0; i < numif; i++) {
if (kstat_read(kc, ksp[i], NULL) == -1)
for (int i = 0; i < numif; i++) {
if (kstat_read(kc, ksp[i], NULL) == -1)
char errbuf[1024];
WARNING("interface plugin: perfstat_netinterface: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("interface plugin: perfstat_netinterface: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (pnif != nif || ifstat == NULL) {
}
if (pnif != nif || ifstat == NULL) {
char errbuf[1024];
WARNING("interface plugin: perfstat_netinterface (interfaces=%d): %s", nif,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("interface plugin: perfstat_netinterface (interfaces=%d): %s", nif,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
for (int i = 0; i < ifs; i++) {
}
for (int i = 0; i < ifs; i++) {
}
#endif /* HAVE_PERFSTAT */
}
#endif /* HAVE_PERFSTAT */
} /* int interface_read */
void module_register(void) {
} /* int interface_read */
void module_register(void) {
ERROR("ipc plugin: semctl(2) failed: %s. "
"Maybe the kernel is not configured for semaphores?",
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("ipc plugin: semctl(2) failed: %s. "
"Maybe the kernel is not configured for semaphores?",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
ipc_submit_g("sem", "count", "arrays", seminfo.semusz);
ipc_submit_g("sem", "count", "total", seminfo.semaem);
}
ipc_submit_g("sem", "count", "arrays", seminfo.semusz);
ipc_submit_g("sem", "count", "total", seminfo.semaem);
} /* }}} int ipc_read_sem */
static int ipc_read_shm(void) /* {{{ */
} /* }}} int ipc_read_sem */
static int ipc_read_shm(void) /* {{{ */
ERROR("ipc plugin: shmctl(2) failed: %s. "
"Maybe the kernel is not configured for shared memory?",
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("ipc plugin: shmctl(2) failed: %s. "
"Maybe the kernel is not configured for shared memory?",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
ipc_submit_g("shm", "segments", NULL, shm_info.used_ids);
ipc_submit_g("shm", "bytes", "total", shm_info.shm_tot * pagesize_g);
ipc_submit_g("shm", "bytes", "rss", shm_info.shm_rss * pagesize_g);
ipc_submit_g("shm", "bytes", "swapped", shm_info.shm_swp * pagesize_g);
}
ipc_submit_g("shm", "segments", NULL, shm_info.used_ids);
ipc_submit_g("shm", "bytes", "total", shm_info.shm_tot * pagesize_g);
ipc_submit_g("shm", "bytes", "rss", shm_info.shm_rss * pagesize_g);
ipc_submit_g("shm", "bytes", "swapped", shm_info.shm_swp * pagesize_g);
}
/* }}} int ipc_read_shm */
}
/* }}} int ipc_read_shm */
if (msgctl(0, MSG_INFO, (struct msqid_ds *)(void *)&msginfo) < 0) {
ERROR("Kernel is not configured for message queues");
if (msgctl(0, MSG_INFO, (struct msqid_ds *)(void *)&msginfo) < 0) {
ERROR("Kernel is not configured for message queues");
}
ipc_submit_g("msg", "count", "queues", msginfo.msgmni);
ipc_submit_g("msg", "count", "headers", msginfo.msgmap);
ipc_submit_g("msg", "count", "space", msginfo.msgtql);
}
ipc_submit_g("msg", "count", "queues", msginfo.msgmni);
ipc_submit_g("msg", "count", "headers", msginfo.msgmap);
ipc_submit_g("msg", "count", "space", msginfo.msgtql);
}
/* }}} int ipc_read_msg */
static int ipc_init(void) /* {{{ */
{
pagesize_g = sysconf(_SC_PAGESIZE);
}
/* }}} int ipc_read_msg */
static int ipc_init(void) /* {{{ */
{
pagesize_g = sysconf(_SC_PAGESIZE);
}
/* }}} */
/* #endif KERNEL_LINUX */
}
/* }}} */
/* #endif KERNEL_LINUX */
char errbuf[1024];
WARNING("ipc plugin: get_ipc_info: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("ipc plugin: get_ipc_info: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
if (size % stsize) {
ERROR("ipc plugin: ipc_get_info: missmatch struct size and buffer size");
if (size % stsize) {
ERROR("ipc plugin: ipc_get_info: missmatch struct size and buffer size");
}
*nmemb = size / stsize;
}
*nmemb = size / stsize;
buff = malloc(size);
if (buff == NULL) {
ERROR("ipc plugin: ipc_get_info malloc failed.");
buff = malloc(size);
if (buff == NULL) {
ERROR("ipc plugin: ipc_get_info malloc failed.");
}
if (get_ipc_info(cid, cmd, version, buff, &size) < 0) {
}
if (get_ipc_info(cid, cmd, version, buff, &size) < 0) {
WARNING("ipc plugin: get_ipc_info: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
free(buff);
WARNING("ipc plugin: get_ipc_info: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
free(buff);
ipc_submit_g("sem", "count", "arrays", sem_nsems);
ipc_submit_g("sem", "count", "total", sems);
ipc_submit_g("sem", "count", "arrays", sem_nsems);
ipc_submit_g("sem", "count", "total", sems);
} /* }}} int ipc_read_sem */
static int ipc_read_shm(void) /* {{{ */
} /* }}} int ipc_read_sem */
static int ipc_read_shm(void) /* {{{ */
ipc_submit_g("shm", "segments", NULL, shm_segments);
ipc_submit_g("shm", "bytes", "total", shm_bytes);
ipc_submit_g("shm", "segments", NULL, shm_segments);
ipc_submit_g("shm", "bytes", "total", shm_bytes);
}
/* }}} int ipc_read_shm */
}
/* }}} int ipc_read_shm */
ipc_submit_g("msg", "count", "headers", msg_qnum);
ipc_submit_g("msg", "count", "space", msg_used_space);
ipc_submit_g("msg", "count", "headers", msg_qnum);
ipc_submit_g("msg", "count", "space", msg_used_space);
}
/* }}} */
#endif /* KERNEL_AIX */
}
/* }}} */
#endif /* KERNEL_AIX */
x |= ipc_read_sem();
x |= ipc_read_msg();
x |= ipc_read_sem();
x |= ipc_read_msg();
/* Both `ignorelist' and `plugin_instance' may be NULL. */
if (ignorelist_match(ignorelist, sensor_name_ptr) != 0)
/* Both `ignorelist' and `plugin_instance' may be NULL. */
if (ignorelist_match(ignorelist, sensor_name_ptr) != 0)
/* FIXME: Use rate unit or base unit to scale the value */
/* FIXME: Use rate unit or base unit to scale the value */
"because I don't know how to handle its type (%#x, %s). "
"If you need this sensor, please file a bug report.",
sensor_name_ptr, sensor_type, sensor_type_str);
"because I don't know how to handle its type (%#x, %s). "
"If you need this sensor, please file a bug report.",
sensor_name_ptr, sensor_type, sensor_type_str);
}
} /* switch (sensor_type) */
}
} /* switch (sensor_type) */
if (list_item != NULL) {
pthread_mutex_unlock(&sensor_list_lock);
if (list_item != NULL) {
pthread_mutex_unlock(&sensor_list_lock);
}
list_item = (c_ipmi_sensor_list_t *)calloc(1, sizeof(c_ipmi_sensor_list_t));
if (list_item == NULL) {
pthread_mutex_unlock(&sensor_list_lock);
}
list_item = (c_ipmi_sensor_list_t *)calloc(1, sizeof(c_ipmi_sensor_list_t));
if (list_item == NULL) {
pthread_mutex_unlock(&sensor_list_lock);
}
list_item->sensor_id = ipmi_sensor_convert_to_id(sensor);
}
list_item->sensor_id = ipmi_sensor_convert_to_id(sensor);
plugin_dispatch_notification(&n);
}
plugin_dispatch_notification(&n);
}
} /* int sensor_list_add */
static int sensor_list_remove(ipmi_sensor_t *sensor) {
} /* int sensor_list_add */
static int sensor_list_remove(ipmi_sensor_t *sensor) {
if (list_item == NULL) {
pthread_mutex_unlock(&sensor_list_lock);
if (list_item == NULL) {
pthread_mutex_unlock(&sensor_list_lock);
} /* int sensor_list_remove */
static int sensor_list_read_all(void) {
} /* int sensor_list_remove */
static int sensor_list_read_all(void) {
pthread_mutex_unlock(&sensor_list_lock);
pthread_mutex_unlock(&sensor_list_lock);
} /* int sensor_list_read_all */
static int sensor_list_remove_all(void) {
} /* int sensor_list_read_all */
static int sensor_list_remove_all(void) {
list_item = list_next;
} /* while (list_item) */
list_item = list_next;
} /* while (list_item) */
} /* int sensor_list_remove_all */
/*
} /* int sensor_list_remove_all */
/*
os_handler = ipmi_posix_thread_setup_os_handler(SIGIO);
if (os_handler == NULL) {
ERROR("ipmi plugin: ipmi_posix_thread_setup_os_handler failed.");
os_handler = ipmi_posix_thread_setup_os_handler(SIGIO);
if (os_handler == NULL) {
ERROR("ipmi plugin: ipmi_posix_thread_setup_os_handler failed.");
/* user data = */ NULL, &smi_connection);
if (status != 0) {
c_ipmi_error("ipmi_smi_setup_con", status);
/* user data = */ NULL, &smi_connection);
if (status != 0) {
c_ipmi_error("ipmi_smi_setup_con", status);
}
ipmi_open_option_t open_option[1] = {[0] = {.option = IPMI_OPEN_OPTION_ALL,
}
ipmi_open_option_t open_option[1] = {[0] = {.option = IPMI_OPEN_OPTION_ALL,
sizeof(open_option) / sizeof(open_option[0]), &domain_id);
if (status != 0) {
c_ipmi_error("ipmi_open_domain", status);
sizeof(open_option) / sizeof(open_option[0]), &domain_id);
if (status != 0) {
c_ipmi_error("ipmi_open_domain", status);
}
*ret_os_handler = os_handler;
}
*ret_os_handler = os_handler;
} /* int thread_init */
static void *thread_main(void __attribute__((unused)) * user_data) {
} /* int thread_init */
static void *thread_main(void __attribute__((unused)) * user_data) {
status = thread_init(&os_handler);
if (status != 0) {
ERROR("ipmi plugin: thread_init failed.\n");
status = thread_init(&os_handler);
if (status != 0) {
ERROR("ipmi plugin: thread_init failed.\n");
}
while (c_ipmi_active != 0) {
}
while (c_ipmi_active != 0) {
ipmi_posix_thread_free_os_handler(os_handler);
ipmi_posix_thread_free_os_handler(os_handler);
} /* void *thread_main */
static int c_ipmi_config(const char *key, const char *value) {
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
} /* void *thread_main */
static int c_ipmi_config(const char *key, const char *value) {
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
if (strcasecmp("Sensor", key) == 0) {
ignorelist_add(ignorelist, value);
if (strcasecmp("Sensor", key) == 0) {
ignorelist_add(ignorelist, value);
if (IS_TRUE(value))
c_ipmi_nofiy_notpresent = 1;
} else {
if (IS_TRUE(value))
c_ipmi_nofiy_notpresent = 1;
} else {
} /* int c_ipmi_config */
static int c_ipmi_init(void) {
} /* int c_ipmi_config */
static int c_ipmi_init(void) {
c_ipmi_active = 0;
thread_id = (pthread_t)0;
ERROR("ipmi plugin: pthread_create failed.");
c_ipmi_active = 0;
thread_id = (pthread_t)0;
ERROR("ipmi plugin: pthread_create failed.");
} /* int c_ipmi_init */
static int c_ipmi_read(void) {
if ((c_ipmi_active == 0) || (thread_id == (pthread_t)0)) {
INFO("ipmi plugin: c_ipmi_read: I'm not active, returning false.");
} /* int c_ipmi_init */
static int c_ipmi_read(void) {
if ((c_ipmi_active == 0) || (thread_id == (pthread_t)0)) {
INFO("ipmi plugin: c_ipmi_read: I'm not active, returning false.");
}
sensor_list_read_all();
}
sensor_list_read_all();
else
c_ipmi_init_in_progress = 0;
else
c_ipmi_init_in_progress = 0;
} /* int c_ipmi_read */
static int c_ipmi_shutdown(void) {
} /* int c_ipmi_read */
static int c_ipmi_shutdown(void) {
sensor_list_remove_all();
sensor_list_remove_all();
} /* int c_ipmi_shutdown */
void module_register(void) {
} /* int c_ipmi_shutdown */
void module_register(void) {
else if (strcasecmp(key, "Chain6") == 0)
ip_version = IPV6;
else
else if (strcasecmp(key, "Chain6") == 0)
ip_version = IPV6;
else
ip_chain_t temp = {0};
ip_chain_t * final, **list;
ip_chain_t temp = {0};
ip_chain_t * final, **list;
if (value_copy == NULL) {
char errbuf[1024];
ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if (value_copy == NULL) {
char errbuf[1024];
ERROR("strdup failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
fields_num = strsplit(value_copy, fields, 4);
if (fields_num < 2) {
free(value_copy);
fields_num = strsplit(value_copy, fields, 4);
if (fields_num < 2) {
free(value_copy);
if ((unsigned int)table_len > sizeof(temp.table)) {
ERROR("Table `%s' too long.", table);
free(value_copy);
if ((unsigned int)table_len > sizeof(temp.table)) {
ERROR("Table `%s' too long.", table);
free(value_copy);
}
sstrncpy(temp.table, table, table_len);
}
sstrncpy(temp.table, table, table_len);
if ((unsigned int)chain_len > sizeof(temp.chain)) {
ERROR("Chain `%s' too long.", chain);
free(value_copy);
if ((unsigned int)chain_len > sizeof(temp.chain)) {
ERROR("Chain `%s' too long.", chain);
free(value_copy);
}
sstrncpy(temp.chain, chain, chain_len);
}
sstrncpy(temp.chain, chain, chain_len);
temp.rule.comment = strdup(comment);
if (temp.rule.comment == NULL) {
free(value_copy);
temp.rule.comment = strdup(comment);
if (temp.rule.comment == NULL) {
free(value_copy);
}
temp.rule_type = RTYPE_COMMENT;
}
}
temp.rule_type = RTYPE_COMMENT;
}
char errbuf[1024];
ERROR("realloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(temp.rule.comment);
char errbuf[1024];
ERROR("realloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(temp.rule.comment);
char errbuf[1024];
ERROR("malloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(temp.rule.comment);
char errbuf[1024];
ERROR("malloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(temp.rule.comment);
}
memcpy(final, &temp, sizeof(temp));
chain_list[chain_num] = final;
}
memcpy(final, &temp, sizeof(temp));
chain_list[chain_num] = final;
DEBUG("Chain #%i: table = %s; chain = %s;", chain_num, final->table,
final->chain);
DEBUG("Chain #%i: table = %s; chain = %s;", chain_num, final->table,
final->chain);
} /* int iptables_config */
static int submit6_match(const struct ip6t_entry_match *match,
} /* int iptables_config */
static int submit6_match(const struct ip6t_entry_match *match,
/* Select the rules to collect */
if (chain->rule_type == RTYPE_NUM) {
if (chain->rule.num != rule_num)
/* Select the rules to collect */
if (chain->rule_type == RTYPE_NUM) {
if (chain->rule.num != rule_num)
} else {
if (strcmp(match->u.user.name, "comment") != 0)
} else {
if (strcmp(match->u.user.name, "comment") != 0)
if ((chain->rule_type == RTYPE_COMMENT) &&
(strcmp(chain->rule.comment, (char *)match->data) != 0))
if ((chain->rule_type == RTYPE_COMMENT) &&
(strcmp(chain->rule.comment, (char *)match->data) != 0))
}
sstrncpy(vl.plugin, "ip6tables", sizeof(vl.plugin));
}
sstrncpy(vl.plugin, "ip6tables", sizeof(vl.plugin));
status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
chain->table, chain->chain);
if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
chain->table, chain->chain);
if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
if (chain->name[0] != '\0') {
sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
if (chain->name[0] != '\0') {
sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt};
plugin_dispatch_values(&vl);
vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt};
plugin_dispatch_values(&vl);
} /* int submit6_match */
/* This needs to return `int' for IPT_MATCH_ITERATE to work. */
} /* int submit6_match */
/* This needs to return `int' for IPT_MATCH_ITERATE to work. */
/* Select the rules to collect */
if (chain->rule_type == RTYPE_NUM) {
if (chain->rule.num != rule_num)
/* Select the rules to collect */
if (chain->rule_type == RTYPE_NUM) {
if (chain->rule.num != rule_num)
} else {
if (strcmp(match->u.user.name, "comment") != 0)
} else {
if (strcmp(match->u.user.name, "comment") != 0)
if ((chain->rule_type == RTYPE_COMMENT) &&
(strcmp(chain->rule.comment, (char *)match->data) != 0))
if ((chain->rule_type == RTYPE_COMMENT) &&
(strcmp(chain->rule.comment, (char *)match->data) != 0))
}
sstrncpy(vl.plugin, "iptables", sizeof(vl.plugin));
}
sstrncpy(vl.plugin, "iptables", sizeof(vl.plugin));
status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
chain->table, chain->chain);
if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
chain->table, chain->chain);
if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
if (chain->name[0] != '\0') {
sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
if (chain->name[0] != '\0') {
sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt};
plugin_dispatch_values(&vl);
vl.values = &(value_t){.derive = (derive_t)entry->counters.pcnt};
plugin_dispatch_values(&vl);
} /* int submit_match */
/* ipv6 submit_chain */
} /* int submit_match */
/* ipv6 submit_chain */
num_failures++;
} /* for (i = 0 .. chain_num) */
num_failures++;
} /* for (i = 0 .. chain_num) */
- return ((num_failures < chain_num) ? 0 : -1);
+ return (num_failures < chain_num) ? 0 : -1;
} /* int iptables_read */
static int iptables_shutdown(void) {
} /* int iptables_read */
static int iptables_shutdown(void) {
} /* int iptables_shutdown */
static int iptables_init(void) {
} /* int iptables_shutdown */
static int iptables_init(void) {
"running \"setcap cap_net_admin=ep\" on the collectd binary.");
}
#endif
"running \"setcap cap_net_admin=ep\" on the collectd binary.");
}
#endif
} /* int iptables_init */
void module_register(void) {
} /* int iptables_init */
void module_register(void) {
struct ip_vs_get_services *services = NULL;
if (sockfd < 0)
struct ip_vs_get_services *services = NULL;
if (sockfd < 0)
if (NULL == (services = ipvs_get_services()))
return -1;
if (NULL == (services = ipvs_get_services()))
return -1;
invert = 0;
ignorelist_set_invert(ignorelist, invert);
} else {
invert = 0;
ignorelist_set_invert(ignorelist, invert);
} else {
}
static void irq_submit(const char *irq_name, derive_t value) {
}
static void irq_submit(const char *irq_name, derive_t value) {
char errbuf[1024];
ERROR("irq plugin: fopen (/proc/interrupts): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("irq plugin: fopen (/proc/interrupts): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* Get CPU count from the first line */
}
/* Get CPU count from the first line */
ERROR("irq plugin: unable to get CPU count from first line "
"of /proc/interrupts");
fclose(fh);
ERROR("irq plugin: unable to get CPU count from first line "
"of /proc/interrupts");
fclose(fh);
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
} /* int irq_read */
void module_register(void) {
} /* int irq_read */
void module_register(void) {
o_string = (*jvm_env)->NewStringUTF(jvm_env, (string != NULL) ? string : "");
if (o_string == NULL) {
ERROR("java plugin: ctoj_string: NewStringUTF failed.");
o_string = (*jvm_env)->NewStringUTF(jvm_env, (string != NULL) ? string : "");
if (o_string == NULL) {
ERROR("java plugin: ctoj_string: NewStringUTF failed.");
}
/* Search for the `void setFoo (String s)' method. */
}
/* Search for the `void setFoo (String s)' method. */
ERROR("java plugin: ctoj_string: Cannot find method `void %s (String)'.",
method_name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_string);
ERROR("java plugin: ctoj_string: Cannot find method `void %s (String)'.",
method_name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_string);
/* Decrease reference counter on the java.lang.String object. */
(*jvm_env)->DeleteLocalRef(jvm_env, o_string);
/* Decrease reference counter on the java.lang.String object. */
(*jvm_env)->DeleteLocalRef(jvm_env, o_string);
} /* }}} int ctoj_string */
static jstring ctoj_output_string(JNIEnv *jvm_env, /* {{{ */
} /* }}} int ctoj_string */
static jstring ctoj_output_string(JNIEnv *jvm_env, /* {{{ */
} /* }}} int ctoj_output_string */
static int ctoj_int(JNIEnv *jvm_env, /* {{{ */
} /* }}} int ctoj_output_string */
static int ctoj_int(JNIEnv *jvm_env, /* {{{ */
if (m_set == NULL) {
ERROR("java plugin: ctoj_int: Cannot find method `void %s (int)'.",
method_name);
if (m_set == NULL) {
ERROR("java plugin: ctoj_int: Cannot find method `void %s (int)'.",
method_name);
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_set, value);
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_set, value);
} /* }}} int ctoj_int */
static int ctoj_long(JNIEnv *jvm_env, /* {{{ */
} /* }}} int ctoj_int */
static int ctoj_long(JNIEnv *jvm_env, /* {{{ */
if (m_set == NULL) {
ERROR("java plugin: ctoj_long: Cannot find method `void %s (long)'.",
method_name);
if (m_set == NULL) {
ERROR("java plugin: ctoj_long: Cannot find method `void %s (long)'.",
method_name);
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_set, value);
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_set, value);
} /* }}} int ctoj_long */
static int ctoj_double(JNIEnv *jvm_env, /* {{{ */
} /* }}} int ctoj_long */
static int ctoj_double(JNIEnv *jvm_env, /* {{{ */
if (m_set == NULL) {
ERROR("java plugin: ctoj_double: Cannot find method `void %s (double)'.",
method_name);
if (m_set == NULL) {
ERROR("java plugin: ctoj_double: Cannot find method `void %s (double)'.",
method_name);
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_set, value);
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_set, value);
} /* }}} int ctoj_double */
/* Convert a jlong to a java.lang.Number */
} /* }}} int ctoj_double */
/* Convert a jlong to a java.lang.Number */
if (c_long == NULL) {
ERROR("java plugin: ctoj_jlong_to_number: Looking up the "
"java.lang.Long class failed.");
if (c_long == NULL) {
ERROR("java plugin: ctoj_jlong_to_number: Looking up the "
"java.lang.Long class failed.");
if (m_long_constructor == NULL) {
ERROR("java plugin: ctoj_jlong_to_number: Looking up the "
"`Long (long)' constructor failed.");
if (m_long_constructor == NULL) {
ERROR("java plugin: ctoj_jlong_to_number: Looking up the "
"`Long (long)' constructor failed.");
- return ((*jvm_env)->NewObject(jvm_env, c_long, m_long_constructor, value));
+ return (*jvm_env)->NewObject(jvm_env, c_long, m_long_constructor, value);
} /* }}} jobject ctoj_jlong_to_number */
/* Convert a jdouble to a java.lang.Number */
} /* }}} jobject ctoj_jlong_to_number */
/* Convert a jdouble to a java.lang.Number */
if (c_double == NULL) {
ERROR("java plugin: ctoj_jdouble_to_number: Looking up the "
"java.lang.Double class failed.");
if (c_double == NULL) {
ERROR("java plugin: ctoj_jdouble_to_number: Looking up the "
"java.lang.Double class failed.");
if (m_double_constructor == NULL) {
ERROR("java plugin: ctoj_jdouble_to_number: Looking up the "
"`Double (double)' constructor failed.");
if (m_double_constructor == NULL) {
ERROR("java plugin: ctoj_jdouble_to_number: Looking up the "
"`Double (double)' constructor failed.");
- return (
- (*jvm_env)->NewObject(jvm_env, c_double, m_double_constructor, value));
+ return (*jvm_env)->NewObject(jvm_env, c_double, m_double_constructor, value);
} /* }}} jobject ctoj_jdouble_to_number */
/* Convert a value_t to a java.lang.Number */
static jobject ctoj_value_to_number(JNIEnv *jvm_env, /* {{{ */
value_t value, int ds_type) {
if (ds_type == DS_TYPE_COUNTER)
} /* }}} jobject ctoj_jdouble_to_number */
/* Convert a value_t to a java.lang.Number */
static jobject ctoj_value_to_number(JNIEnv *jvm_env, /* {{{ */
value_t value, int ds_type) {
if (ds_type == DS_TYPE_COUNTER)
- return (ctoj_jlong_to_number(jvm_env, (jlong)value.counter));
+ return ctoj_jlong_to_number(jvm_env, (jlong)value.counter);
else if (ds_type == DS_TYPE_GAUGE)
else if (ds_type == DS_TYPE_GAUGE)
- return (ctoj_jdouble_to_number(jvm_env, (jdouble)value.gauge));
+ return ctoj_jdouble_to_number(jvm_env, (jdouble)value.gauge);
if (ds_type == DS_TYPE_DERIVE)
if (ds_type == DS_TYPE_DERIVE)
- return (ctoj_jlong_to_number(jvm_env, (jlong)value.derive));
+ return ctoj_jlong_to_number(jvm_env, (jlong)value.derive);
if (ds_type == DS_TYPE_ABSOLUTE)
if (ds_type == DS_TYPE_ABSOLUTE)
- return (ctoj_jlong_to_number(jvm_env, (jlong)value.absolute));
+ return ctoj_jlong_to_number(jvm_env, (jlong)value.absolute);
} /* }}} jobject ctoj_value_to_number */
/* Convert a data_source_t to a org/collectd/api/DataSource */
} /* }}} jobject ctoj_value_to_number */
/* Convert a data_source_t to a org/collectd/api/DataSource */
if (c_datasource == NULL) {
ERROR("java plugin: ctoj_data_source: "
"FindClass (org/collectd/api/DataSource) failed.");
if (c_datasource == NULL) {
ERROR("java plugin: ctoj_data_source: "
"FindClass (org/collectd/api/DataSource) failed.");
}
/* Lookup the `ValueList ()' constructor. */
}
/* Lookup the `ValueList ()' constructor. */
if (m_datasource_constructor == NULL) {
ERROR("java plugin: ctoj_data_source: Cannot find the "
"`DataSource ()' constructor.");
if (m_datasource_constructor == NULL) {
ERROR("java plugin: ctoj_data_source: Cannot find the "
"`DataSource ()' constructor.");
}
/* Create a new instance. */
}
/* Create a new instance. */
if (o_datasource == NULL) {
ERROR("java plugin: ctoj_data_source: "
"Creating a new DataSource instance failed.");
if (o_datasource == NULL) {
ERROR("java plugin: ctoj_data_source: "
"Creating a new DataSource instance failed.");
}
/* Set name via `void setName (String name)' */
}
/* Set name via `void setName (String name)' */
ERROR("java plugin: ctoj_data_source: "
"ctoj_string (setName) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
ERROR("java plugin: ctoj_data_source: "
"ctoj_string (setName) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
}
/* Set type via `void setType (int type)' */
}
/* Set type via `void setType (int type)' */
ERROR("java plugin: ctoj_data_source: "
"ctoj_int (setType) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
ERROR("java plugin: ctoj_data_source: "
"ctoj_int (setType) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
}
/* Set min via `void setMin (double min)' */
}
/* Set min via `void setMin (double min)' */
ERROR("java plugin: ctoj_data_source: "
"ctoj_double (setMin) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
ERROR("java plugin: ctoj_data_source: "
"ctoj_double (setMin) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
}
/* Set max via `void setMax (double max)' */
}
/* Set max via `void setMax (double max)' */
ERROR("java plugin: ctoj_data_source: "
"ctoj_double (setMax) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
ERROR("java plugin: ctoj_data_source: "
"ctoj_double (setMax) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
} /* }}} jobject ctoj_data_source */
/* Convert a oconfig_value_t to a org/collectd/api/OConfigValue */
} /* }}} jobject ctoj_data_source */
/* Convert a oconfig_value_t to a org/collectd/api/OConfigValue */
if (c_ocvalue == NULL) {
ERROR("java plugin: ctoj_oconfig_value: "
"FindClass (org/collectd/api/OConfigValue) failed.");
if (c_ocvalue == NULL) {
ERROR("java plugin: ctoj_oconfig_value: "
"FindClass (org/collectd/api/OConfigValue) failed.");
}
if (ocvalue.type == OCONFIG_TYPE_BOOLEAN) {
}
if (ocvalue.type == OCONFIG_TYPE_BOOLEAN) {
if (m_ocvalue_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_value: Cannot find the "
"`OConfigValue (boolean)' constructor.");
if (m_ocvalue_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_value: Cannot find the "
"`OConfigValue (boolean)' constructor.");
- return ((*jvm_env)->NewObject(jvm_env, c_ocvalue, m_ocvalue_constructor,
- tmp_boolean));
+ return (*jvm_env)->NewObject(jvm_env, c_ocvalue, m_ocvalue_constructor,
+ tmp_boolean);
} /* if (ocvalue.type == OCONFIG_TYPE_BOOLEAN) */
else if (ocvalue.type == OCONFIG_TYPE_STRING) {
m_ocvalue_constructor = (*jvm_env)->GetMethodID(
} /* if (ocvalue.type == OCONFIG_TYPE_BOOLEAN) */
else if (ocvalue.type == OCONFIG_TYPE_STRING) {
m_ocvalue_constructor = (*jvm_env)->GetMethodID(
if (m_ocvalue_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_value: Cannot find the "
"`OConfigValue (String)' constructor.");
if (m_ocvalue_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_value: Cannot find the "
"`OConfigValue (String)' constructor.");
}
o_argument = (*jvm_env)->NewStringUTF(jvm_env, ocvalue.value.string);
if (o_argument == NULL) {
ERROR("java plugin: ctoj_oconfig_value: "
"Creating a String object failed.");
}
o_argument = (*jvm_env)->NewStringUTF(jvm_env, ocvalue.value.string);
if (o_argument == NULL) {
ERROR("java plugin: ctoj_oconfig_value: "
"Creating a String object failed.");
}
} else if (ocvalue.type == OCONFIG_TYPE_NUMBER) {
m_ocvalue_constructor = (*jvm_env)->GetMethodID(
}
} else if (ocvalue.type == OCONFIG_TYPE_NUMBER) {
m_ocvalue_constructor = (*jvm_env)->GetMethodID(
if (m_ocvalue_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_value: Cannot find the "
"`OConfigValue (Number)' constructor.");
if (m_ocvalue_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_value: Cannot find the "
"`OConfigValue (Number)' constructor.");
}
o_argument = ctoj_jdouble_to_number(jvm_env, (jdouble)ocvalue.value.number);
if (o_argument == NULL) {
ERROR("java plugin: ctoj_oconfig_value: "
"Creating a Number object failed.");
}
o_argument = ctoj_jdouble_to_number(jvm_env, (jdouble)ocvalue.value.number);
if (o_argument == NULL) {
ERROR("java plugin: ctoj_oconfig_value: "
"Creating a Number object failed.");
}
assert(m_ocvalue_constructor != NULL);
}
assert(m_ocvalue_constructor != NULL);
ERROR("java plugin: ctoj_oconfig_value: "
"Creating an OConfigValue object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_argument);
ERROR("java plugin: ctoj_oconfig_value: "
"Creating an OConfigValue object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_argument);
}
(*jvm_env)->DeleteLocalRef(jvm_env, o_argument);
}
(*jvm_env)->DeleteLocalRef(jvm_env, o_argument);
} /* }}} jobject ctoj_oconfig_value */
/* Convert a oconfig_item_t to a org/collectd/api/OConfigItem */
} /* }}} jobject ctoj_oconfig_value */
/* Convert a oconfig_item_t to a org/collectd/api/OConfigItem */
if (c_ocitem == NULL) {
ERROR("java plugin: ctoj_oconfig_item: "
"FindClass (org/collectd/api/OConfigItem) failed.");
if (c_ocitem == NULL) {
ERROR("java plugin: ctoj_oconfig_item: "
"FindClass (org/collectd/api/OConfigItem) failed.");
}
/* Get the required methods: m_ocitem_constructor, m_addvalue, and m_addchild
}
/* Get the required methods: m_ocitem_constructor, m_addvalue, and m_addchild
if (m_ocitem_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_item: Cannot find the "
"`OConfigItem (String)' constructor.");
if (m_ocitem_constructor == NULL) {
ERROR("java plugin: ctoj_oconfig_item: Cannot find the "
"`OConfigItem (String)' constructor.");
}
m_addvalue = (*jvm_env)->GetMethodID(jvm_env, c_ocitem, "addValue",
}
m_addvalue = (*jvm_env)->GetMethodID(jvm_env, c_ocitem, "addValue",
if (m_addvalue == NULL) {
ERROR("java plugin: ctoj_oconfig_item: Cannot find the "
"`addValue (OConfigValue)' method.");
if (m_addvalue == NULL) {
ERROR("java plugin: ctoj_oconfig_item: Cannot find the "
"`addValue (OConfigValue)' method.");
}
m_addchild = (*jvm_env)->GetMethodID(jvm_env, c_ocitem, "addChild",
}
m_addchild = (*jvm_env)->GetMethodID(jvm_env, c_ocitem, "addChild",
if (m_addchild == NULL) {
ERROR("java plugin: ctoj_oconfig_item: Cannot find the "
"`addChild (OConfigItem)' method.");
if (m_addchild == NULL) {
ERROR("java plugin: ctoj_oconfig_item: Cannot find the "
"`addChild (OConfigItem)' method.");
if (o_key == NULL) {
ERROR("java plugin: ctoj_oconfig_item: "
"Creating String object failed.");
if (o_key == NULL) {
ERROR("java plugin: ctoj_oconfig_item: "
"Creating String object failed.");
}
/* Create an OConfigItem object */
}
/* Create an OConfigItem object */
ERROR("java plugin: ctoj_oconfig_item: "
"Creating an OConfigItem object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_key);
ERROR("java plugin: ctoj_oconfig_item: "
"Creating an OConfigItem object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_key);
}
/* We don't need the String object any longer.. */
}
/* We don't need the String object any longer.. */
ERROR("java plugin: ctoj_oconfig_item: "
"Creating an OConfigValue object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_ocitem);
ERROR("java plugin: ctoj_oconfig_item: "
"Creating an OConfigValue object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_ocitem);
}
(*jvm_env)->CallVoidMethod(jvm_env, o_ocitem, m_addvalue, o_value);
}
(*jvm_env)->CallVoidMethod(jvm_env, o_ocitem, m_addvalue, o_value);
ERROR("java plugin: ctoj_oconfig_item: "
"Creating an OConfigItem object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_ocitem);
ERROR("java plugin: ctoj_oconfig_item: "
"Creating an OConfigItem object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_ocitem);
}
(*jvm_env)->CallVoidMethod(jvm_env, o_ocitem, m_addchild, o_child);
(*jvm_env)->DeleteLocalRef(jvm_env, o_child);
} /* }}} for (i = 0; i < ci->children_num; i++) */
}
(*jvm_env)->CallVoidMethod(jvm_env, o_ocitem, m_addchild, o_child);
(*jvm_env)->DeleteLocalRef(jvm_env, o_child);
} /* }}} for (i = 0; i < ci->children_num; i++) */
} /* }}} jobject ctoj_oconfig_item */
/* Convert a data_set_t to a org/collectd/api/DataSet */
} /* }}} jobject ctoj_oconfig_item */
/* Convert a data_set_t to a org/collectd/api/DataSet */
if (c_dataset == NULL) {
ERROR("java plugin: ctoj_data_set: Looking up the "
"org/collectd/api/DataSet class failed.");
if (c_dataset == NULL) {
ERROR("java plugin: ctoj_data_set: Looking up the "
"org/collectd/api/DataSet class failed.");
}
/* Search for the `DataSet (String type)' constructor. */
}
/* Search for the `DataSet (String type)' constructor. */
if (m_constructor == NULL) {
ERROR("java plugin: ctoj_data_set: Looking up the "
"`DataSet (String)' constructor failed.");
if (m_constructor == NULL) {
ERROR("java plugin: ctoj_data_set: Looking up the "
"`DataSet (String)' constructor failed.");
}
/* Search for the `void addDataSource (DataSource)' method. */
}
/* Search for the `void addDataSource (DataSource)' method. */
if (m_add == NULL) {
ERROR("java plugin: ctoj_data_set: Looking up the "
"`addDataSource (DataSource)' method failed.");
if (m_add == NULL) {
ERROR("java plugin: ctoj_data_set: Looking up the "
"`addDataSource (DataSource)' method failed.");
}
o_type = (*jvm_env)->NewStringUTF(jvm_env, ds->type);
if (o_type == NULL) {
ERROR("java plugin: ctoj_data_set: Creating a String object failed.");
}
o_type = (*jvm_env)->NewStringUTF(jvm_env, ds->type);
if (o_type == NULL) {
ERROR("java plugin: ctoj_data_set: Creating a String object failed.");
}
o_dataset = (*jvm_env)->NewObject(jvm_env, c_dataset, m_constructor, o_type);
if (o_dataset == NULL) {
ERROR("java plugin: ctoj_data_set: Creating a DataSet object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_type);
}
o_dataset = (*jvm_env)->NewObject(jvm_env, c_dataset, m_constructor, o_type);
if (o_dataset == NULL) {
ERROR("java plugin: ctoj_data_set: Creating a DataSet object failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_type);
}
/* Decrease reference counter on the java.lang.String object. */
}
/* Decrease reference counter on the java.lang.String object. */
ERROR("java plugin: ctoj_data_set: ctoj_data_source (%s.%s) failed",
ds->type, ds->ds[i].name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_dataset);
ERROR("java plugin: ctoj_data_set: ctoj_data_source (%s.%s) failed",
ds->type, ds->ds[i].name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_dataset);
}
(*jvm_env)->CallVoidMethod(jvm_env, o_dataset, m_add, o_datasource);
}
(*jvm_env)->CallVoidMethod(jvm_env, o_dataset, m_add, o_datasource);
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
} /* for (i = 0; i < ds->ds_num; i++) */
(*jvm_env)->DeleteLocalRef(jvm_env, o_datasource);
} /* for (i = 0; i < ds->ds_num; i++) */
} /* }}} jobject ctoj_data_set */
static int ctoj_value_list_add_value(JNIEnv *jvm_env, /* {{{ */
} /* }}} jobject ctoj_data_set */
static int ctoj_value_list_add_value(JNIEnv *jvm_env, /* {{{ */
if (m_addvalue == NULL) {
ERROR("java plugin: ctoj_value_list_add_value: "
"Cannot find method `void addValue (Number)'.");
if (m_addvalue == NULL) {
ERROR("java plugin: ctoj_value_list_add_value: "
"Cannot find method `void addValue (Number)'.");
}
o_number = ctoj_value_to_number(jvm_env, value, ds_type);
if (o_number == NULL) {
ERROR("java plugin: ctoj_value_list_add_value: "
"ctoj_value_to_number failed.");
}
o_number = ctoj_value_to_number(jvm_env, value, ds_type);
if (o_number == NULL) {
ERROR("java plugin: ctoj_value_list_add_value: "
"ctoj_value_to_number failed.");
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_addvalue, o_number);
(*jvm_env)->DeleteLocalRef(jvm_env, o_number);
}
(*jvm_env)->CallVoidMethod(jvm_env, object_ptr, m_addvalue, o_number);
(*jvm_env)->DeleteLocalRef(jvm_env, o_number);
} /* }}} int ctoj_value_list_add_value */
static int ctoj_value_list_add_data_set(JNIEnv *jvm_env, /* {{{ */
} /* }}} int ctoj_value_list_add_value */
static int ctoj_value_list_add_data_set(JNIEnv *jvm_env, /* {{{ */
if (m_setdataset == NULL) {
ERROR("java plugin: ctoj_value_list_add_data_set: "
"Cannot find the `void setDataSet (DataSet)' method.");
if (m_setdataset == NULL) {
ERROR("java plugin: ctoj_value_list_add_data_set: "
"Cannot find the `void setDataSet (DataSet)' method.");
}
/* Create a DataSet object. */
}
/* Create a DataSet object. */
ERROR("java plugin: ctoj_value_list_add_data_set: "
"ctoj_data_set (%s) failed.",
ds->type);
ERROR("java plugin: ctoj_value_list_add_data_set: "
"ctoj_data_set (%s) failed.",
ds->type);
}
/* Actually call the method. */
}
/* Actually call the method. */
/* Decrease reference counter on the List<DataSource> object. */
(*jvm_env)->DeleteLocalRef(jvm_env, o_dataset);
/* Decrease reference counter on the List<DataSource> object. */
(*jvm_env)->DeleteLocalRef(jvm_env, o_dataset);
} /* }}} int ctoj_value_list_add_data_set */
/* Convert a value_list_t (and data_set_t) to a org/collectd/api/ValueList */
} /* }}} int ctoj_value_list_add_data_set */
/* Convert a value_list_t (and data_set_t) to a org/collectd/api/ValueList */
if (c_valuelist == NULL) {
ERROR("java plugin: ctoj_value_list: "
"FindClass (org/collectd/api/ValueList) failed.");
if (c_valuelist == NULL) {
ERROR("java plugin: ctoj_value_list: "
"FindClass (org/collectd/api/ValueList) failed.");
}
/* Lookup the `ValueList ()' constructor. */
}
/* Lookup the `ValueList ()' constructor. */
if (m_valuelist_constructor == NULL) {
ERROR("java plugin: ctoj_value_list: Cannot find the "
"`ValueList ()' constructor.");
if (m_valuelist_constructor == NULL) {
ERROR("java plugin: ctoj_value_list: Cannot find the "
"`ValueList ()' constructor.");
}
/* Create a new instance. */
}
/* Create a new instance. */
if (o_valuelist == NULL) {
ERROR("java plugin: ctoj_value_list: Creating a new ValueList instance "
"failed.");
if (o_valuelist == NULL) {
ERROR("java plugin: ctoj_value_list: Creating a new ValueList instance "
"failed.");
}
status = ctoj_value_list_add_data_set(jvm_env, c_valuelist, o_valuelist, ds);
}
status = ctoj_value_list_add_data_set(jvm_env, c_valuelist, o_valuelist, ds);
ERROR("java plugin: ctoj_value_list: "
"ctoj_value_list_add_data_set failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
ERROR("java plugin: ctoj_value_list: "
"ctoj_value_list_add_data_set failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
}
/* Set the strings.. */
}
/* Set the strings.. */
ERROR("java plugin: ctoj_value_list: ctoj_string (%s) failed.", \
method_name); \
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist); \
ERROR("java plugin: ctoj_value_list: ctoj_string (%s) failed.", \
method_name); \
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist); \
if (status != 0) {
ERROR("java plugin: ctoj_value_list: ctoj_long (setTime) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
if (status != 0) {
ERROR("java plugin: ctoj_value_list: ctoj_long (setTime) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
}
/* Set the `interval' member.. */
}
/* Set the `interval' member.. */
if (status != 0) {
ERROR("java plugin: ctoj_value_list: ctoj_long (setInterval) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
if (status != 0) {
ERROR("java plugin: ctoj_value_list: ctoj_long (setInterval) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
}
for (size_t i = 0; i < vl->values_len; i++) {
}
for (size_t i = 0; i < vl->values_len; i++) {
ERROR("java plugin: ctoj_value_list: "
"ctoj_value_list_add_value failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
ERROR("java plugin: ctoj_value_list: "
"ctoj_value_list_add_value failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_valuelist);
} /* }}} jobject ctoj_value_list */
/* Convert a notification_t to a org/collectd/api/Notification */
} /* }}} jobject ctoj_value_list */
/* Convert a notification_t to a org/collectd/api/Notification */
if (c_notification == NULL) {
ERROR("java plugin: ctoj_notification: "
"FindClass (org/collectd/api/Notification) failed.");
if (c_notification == NULL) {
ERROR("java plugin: ctoj_notification: "
"FindClass (org/collectd/api/Notification) failed.");
}
/* Lookup the `Notification ()' constructor. */
}
/* Lookup the `Notification ()' constructor. */
if (m_constructor == NULL) {
ERROR("java plugin: ctoj_notification: Cannot find the "
"`Notification ()' constructor.");
if (m_constructor == NULL) {
ERROR("java plugin: ctoj_notification: Cannot find the "
"`Notification ()' constructor.");
}
/* Create a new instance. */
}
/* Create a new instance. */
if (o_notification == NULL) {
ERROR("java plugin: ctoj_notification: Creating a new Notification "
"instance failed.");
if (o_notification == NULL) {
ERROR("java plugin: ctoj_notification: Creating a new Notification "
"instance failed.");
}
/* Set the strings.. */
}
/* Set the strings.. */
ERROR("java plugin: ctoj_notification: ctoj_string (%s) failed.", \
method_name); \
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification); \
ERROR("java plugin: ctoj_notification: ctoj_string (%s) failed.", \
method_name); \
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification); \
if (status != 0) {
ERROR("java plugin: ctoj_notification: ctoj_long (setTime) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
if (status != 0) {
ERROR("java plugin: ctoj_notification: ctoj_long (setTime) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
}
/* Set the `severity' member.. */
}
/* Set the `severity' member.. */
if (status != 0) {
ERROR("java plugin: ctoj_notification: ctoj_int (setSeverity) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
if (status != 0) {
ERROR("java plugin: ctoj_notification: ctoj_int (setSeverity) failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
- return (o_notification);
} /* }}} jobject ctoj_notification */
/*
} /* }}} jobject ctoj_notification */
/*
if (method_id == NULL) {
ERROR("java plugin: jtoc_string: Cannot find method `String %s ()'.",
method_name);
if (method_id == NULL) {
ERROR("java plugin: jtoc_string: Cannot find method `String %s ()'.",
method_name);
}
string_obj = (*jvm_env)->CallObjectMethod(jvm_env, object_ptr, method_id);
if ((string_obj == NULL) && (empty_okay == 0)) {
ERROR("java plugin: jtoc_string: CallObjectMethod (%s) failed.",
method_name);
}
string_obj = (*jvm_env)->CallObjectMethod(jvm_env, object_ptr, method_id);
if ((string_obj == NULL) && (empty_okay == 0)) {
ERROR("java plugin: jtoc_string: CallObjectMethod (%s) failed.",
method_name);
} else if ((string_obj == NULL) && (empty_okay != 0)) {
memset(buffer, 0, buffer_size);
} else if ((string_obj == NULL) && (empty_okay != 0)) {
memset(buffer, 0, buffer_size);
}
c_str = (*jvm_env)->GetStringUTFChars(jvm_env, string_obj, 0);
if (c_str == NULL) {
ERROR("java plugin: jtoc_string: GetStringUTFChars failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, string_obj);
}
c_str = (*jvm_env)->GetStringUTFChars(jvm_env, string_obj, 0);
if (c_str == NULL) {
ERROR("java plugin: jtoc_string: GetStringUTFChars failed.");
(*jvm_env)->DeleteLocalRef(jvm_env, string_obj);
}
sstrncpy(buffer, c_str, buffer_size);
}
sstrncpy(buffer, c_str, buffer_size);
(*jvm_env)->ReleaseStringUTFChars(jvm_env, string_obj, c_str);
(*jvm_env)->DeleteLocalRef(jvm_env, string_obj);
(*jvm_env)->ReleaseStringUTFChars(jvm_env, string_obj, c_str);
(*jvm_env)->DeleteLocalRef(jvm_env, string_obj);
} /* }}} int jtoc_string */
/* Call an `int <method> ()' method. */
} /* }}} int jtoc_string */
/* Call an `int <method> ()' method. */
if (method_id == NULL) {
ERROR("java plugin: jtoc_int: Cannot find method `int %s ()'.",
method_name);
if (method_id == NULL) {
ERROR("java plugin: jtoc_int: Cannot find method `int %s ()'.",
method_name);
}
*ret_value = (*jvm_env)->CallIntMethod(jvm_env, object_ptr, method_id);
}
*ret_value = (*jvm_env)->CallIntMethod(jvm_env, object_ptr, method_id);
} /* }}} int jtoc_int */
/* Call a `long <method> ()' method. */
} /* }}} int jtoc_int */
/* Call a `long <method> ()' method. */
if (method_id == NULL) {
ERROR("java plugin: jtoc_long: Cannot find method `long %s ()'.",
method_name);
if (method_id == NULL) {
ERROR("java plugin: jtoc_long: Cannot find method `long %s ()'.",
method_name);
}
*ret_value = (*jvm_env)->CallLongMethod(jvm_env, object_ptr, method_id);
}
*ret_value = (*jvm_env)->CallLongMethod(jvm_env, object_ptr, method_id);
} /* }}} int jtoc_long */
/* Call a `double <method> ()' method. */
} /* }}} int jtoc_long */
/* Call a `double <method> ()' method. */
if (method_id == NULL) {
ERROR("java plugin: jtoc_double: Cannot find method `double %s ()'.",
method_name);
if (method_id == NULL) {
ERROR("java plugin: jtoc_double: Cannot find method `double %s ()'.",
method_name);
}
*ret_value = (*jvm_env)->CallDoubleMethod(jvm_env, object_ptr, method_id);
}
*ret_value = (*jvm_env)->CallDoubleMethod(jvm_env, object_ptr, method_id);
} /* }}} int jtoc_double */
static int jtoc_value(JNIEnv *jvm_env, /* {{{ */
} /* }}} int jtoc_double */
static int jtoc_value(JNIEnv *jvm_env, /* {{{ */
if (status != 0) {
ERROR("java plugin: jtoc_value: "
"jtoc_double failed.");
if (status != 0) {
ERROR("java plugin: jtoc_value: "
"jtoc_double failed.");
}
(*ret_value).gauge = (gauge_t)tmp_double;
} else {
}
(*ret_value).gauge = (gauge_t)tmp_double;
} else {
if (status != 0) {
ERROR("java plugin: jtoc_value: "
"jtoc_long failed.");
if (status != 0) {
ERROR("java plugin: jtoc_value: "
"jtoc_long failed.");
}
if (ds_type == DS_TYPE_DERIVE)
}
if (ds_type == DS_TYPE_DERIVE)
(*ret_value).counter = (counter_t)tmp_long;
}
(*ret_value).counter = (counter_t)tmp_long;
}
} /* }}} int jtoc_value */
/* Read a List<Number>, convert it to `value_t' and add it to the given
} /* }}} int jtoc_value */
/* Read a List<Number>, convert it to `value_t' and add it to the given
(*jvm_env)->DeleteLocalRef(jvm_env, o_number_array); \
if (o_list != NULL) \
(*jvm_env)->DeleteLocalRef(jvm_env, o_list); \
(*jvm_env)->DeleteLocalRef(jvm_env, o_number_array); \
if (o_list != NULL) \
(*jvm_env)->DeleteLocalRef(jvm_env, o_list); \
/* Call: List<Number> ValueList.getValues () */
m_getvalues = (*jvm_env)->GetMethodID(jvm_env, class_ptr, "getValues",
/* Call: List<Number> ValueList.getValues () */
m_getvalues = (*jvm_env)->GetMethodID(jvm_env, class_ptr, "getValues",
#undef BAIL_OUT
(*jvm_env)->DeleteLocalRef(jvm_env, o_number_array);
(*jvm_env)->DeleteLocalRef(jvm_env, o_list);
#undef BAIL_OUT
(*jvm_env)->DeleteLocalRef(jvm_env, o_number_array);
(*jvm_env)->DeleteLocalRef(jvm_env, o_list);
} /* }}} int jtoc_values_array */
/* Convert a org/collectd/api/ValueList to a value_list_t. */
} /* }}} int jtoc_values_array */
/* Convert a org/collectd/api/ValueList to a value_list_t. */
class_ptr = (*jvm_env)->GetObjectClass(jvm_env, object_ptr);
if (class_ptr == NULL) {
ERROR("java plugin: jtoc_value_list: GetObjectClass failed.");
class_ptr = (*jvm_env)->GetObjectClass(jvm_env, object_ptr);
if (class_ptr == NULL) {
ERROR("java plugin: jtoc_value_list: GetObjectClass failed.");
object_ptr, method); \
if (status != 0) { \
ERROR("java plugin: jtoc_value_list: jtoc_string (%s) failed.", method); \
object_ptr, method); \
if (status != 0) { \
ERROR("java plugin: jtoc_value_list: jtoc_string (%s) failed.", method); \
ERROR("java plugin: jtoc_value_list: Data-set `%s' is not defined. "
"Please consult the types.db(5) manpage for mor information.",
vl->type);
ERROR("java plugin: jtoc_value_list: Data-set `%s' is not defined. "
"Please consult the types.db(5) manpage for mor information.",
vl->type);
}
SET_STRING(vl->host, "getHost", /* empty = */ 0);
}
SET_STRING(vl->host, "getHost", /* empty = */ 0);
status = jtoc_long(jvm_env, &tmp_long, class_ptr, object_ptr, "getTime");
if (status != 0) {
ERROR("java plugin: jtoc_value_list: jtoc_long (getTime) failed.");
status = jtoc_long(jvm_env, &tmp_long, class_ptr, object_ptr, "getTime");
if (status != 0) {
ERROR("java plugin: jtoc_value_list: jtoc_long (getTime) failed.");
}
/* Java measures time in milliseconds. */
vl->time = MS_TO_CDTIME_T(tmp_long);
}
/* Java measures time in milliseconds. */
vl->time = MS_TO_CDTIME_T(tmp_long);
status = jtoc_long(jvm_env, &tmp_long, class_ptr, object_ptr, "getInterval");
if (status != 0) {
ERROR("java plugin: jtoc_value_list: jtoc_long (getInterval) failed.");
status = jtoc_long(jvm_env, &tmp_long, class_ptr, object_ptr, "getInterval");
if (status != 0) {
ERROR("java plugin: jtoc_value_list: jtoc_long (getInterval) failed.");
}
vl->interval = MS_TO_CDTIME_T(tmp_long);
status = jtoc_values_array(jvm_env, ds, vl, class_ptr, object_ptr);
if (status != 0) {
ERROR("java plugin: jtoc_value_list: jtoc_values_array failed.");
}
vl->interval = MS_TO_CDTIME_T(tmp_long);
status = jtoc_values_array(jvm_env, ds, vl, class_ptr, object_ptr);
if (status != 0) {
ERROR("java plugin: jtoc_value_list: jtoc_values_array failed.");
} /* }}} int jtoc_value_list */
/* Convert a org/collectd/api/Notification to a notification_t. */
} /* }}} int jtoc_value_list */
/* Convert a org/collectd/api/Notification to a notification_t. */
class_ptr = (*jvm_env)->GetObjectClass(jvm_env, object_ptr);
if (class_ptr == NULL) {
ERROR("java plugin: jtoc_notification: GetObjectClass failed.");
class_ptr = (*jvm_env)->GetObjectClass(jvm_env, object_ptr);
if (class_ptr == NULL) {
ERROR("java plugin: jtoc_notification: GetObjectClass failed.");
if (status != 0) { \
ERROR("java plugin: jtoc_notification: jtoc_string (%s) failed.", \
method); \
if (status != 0) { \
ERROR("java plugin: jtoc_notification: jtoc_string (%s) failed.", \
method); \
status = jtoc_long(jvm_env, &tmp_long, class_ptr, object_ptr, "getTime");
if (status != 0) {
ERROR("java plugin: jtoc_notification: jtoc_long (getTime) failed.");
status = jtoc_long(jvm_env, &tmp_long, class_ptr, object_ptr, "getTime");
if (status != 0) {
ERROR("java plugin: jtoc_notification: jtoc_long (getTime) failed.");
}
/* Java measures time in milliseconds. */
n->time = MS_TO_CDTIME_T(tmp_long);
}
/* Java measures time in milliseconds. */
n->time = MS_TO_CDTIME_T(tmp_long);
status = jtoc_int(jvm_env, &tmp_int, class_ptr, object_ptr, "getSeverity");
if (status != 0) {
ERROR("java plugin: jtoc_notification: jtoc_int (getSeverity) failed.");
status = jtoc_int(jvm_env, &tmp_int, class_ptr, object_ptr, "getSeverity");
if (status != 0) {
ERROR("java plugin: jtoc_notification: jtoc_int (getSeverity) failed.");
}
n->severity = (int)tmp_int;
}
n->severity = (int)tmp_int;
} /* }}} int jtoc_notification */
/*
* Functions accessible from Java
} /* }}} int jtoc_notification */
/*
* Functions accessible from Java
status = jtoc_value_list(jvm_env, &vl, java_vl);
if (status != 0) {
ERROR("java plugin: cjni_api_dispatch_values: jtoc_value_list failed.");
status = jtoc_value_list(jvm_env, &vl, java_vl);
if (status != 0) {
ERROR("java plugin: cjni_api_dispatch_values: jtoc_value_list failed.");
}
status = plugin_dispatch_values(&vl);
sfree(vl.values);
}
status = plugin_dispatch_values(&vl);
sfree(vl.values);
} /* }}} jint cjni_api_dispatch_values */
static jint JNICALL cjni_api_dispatch_notification(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_dispatch_values */
static jint JNICALL cjni_api_dispatch_notification(JNIEnv *jvm_env, /* {{{ */
if (status != 0) {
ERROR("java plugin: cjni_api_dispatch_notification: jtoc_notification "
"failed.");
if (status != 0) {
ERROR("java plugin: cjni_api_dispatch_notification: jtoc_notification "
"failed.");
}
status = plugin_dispatch_notification(&n);
}
status = plugin_dispatch_notification(&n);
} /* }}} jint cjni_api_dispatch_notification */
static jobject JNICALL cjni_api_get_ds(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_dispatch_notification */
static jobject JNICALL cjni_api_get_ds(JNIEnv *jvm_env, /* {{{ */
ds_name = (*jvm_env)->GetStringUTFChars(jvm_env, o_string_type, 0);
if (ds_name == NULL) {
ERROR("java plugin: cjni_api_get_ds: GetStringUTFChars failed.");
ds_name = (*jvm_env)->GetStringUTFChars(jvm_env, o_string_type, 0);
if (ds_name == NULL) {
ERROR("java plugin: cjni_api_get_ds: GetStringUTFChars failed.");
}
ds = plugin_get_ds(ds_name);
}
ds = plugin_get_ds(ds_name);
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_string_type, ds_name);
if (ds == NULL)
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_string_type, ds_name);
if (ds == NULL)
o_dataset = ctoj_data_set(jvm_env, ds);
o_dataset = ctoj_data_set(jvm_env, ds);
} /* }}} jint cjni_api_get_ds */
static jint JNICALL cjni_api_register_config(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_config) {
} /* }}} jint cjni_api_get_ds */
static jint JNICALL cjni_api_register_config(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_config) {
- return (cjni_callback_register(jvm_env, o_name, o_config, CB_TYPE_CONFIG));
+ return cjni_callback_register(jvm_env, o_name, o_config, CB_TYPE_CONFIG);
} /* }}} jint cjni_api_register_config */
static jint JNICALL cjni_api_register_init(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_config) {
} /* }}} jint cjni_api_register_config */
static jint JNICALL cjni_api_register_init(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_config) {
- return (cjni_callback_register(jvm_env, o_name, o_config, CB_TYPE_INIT));
+ return cjni_callback_register(jvm_env, o_name, o_config, CB_TYPE_INIT);
} /* }}} jint cjni_api_register_init */
static jint JNICALL cjni_api_register_read(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_register_init */
static jint JNICALL cjni_api_register_read(JNIEnv *jvm_env, /* {{{ */
cbi = cjni_callback_info_create(jvm_env, o_name, o_read, CB_TYPE_READ);
if (cbi == NULL)
cbi = cjni_callback_info_create(jvm_env, o_name, o_read, CB_TYPE_READ);
if (cbi == NULL)
DEBUG("java plugin: Registering new read callback: %s", cbi->name);
DEBUG("java plugin: Registering new read callback: %s", cbi->name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_read);
(*jvm_env)->DeleteLocalRef(jvm_env, o_read);
} /* }}} jint cjni_api_register_read */
static jint JNICALL cjni_api_register_write(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_register_read */
static jint JNICALL cjni_api_register_write(JNIEnv *jvm_env, /* {{{ */
cbi = cjni_callback_info_create(jvm_env, o_name, o_write, CB_TYPE_WRITE);
if (cbi == NULL)
cbi = cjni_callback_info_create(jvm_env, o_name, o_write, CB_TYPE_WRITE);
if (cbi == NULL)
DEBUG("java plugin: Registering new write callback: %s", cbi->name);
DEBUG("java plugin: Registering new write callback: %s", cbi->name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_write);
(*jvm_env)->DeleteLocalRef(jvm_env, o_write);
} /* }}} jint cjni_api_register_write */
static jint JNICALL cjni_api_register_flush(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_register_write */
static jint JNICALL cjni_api_register_flush(JNIEnv *jvm_env, /* {{{ */
cbi = cjni_callback_info_create(jvm_env, o_name, o_flush, CB_TYPE_FLUSH);
if (cbi == NULL)
cbi = cjni_callback_info_create(jvm_env, o_name, o_flush, CB_TYPE_FLUSH);
if (cbi == NULL)
DEBUG("java plugin: Registering new flush callback: %s", cbi->name);
DEBUG("java plugin: Registering new flush callback: %s", cbi->name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_flush);
(*jvm_env)->DeleteLocalRef(jvm_env, o_flush);
} /* }}} jint cjni_api_register_flush */
static jint JNICALL cjni_api_register_shutdown(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_shutdown) {
} /* }}} jint cjni_api_register_flush */
static jint JNICALL cjni_api_register_shutdown(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_shutdown) {
- return (
- cjni_callback_register(jvm_env, o_name, o_shutdown, CB_TYPE_SHUTDOWN));
+ return cjni_callback_register(jvm_env, o_name, o_shutdown, CB_TYPE_SHUTDOWN);
} /* }}} jint cjni_api_register_shutdown */
static jint JNICALL cjni_api_register_log(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_register_shutdown */
static jint JNICALL cjni_api_register_log(JNIEnv *jvm_env, /* {{{ */
cbi = cjni_callback_info_create(jvm_env, o_name, o_log, CB_TYPE_LOG);
if (cbi == NULL)
cbi = cjni_callback_info_create(jvm_env, o_name, o_log, CB_TYPE_LOG);
if (cbi == NULL)
DEBUG("java plugin: Registering new log callback: %s", cbi->name);
DEBUG("java plugin: Registering new log callback: %s", cbi->name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_log);
(*jvm_env)->DeleteLocalRef(jvm_env, o_log);
} /* }}} jint cjni_api_register_log */
static jint JNICALL cjni_api_register_notification(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_register_log */
static jint JNICALL cjni_api_register_notification(JNIEnv *jvm_env, /* {{{ */
cbi = cjni_callback_info_create(jvm_env, o_name, o_notification,
CB_TYPE_NOTIFICATION);
if (cbi == NULL)
cbi = cjni_callback_info_create(jvm_env, o_name, o_notification,
CB_TYPE_NOTIFICATION);
if (cbi == NULL)
DEBUG("java plugin: Registering new notification callback: %s", cbi->name);
DEBUG("java plugin: Registering new notification callback: %s", cbi->name);
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
} /* }}} jint cjni_api_register_notification */
static jint JNICALL cjni_api_register_match_target(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_register_notification */
static jint JNICALL cjni_api_register_match_target(JNIEnv *jvm_env, /* {{{ */
if (c_name == NULL) {
ERROR("java plugin: cjni_api_register_match_target: "
"GetStringUTFChars failed.");
if (c_name == NULL) {
ERROR("java plugin: cjni_api_register_match_target: "
"GetStringUTFChars failed.");
}
status = cjni_callback_register(jvm_env, o_name, o_match, type);
if (status != 0) {
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
}
status = cjni_callback_register(jvm_env, o_name, o_match, type);
if (status != 0) {
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
}
if (type == CB_TYPE_MATCH) {
}
if (type == CB_TYPE_MATCH) {
ERROR("java plugin: cjni_api_register_match_target: "
"Don't know whether to create a match or a target.");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
ERROR("java plugin: cjni_api_register_match_target: "
"Don't know whether to create a match or a target.");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
"%s failed.",
(type == CB_TYPE_MATCH) ? "fc_register_match" : "fc_register_target");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
"%s failed.",
(type == CB_TYPE_MATCH) ? "fc_register_match" : "fc_register_target");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
}
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
}
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
} /* }}} jint cjni_api_register_match_target */
static jint JNICALL cjni_api_register_match(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_match) {
} /* }}} jint cjni_api_register_match_target */
static jint JNICALL cjni_api_register_match(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_match) {
- return (cjni_api_register_match_target(jvm_env, this, o_name, o_match,
- CB_TYPE_MATCH));
+ return cjni_api_register_match_target(jvm_env, this, o_name, o_match,
+ CB_TYPE_MATCH);
} /* }}} jint cjni_api_register_match */
static jint JNICALL cjni_api_register_target(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_target) {
} /* }}} jint cjni_api_register_match */
static jint JNICALL cjni_api_register_target(JNIEnv *jvm_env, /* {{{ */
jobject this, jobject o_name,
jobject o_target) {
- return (cjni_api_register_match_target(jvm_env, this, o_name, o_target,
- CB_TYPE_TARGET));
+ return cjni_api_register_match_target(jvm_env, this, o_name, o_target,
+ CB_TYPE_TARGET);
} /* }}} jint cjni_api_register_target */
static void JNICALL cjni_api_log(JNIEnv *jvm_env, /* {{{ */
} /* }}} jint cjni_api_register_target */
static void JNICALL cjni_api_log(JNIEnv *jvm_env, /* {{{ */
default:
ERROR("java plugin: cjni_callback_info_create: Unknown type: %#x", type);
default:
ERROR("java plugin: cjni_callback_info_create: Unknown type: %#x", type);
}
c_name = (*jvm_env)->GetStringUTFChars(jvm_env, o_name, 0);
if (c_name == NULL) {
ERROR("java plugin: cjni_callback_info_create: "
"GetStringUTFChars failed.");
}
c_name = (*jvm_env)->GetStringUTFChars(jvm_env, o_name, 0);
if (c_name == NULL) {
ERROR("java plugin: cjni_callback_info_create: "
"GetStringUTFChars failed.");
}
cbi = calloc(1, sizeof(*cbi));
if (cbi == NULL) {
ERROR("java plugin: cjni_callback_info_create: calloc failed.");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
}
cbi = calloc(1, sizeof(*cbi));
if (cbi == NULL) {
ERROR("java plugin: cjni_callback_info_create: calloc failed.");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
ERROR("java plugin: cjni_callback_info_create: strdup failed.");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
sfree(cbi);
ERROR("java plugin: cjni_callback_info_create: strdup failed.");
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
sfree(cbi);
}
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
}
(*jvm_env)->ReleaseStringUTFChars(jvm_env, o_name, c_name);
ERROR("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
sfree(cbi->name);
sfree(cbi);
ERROR("java plugin: cjni_callback_info_create: NewGlobalRef failed.");
sfree(cbi->name);
sfree(cbi);
}
cbi->class = (*jvm_env)->GetObjectClass(jvm_env, cbi->object);
}
cbi->class = (*jvm_env)->GetObjectClass(jvm_env, cbi->object);
(*jvm_env)->DeleteGlobalRef(jvm_env, cbi->object);
sfree(cbi->name);
sfree(cbi);
(*jvm_env)->DeleteGlobalRef(jvm_env, cbi->object);
sfree(cbi->name);
sfree(cbi);
}
cbi->method = (*jvm_env)->GetMethodID(jvm_env, cbi->class, method_name,
}
cbi->method = (*jvm_env)->GetMethodID(jvm_env, cbi->class, method_name,
(*jvm_env)->DeleteGlobalRef(jvm_env, cbi->object);
sfree(cbi->name);
sfree(cbi);
(*jvm_env)->DeleteGlobalRef(jvm_env, cbi->object);
sfree(cbi->name);
sfree(cbi);
} /* }}} cjni_callback_info_t cjni_callback_info_create */
/* Allocate a `cjni_callback_info_t' via `cjni_callback_info_create' and add it
} /* }}} cjni_callback_info_t cjni_callback_info_create */
/* Allocate a `cjni_callback_info_t' via `cjni_callback_info_create' and add it
cbi = cjni_callback_info_create(jvm_env, o_name, o_callback, type);
if (cbi == NULL)
cbi = cjni_callback_info_create(jvm_env, o_name, o_callback, type);
if (cbi == NULL)
#if COLLECT_DEBUG
switch (type) {
#if COLLECT_DEBUG
switch (type) {
(*jvm_env)->DeleteGlobalRef(jvm_env, cbi->object);
free(cbi);
(*jvm_env)->DeleteGlobalRef(jvm_env, cbi->object);
free(cbi);
}
java_callbacks = tmp;
java_callbacks[java_callbacks_num] = *cbi;
}
java_callbacks = tmp;
java_callbacks[java_callbacks_num] = *cbi;
pthread_mutex_unlock(&java_callbacks_lock);
free(cbi);
pthread_mutex_unlock(&java_callbacks_lock);
free(cbi);
} /* }}} int cjni_callback_register */
/* Callback for `pthread_key_create'. It frees the data contained in
} /* }}} int cjni_callback_register */
/* Callback for `pthread_key_create'. It frees the data contained in
ERROR("cjni_init_native: Cannot find the API class \"org.collectd.api"
".Collectd\". Please set the correct class path "
"using 'JVMArg \"-Djava.class.path=...\"'.");
ERROR("cjni_init_native: Cannot find the API class \"org.collectd.api"
".Collectd\". Please set the correct class path "
"using 'JVMArg \"-Djava.class.path=...\"'.");
}
status = (*jvm_env)->RegisterNatives(
jvm_env, api_class_ptr, jni_api_functions, (jint)jni_api_functions_num);
if (status != 0) {
ERROR("cjni_init_native: RegisterNatives failed with status %i.", status);
}
status = (*jvm_env)->RegisterNatives(
jvm_env, api_class_ptr, jni_api_functions, (jint)jni_api_functions_num);
if (status != 0) {
ERROR("cjni_init_native: RegisterNatives failed with status %i.", status);
} /* }}} int cjni_init_native */
/* Create the JVM. This is called when the first thread tries to access the JVM
} /* }}} int cjni_init_native */
/* Create the JVM. This is called when the first thread tries to access the JVM
int status;
if (jvm != NULL)
int status;
if (jvm != NULL)
status = pthread_key_create(&jvm_env_key, cjni_jvm_env_destroy);
if (status != 0) {
ERROR("java plugin: cjni_create_jvm: pthread_key_create failed "
"with status %i.",
status);
status = pthread_key_create(&jvm_env_key, cjni_jvm_env_destroy);
if (status != 0) {
ERROR("java plugin: cjni_create_jvm: pthread_key_create failed "
"with status %i.",
status);
ERROR("java plugin: cjni_create_jvm: "
"JNI_CreateJavaVM failed with status %i.",
status);
ERROR("java plugin: cjni_create_jvm: "
"JNI_CreateJavaVM failed with status %i.",
status);
}
assert(jvm != NULL);
assert(jvm_env != NULL);
}
assert(jvm != NULL);
assert(jvm_env != NULL);
status = cjni_init_native(jvm_env);
if (status != 0) {
ERROR("java plugin: cjni_create_jvm: cjni_init_native failed.");
status = cjni_init_native(jvm_env);
if (status != 0) {
ERROR("java plugin: cjni_create_jvm: cjni_init_native failed.");
}
DEBUG("java plugin: The JVM has been created.");
}
DEBUG("java plugin: The JVM has been created.");
} /* }}} int cjni_create_jvm */
/* Increase the reference counter to the JVM for this thread. If it was zero,
} /* }}} int cjni_create_jvm */
/* Increase the reference counter to the JVM for this thread. If it was zero,
status = cjni_create_jvm();
if (status != 0) {
ERROR("java plugin: cjni_thread_attach: cjni_create_jvm failed.");
status = cjni_create_jvm();
if (status != 0) {
ERROR("java plugin: cjni_thread_attach: cjni_create_jvm failed.");
cjni_env = calloc(1, sizeof(*cjni_env));
if (cjni_env == NULL) {
ERROR("java plugin: cjni_thread_attach: calloc failed.");
cjni_env = calloc(1, sizeof(*cjni_env));
if (cjni_env == NULL) {
ERROR("java plugin: cjni_thread_attach: calloc failed.");
}
cjni_env->reference_counter = 0;
cjni_env->jvm_env = NULL;
}
cjni_env->reference_counter = 0;
cjni_env->jvm_env = NULL;
ERROR("java plugin: cjni_thread_attach: AttachCurrentThread failed "
"with status %i.",
status);
ERROR("java plugin: cjni_thread_attach: AttachCurrentThread failed "
"with status %i.",
status);
}
cjni_env->reference_counter = 1;
}
cjni_env->reference_counter = 1;
DEBUG("java plugin: cjni_thread_attach: cjni_env->reference_counter = %i",
cjni_env->reference_counter);
assert(jvm_env != NULL);
DEBUG("java plugin: cjni_thread_attach: cjni_env->reference_counter = %i",
cjni_env->reference_counter);
assert(jvm_env != NULL);
} /* }}} JNIEnv *cjni_thread_attach */
/* Decrease the reference counter of this thread. If it reaches zero, detach
} /* }}} JNIEnv *cjni_thread_attach */
/* Decrease the reference counter of this thread. If it reaches zero, detach
cjni_env = pthread_getspecific(jvm_env_key);
if (cjni_env == NULL) {
ERROR("java plugin: cjni_thread_detach: pthread_getspecific failed.");
cjni_env = pthread_getspecific(jvm_env_key);
if (cjni_env == NULL) {
ERROR("java plugin: cjni_thread_detach: pthread_getspecific failed.");
}
assert(cjni_env->reference_counter > 0);
}
assert(cjni_env->reference_counter > 0);
cjni_env->reference_counter);
if (cjni_env->reference_counter > 0)
cjni_env->reference_counter);
if (cjni_env->reference_counter > 0)
status = (*jvm)->DetachCurrentThread(jvm);
if (status != 0) {
status = (*jvm)->DetachCurrentThread(jvm);
if (status != 0) {
cjni_env->reference_counter = 0;
cjni_env->jvm_env = NULL;
cjni_env->reference_counter = 0;
cjni_env->jvm_env = NULL;
} /* }}} int cjni_thread_detach */
static int cjni_config_add_jvm_arg(oconfig_item_t *ci) /* {{{ */
} /* }}} int cjni_thread_detach */
static int cjni_config_add_jvm_arg(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("java plugin: `JVMArg' needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("java plugin: `JVMArg' needs exactly one string argument.");
"`LoadPlugin' options! The JVM is already started and I have to "
"ignore this argument: %s",
ci->values[0].value.string);
"`LoadPlugin' options! The JVM is already started and I have to "
"ignore this argument: %s",
ci->values[0].value.string);
}
tmp = realloc(jvm_argv, sizeof(char *) * (jvm_argc + 1));
if (tmp == NULL) {
ERROR("java plugin: realloc failed.");
}
tmp = realloc(jvm_argv, sizeof(char *) * (jvm_argc + 1));
if (tmp == NULL) {
ERROR("java plugin: realloc failed.");
}
jvm_argv = tmp;
jvm_argv[jvm_argc] = strdup(ci->values[0].value.string);
if (jvm_argv[jvm_argc] == NULL) {
ERROR("java plugin: strdup failed.");
}
jvm_argv = tmp;
jvm_argv[jvm_argc] = strdup(ci->values[0].value.string);
if (jvm_argv[jvm_argc] == NULL) {
ERROR("java plugin: strdup failed.");
} /* }}} int cjni_config_add_jvm_arg */
static int cjni_config_load_plugin(oconfig_item_t *ci) /* {{{ */
} /* }}} int cjni_config_add_jvm_arg */
static int cjni_config_load_plugin(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("java plugin: `LoadPlugin' needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("java plugin: `LoadPlugin' needs exactly one string argument.");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
class = realloc(java_classes_list,
(java_classes_list_len + 1) * sizeof(*java_classes_list));
if (class == NULL) {
ERROR("java plugin: realloc failed.");
cjni_thread_detach();
class = realloc(java_classes_list,
(java_classes_list_len + 1) * sizeof(*java_classes_list));
if (class == NULL) {
ERROR("java plugin: realloc failed.");
cjni_thread_detach();
}
java_classes_list = class;
class = java_classes_list + java_classes_list_len;
}
java_classes_list = class;
class = java_classes_list + java_classes_list_len;
if (class->name == NULL) {
ERROR("java plugin: strdup failed.");
cjni_thread_detach();
if (class->name == NULL) {
ERROR("java plugin: strdup failed.");
cjni_thread_detach();
}
class->class = NULL;
class->object = NULL;
}
class->class = NULL;
class->object = NULL;
class->name);
cjni_thread_detach();
free(class->name);
class->name);
cjni_thread_detach();
free(class->name);
class->name);
cjni_thread_detach();
free(class->name);
class->name);
cjni_thread_detach();
free(class->name);
}
tmp_object = (*jvm_env)->NewObject(jvm_env, class->class, constructor_id);
}
tmp_object = (*jvm_env)->NewObject(jvm_env, class->class, constructor_id);
class->name);
cjni_thread_detach();
free(class->name);
class->name);
cjni_thread_detach();
free(class->name);
}
cjni_thread_detach();
java_classes_list_len++;
}
cjni_thread_detach();
java_classes_list_len++;
} /* }}} int cjni_config_load_plugin */
static int cjni_config_plugin_block(oconfig_item_t *ci) /* {{{ */
} /* }}} int cjni_config_load_plugin */
static int cjni_config_plugin_block(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("java plugin: `Plugin' blocks "
"need exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("java plugin: `Plugin' blocks "
"need exactly one string argument.");
}
name = ci->values[0].value.string;
}
name = ci->values[0].value.string;
"configuration callback has been registered. Please make sure, the "
"`LoadPlugin' lines precede the `Plugin' blocks.",
name);
"configuration callback has been registered. Please make sure, the "
"`LoadPlugin' lines precede the `Plugin' blocks.",
name);
}
DEBUG("java plugin: Configuring %s", name);
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
DEBUG("java plugin: Configuring %s", name);
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
o_ocitem = ctoj_oconfig_item(jvm_env, ci);
if (o_ocitem == NULL) {
ERROR("java plugin: cjni_config_plugin_block: ctoj_oconfig_item failed.");
cjni_thread_detach();
o_ocitem = ctoj_oconfig_item(jvm_env, ci);
if (o_ocitem == NULL) {
ERROR("java plugin: cjni_config_plugin_block: ctoj_oconfig_item failed.");
cjni_thread_detach();
}
class = (*jvm_env)->GetObjectClass(jvm_env, cbi->object);
}
class = (*jvm_env)->GetObjectClass(jvm_env, cbi->object);
(*jvm_env)->DeleteLocalRef(jvm_env, o_ocitem);
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, o_ocitem);
cjni_thread_detach();
} /* }}} int cjni_config_plugin_block */
static int cjni_config_perform(oconfig_item_t *ci) /* {{{ */
} /* }}} int cjni_config_plugin_block */
static int cjni_config_perform(oconfig_item_t *ci) /* {{{ */
if ((success == 0) && (errors > 0)) {
ERROR("java plugin: All statements failed.");
if ((success == 0) && (errors > 0)) {
ERROR("java plugin: All statements failed.");
} /* }}} int cjni_config_perform */
/* Copy the children of `ci' to the global `config_block' variable. */
} /* }}} int cjni_config_perform */
/* Copy the children of `ci' to the global `config_block' variable. */
assert(ci != NULL);
if (ci->children_num == 0)
assert(ci != NULL);
if (ci->children_num == 0)
- return (0); /* nothing to do */
+ return 0; /* nothing to do */
ci_copy = oconfig_clone(ci);
if (ci_copy == NULL) {
ERROR("java plugin: oconfig_clone failed.");
ci_copy = oconfig_clone(ci);
if (ci_copy == NULL) {
ERROR("java plugin: oconfig_clone failed.");
}
if (config_block == NULL) {
config_block = ci_copy;
}
if (config_block == NULL) {
config_block = ci_copy;
}
tmp = realloc(config_block->children,
}
tmp = realloc(config_block->children,
if (tmp == NULL) {
ERROR("java plugin: realloc failed.");
oconfig_free(ci_copy);
if (tmp == NULL) {
ERROR("java plugin: realloc failed.");
oconfig_free(ci_copy);
}
config_block->children = tmp;
}
config_block->children = tmp;
} /* }}} int cjni_config_callback */
/* Free the data contained in the `user_data_t' pointer passed to `cjni_read'
} /* }}} int cjni_config_callback */
/* Free the data contained in the `user_data_t' pointer passed to `cjni_read'
if (jvm == NULL) {
ERROR("java plugin: cjni_read: jvm == NULL");
if (jvm == NULL) {
ERROR("java plugin: cjni_read: jvm == NULL");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_read: Invalid user data.");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_read: Invalid user data.");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
cbi = (cjni_callback_info_t *)ud->data;
ret_status = (*jvm_env)->CallIntMethod(jvm_env, cbi->object, cbi->method);
cjni_thread_detach();
cbi = (cjni_callback_info_t *)ud->data;
ret_status = (*jvm_env)->CallIntMethod(jvm_env, cbi->object, cbi->method);
cjni_thread_detach();
} /* }}} int cjni_read */
/* Call the CB_TYPE_WRITE callback pointed to by the `user_data_t' pointer. */
} /* }}} int cjni_read */
/* Call the CB_TYPE_WRITE callback pointed to by the `user_data_t' pointer. */
if (jvm == NULL) {
ERROR("java plugin: cjni_write: jvm == NULL");
if (jvm == NULL) {
ERROR("java plugin: cjni_write: jvm == NULL");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_write: Invalid user data.");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_write: Invalid user data.");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
cbi = (cjni_callback_info_t *)ud->data;
cbi = (cjni_callback_info_t *)ud->data;
if (vl_java == NULL) {
ERROR("java plugin: cjni_write: ctoj_value_list failed.");
cjni_thread_detach();
if (vl_java == NULL) {
ERROR("java plugin: cjni_write: ctoj_value_list failed.");
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, vl_java);
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, vl_java);
cjni_thread_detach();
} /* }}} int cjni_write */
/* Call the CB_TYPE_FLUSH callback pointed to by the `user_data_t' pointer. */
} /* }}} int cjni_write */
/* Call the CB_TYPE_FLUSH callback pointed to by the `user_data_t' pointer. */
if (jvm == NULL) {
ERROR("java plugin: cjni_flush: jvm == NULL");
if (jvm == NULL) {
ERROR("java plugin: cjni_flush: jvm == NULL");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_flush: Invalid user data.");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_flush: Invalid user data.");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
cbi = (cjni_callback_info_t *)ud->data;
cbi = (cjni_callback_info_t *)ud->data;
ERROR("java plugin: cjni_flush: Converting double "
"to Number object failed.");
cjni_thread_detach();
ERROR("java plugin: cjni_flush: Converting double "
"to Number object failed.");
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, o_timeout);
ERROR("java plugin: cjni_flush: NewStringUTF failed.");
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, o_timeout);
ERROR("java plugin: cjni_flush: NewStringUTF failed.");
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, o_timeout);
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, o_timeout);
cjni_thread_detach();
} /* }}} int cjni_flush */
/* Call the CB_TYPE_LOG callback pointed to by the `user_data_t' pointer. */
} /* }}} int cjni_flush */
/* Call the CB_TYPE_LOG callback pointed to by the `user_data_t' pointer. */
if (jvm == NULL) {
ERROR("java plugin: cjni_read: jvm == NULL");
if (jvm == NULL) {
ERROR("java plugin: cjni_read: jvm == NULL");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_read: Invalid user data.");
}
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("java plugin: cjni_read: Invalid user data.");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
cbi = (cjni_callback_info_t *)ud->data;
cbi = (cjni_callback_info_t *)ud->data;
if (o_notification == NULL) {
ERROR("java plugin: cjni_notification: ctoj_notification failed.");
cjni_thread_detach();
if (o_notification == NULL) {
ERROR("java plugin: cjni_notification: ctoj_notification failed.");
cjni_thread_detach();
}
ret_status = (*jvm_env)->CallIntMethod(jvm_env, cbi->object, cbi->method,
}
ret_status = (*jvm_env)->CallIntMethod(jvm_env, cbi->object, cbi->method,
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
cjni_thread_detach();
(*jvm_env)->DeleteLocalRef(jvm_env, o_notification);
cjni_thread_detach();
} /* }}} int cjni_notification */
/* Callbacks for matches implemented in Java */
} /* }}} int cjni_notification */
/* Callbacks for matches implemented in Java */
if (jvm == NULL) {
ERROR("java plugin: cjni_read: jvm == NULL");
if (jvm == NULL) {
ERROR("java plugin: cjni_read: jvm == NULL");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
/* Find out whether to create a match or a target. */
if (strcasecmp("Match", ci->key) == 0)
/* Find out whether to create a match or a target. */
if (strcasecmp("Match", ci->key) == 0)
cbi_ret->name, (type == CB_TYPE_MATCH) ? "match" : "target");
/* Success! */
cbi_ret->name, (type == CB_TYPE_MATCH) ? "match" : "target");
/* Success! */
#undef BAIL_OUT
} /* }}} int cjni_match_target_create */
#undef BAIL_OUT
} /* }}} int cjni_match_target_create */
cjni_callback_info_destroy(*user_data);
*user_data = NULL;
cjni_callback_info_destroy(*user_data);
*user_data = NULL;
} /* }}} int cjni_match_target_destroy */
static int cjni_match_target_invoke(const data_set_t *ds, /* {{{ */
} /* }}} int cjni_match_target_destroy */
static int cjni_match_target_invoke(const data_set_t *ds, /* {{{ */
if (jvm == NULL) {
ERROR("java plugin: cjni_match_target_invoke: jvm == NULL");
if (jvm == NULL) {
ERROR("java plugin: cjni_match_target_invoke: jvm == NULL");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
cbi = (cjni_callback_info_t *)*user_data;
cbi = (cjni_callback_info_t *)*user_data;
if (o_vl == NULL) {
ERROR("java plugin: cjni_match_target_invoke: ctoj_value_list failed.");
cjni_thread_detach();
if (o_vl == NULL) {
ERROR("java plugin: cjni_match_target_invoke: ctoj_value_list failed.");
cjni_thread_detach();
}
o_ds = ctoj_data_set(jvm_env, ds);
if (o_ds == NULL) {
ERROR("java plugin: cjni_match_target_invoke: ctoj_value_list failed.");
cjni_thread_detach();
}
o_ds = ctoj_data_set(jvm_env, ds);
if (o_ds == NULL) {
ERROR("java plugin: cjni_match_target_invoke: ctoj_value_list failed.");
cjni_thread_detach();
} /* if (cbi->type == CB_TYPE_TARGET) */
cjni_thread_detach();
} /* if (cbi->type == CB_TYPE_TARGET) */
cjni_thread_detach();
} /* }}} int cjni_match_target_invoke */
/* Iterate over `java_callbacks' and call all CB_TYPE_INIT callbacks. */
} /* }}} int cjni_match_target_invoke */
/* Iterate over `java_callbacks' and call all CB_TYPE_INIT callbacks. */
} /* }}} int cjni_init_plugins */
/* Iterate over `java_callbacks' and call all CB_TYPE_SHUTDOWN callbacks. */
} /* }}} int cjni_init_plugins */
/* Iterate over `java_callbacks' and call all CB_TYPE_SHUTDOWN callbacks. */
} /* }}} int cjni_shutdown_plugins */
static int cjni_shutdown(void) /* {{{ */
} /* }}} int cjni_shutdown_plugins */
static int cjni_shutdown(void) /* {{{ */
int status;
if (jvm == NULL)
int status;
if (jvm == NULL)
jvm_env = NULL;
args.version = JNI_VERSION_1_2;
jvm_env = NULL;
args.version = JNI_VERSION_1_2;
ERROR("java plugin: cjni_shutdown: AttachCurrentThread failed with status "
"%i.",
status);
ERROR("java plugin: cjni_shutdown: AttachCurrentThread failed with status "
"%i.",
status);
}
/* Execute all the shutdown functions registered by plugins. */
}
/* Execute all the shutdown functions registered by plugins. */
jvm_argc = 0;
sfree(jvm_argv);
jvm_argc = 0;
sfree(jvm_argv);
} /* }}} int cjni_shutdown */
/* Initialization: Create a JVM, load all configured classes and call their
} /* }}} int cjni_shutdown */
/* Initialization: Create a JVM, load all configured classes and call their
if ((config_block == NULL) && (jvm == NULL)) {
ERROR("java plugin: cjni_init: No configuration block for "
"the java plugin was found.");
if ((config_block == NULL) && (jvm == NULL)) {
ERROR("java plugin: cjni_init: No configuration block for "
"the java plugin was found.");
}
if (config_block != NULL) {
}
if (config_block != NULL) {
if (jvm == NULL) {
ERROR("java plugin: cjni_init: jvm == NULL");
if (jvm == NULL) {
ERROR("java plugin: cjni_init: jvm == NULL");
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
}
jvm_env = cjni_thread_attach();
if (jvm_env == NULL)
cjni_init_plugins(jvm_env);
cjni_thread_detach();
cjni_init_plugins(jvm_env);
cjni_thread_detach();
} /* }}} int cjni_init */
void module_register(void) {
} /* }}} int cjni_init */
void module_register(void) {
} /* char *sstrerror */
static int lcc_set_errno(lcc_connection_t *c, int err) /* {{{ */
{
if (c == NULL)
} /* char *sstrerror */
static int lcc_set_errno(lcc_connection_t *c, int err) /* {{{ */
{
if (c == NULL)
sstrerror(err, c->errbuf, sizeof(c->errbuf));
c->errbuf[sizeof(c->errbuf) - 1] = 0;
sstrerror(err, c->errbuf, sizeof(c->errbuf));
c->errbuf[sizeof(c->errbuf) - 1] = 0;
} /* }}} int lcc_set_errno */
static char *lcc_strescape(char *dest, const char *src,
} /* }}} int lcc_set_errno */
static char *lcc_strescape(char *dest, const char *src,
size_t src_pos;
if ((dest == NULL) || (src == NULL))
size_t src_pos;
if ((dest == NULL) || (src == NULL))
dest_pos = 0;
src_pos = 0;
dest_pos = 0;
src_pos = 0;
} /* }}} char *lcc_strescape */
/* lcc_chomp: Removes all control-characters at the end of a string. */
} /* }}} char *lcc_strescape */
/* lcc_chomp: Removes all control-characters at the end of a string. */
status = fprintf(c->fh, "%s\r\n", command);
if (status < 0) {
lcc_set_errno(c, errno);
status = fprintf(c->fh, "%s\r\n", command);
if (status < 0) {
lcc_set_errno(c, errno);
} /* }}} int lcc_send */
static int lcc_receive(lcc_connection_t *c, /* {{{ */
} /* }}} int lcc_send */
static int lcc_receive(lcc_connection_t *c, /* {{{ */
ptr = fgets(buffer, sizeof(buffer), c->fh);
if (ptr == NULL) {
lcc_set_errno(c, errno);
ptr = fgets(buffer, sizeof(buffer), c->fh);
if (ptr == NULL) {
lcc_set_errno(c, errno);
}
lcc_chomp(buffer);
lcc_tracef("receive: <-- %s\n", buffer);
}
lcc_chomp(buffer);
lcc_tracef("receive: <-- %s\n", buffer);
res.status = (int)strtol(buffer, &ptr, 0);
if ((errno != 0) || (ptr == &buffer[0])) {
lcc_set_errno(c, errno);
res.status = (int)strtol(buffer, &ptr, 0);
if ((errno != 0) || (ptr == &buffer[0])) {
lcc_set_errno(c, errno);
}
/* Skip white spaces after the status number */
}
/* Skip white spaces after the status number */
/* Error or no lines follow: We're done. */
if (res.status <= 0) {
memcpy(ret_res, &res, sizeof(res));
/* Error or no lines follow: We're done. */
if (res.status <= 0) {
memcpy(ret_res, &res, sizeof(res));
}
/* Allocate space for the char-pointers */
}
/* Allocate space for the char-pointers */
res.lines = malloc(res.lines_num * sizeof(*res.lines));
if (res.lines == NULL) {
lcc_set_errno(c, ENOMEM);
res.lines = malloc(res.lines_num * sizeof(*res.lines));
if (res.lines == NULL) {
lcc_set_errno(c, ENOMEM);
}
/* Now receive all the lines */
}
/* Now receive all the lines */
free(res.lines[i]);
}
free(res.lines);
free(res.lines[i]);
}
free(res.lines);
}
memcpy(ret_res, &res, sizeof(res));
}
memcpy(ret_res, &res, sizeof(res));
} /* }}} int lcc_receive */
static int lcc_sendreceive(lcc_connection_t *c, /* {{{ */
} /* }}} int lcc_receive */
static int lcc_sendreceive(lcc_connection_t *c, /* {{{ */
if (c->fh == NULL) {
lcc_set_errno(c, EBADF);
if (c->fh == NULL) {
lcc_set_errno(c, EBADF);
}
status = lcc_send(c, command);
if (status != 0)
}
status = lcc_send(c, command);
if (status != 0)
status = lcc_receive(c, &res);
if (status == 0)
memcpy(ret_res, &res, sizeof(*ret_res));
status = lcc_receive(c, &res);
if (status == 0)
memcpy(ret_res, &res, sizeof(*ret_res));
} /* }}} int lcc_sendreceive */
static int lcc_open_unixsocket(lcc_connection_t *c, const char *path) /* {{{ */
} /* }}} int lcc_sendreceive */
static int lcc_open_unixsocket(lcc_connection_t *c, const char *path) /* {{{ */
fd = socket(AF_UNIX, SOCK_STREAM, /* protocol = */ 0);
if (fd < 0) {
lcc_set_errno(c, errno);
fd = socket(AF_UNIX, SOCK_STREAM, /* protocol = */ 0);
if (fd < 0) {
lcc_set_errno(c, errno);
}
sa.sun_family = AF_UNIX;
}
sa.sun_family = AF_UNIX;
if (status != 0) {
lcc_set_errno(c, errno);
close(fd);
if (status != 0) {
lcc_set_errno(c, errno);
close(fd);
}
c->fh = fdopen(fd, "r+");
if (c->fh == NULL) {
lcc_set_errno(c, errno);
close(fd);
}
c->fh = fdopen(fd, "r+");
if (c->fh == NULL) {
lcc_set_errno(c, errno);
close(fd);
} /* }}} int lcc_open_unixsocket */
static int lcc_open_netsocket(lcc_connection_t *c, /* {{{ */
} /* }}} int lcc_open_unixsocket */
static int lcc_open_netsocket(lcc_connection_t *c, /* {{{ */
port = strchr(addr, ']');
if (port == NULL) {
LCC_SET_ERRSTR(c, "malformed address: %s", addr_orig);
port = strchr(addr, ']');
if (port == NULL) {
LCC_SET_ERRSTR(c, "malformed address: %s", addr_orig);
port = NULL;
else {
LCC_SET_ERRSTR(c, "garbage after address: %s", port);
port = NULL;
else {
LCC_SET_ERRSTR(c, "garbage after address: %s", port);
}
} /* if (*addr = ']') */
else if (strchr(addr, '.') != NULL) /* Hostname or IPv4 */
}
} /* if (*addr = ']') */
else if (strchr(addr, '.') != NULL) /* Hostname or IPv4 */
&ai_res);
if (status != 0) {
LCC_SET_ERRSTR(c, "getaddrinfo: %s", gai_strerror(status));
&ai_res);
if (status != 0) {
LCC_SET_ERRSTR(c, "getaddrinfo: %s", gai_strerror(status));
}
for (struct addrinfo *ai_ptr = ai_res; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_res; ai_ptr != NULL;
if (status != 0) {
lcc_set_errno(c, status);
freeaddrinfo(ai_res);
if (status != 0) {
lcc_set_errno(c, status);
freeaddrinfo(ai_res);
} /* }}} int lcc_open_netsocket */
static int lcc_open_socket(lcc_connection_t *c, const char *addr) /* {{{ */
} /* }}} int lcc_open_netsocket */
static int lcc_open_socket(lcc_connection_t *c, const char *addr) /* {{{ */
int status = 0;
if (addr == NULL)
int status = 0;
if (addr == NULL)
assert(c != NULL);
assert(c->fh == NULL);
assert(c != NULL);
assert(c->fh == NULL);
else
status = lcc_open_netsocket(c, addr);
else
status = lcc_open_netsocket(c, addr);
} /* }}} int lcc_open_socket */
/*
} /* }}} int lcc_open_socket */
/*
*/
unsigned int lcc_version(void) /* {{{ */
{
*/
unsigned int lcc_version(void) /* {{{ */
{
} /* }}} unsigned int lcc_version */
const char *lcc_version_string(void) /* {{{ */
{
} /* }}} unsigned int lcc_version */
const char *lcc_version_string(void) /* {{{ */
{
- return (LCC_VERSION_STRING);
+ return LCC_VERSION_STRING;
} /* }}} const char *lcc_version_string */
const char *lcc_version_extra(void) /* {{{ */
{
} /* }}} const char *lcc_version_string */
const char *lcc_version_extra(void) /* {{{ */
{
- return (LCC_VERSION_EXTRA);
+ return LCC_VERSION_EXTRA;
} /* }}} const char *lcc_version_extra */
int lcc_connect(const char *address, lcc_connection_t **ret_con) /* {{{ */
} /* }}} const char *lcc_version_extra */
int lcc_connect(const char *address, lcc_connection_t **ret_con) /* {{{ */
int status;
if (address == NULL)
int status;
if (address == NULL)
c = calloc(1, sizeof(*c));
if (c == NULL)
c = calloc(1, sizeof(*c));
if (c == NULL)
status = lcc_open_socket(c, address);
if (status != 0) {
lcc_disconnect(c);
status = lcc_open_socket(c, address);
if (status != 0) {
lcc_disconnect(c);
} /* }}} int lcc_connect */
int lcc_disconnect(lcc_connection_t *c) /* {{{ */
{
if (c == NULL)
} /* }}} int lcc_connect */
int lcc_disconnect(lcc_connection_t *c) /* {{{ */
{
if (c == NULL)
if (c->fh != NULL) {
fclose(c->fh);
if (c->fh != NULL) {
fclose(c->fh);
} /* }}} int lcc_disconnect */
int lcc_getval(lcc_connection_t *c, lcc_identifier_t *ident, /* {{{ */
} /* }}} int lcc_disconnect */
int lcc_getval(lcc_connection_t *c, lcc_identifier_t *ident, /* {{{ */
int status;
if (c == NULL)
int status;
if (c == NULL)
if (ident == NULL) {
lcc_set_errno(c, EINVAL);
if (ident == NULL) {
lcc_set_errno(c, EINVAL);
}
/* Build a commend with an escaped version of the identifier string. */
status = lcc_identifier_to_string(c, ident_str, sizeof(ident_str), ident);
if (status != 0)
}
/* Build a commend with an escaped version of the identifier string. */
status = lcc_identifier_to_string(c, ident_str, sizeof(ident_str), ident);
if (status != 0)
snprintf(command, sizeof(command), "GETVAL %s",
lcc_strescape(ident_esc, ident_str, sizeof(ident_esc)));
snprintf(command, sizeof(command), "GETVAL %s",
lcc_strescape(ident_esc, ident_str, sizeof(ident_esc)));
/* Send talk to the daemon.. */
status = lcc_sendreceive(c, command, &res);
if (status != 0)
/* Send talk to the daemon.. */
status = lcc_sendreceive(c, command, &res);
if (status != 0)
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
}
values_num = res.lines_num;
}
values_num = res.lines_num;
} \
free(values_names); \
lcc_response_free(&res); \
} \
free(values_names); \
lcc_response_free(&res); \
} while (0)
/* If neither the values nor the names are requested, return here.. */
} while (0)
/* If neither the values nor the names are requested, return here.. */
if (ret_values_num != NULL)
*ret_values_num = values_num;
lcc_response_free(&res);
if (ret_values_num != NULL)
*ret_values_num = values_num;
lcc_response_free(&res);
}
/* Allocate space for the values */
}
/* Allocate space for the values */
} /* }}} int lcc_getval */
int lcc_putval(lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */
} /* }}} int lcc_getval */
int lcc_putval(lcc_connection_t *c, const lcc_value_list_t *vl) /* {{{ */
if ((c == NULL) || (vl == NULL) || (vl->values_len < 1) ||
(vl->values == NULL) || (vl->values_types == NULL)) {
lcc_set_errno(c, EINVAL);
if ((c == NULL) || (vl == NULL) || (vl->values_len < 1) ||
(vl->values == NULL) || (vl->values_types == NULL)) {
lcc_set_errno(c, EINVAL);
}
status = lcc_identifier_to_string(c, ident_str, sizeof(ident_str),
&vl->identifier);
if (status != 0)
}
status = lcc_identifier_to_string(c, ident_str, sizeof(ident_str),
&vl->identifier);
if (status != 0)
SSTRCATF(command, "PUTVAL %s",
lcc_strescape(ident_esc, ident_str, sizeof(ident_esc)));
SSTRCATF(command, "PUTVAL %s",
lcc_strescape(ident_esc, ident_str, sizeof(ident_esc)));
status = lcc_sendreceive(c, command, &res);
if (status != 0)
status = lcc_sendreceive(c, command, &res);
if (status != 0)
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
}
lcc_response_free(&res);
}
lcc_response_free(&res);
} /* }}} int lcc_putval */
int lcc_flush(lcc_connection_t *c, const char *plugin, /* {{{ */
} /* }}} int lcc_putval */
int lcc_flush(lcc_connection_t *c, const char *plugin, /* {{{ */
if (c == NULL) {
lcc_set_errno(c, EINVAL);
if (c == NULL) {
lcc_set_errno(c, EINVAL);
}
SSTRCPY(command, "FLUSH");
}
SSTRCPY(command, "FLUSH");
status = lcc_identifier_to_string(c, ident_str, sizeof(ident_str), ident);
if (status != 0)
status = lcc_identifier_to_string(c, ident_str, sizeof(ident_str), ident);
if (status != 0)
SSTRCATF(command, " identifier=%s",
lcc_strescape(ident_esc, ident_str, sizeof(ident_esc)));
SSTRCATF(command, " identifier=%s",
lcc_strescape(ident_esc, ident_str, sizeof(ident_esc)));
status = lcc_sendreceive(c, command, &res);
if (status != 0)
status = lcc_sendreceive(c, command, &res);
if (status != 0)
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
}
lcc_response_free(&res);
}
lcc_response_free(&res);
} /* }}} int lcc_flush */
/* TODO: Implement lcc_putnotif */
} /* }}} int lcc_flush */
/* TODO: Implement lcc_putnotif */
size_t ident_num;
if (c == NULL)
size_t ident_num;
if (c == NULL)
if ((ret_ident == NULL) || (ret_ident_num == NULL)) {
lcc_set_errno(c, EINVAL);
if ((ret_ident == NULL) || (ret_ident_num == NULL)) {
lcc_set_errno(c, EINVAL);
}
status = lcc_sendreceive(c, "LISTVAL", &res);
if (status != 0)
}
status = lcc_sendreceive(c, "LISTVAL", &res);
if (status != 0)
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
if (res.status != 0) {
LCC_SET_ERRSTR(c, "Server error: %s", res.message);
lcc_response_free(&res);
}
ident_num = res.lines_num;
}
ident_num = res.lines_num;
if (ident == NULL) {
lcc_response_free(&res);
lcc_set_errno(c, ENOMEM);
if (ident == NULL) {
lcc_response_free(&res);
lcc_set_errno(c, ENOMEM);
}
for (size_t i = 0; i < res.lines_num; i++) {
}
for (size_t i = 0; i < res.lines_num; i++) {
if (status != 0) {
free(ident);
if (status != 0) {
free(ident);
}
*ret_ident = ident;
*ret_ident_num = ident_num;
}
*ret_ident = ident;
*ret_ident_num = ident_num;
} /* }}} int lcc_listval */
const char *lcc_strerror(lcc_connection_t *c) /* {{{ */
{
if (c == NULL)
} /* }}} int lcc_listval */
const char *lcc_strerror(lcc_connection_t *c) /* {{{ */
{
if (c == NULL)
- return ("Invalid object");
- return (c->errbuf);
+ return "Invalid object";
+ return c->errbuf;
} /* }}} const char *lcc_strerror */
int lcc_identifier_to_string(lcc_connection_t *c, /* {{{ */
} /* }}} const char *lcc_strerror */
int lcc_identifier_to_string(lcc_connection_t *c, /* {{{ */
const lcc_identifier_t *ident) {
if ((string == NULL) || (string_size < 6) || (ident == NULL)) {
lcc_set_errno(c, EINVAL);
const lcc_identifier_t *ident) {
if ((string == NULL) || (string_size < 6) || (ident == NULL)) {
lcc_set_errno(c, EINVAL);
}
if (ident->plugin_instance[0] == 0) {
}
if (ident->plugin_instance[0] == 0) {
}
string[string_size - 1] = 0;
}
string[string_size - 1] = 0;
} /* }}} int lcc_identifier_to_string */
int lcc_string_to_identifier(lcc_connection_t *c, /* {{{ */
} /* }}} int lcc_identifier_to_string */
int lcc_string_to_identifier(lcc_connection_t *c, /* {{{ */
string_copy = strdup(string);
if (string_copy == NULL) {
lcc_set_errno(c, ENOMEM);
string_copy = strdup(string);
if (string_copy == NULL) {
lcc_set_errno(c, ENOMEM);
if (plugin == NULL) {
LCC_SET_ERRSTR(c, "Malformed identifier string: %s", string);
free(string_copy);
if (plugin == NULL) {
LCC_SET_ERRSTR(c, "Malformed identifier string: %s", string);
free(string_copy);
if (type == NULL) {
LCC_SET_ERRSTR(c, "Malformed identifier string: %s", string);
free(string_copy);
if (type == NULL) {
LCC_SET_ERRSTR(c, "Malformed identifier string: %s", string);
free(string_copy);
SSTRCPY(ident->type_instance, type_instance);
free(string_copy);
SSTRCPY(ident->type_instance, type_instance);
free(string_copy);
} /* }}} int lcc_string_to_identifier */
int lcc_identifier_compare(const void *a, /* {{{ */
} /* }}} int lcc_string_to_identifier */
int lcc_identifier_compare(const void *a, /* {{{ */
int status;
if ((i0 == NULL) && (i1 == NULL))
int status;
if ((i0 == NULL) && (i1 == NULL))
#define CMP_FIELD(f) \
do { \
status = strcmp(i0->f, i1->f); \
if (status != 0) \
#define CMP_FIELD(f) \
do { \
status = strcmp(i0->f, i1->f); \
if (status != 0) \
} while (0);
CMP_FIELD(host);
} while (0);
CMP_FIELD(host);
} /* }}} int lcc_identifier_compare */
int lcc_sort_identifiers(lcc_connection_t *c, /* {{{ */
lcc_identifier_t *idents, size_t idents_num) {
if (idents == NULL) {
lcc_set_errno(c, EINVAL);
} /* }}} int lcc_identifier_compare */
int lcc_sort_identifiers(lcc_connection_t *c, /* {{{ */
lcc_identifier_t *idents, size_t idents_num) {
if (idents == NULL) {
lcc_set_errno(c, EINVAL);
}
qsort(idents, idents_num, sizeof(*idents), lcc_identifier_compare);
}
qsort(idents, idents_num, sizeof(*idents), lcc_identifier_compare);
} /* }}} int lcc_sort_identifiers */
} /* }}} int lcc_sort_identifiers */
static int server_close_socket(lcc_server_t *srv) /* {{{ */
{
if (srv == NULL)
static int server_close_socket(lcc_server_t *srv) /* {{{ */
{
if (srv == NULL)
close(srv->fd);
srv->fd = -1;
close(srv->fd);
srv->fd = -1;
srv->sa = NULL;
srv->sa_len = 0;
srv->sa = NULL;
srv->sa_len = 0;
} /* }}} int server_close_socket */
static void int_server_destroy(lcc_server_t *srv) /* {{{ */
} /* }}} int server_close_socket */
static void int_server_destroy(lcc_server_t *srv) /* {{{ */
int status;
if (srv == NULL)
int status;
if (srv == NULL)
if (srv->fd >= 0)
server_close_socket(srv);
if (srv->fd >= 0)
server_close_socket(srv);
status = getaddrinfo(srv->node, srv->service, &ai_hints, &ai_list);
if (status != 0)
status = getaddrinfo(srv->node, srv->service, &ai_hints, &ai_list);
if (status != 0)
assert(ai_list != NULL);
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
assert(ai_list != NULL);
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
freeaddrinfo(ai_list);
if (srv->fd < 0)
freeaddrinfo(ai_list);
if (srv->fd < 0)
- return (-1);
- return (0);
} /* }}} int server_open_socket */
static int server_send_buffer(lcc_server_t *srv) /* {{{ */
} /* }}} int server_open_socket */
static int server_send_buffer(lcc_server_t *srv) /* {{{ */
if (srv->fd < 0) {
status = server_open_socket(srv);
if (status != 0)
if (srv->fd < 0) {
status = server_open_socket(srv);
if (status != 0)
}
buffer_size = sizeof(buffer);
}
buffer_size = sizeof(buffer);
status = lcc_network_buffer_finalize(srv->buffer);
if (status != 0) {
lcc_network_buffer_initialize(srv->buffer);
status = lcc_network_buffer_finalize(srv->buffer);
if (status != 0) {
lcc_network_buffer_initialize(srv->buffer);
}
status = lcc_network_buffer_get(srv->buffer, buffer, &buffer_size);
lcc_network_buffer_initialize(srv->buffer);
if (status != 0)
}
status = lcc_network_buffer_get(srv->buffer, buffer, &buffer_size);
lcc_network_buffer_initialize(srv->buffer);
if (status != 0)
if (buffer_size > sizeof(buffer))
buffer_size = sizeof(buffer);
if (buffer_size > sizeof(buffer))
buffer_size = sizeof(buffer);
- return (status);
- return (0);
+ return status;
+ return 0;
} /* }}} int server_send_buffer */
static int server_value_add(lcc_server_t *srv, /* {{{ */
} /* }}} int server_send_buffer */
static int server_value_add(lcc_server_t *srv, /* {{{ */
status = lcc_network_buffer_add_value(srv->buffer, vl);
if (status == 0)
status = lcc_network_buffer_add_value(srv->buffer, vl);
if (status == 0)
- return (lcc_network_buffer_add_value(srv->buffer, vl));
+ return lcc_network_buffer_add_value(srv->buffer, vl);
} /* }}} int server_value_add */
/*
} /* }}} int server_value_add */
/*
net = calloc(1, sizeof(*net));
if (net == NULL)
net = calloc(1, sizeof(*net));
if (net == NULL)
} /* }}} lcc_network_t *lcc_network_create */
void lcc_network_destroy(lcc_network_t *net) /* {{{ */
} /* }}} lcc_network_t *lcc_network_create */
void lcc_network_destroy(lcc_network_t *net) /* {{{ */
lcc_server_t *srv;
if ((net == NULL) || (node == NULL))
lcc_server_t *srv;
if ((net == NULL) || (node == NULL))
if (service == NULL)
service = NET_DEFAULT_PORT;
srv = calloc(1, sizeof(*srv));
if (srv == NULL)
if (service == NULL)
service = NET_DEFAULT_PORT;
srv = calloc(1, sizeof(*srv));
if (srv == NULL)
srv->fd = -1;
srv->security_level = NONE;
srv->fd = -1;
srv->security_level = NONE;
srv->node = strdup(node);
if (srv->node == NULL) {
free(srv);
srv->node = strdup(node);
if (srv->node == NULL) {
free(srv);
}
srv->service = strdup(service);
if (srv->service == NULL) {
free(srv->node);
free(srv);
}
srv->service = strdup(service);
if (srv->service == NULL) {
free(srv->node);
free(srv);
}
srv->buffer = lcc_network_buffer_create(/* size = */ 0);
}
srv->buffer = lcc_network_buffer_create(/* size = */ 0);
free(srv->service);
free(srv->node);
free(srv);
free(srv->service);
free(srv->node);
free(srv);
}
if (net->servers == NULL) {
}
if (net->servers == NULL) {
} /* }}} lcc_server_t *lcc_server_create */
int lcc_server_destroy(lcc_network_t *net, lcc_server_t *srv) /* {{{ */
{
if ((net == NULL) || (srv == NULL))
} /* }}} lcc_server_t *lcc_server_create */
int lcc_server_destroy(lcc_network_t *net, lcc_server_t *srv) /* {{{ */
{
if ((net == NULL) || (srv == NULL))
if (net->servers == srv) {
net->servers = srv->next;
if (net->servers == srv) {
net->servers = srv->next;
prev = prev->next;
if (prev == NULL)
prev = prev->next;
if (prev == NULL)
prev->next = srv->next;
srv->next = NULL;
prev->next = srv->next;
srv->next = NULL;
} /* }}} int lcc_server_destroy */
int lcc_server_set_ttl(lcc_server_t *srv, uint8_t ttl) /* {{{ */
{
if (srv == NULL)
} /* }}} int lcc_server_destroy */
int lcc_server_set_ttl(lcc_server_t *srv, uint8_t ttl) /* {{{ */
{
if (srv == NULL)
} /* }}} int lcc_server_set_ttl */
int lcc_server_set_interface(lcc_server_t *srv, char const *interface) /* {{{ */
} /* }}} int lcc_server_set_ttl */
int lcc_server_set_interface(lcc_server_t *srv, char const *interface) /* {{{ */
int status;
if ((srv == NULL) || (interface == NULL))
int status;
if ((srv == NULL) || (interface == NULL))
if_index = if_nametoindex(interface);
if (if_index == 0)
if_index = if_nametoindex(interface);
if (if_index == 0)
/* IPv4 multicast */
if (srv->sa->sa_family == AF_INET) {
/* IPv4 multicast */
if (srv->sa->sa_family == AF_INET) {
status =
setsockopt(srv->fd, IPPROTO_IP, IP_MULTICAST_IF, &mreq, sizeof(mreq));
if (status != 0)
status =
setsockopt(srv->fd, IPPROTO_IP, IP_MULTICAST_IF, &mreq, sizeof(mreq));
if (status != 0)
status = setsockopt(srv->fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index,
sizeof(if_index));
if (status != 0)
status = setsockopt(srv->fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index,
sizeof(if_index));
if (status != 0)
status = setsockopt(srv->fd, SOL_SOCKET, SO_BINDTODEVICE, interface,
(socklen_t)(strlen(interface) + 1));
if (status != 0)
status = setsockopt(srv->fd, SOL_SOCKET, SO_BINDTODEVICE, interface,
(socklen_t)(strlen(interface) + 1));
if (status != 0)
} /* }}} int lcc_server_set_interface */
int lcc_server_set_security_level(lcc_server_t *srv, /* {{{ */
lcc_security_level_t level,
const char *username, const char *password) {
} /* }}} int lcc_server_set_interface */
int lcc_server_set_security_level(lcc_server_t *srv, /* {{{ */
lcc_security_level_t level,
const char *username, const char *password) {
- return (lcc_network_buffer_set_security_level(srv->buffer, level, username,
- password));
+ return lcc_network_buffer_set_security_level(srv->buffer, level, username,
+ password);
} /* }}} int lcc_server_set_security_level */
int lcc_network_values_send(lcc_network_t *net, /* {{{ */
const lcc_value_list_t *vl) {
if ((net == NULL) || (vl == NULL))
} /* }}} int lcc_server_set_security_level */
int lcc_network_values_send(lcc_network_t *net, /* {{{ */
const lcc_value_list_t *vl) {
if ((net == NULL) || (vl == NULL))
for (lcc_server_t *srv = net->servers; srv != NULL; srv = srv->next)
server_value_add(srv, vl);
for (lcc_server_t *srv = net->servers; srv != NULL; srv = srv->next)
server_value_add(srv, vl);
} /* }}} int lcc_network_values_send */
} /* }}} int lcc_network_values_send */
static _Bool need_init = 1;
if (!need_init)
static _Bool need_init = 1;
if (!need_init)
need_init = 0;
#if HAVE_GCRYPT_H
#if GCRYPT_VERSION_NUMBER < 0x010600
if (gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread))
need_init = 0;
#if HAVE_GCRYPT_H
#if GCRYPT_VERSION_NUMBER < 0x010600
if (gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread))
#endif
if (!gcry_check_version(GCRYPT_VERSION))
#endif
if (!gcry_check_version(GCRYPT_VERSION))
if (!gcry_control(GCRYCTL_INIT_SECMEM, 32768, 0))
if (!gcry_control(GCRYCTL_INIT_SECMEM, 32768, 0))
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
result = 1;
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
result = 1;
#endif
} /* }}} _Bool have_gcrypt */
#endif
} /* }}} _Bool have_gcrypt */
hi = (uint32_t)(val >> 32);
lo = (uint32_t)(val & 0x00000000FFFFFFFF);
hi = (uint32_t)(val >> 32);
lo = (uint32_t)(val & 0x00000000FFFFFFFF);
hi = htonl(hi);
lo = htonl(lo);
hi = htonl(hi);
lo = htonl(lo);
- return ((((uint64_t)lo) << 32) | ((uint64_t)hi));
+ return (((uint64_t)lo) << 32) | ((uint64_t)hi);
} /* }}} uint64_t htonll */
#endif
} /* }}} uint64_t htonll */
#endif
out.byte[4] = out.byte[5] = 0x00;
out.byte[6] = 0xf8;
out.byte[7] = 0x7f;
out.byte[4] = out.byte[5] = 0x00;
out.byte[6] = 0xf8;
out.byte[7] = 0x7f;
else if (config == 2) {
in.floating = val;
out.byte[0] = in.byte[7];
else if (config == 2) {
in.floating = val;
out.byte[0] = in.byte[7];
out.byte[5] = in.byte[2];
out.byte[6] = in.byte[1];
out.byte[7] = in.byte[0];
out.byte[5] = in.byte[2];
out.byte[6] = in.byte[1];
out.byte[7] = in.byte[0];
} else if (config == 3) {
in.floating = val;
out.byte[0] = in.byte[4];
} else if (config == 3) {
in.floating = val;
out.byte[0] = in.byte[4];
out.byte[5] = in.byte[1];
out.byte[6] = in.byte[2];
out.byte[7] = in.byte[3];
out.byte[5] = in.byte[1];
out.byte[6] = in.byte[2];
out.byte[7] = in.byte[3];
} else {
/* If in doubt, just copy the value back to the caller. */
} else {
/* If in doubt, just copy the value back to the caller. */
}
} /* }}} double htond */
}
} /* }}} double htond */
sizeof(pkg_values_types) + sizeof(pkg_values);
if (*ret_buffer_len < packet_len)
sizeof(pkg_values_types) + sizeof(pkg_values);
if (*ret_buffer_len < packet_len)
pkg_type = htons(TYPE_VALUES);
pkg_length = htons((uint16_t)packet_len);
pkg_type = htons(TYPE_VALUES);
pkg_length = htons((uint16_t)packet_len);
} /* switch (vl->values_types[i]) */
} /* for (vl->values_len) */
} /* switch (vl->values_types[i]) */
} /* for (vl->values_len) */
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
} /* }}} int nb_add_values */
static int nb_add_number(char **ret_buffer, /* {{{ */
} /* }}} int nb_add_values */
static int nb_add_number(char **ret_buffer, /* {{{ */
packet_len = sizeof(pkg_type) + sizeof(pkg_length) + sizeof(pkg_value);
if (*ret_buffer_len < packet_len)
packet_len = sizeof(pkg_type) + sizeof(pkg_length) + sizeof(pkg_value);
if (*ret_buffer_len < packet_len)
pkg_type = htons(type);
pkg_length = htons((uint16_t)packet_len);
pkg_type = htons(type);
pkg_length = htons((uint16_t)packet_len);
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
} /* }}} int nb_add_number */
static int nb_add_time(char **ret_buffer, /* {{{ */
size_t *ret_buffer_len, uint16_t type, double value) {
/* Convert to collectd's "cdtime" representation. */
uint64_t cdtime_value = (uint64_t)(value * 1073741824.0);
} /* }}} int nb_add_number */
static int nb_add_time(char **ret_buffer, /* {{{ */
size_t *ret_buffer_len, uint16_t type, double value) {
/* Convert to collectd's "cdtime" representation. */
uint64_t cdtime_value = (uint64_t)(value * 1073741824.0);
- return (nb_add_number(ret_buffer, ret_buffer_len, type, cdtime_value));
+ return nb_add_number(ret_buffer, ret_buffer_len, type, cdtime_value);
} /* }}} int nb_add_time */
static int nb_add_string(char **ret_buffer, /* {{{ */
} /* }}} int nb_add_time */
static int nb_add_string(char **ret_buffer, /* {{{ */
packet_len = sizeof(pkg_type) + sizeof(pkg_length) + str_len + 1;
if (*ret_buffer_len < packet_len)
packet_len = sizeof(pkg_type) + sizeof(pkg_length) + str_len + 1;
if (*ret_buffer_len < packet_len)
pkg_type = htons(type);
pkg_length = htons((uint16_t)packet_len);
pkg_type = htons(type);
pkg_length = htons((uint16_t)packet_len);
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
} /* }}} int nb_add_string */
static int nb_add_value_list(lcc_network_buffer_t *nb, /* {{{ */
} /* }}} int nb_add_string */
static int nb_add_value_list(lcc_network_buffer_t *nb, /* {{{ */
if (strcmp(ident_dst->host, ident_src->host) != 0) {
if (nb_add_string(&buffer, &buffer_size, TYPE_HOST, ident_src->host,
strlen(ident_src->host)) != 0)
if (strcmp(ident_dst->host, ident_src->host) != 0) {
if (nb_add_string(&buffer, &buffer_size, TYPE_HOST, ident_src->host,
strlen(ident_src->host)) != 0)
SSTRNCPY(ident_dst->host, ident_src->host, sizeof(ident_dst->host));
}
if (strcmp(ident_dst->plugin, ident_src->plugin) != 0) {
if (nb_add_string(&buffer, &buffer_size, TYPE_PLUGIN, ident_src->plugin,
strlen(ident_src->plugin)) != 0)
SSTRNCPY(ident_dst->host, ident_src->host, sizeof(ident_dst->host));
}
if (strcmp(ident_dst->plugin, ident_src->plugin) != 0) {
if (nb_add_string(&buffer, &buffer_size, TYPE_PLUGIN, ident_src->plugin,
strlen(ident_src->plugin)) != 0)
SSTRNCPY(ident_dst->plugin, ident_src->plugin, sizeof(ident_dst->plugin));
}
SSTRNCPY(ident_dst->plugin, ident_src->plugin, sizeof(ident_dst->plugin));
}
if (nb_add_string(&buffer, &buffer_size, TYPE_PLUGIN_INSTANCE,
ident_src->plugin_instance,
strlen(ident_src->plugin_instance)) != 0)
if (nb_add_string(&buffer, &buffer_size, TYPE_PLUGIN_INSTANCE,
ident_src->plugin_instance,
strlen(ident_src->plugin_instance)) != 0)
SSTRNCPY(ident_dst->plugin_instance, ident_src->plugin_instance,
sizeof(ident_dst->plugin_instance));
}
SSTRNCPY(ident_dst->plugin_instance, ident_src->plugin_instance,
sizeof(ident_dst->plugin_instance));
}
if (strcmp(ident_dst->type, ident_src->type) != 0) {
if (nb_add_string(&buffer, &buffer_size, TYPE_TYPE, ident_src->type,
strlen(ident_src->type)) != 0)
if (strcmp(ident_dst->type, ident_src->type) != 0) {
if (nb_add_string(&buffer, &buffer_size, TYPE_TYPE, ident_src->type,
strlen(ident_src->type)) != 0)
SSTRNCPY(ident_dst->type, ident_src->type, sizeof(ident_dst->type));
}
SSTRNCPY(ident_dst->type, ident_src->type, sizeof(ident_dst->type));
}
if (nb_add_string(&buffer, &buffer_size, TYPE_TYPE_INSTANCE,
ident_src->type_instance,
strlen(ident_src->type_instance)) != 0)
if (nb_add_string(&buffer, &buffer_size, TYPE_TYPE_INSTANCE,
ident_src->type_instance,
strlen(ident_src->type_instance)) != 0)
SSTRNCPY(ident_dst->type_instance, ident_src->type_instance,
sizeof(ident_dst->type_instance));
}
if (nb->state.time != vl->time) {
if (nb_add_time(&buffer, &buffer_size, TYPE_TIME_HR, vl->time))
SSTRNCPY(ident_dst->type_instance, ident_src->type_instance,
sizeof(ident_dst->type_instance));
}
if (nb->state.time != vl->time) {
if (nb_add_time(&buffer, &buffer_size, TYPE_TIME_HR, vl->time))
nb->state.time = vl->time;
}
if (nb->state.interval != vl->interval) {
if (nb_add_time(&buffer, &buffer_size, TYPE_INTERVAL_HR, vl->interval))
nb->state.time = vl->time;
}
if (nb->state.interval != vl->interval) {
if (nb_add_time(&buffer, &buffer_size, TYPE_INTERVAL_HR, vl->interval))
nb->state.interval = vl->interval;
}
if (nb_add_values(&buffer, &buffer_size, vl) != 0)
nb->state.interval = vl->interval;
}
if (nb_add_values(&buffer, &buffer_size, vl) != 0)
nb->ptr = buffer;
nb->free = buffer_size;
nb->ptr = buffer;
nb->free = buffer_size;
} /* }}} int nb_add_value_list */
#if HAVE_GCRYPT_H
} /* }}} int nb_add_value_list */
#if HAVE_GCRYPT_H
hd = NULL;
err = gcry_md_open(&hd, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC);
if (err != 0)
hd = NULL;
err = gcry_md_open(&hd, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC);
if (err != 0)
assert(nb->password != NULL);
err = gcry_md_setkey(hd, nb->password, strlen(nb->password));
if (err != 0) {
gcry_md_close(hd);
assert(nb->password != NULL);
err = gcry_md_setkey(hd, nb->password, strlen(nb->password));
if (err != 0) {
gcry_md_close(hd);
}
gcry_md_write(hd, buffer, buffer_size);
hash = gcry_md_read(hd, GCRY_MD_SHA256);
if (hash == NULL) {
gcry_md_close(hd);
}
gcry_md_write(hd, buffer, buffer_size);
hash = gcry_md_read(hd, GCRY_MD_SHA256);
if (hash == NULL) {
gcry_md_close(hd);
}
assert(((2 * sizeof(uint16_t)) + hash_length) == PART_SIGNATURE_SHA256_SIZE);
memcpy(nb->buffer + (2 * sizeof(uint16_t)), hash, hash_length);
gcry_md_close(hd);
}
assert(((2 * sizeof(uint16_t)) + hash_length) == PART_SIGNATURE_SHA256_SIZE);
memcpy(nb->buffer + (2 * sizeof(uint16_t)), hash, hash_length);
gcry_md_close(hd);
} /* }}} int nb_add_signature */
static int nb_add_encryption(lcc_network_buffer_t *nb) /* {{{ */
} /* }}} int nb_add_signature */
static int nb_add_encryption(lcc_network_buffer_t *nb) /* {{{ */
err = gcry_cipher_open(&nb->encr_cypher, GCRY_CIPHER_AES256,
GCRY_CIPHER_MODE_OFB, /* flags = */ 0);
if (err != 0)
err = gcry_cipher_open(&nb->encr_cypher, GCRY_CIPHER_AES256,
GCRY_CIPHER_MODE_OFB, /* flags = */ 0);
if (err != 0)
/* Calculate our 256bit key used for AES */
gcry_md_hash_buffer(GCRY_MD_SHA256, password_hash, nb->password,
/* Calculate our 256bit key used for AES */
gcry_md_hash_buffer(GCRY_MD_SHA256, password_hash, nb->password,
if (err != 0) {
gcry_cipher_close(nb->encr_cypher);
nb->encr_cypher = NULL;
if (err != 0) {
gcry_cipher_close(nb->encr_cypher);
nb->encr_cypher = NULL;
}
} else /* if (nb->encr_cypher != NULL) */
{
}
} else /* if (nb->encr_cypher != NULL) */
{
if (err != 0) {
gcry_cipher_close(nb->encr_cypher);
nb->encr_cypher = NULL;
if (err != 0) {
gcry_cipher_close(nb->encr_cypher);
nb->encr_cypher = NULL;
}
/* Encrypt the buffer in-place */
}
/* Encrypt the buffer in-place */
if (err != 0) {
gcry_cipher_close(nb->encr_cypher);
nb->encr_cypher = NULL;
if (err != 0) {
gcry_cipher_close(nb->encr_cypher);
nb->encr_cypher = NULL;
} /* }}} int nb_add_encryption */
#endif
} /* }}} int nb_add_encryption */
#endif
if (size < 128) {
errno = EINVAL;
if (size < 128) {
errno = EINVAL;
}
nb = calloc(1, sizeof(*nb));
if (nb == NULL)
}
nb = calloc(1, sizeof(*nb));
if (nb == NULL)
nb->size = size;
nb->buffer = calloc(1, nb->size);
if (nb->buffer == NULL) {
free(nb);
nb->size = size;
nb->buffer = calloc(1, nb->size);
if (nb->buffer == NULL) {
free(nb);
nb->username = NULL;
nb->password = NULL;
nb->username = NULL;
nb->password = NULL;
} /* }}} lcc_network_buffer_t *lcc_network_buffer_create */
void lcc_network_buffer_destroy(lcc_network_buffer_t *nb) /* {{{ */
} /* }}} lcc_network_buffer_t *lcc_network_buffer_create */
void lcc_network_buffer_destroy(lcc_network_buffer_t *nb) /* {{{ */
nb->password = NULL;
nb->seclevel = NONE;
lcc_network_buffer_initialize(nb);
nb->password = NULL;
nb->seclevel = NONE;
lcc_network_buffer_initialize(nb);
username_copy = strdup(username);
password_copy = strdup(password);
if ((username_copy == NULL) || (password_copy == NULL)) {
free(username_copy);
free(password_copy);
username_copy = strdup(username);
password_copy = strdup(password);
if ((username_copy == NULL) || (password_copy == NULL)) {
free(username_copy);
free(password_copy);
nb->seclevel = level;
lcc_network_buffer_initialize(nb);
nb->seclevel = level;
lcc_network_buffer_initialize(nb);
} /* }}} int lcc_network_buffer_set_security_level */
int lcc_network_buffer_initialize(lcc_network_buffer_t *nb) /* {{{ */
{
if (nb == NULL)
} /* }}} int lcc_network_buffer_set_security_level */
int lcc_network_buffer_initialize(lcc_network_buffer_t *nb) /* {{{ */
{
if (nb == NULL)
memset(nb->buffer, 0, nb->size);
memset(&nb->state, 0, sizeof(nb->state));
memset(nb->buffer, 0, nb->size);
memset(&nb->state, 0, sizeof(nb->state));
} /* }}} int lcc_network_buffer_initialize */
int lcc_network_buffer_finalize(lcc_network_buffer_t *nb) /* {{{ */
{
if (nb == NULL)
} /* }}} int lcc_network_buffer_initialize */
int lcc_network_buffer_finalize(lcc_network_buffer_t *nb) /* {{{ */
{
if (nb == NULL)
#if HAVE_GCRYPT_H
if (nb->seclevel == SIGN)
#if HAVE_GCRYPT_H
if (nb->seclevel == SIGN)
return nb_add_encryption(nb);
#endif
return nb_add_encryption(nb);
#endif
} /* }}} int lcc_network_buffer_finalize */
int lcc_network_buffer_add_value(lcc_network_buffer_t *nb, /* {{{ */
} /* }}} int lcc_network_buffer_finalize */
int lcc_network_buffer_add_value(lcc_network_buffer_t *nb, /* {{{ */
int status;
if ((nb == NULL) || (vl == NULL))
int status;
if ((nb == NULL) || (vl == NULL))
status = nb_add_value_list(nb, vl);
status = nb_add_value_list(nb, vl);
} /* }}} int lcc_network_buffer_add_value */
int lcc_network_buffer_get(lcc_network_buffer_t *nb, /* {{{ */
} /* }}} int lcc_network_buffer_add_value */
int lcc_network_buffer_get(lcc_network_buffer_t *nb, /* {{{ */
size_t sz_available;
if ((nb == NULL) || (buffer_size == NULL))
size_t sz_available;
if ((nb == NULL) || (buffer_size == NULL))
assert(nb->size >= nb->free);
sz_required = nb->size - nb->free;
assert(nb->size >= nb->free);
sz_required = nb->size - nb->free;
memcpy(buffer, nb->buffer,
(sz_available < sz_required) ? sz_available : sz_required);
memcpy(buffer, nb->buffer,
(sz_available < sz_required) ? sz_available : sz_required);
} /* }}} int lcc_network_buffer_get */
} /* }}} int lcc_network_buffer_get */
status = yyparse();
if (status != 0) {
fprintf(stderr, "yyparse returned error #%i\n", status);
status = yyparse();
if (status != 0) {
fprintf(stderr, "yyparse returned error #%i\n", status);
ci_root = NULL;
yyset_in((FILE *)0);
ci_root = NULL;
yyset_in((FILE *)0);
} /* oconfig_item_t *oconfig_parse_fh */
oconfig_item_t *oconfig_parse_file(const char *file) {
} /* oconfig_item_t *oconfig_parse_fh */
oconfig_item_t *oconfig_parse_file(const char *file) {
fh = fopen(file, "r");
if (fh == NULL) {
fprintf(stderr, "fopen (%s) failed: %s\n", file, strerror(errno));
fh = fopen(file, "r");
if (fh == NULL) {
fprintf(stderr, "fopen (%s) failed: %s\n", file, strerror(errno));
}
ret = oconfig_parse_fh(fh);
}
ret = oconfig_parse_fh(fh);
} /* oconfig_item_t *oconfig_parse_file */
oconfig_item_t *oconfig_clone(const oconfig_item_t *ci_orig) {
} /* oconfig_item_t *oconfig_parse_file */
oconfig_item_t *oconfig_clone(const oconfig_item_t *ci_orig) {
ci_copy = calloc(1, sizeof(*ci_copy));
if (ci_copy == NULL) {
fprintf(stderr, "calloc failed.\n");
ci_copy = calloc(1, sizeof(*ci_copy));
if (ci_copy == NULL) {
fprintf(stderr, "calloc failed.\n");
}
ci_copy->values = NULL;
ci_copy->parent = NULL;
}
ci_copy->values = NULL;
ci_copy->parent = NULL;
if (ci_copy->key == NULL) {
fprintf(stderr, "strdup failed.\n");
free(ci_copy);
if (ci_copy->key == NULL) {
fprintf(stderr, "strdup failed.\n");
free(ci_copy);
}
if (ci_orig->values_num > 0) /* {{{ */
}
if (ci_orig->values_num > 0) /* {{{ */
fprintf(stderr, "calloc failed.\n");
free(ci_copy->key);
free(ci_copy);
fprintf(stderr, "calloc failed.\n");
free(ci_copy->key);
free(ci_copy);
}
ci_copy->values_num = ci_orig->values_num;
}
ci_copy->values_num = ci_orig->values_num;
if (ci_copy->values[i].value.string == NULL) {
fprintf(stderr, "strdup failed.\n");
oconfig_free(ci_copy);
if (ci_copy->values[i].value.string == NULL) {
fprintf(stderr, "strdup failed.\n");
oconfig_free(ci_copy);
}
} else /* ci_copy->values[i].type != OCONFIG_TYPE_STRING) */
{
}
} else /* ci_copy->values[i].type != OCONFIG_TYPE_STRING) */
{
if (ci_copy->children == NULL) {
fprintf(stderr, "calloc failed.\n");
oconfig_free(ci_copy);
if (ci_copy->children == NULL) {
fprintf(stderr, "calloc failed.\n");
oconfig_free(ci_copy);
}
ci_copy->children_num = ci_orig->children_num;
}
ci_copy->children_num = ci_orig->children_num;
child = oconfig_clone(ci_orig->children + i);
if (child == NULL) {
oconfig_free(ci_copy);
child = oconfig_clone(ci_orig->children + i);
if (child == NULL) {
oconfig_free(ci_copy);
}
child->parent = ci_copy;
ci_copy->children[i] = *child;
}
child->parent = ci_copy;
ci_copy->children[i] = *child;
} /* for (i = 0; i < ci_copy->children_num; i++) */
} /* }}} if (ci_orig->children_num > 0) */
} /* for (i = 0; i < ci_copy->children_num; i++) */
} /* }}} if (ci_orig->children_num > 0) */
} /* oconfig_item_t *oconfig_clone */
static void oconfig_free_all(oconfig_item_t *ci) {
} /* oconfig_item_t *oconfig_clone */
static void oconfig_free_all(oconfig_item_t *ci) {
"is not available, because I can't determine the "
"number of CPUS on this system. Sorry.");
#endif
"is not available, because I can't determine the "
"number of CPUS on this system. Sorry.");
#endif
}
static void load_submit(gauge_t snum, gauge_t mnum, gauge_t lnum) {
int cores = 0;
}
static void load_submit(gauge_t snum, gauge_t mnum, gauge_t lnum) {
int cores = 0;
if ((loadavg = fopen("/proc/loadavg", "r")) == NULL) {
char errbuf[1024];
WARNING("load: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if ((loadavg = fopen("/proc/loadavg", "r")) == NULL) {
char errbuf[1024];
WARNING("load: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (fgets(buffer, 16, loadavg) == NULL) {
char errbuf[1024];
WARNING("load: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(loadavg);
}
if (fgets(buffer, 16, loadavg) == NULL) {
char errbuf[1024];
WARNING("load: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(loadavg);
numfields = strsplit(buffer, fields, 8);
if (numfields < 3)
numfields = strsplit(buffer, fields, 8);
if (numfields < 3)
snum = atof(fields[0]);
mnum = atof(fields[1]);
snum = atof(fields[0]);
mnum = atof(fields[1]);
char errbuf[1024];
WARNING("load: perfstat_cpu : %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("load: perfstat_cpu : %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
snum = (float)cputotal.loadavg[0] / (float)(1 << SBITS);
}
snum = (float)cputotal.loadavg[0] / (float)(1 << SBITS);
#error "No applicable input method."
#endif
#error "No applicable input method."
#endif
}
void module_register(void) {
}
void module_register(void) {
if (g == NULL) {
fprintf(stderr, "Could not allocate JSON generator.\n");
if (g == NULL) {
fprintf(stderr, "Could not allocate JSON generator.\n");
}
if (yajl_gen_map_open(g) != yajl_gen_status_ok)
}
if (yajl_gen_map_open(g) != yajl_gen_status_ok)
}
log_logstash_print(g, LOG_INFO, (n->time != 0) ? n->time : cdtime());
}
log_logstash_print(g, LOG_INFO, (n->time != 0) ? n->time : cdtime());
err:
yajl_gen_free(g);
fprintf(stderr, "Could not correctly generate JSON notification\n");
err:
yajl_gen_free(g);
fprintf(stderr, "Could not correctly generate JSON notification\n");
} /* int log_logstash_notification */
void module_register(void) {
} /* int log_logstash_notification */
void module_register(void) {
if (log_level < 0) {
log_level = LOG_INFO;
ERROR("logfile: invalid loglevel [%s] defaulting to 'info'", value);
if (log_level < 0) {
log_level = LOG_INFO;
ERROR("logfile: invalid loglevel [%s] defaulting to 'info'", value);
}
} else if (0 == strcasecmp(key, "File")) {
sfree(log_file);
}
} else if (0 == strcasecmp(key, "File")) {
sfree(log_file);
logfile_print(buf, LOG_INFO, (n->time != 0) ? n->time : cdtime());
logfile_print(buf, LOG_INFO, (n->time != 0) ? n->time : cdtime());
} /* int logfile_notification */
void module_register(void) {
} /* int logfile_notification */
void module_register(void) {
else
report_by_serial = 0;
} else {
else
report_by_serial = 0;
} else {
} /* int lpar_config */
static int lpar_init(void) {
} /* int lpar_config */
static int lpar_init(void) {
char errbuf[1024];
ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)",
sstrerror(errno, errbuf, sizeof(errbuf)), status);
char errbuf[1024];
ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)",
sstrerror(errno, errbuf, sizeof(errbuf)), status);
}
#if PERFSTAT_SUPPORTS_DONATION
}
#if PERFSTAT_SUPPORTS_DONATION
} /* int lpar_init */
static void lpar_submit(const char *type_instance, double value) {
} /* int lpar_init */
static void lpar_submit(const char *type_instance, double value) {
from chassis to chassis through Live Partition Mobility (LPM). */
if (uname(&name) != 0) {
ERROR("lpar plugin: uname failed.");
from chassis to chassis through Live Partition Mobility (LPM). */
if (uname(&name) != 0) {
ERROR("lpar plugin: uname failed.");
}
sstrncpy(serial, name.machine, sizeof(serial));
}
sstrncpy(serial, name.machine, sizeof(serial));
char errbuf[1024];
ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)",
sstrerror(errno, errbuf, sizeof(errbuf)), status);
char errbuf[1024];
ERROR("lpar plugin: perfstat_partition_total failed: %s (%i)",
sstrerror(errno, errbuf, sizeof(errbuf)), status);
}
/* Number of ticks since we last run. */
}
/* Number of ticks since we last run. */
if (ticks == 0) {
/* The stats have not been updated. Return now to avoid
* dividing by zero */
if (ticks == 0) {
/* The stats have not been updated. Return now to avoid
* dividing by zero */
memcpy(&lparstats_old, &lparstats, sizeof(lparstats_old));
memcpy(&lparstats_old, &lparstats, sizeof(lparstats_old));
} /* int lpar_read */
void module_register(void) {
} /* int lpar_read */
void module_register(void) {
if (!lua_isfunction(L, -1)) {
lua_pop(L, 1);
if (!lua_isfunction(L, -1)) {
lua_pop(L, 1);
} /* }}} int clua_load_callback */
/* Store the threads in a global variable so they are not cleaned up by the
} /* }}} int clua_load_callback */
/* Store the threads in a global variable so they are not cleaned up by the
lua_pushvalue(L, idx); /* +1 = 3 */
if (!lua_isthread(L, -1)) {
lua_pop(L, 3); /* -3 = 0 */
lua_pushvalue(L, idx); /* +1 = 3 */
if (!lua_isthread(L, -1)) {
lua_pop(L, 3); /* -3 = 0 */
}
luaL_ref(L, LUA_REGISTRYINDEX);
lua_pop(L, 1); /* -1 = 0 */
}
luaL_ref(L, LUA_REGISTRYINDEX);
lua_pop(L, 1); /* -1 = 0 */
} /* }}} int clua_store_thread */
static int clua_read(user_data_t *ud) /* {{{ */
} /* }}} int clua_store_thread */
static int clua_read(user_data_t *ud) /* {{{ */
ERROR("Lua plugin: Unable to load callback \"%s\" (id %i).",
cb->lua_function_name, cb->callback_id);
pthread_mutex_unlock(&cb->lock);
ERROR("Lua plugin: Unable to load callback \"%s\" (id %i).",
cb->lua_function_name, cb->callback_id);
pthread_mutex_unlock(&cb->lock);
ERROR("Lua plugin: Calling a read callback failed: %s", errmsg);
lua_pop(L, 1);
pthread_mutex_unlock(&cb->lock);
ERROR("Lua plugin: Calling a read callback failed: %s", errmsg);
lua_pop(L, 1);
pthread_mutex_unlock(&cb->lock);
}
if (!lua_isnumber(L, -1)) {
}
if (!lua_isnumber(L, -1)) {
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
} /* }}} int clua_read */
static int clua_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
} /* }}} int clua_read */
static int clua_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
ERROR("Lua plugin: Unable to load callback \"%s\" (id %i).",
cb->lua_function_name, cb->callback_id);
pthread_mutex_unlock(&cb->lock);
ERROR("Lua plugin: Unable to load callback \"%s\" (id %i).",
cb->lua_function_name, cb->callback_id);
pthread_mutex_unlock(&cb->lock);
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
ERROR("Lua plugin: luaC_pushvaluelist failed.");
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
ERROR("Lua plugin: luaC_pushvaluelist failed.");
ERROR("Lua plugin: Calling the write callback failed:\n%s", errmsg);
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
ERROR("Lua plugin: Calling the write callback failed:\n%s", errmsg);
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
}
if (!lua_isnumber(L, -1)) {
}
if (!lua_isnumber(L, -1)) {
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
lua_pop(L, 1); /* -1 = 0 */
pthread_mutex_unlock(&cb->lock);
} /* }}} int clua_write */
/*
} /* }}} int clua_write */
/*
script->lua_state = luaL_newstate();
if (script->lua_state == NULL) {
ERROR("Lua plugin: luaL_newstate() failed.");
script->lua_state = luaL_newstate();
if (script->lua_state == NULL) {
ERROR("Lua plugin: luaL_newstate() failed.");
}
/* Open up all the standard Lua libraries. */
}
/* Open up all the standard Lua libraries. */
lua_pop(script->lua_state, 1);
}
lua_pop(script->lua_state, 1);
}
} /* }}} int lua_script_init */
static int lua_script_load(const char *script_path) /* {{{ */
} /* }}} int lua_script_init */
static int lua_script_load(const char *script_path) /* {{{ */
lua_script_t *script = malloc(sizeof(*script));
if (script == NULL) {
ERROR("Lua plugin: malloc failed.");
lua_script_t *script = malloc(sizeof(*script));
if (script == NULL) {
ERROR("Lua plugin: malloc failed.");
}
int status = lua_script_init(script);
if (status != 0) {
lua_script_free(script);
}
int status = lua_script_init(script);
if (status != 0) {
lua_script_free(script);
}
script->script_path = strdup(script_path);
if (script->script_path == NULL) {
ERROR("Lua plugin: strdup failed.");
lua_script_free(script);
}
script->script_path = strdup(script_path);
if (script->script_path == NULL) {
ERROR("Lua plugin: strdup failed.");
lua_script_free(script);
}
status = luaL_loadfile(script->lua_state, script->script_path);
}
status = luaL_loadfile(script->lua_state, script->script_path);
lua_tostring(script->lua_state, -1));
lua_pop(script->lua_state, 1);
lua_script_free(script);
lua_tostring(script->lua_state, -1));
lua_pop(script->lua_state, 1);
lua_script_free(script);
}
status = lua_pcall(script->lua_state,
}
status = lua_pcall(script->lua_state,
script->script_path, errmsg);
lua_script_free(script);
script->script_path, errmsg);
lua_script_free(script);
}
/* Append this script to the global list of scripts. */
}
/* Append this script to the global list of scripts. */
} /* }}} int lua_script_load */
static int lua_config_base_path(const oconfig_item_t *ci) /* {{{ */
{
int status = cf_util_get_string_buffer(ci, base_path, sizeof(base_path));
if (status != 0)
} /* }}} int lua_script_load */
static int lua_config_base_path(const oconfig_item_t *ci) /* {{{ */
{
int status = cf_util_get_string_buffer(ci, base_path, sizeof(base_path));
if (status != 0)
size_t len = strlen(base_path);
while ((len > 0) && (base_path[len - 1] == '/')) {
size_t len = strlen(base_path);
while ((len > 0) && (base_path[len - 1] == '/')) {
DEBUG("Lua plugin: base_path = \"%s\";", base_path);
DEBUG("Lua plugin: base_path = \"%s\";", base_path);
} /* }}} int lua_config_base_path */
static int lua_config_script(const oconfig_item_t *ci) /* {{{ */
} /* }}} int lua_config_base_path */
static int lua_config_script(const oconfig_item_t *ci) /* {{{ */
int status = cf_util_get_string_buffer(ci, rel_path, sizeof(rel_path));
if (status != 0)
int status = cf_util_get_string_buffer(ci, rel_path, sizeof(rel_path));
if (status != 0)
status = lua_script_load(abs_path);
if (status != 0)
status = lua_script_load(abs_path);
if (status != 0)
INFO("Lua plugin: File \"%s\" loaded successfully", abs_path);
INFO("Lua plugin: File \"%s\" loaded successfully", abs_path);
{
lua_script_free(scripts);
{
lua_script_free(scripts);
} /* }}} int lua_shutdown */
void module_register(void) {
} /* }}} int lua_shutdown */
void module_register(void) {
lvm = lvm_init(NULL);
if (!lvm) {
ERROR("lvm plugin: lvm_init failed.");
lvm = lvm_init(NULL);
if (!lvm) {
ERROR("lvm plugin: lvm_init failed.");
}
vg_names = lvm_list_vg_names(lvm);
if (!vg_names) {
ERROR("lvm plugin lvm_list_vg_name failed %s", lvm_errmsg(lvm));
lvm_quit(lvm);
}
vg_names = lvm_list_vg_names(lvm);
if (!vg_names) {
ERROR("lvm plugin lvm_list_vg_name failed %s", lvm_errmsg(lvm));
lvm_quit(lvm);
}
dm_list_iterate_items(name_list, vg_names) {
}
dm_list_iterate_items(name_list, vg_names) {
} /*lvm_read */
void module_register(void) {
} /*lvm_read */
void module_register(void) {
for (size_t i = 0; i < STATIC_ARRAY_SIZE(bounds); i++)
bounds[i]++;
for (size_t i = 0; i < STATIC_ARRAY_SIZE(bounds); i++)
bounds[i]++;
}
static int madwifi_config(const char *key, const char *value) {
}
static int madwifi_config(const char *key, const char *value) {
int id = watchitem_find(value);
if (id < 0)
int id = watchitem_find(value);
if (id < 0)
else
watchlist_add(watch_items, id);
}
else
watchlist_add(watch_items, id);
}
int id = watchitem_find(value);
if (id < 0)
int id = watchitem_find(value);
if (id < 0)
else
watchlist_remove(watch_items, id);
}
else
watchlist_remove(watch_items, id);
}
int id = watchitem_find(value);
if (id < 0)
int id = watchitem_find(value);
if (id < 0)
else
watchlist_add(misc_items, id);
}
else
watchlist_add(misc_items, id);
}
int id = watchitem_find(value);
if (id < 0)
int id = watchitem_find(value);
if (id < 0)
else
watchlist_remove(misc_items, id);
}
else
else
watchlist_remove(misc_items, id);
}
else
}
static void submit(const char *dev, const char *type, const char *ti1,
}
static void submit(const char *dev, const char *type, const char *ti1,
"SIOCGATHSTATS to device %s "
"failed with status %i.",
dev, status);
"SIOCGATHSTATS to device %s "
"failed with status %i.",
dev, status);
}
/* These stats are handled as a special case, because they are
}
/* These stats are handled as a special case, because they are
/* All other ath statistics */
process_stat_struct(ATH_STAT, &stats, dev, NULL, "ath_stat", "ast_misc");
/* All other ath statistics */
process_stat_struct(ATH_STAT, &stats, dev, NULL, "ath_stat", "ast_misc");
}
static int process_80211stats(int sk, const char *dev) {
}
static int process_80211stats(int sk, const char *dev) {
"SIOCG80211STATS to device %s "
"failed with status %i.",
dev, status);
"SIOCG80211STATS to device %s "
"failed with status %i.",
dev, status);
}
process_stat_struct(IFA_STAT, &stats, dev, NULL, "ath_stat", "is_misc");
}
process_stat_struct(IFA_STAT, &stats, dev, NULL, "ath_stat", "is_misc");
}
static int process_station(int sk, const char *dev,
}
static int process_station(int sk, const char *dev,
"IEEE80211_IOCTL_STA_STATS to device %s "
"failed with status %i.",
dev, status);
"IEEE80211_IOCTL_STA_STATS to device %s "
"failed with status %i.",
dev, status);
}
/* These two stats are handled as a special case as they are
}
/* These two stats are handled as a special case as they are
/* All other node statistics */
process_stat_struct(NOD_STAT, ns, dev, mac, "node_stat", "ns_misc");
/* All other node statistics */
process_stat_struct(NOD_STAT, ns, dev, mac, "node_stat", "ns_misc");
}
static int process_stations(int sk, const char *dev) {
}
static int process_stations(int sk, const char *dev) {
"IEEE80211_IOCTL_STA_INFO to device %s "
"failed with status %i.",
dev, status);
"IEEE80211_IOCTL_STA_INFO to device %s "
"failed with status %i.",
dev, status);
}
len = iwr.u.data.length;
}
len = iwr.u.data.length;
if (item_watched(STAT_ATH_NODES))
submit_gauge(dev, "ath_nodes", NULL, NULL, nodes);
if (item_watched(STAT_ATH_NODES))
submit_gauge(dev, "ath_nodes", NULL, NULL, nodes);
}
static int process_device(int sk, const char *dev) {
}
static int process_device(int sk, const char *dev) {
if (status == 0)
num_success++;
if (status == 0)
num_success++;
- return ((num_success == 0) ? -1 : 0);
+ return (num_success == 0) ? -1 : 0;
}
static int check_devname(const char *dev) {
}
static int check_devname(const char *dev) {
nets = opendir("/sys/class/net/");
if (nets == NULL) {
WARNING("madwifi plugin: opening /sys/class/net failed");
nets = opendir("/sys/class/net/");
if (nets == NULL) {
WARNING("madwifi plugin: opening /sys/class/net failed");
closedir(nets);
if ((num_success == 0) && (num_fail != 0))
closedir(nets);
if ((num_success == 0) && (num_fail != 0))
- return (-1);
- return (0);
}
static int procfs_iterate(int sk) {
}
static int procfs_iterate(int sk) {
if ((fh = fopen("/proc/net/dev", "r")) == NULL) {
WARNING("madwifi plugin: opening /proc/net/dev failed");
if ((fh = fopen("/proc/net/dev", "r")) == NULL) {
WARNING("madwifi plugin: opening /proc/net/dev failed");
fclose(fh);
if ((num_success == 0) && (num_fail != 0))
fclose(fh);
if ((num_success == 0) && (num_fail != 0))
sk = socket(AF_INET, SOCK_DGRAM, 0);
if (sk < 0)
sk = socket(AF_INET, SOCK_DGRAM, 0);
if (sk < 0)
/* procfs iteration is not safe because it does not check whether given
interface is madwifi interface and there are private ioctls used, which
/* procfs iteration is not safe because it does not check whether given
interface is madwifi interface and there are private ioctls used, which
} /* }}} int mec_create */
static int mec_destroy(__attribute__((unused)) void **user_data) /* {{{ */
{
} /* }}} int mec_create */
static int mec_destroy(__attribute__((unused)) void **user_data) /* {{{ */
{
} /* }}} int mec_destroy */
static int mec_match(__attribute__((unused)) const data_set_t *ds, /* {{{ */
} /* }}} int mec_destroy */
static int mec_match(__attribute__((unused)) const data_set_t *ds, /* {{{ */
}
if ((num_counters != 0) && (num_counters == num_empty))
}
if ((num_counters != 0) && (num_counters == num_empty))
- return (FC_MATCH_MATCHES);
+ return FC_MATCH_MATCHES;
- return (FC_MATCH_NO_MATCH);
+ return FC_MATCH_NO_MATCH;
} /* }}} int mec_match */
void module_register(void) {
} /* }}} int mec_match */
void module_register(void) {
(ci->values[1].type != OCONFIG_TYPE_NUMBER)) {
ERROR("hashed match: The `Match' option requires "
"exactly two numeric arguments.");
(ci->values[1].type != OCONFIG_TYPE_NUMBER)) {
ERROR("hashed match: The `Match' option requires "
"exactly two numeric arguments.");
}
if ((ci->values[0].value.number < 0) || (ci->values[1].value.number < 0)) {
ERROR("hashed match: The arguments of the `Match' "
"option must be positive.");
}
if ((ci->values[0].value.number < 0) || (ci->values[1].value.number < 0)) {
ERROR("hashed match: The arguments of the `Match' "
"option must be positive.");
}
tmp = realloc(m->matches, sizeof(*tmp) * (m->matches_num + 1));
if (tmp == NULL) {
ERROR("hashed match: realloc failed.");
}
tmp = realloc(m->matches, sizeof(*tmp) * (m->matches_num + 1));
if (tmp == NULL) {
ERROR("hashed match: realloc failed.");
}
m->matches = tmp;
tmp = m->matches + m->matches_num;
}
m->matches = tmp;
tmp = m->matches + m->matches_num;
if (tmp->match >= tmp->total) {
ERROR("hashed match: The first argument of the `Match' option "
"must be smaller than the second argument.");
if (tmp->match >= tmp->total) {
ERROR("hashed match: The first argument of the `Match' option "
"must be smaller than the second argument.");
}
assert(tmp->total != 0);
m->matches_num++;
}
assert(tmp->total != 0);
m->matches_num++;
} /* }}} int mh_config_match */
static int mh_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
} /* }}} int mh_config_match */
static int mh_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("mh_create: calloc failed.");
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("mh_create: calloc failed.");
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
sfree(m->matches);
sfree(m);
ERROR("hashed match: No matches were configured. Not creating match.");
sfree(m->matches);
sfree(m);
ERROR("hashed match: No matches were configured. Not creating match.");
} /* }}} int mh_create */
static int mh_destroy(void **user_data) /* {{{ */
} /* }}} int mh_create */
static int mh_destroy(void **user_data) /* {{{ */
mh_match_t *mh;
if ((user_data == NULL) || (*user_data == NULL))
mh_match_t *mh;
if ((user_data == NULL) || (*user_data == NULL))
mh = *user_data;
sfree(mh->matches);
sfree(mh);
mh = *user_data;
sfree(mh->matches);
sfree(mh);
} /* }}} int mh_destroy */
static int mh_match(const data_set_t __attribute__((unused)) * ds, /* {{{ */
} /* }}} int mh_destroy */
static int mh_match(const data_set_t __attribute__((unused)) * ds, /* {{{ */
uint32_t hash_val;
if ((user_data == NULL) || (*user_data == NULL))
uint32_t hash_val;
if ((user_data == NULL) || (*user_data == NULL))
for (size_t i = 0; i < m->matches_num; i++)
if ((hash_val % m->matches[i].total) == m->matches[i].match)
for (size_t i = 0; i < m->matches_num; i++)
if ((hash_val % m->matches[i].total) == m->matches[i].match)
- return (FC_MATCH_MATCHES);
+ return FC_MATCH_MATCHES;
- return (FC_MATCH_NO_MATCH);
+ return FC_MATCH_NO_MATCH;
} /* }}} int mh_match */
void module_register(void) {
} /* }}} int mh_match */
void module_register(void) {
static int mr_match_regexen(mr_regex_t *re_head, /* {{{ */
const char *string) {
if (re_head == NULL)
static int mr_match_regexen(mr_regex_t *re_head, /* {{{ */
const char *string) {
if (re_head == NULL)
- return (FC_MATCH_MATCHES);
+ return FC_MATCH_MATCHES;
for (mr_regex_t *re = re_head; re != NULL; re = re->next) {
int status;
for (mr_regex_t *re = re_head; re != NULL; re = re->next) {
int status;
} else {
DEBUG("regex match: Regular expression `%s' does not match `%s'.",
re->re_str, string);
} else {
DEBUG("regex match: Regular expression `%s' does not match `%s'.",
re->re_str, string);
- return (FC_MATCH_NO_MATCH);
+ return FC_MATCH_NO_MATCH;
- return (FC_MATCH_MATCHES);
+ return FC_MATCH_MATCHES;
} /* }}} int mr_match_regexen */
static int mr_add_regex(mr_regex_t **re_head, const char *re_str, /* {{{ */
} /* }}} int mr_match_regexen */
static int mr_add_regex(mr_regex_t **re_head, const char *re_str, /* {{{ */
re = calloc(1, sizeof(*re));
if (re == NULL) {
log_err("mr_add_regex: calloc failed.");
re = calloc(1, sizeof(*re));
if (re == NULL) {
log_err("mr_add_regex: calloc failed.");
if (re->re_str == NULL) {
sfree(re);
log_err("mr_add_regex: strdup failed.");
if (re->re_str == NULL) {
sfree(re);
log_err("mr_add_regex: strdup failed.");
}
status = regcomp(&re->re, re->re_str, REG_EXTENDED | REG_NOSUB);
}
status = regcomp(&re->re, re->re_str, REG_EXTENDED | REG_NOSUB);
errmsg);
sfree(re->re_str);
sfree(re);
errmsg);
sfree(re->re_str);
sfree(re);
}
if (*re_head == NULL) {
}
if (*re_head == NULL) {
} /* }}} int mr_add_regex */
static int mr_config_add_regex(mr_regex_t **re_head, /* {{{ */
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
log_warn("`%s' needs exactly one string argument.", ci->key);
} /* }}} int mr_add_regex */
static int mr_config_add_regex(mr_regex_t **re_head, /* {{{ */
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
log_warn("`%s' needs exactly one string argument.", ci->key);
}
return mr_add_regex(re_head, ci->values[0].value.string, ci->key);
}
return mr_add_regex(re_head, ci->values[0].value.string, ci->key);
if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
log_warn("`%s' needs exactly two string arguments.", ci->key);
if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
log_warn("`%s' needs exactly two string arguments.", ci->key);
}
if (*meta == NULL) {
*meta = llist_create();
if (*meta == NULL) {
log_err("mr_config_add_meta_regex: llist_create failed.");
}
if (*meta == NULL) {
*meta = llist_create();
if (*meta == NULL) {
log_err("mr_config_add_meta_regex: llist_create failed.");
meta_key = strdup(meta_key);
if (meta_key == NULL) {
log_err("mr_config_add_meta_regex: strdup failed.");
meta_key = strdup(meta_key);
if (meta_key == NULL) {
log_err("mr_config_add_meta_regex: strdup failed.");
}
entry = llentry_create(meta_key, NULL);
if (entry == NULL) {
log_err("mr_config_add_meta_regex: llentry_create failed.");
sfree(meta_key);
}
entry = llentry_create(meta_key, NULL);
if (entry == NULL) {
log_err("mr_config_add_meta_regex: llentry_create failed.");
sfree(meta_key);
}
/* meta_key and entry will now be freed by mr_free_match(). */
llist_append(*meta, entry);
}
/* meta_key and entry will now be freed by mr_free_match(). */
llist_append(*meta, entry);
m = calloc(1, sizeof(*m));
if (m == NULL) {
log_err("mr_create: calloc failed.");
m = calloc(1, sizeof(*m));
if (m == NULL) {
log_err("mr_create: calloc failed.");
if (status != 0) {
mr_free_match(m);
if (status != 0) {
mr_free_match(m);
} /* }}} int mr_create */
static int mr_destroy(void **user_data) /* {{{ */
{
if ((user_data != NULL) && (*user_data != NULL))
mr_free_match(*user_data);
} /* }}} int mr_create */
static int mr_destroy(void **user_data) /* {{{ */
{
if ((user_data != NULL) && (*user_data != NULL))
mr_free_match(*user_data);
} /* }}} int mr_destroy */
static int mr_match(const data_set_t __attribute__((unused)) * ds, /* {{{ */
} /* }}} int mr_destroy */
static int mr_match(const data_set_t __attribute__((unused)) * ds, /* {{{ */
int nomatch_value = FC_MATCH_NO_MATCH;
if ((user_data == NULL) || (*user_data == NULL))
int nomatch_value = FC_MATCH_NO_MATCH;
if ((user_data == NULL) || (*user_data == NULL))
}
if (mr_match_regexen(m->host, vl->host) == FC_MATCH_NO_MATCH)
}
if (mr_match_regexen(m->host, vl->host) == FC_MATCH_NO_MATCH)
- return (nomatch_value);
if (mr_match_regexen(m->plugin, vl->plugin) == FC_MATCH_NO_MATCH)
if (mr_match_regexen(m->plugin, vl->plugin) == FC_MATCH_NO_MATCH)
- return (nomatch_value);
if (mr_match_regexen(m->plugin_instance, vl->plugin_instance) ==
FC_MATCH_NO_MATCH)
if (mr_match_regexen(m->plugin_instance, vl->plugin_instance) ==
FC_MATCH_NO_MATCH)
- return (nomatch_value);
if (mr_match_regexen(m->type, vl->type) == FC_MATCH_NO_MATCH)
if (mr_match_regexen(m->type, vl->type) == FC_MATCH_NO_MATCH)
- return (nomatch_value);
if (mr_match_regexen(m->type_instance, vl->type_instance) ==
FC_MATCH_NO_MATCH)
if (mr_match_regexen(m->type_instance, vl->type_instance) ==
FC_MATCH_NO_MATCH)
- return (nomatch_value);
if (vl->meta != NULL) {
for (llentry_t *e = llist_head(m->meta); e != NULL; e = e->next) {
mr_regex_t *meta_re = (mr_regex_t *)e->value;
char *value;
int status = meta_data_get_string(vl->meta, e->key, &value);
if (status == (-ENOENT)) /* key is not present */
if (vl->meta != NULL) {
for (llentry_t *e = llist_head(m->meta); e != NULL; e = e->next) {
mr_regex_t *meta_re = (mr_regex_t *)e->value;
char *value;
int status = meta_data_get_string(vl->meta, e->key, &value);
if (status == (-ENOENT)) /* key is not present */
- return (nomatch_value);
if (status != 0) /* some other problem */
continue; /* error will have already been printed. */
if (mr_match_regexen(meta_re, value) == FC_MATCH_NO_MATCH) {
sfree(value);
if (status != 0) /* some other problem */
continue; /* error will have already been printed. */
if (mr_match_regexen(meta_re, value) == FC_MATCH_NO_MATCH) {
sfree(value);
- return (nomatch_value);
} /* }}} int mr_match */
void module_register(void) {
} /* }}} int mr_match */
void module_register(void) {
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("mt_create: calloc failed.");
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("mt_create: calloc failed.");
if (status != 0) {
free(m);
if (status != 0) {
free(m);
} /* }}} int mt_create */
static int mt_destroy(void **user_data) /* {{{ */
} /* }}} int mt_create */
static int mt_destroy(void **user_data) /* {{{ */
} /* }}} int mt_destroy */
static int mt_match(const data_set_t __attribute__((unused)) * ds, /* {{{ */
} /* }}} int mt_destroy */
static int mt_match(const data_set_t __attribute__((unused)) * ds, /* {{{ */
cdtime_t now;
if ((user_data == NULL) || (*user_data == NULL))
cdtime_t now;
if ((user_data == NULL) || (*user_data == NULL))
m = *user_data;
now = cdtime();
if (m->future != 0) {
if (vl->time >= (now + m->future))
m = *user_data;
now = cdtime();
if (m->future != 0) {
if (vl->time >= (now + m->future))
- return (FC_MATCH_MATCHES);
+ return FC_MATCH_MATCHES;
}
if (m->past != 0) {
if (vl->time <= (now - m->past))
}
if (m->past != 0) {
if (vl->time <= (now - m->past))
- return (FC_MATCH_MATCHES);
+ return FC_MATCH_MATCHES;
- return (FC_MATCH_NO_MATCH);
+ return FC_MATCH_NO_MATCH;
} /* }}} int mt_match */
void module_register(void) {
} /* }}} int mt_match */
void module_register(void) {
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("`value' match: `%s' needs exactly one string argument.", ci->key);
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("`value' match: `%s' needs exactly one string argument.", ci->key);
}
if (strcasecmp("All", ci->values[0].value.string) == 0)
}
if (strcasecmp("All", ci->values[0].value.string) == 0)
ERROR("`value' match: Passing `%s' to the `%s' option is invalid. "
"The argument must either be `All' or `Any'.",
ci->values[0].value.string, ci->key);
ERROR("`value' match: Passing `%s' to the `%s' option is invalid. "
"The argument must either be `All' or `Any'.",
ci->values[0].value.string, ci->key);
} /* }}} int mv_config_add_satisfy */
static int mv_config_add_data_source(mv_match_t *m, /* {{{ */
} /* }}} int mv_config_add_satisfy */
static int mv_config_add_data_source(mv_match_t *m, /* {{{ */
/* Check number of arbuments. */
if (ci->values_num < 1) {
ERROR("`value' match: `%s' needs at least one argument.", ci->key);
/* Check number of arbuments. */
if (ci->values_num < 1) {
ERROR("`value' match: `%s' needs at least one argument.", ci->key);
}
/* Check type of arguments */
}
/* Check type of arguments */
ci->key, i + 1,
(ci->values[i].type == OCONFIG_TYPE_BOOLEAN) ? "truth value"
: "number");
ci->key, i + 1,
(ci->values[i].type == OCONFIG_TYPE_BOOLEAN) ? "truth value"
: "number");
}
/* Allocate space for the char pointers */
}
/* Allocate space for the char pointers */
temp = realloc(m->data_sources, new_data_sources_num * sizeof(char *));
if (temp == NULL) {
ERROR("`value' match: realloc failed.");
temp = realloc(m->data_sources, new_data_sources_num * sizeof(char *));
if (temp == NULL) {
ERROR("`value' match: realloc failed.");
}
m->data_sources = temp;
}
m->data_sources = temp;
} /* }}} int mv_config_add_data_source */
static int mv_config_add_gauge(gauge_t *ret_value, /* {{{ */
} /* }}} int mv_config_add_data_source */
static int mv_config_add_gauge(gauge_t *ret_value, /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("`value' match: `%s' needs exactly one numeric argument.", ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
ERROR("`value' match: `%s' needs exactly one numeric argument.", ci->key);
}
*ret_value = ci->values[0].value.number;
}
*ret_value = ci->values[0].value.number;
} /* }}} int mv_config_add_gauge */
static int mv_config_add_boolean(int *ret_value, /* {{{ */
} /* }}} int mv_config_add_gauge */
static int mv_config_add_boolean(int *ret_value, /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
ERROR("`value' match: `%s' needs exactly one boolean argument.", ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
ERROR("`value' match: `%s' needs exactly one boolean argument.", ci->key);
}
if (ci->values[0].value.boolean)
}
if (ci->values[0].value.boolean)
} /* }}} int mv_config_add_boolean */
static int mv_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
} /* }}} int mv_config_add_boolean */
static int mv_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("mv_create: calloc failed.");
m = calloc(1, sizeof(*m));
if (m == NULL) {
ERROR("mv_create: calloc failed.");
if (status != 0) {
mv_free_match(m);
if (status != 0) {
mv_free_match(m);
} /* }}} int mv_create */
static int mv_destroy(void **user_data) /* {{{ */
{
if ((user_data != NULL) && (*user_data != NULL))
mv_free_match(*user_data);
} /* }}} int mv_create */
static int mv_destroy(void **user_data) /* {{{ */
{
if ((user_data != NULL) && (*user_data != NULL))
mv_free_match(*user_data);
} /* }}} int mv_destroy */
static int mv_match(const data_set_t *ds, const value_list_t *vl, /* {{{ */
} /* }}} int mv_destroy */
static int mv_match(const data_set_t *ds, const value_list_t *vl, /* {{{ */
int status;
if ((user_data == NULL) || (*user_data == NULL))
int status;
if ((user_data == NULL) || (*user_data == NULL))
if (values == NULL) {
ERROR("`value' match: Retrieving the current rate from the cache "
"failed.");
if (values == NULL) {
ERROR("`value' match: Retrieving the current rate from the cache "
"failed.");
}
status = FC_MATCH_NO_MATCH;
}
status = FC_MATCH_NO_MATCH;
} /* for (i = 0; i < ds->ds_num; i++) */
free(values);
} /* for (i = 0; i < ds->ds_num; i++) */
free(values);
} /* }}} int mv_match */
void module_register(void) {
} /* }}} int mv_match */
void module_register(void) {
ERROR("mbmon: getaddrinfo (%s, %s): %s", host, port,
(ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(ai_return));
ERROR("mbmon: getaddrinfo (%s, %s): %s", host, port,
(ai_return == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(ai_return));
if (fd < 0) {
ERROR("mbmon: Could not connect to daemon.");
if (fd < 0) {
ERROR("mbmon: Could not connect to daemon.");
}
/* receive data from the mbmon daemon */
}
/* receive data from the mbmon daemon */
ERROR("mbmon: Error reading from socket: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
ERROR("mbmon: Error reading from socket: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
"Buffer: `%s'",
buffer);
close(fd);
"Buffer: `%s'",
buffer);
close(fd);
}
static int mbmon_config(const char *key, const char *value) {
}
static int mbmon_config(const char *key, const char *value) {
free(mbmon_port);
mbmon_port = strdup(value);
} else {
free(mbmon_port);
mbmon_port = strdup(value);
} else {
}
static void mbmon_submit(const char *type, const char *type_instance,
}
static void mbmon_submit(const char *type, const char *type_instance,
/* get data from daemon */
if (mbmon_query_daemon(buf, sizeof(buf)) < 0)
/* get data from daemon */
if (mbmon_query_daemon(buf, sizeof(buf)) < 0)
s = buf;
while ((t = strchr(s, ':')) != NULL) {
s = buf;
while ((t = strchr(s, ':')) != NULL) {
} /* void mbmon_read */
/* module_register
} /* void mbmon_read */
/* module_register
0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
} else if (strcasecmp("McelogLogfile", child->key) == 0) {
if (cf_util_get_string_buffer(child, g_mcelog_config.logfile,
sizeof(g_mcelog_config.logfile)) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
} else if (strcasecmp("McelogLogfile", child->key) == 0) {
if (cf_util_get_string_buffer(child, g_mcelog_config.logfile,
sizeof(g_mcelog_config.logfile)) < 0) {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
} else {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
} else {
ERROR(MCELOG_PLUGIN ": Invalid configuration option: \"%s\".",
child->key);
}
static int socket_close(socket_adapter_t *self) {
}
static int socket_close(socket_adapter_t *self) {
}
}
pthread_rwlock_unlock(&self->lock);
}
}
pthread_rwlock_unlock(&self->lock);
}
static int socket_write(socket_adapter_t *self, const char *msg,
}
static int socket_write(socket_adapter_t *self, const char *msg,
if (swrite(self->sock_fd, msg, len) < 0)
ret = -1;
pthread_rwlock_unlock(&self->lock);
if (swrite(self->sock_fd, msg, len) < 0)
ret = -1;
pthread_rwlock_unlock(&self->lock);
}
static void mcelog_dispatch_notification(notification_t *n) {
}
static void mcelog_dispatch_notification(notification_t *n) {
ERROR(MCELOG_PLUGIN ": Could not create a socket. %s",
sstrerror(errno, errbuff, sizeof(errbuff)));
pthread_rwlock_unlock(&self->lock);
ERROR(MCELOG_PLUGIN ": Could not create a socket. %s",
sstrerror(errno, errbuff, sizeof(errbuff)));
pthread_rwlock_unlock(&self->lock);
}
/* Set socket timeout option */
}
/* Set socket timeout option */
.type_instance = "mcelog_status"});
}
pthread_rwlock_unlock(&self->lock);
.type_instance = "mcelog_status"});
}
pthread_rwlock_unlock(&self->lock);
}
static int mcelog_prepare_notification(notification_t *n,
const mcelog_memory_rec_t *mr) {
if (n == NULL || mr == NULL)
}
static int mcelog_prepare_notification(notification_t *n,
const mcelog_memory_rec_t *mr) {
if (n == NULL || mr == NULL)
if ((mr->location[0] != '\0') &&
(plugin_notification_meta_add_string(n, MCELOG_SOCKET_STR, mr->location) <
0)) {
ERROR(MCELOG_PLUGIN ": add memory location meta data failed");
if ((mr->location[0] != '\0') &&
(plugin_notification_meta_add_string(n, MCELOG_SOCKET_STR, mr->location) <
0)) {
ERROR(MCELOG_PLUGIN ": add memory location meta data failed");
}
if ((mr->dimm_name[0] != '\0') &&
(plugin_notification_meta_add_string(n, MCELOG_DIMM_NAME, mr->dimm_name) <
0)) {
ERROR(MCELOG_PLUGIN ": add DIMM name meta data failed");
plugin_notification_meta_free(n->meta);
}
if ((mr->dimm_name[0] != '\0') &&
(plugin_notification_meta_add_string(n, MCELOG_DIMM_NAME, mr->dimm_name) <
0)) {
ERROR(MCELOG_PLUGIN ": add DIMM name meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(n, MCELOG_CORRECTED_ERR,
mr->corrected_err_total) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(n, MCELOG_CORRECTED_ERR,
mr->corrected_err_total) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(
n, "corrected memory timed errors", mr->corrected_err_timed) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected timed errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(
n, "corrected memory timed errors", mr->corrected_err_timed) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected timed errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if ((mr->corrected_err_timed_period[0] != '\0') &&
(plugin_notification_meta_add_string(n, "corrected errors time period",
}
if ((mr->corrected_err_timed_period[0] != '\0') &&
(plugin_notification_meta_add_string(n, "corrected errors time period",
0)) {
ERROR(MCELOG_PLUGIN ": add corrected errors period meta data failed");
plugin_notification_meta_free(n->meta);
0)) {
ERROR(MCELOG_PLUGIN ": add corrected errors period meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(n, MCELOG_UNCORRECTED_ERR,
mr->uncorrected_err_total) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(n, MCELOG_UNCORRECTED_ERR,
mr->uncorrected_err_total) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(n,
"uncorrected memory timed errors",
mr->uncorrected_err_timed) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected timed errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if (plugin_notification_meta_add_signed_int(n,
"uncorrected memory timed errors",
mr->uncorrected_err_timed) < 0) {
ERROR(MCELOG_PLUGIN ": add corrected timed errors meta data failed");
plugin_notification_meta_free(n->meta);
}
if ((mr->uncorrected_err_timed_period[0] != '\0') &&
(plugin_notification_meta_add_string(n, "uncorrected errors time period",
}
if ((mr->uncorrected_err_timed_period[0] != '\0') &&
(plugin_notification_meta_add_string(n, "uncorrected errors time period",
0)) {
ERROR(MCELOG_PLUGIN ": add corrected errors period meta data failed");
plugin_notification_meta_free(n->meta);
0)) {
ERROR(MCELOG_PLUGIN ": add corrected errors period meta data failed");
plugin_notification_meta_free(n->meta);
}
static int mcelog_submit(const mcelog_memory_rec_t *mr) {
if (!mr) {
ERROR(MCELOG_PLUGIN ": %s: NULL pointer", __FUNCTION__);
}
static int mcelog_submit(const mcelog_memory_rec_t *mr) {
if (!mr) {
ERROR(MCELOG_PLUGIN ": %s: NULL pointer", __FUNCTION__);
vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_timed};
plugin_dispatch_values(&vl);
vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_timed};
plugin_dispatch_values(&vl);
}
static int parse_memory_info(FILE *p_file, mcelog_memory_rec_t *memory_record) {
}
static int parse_memory_info(FILE *p_file, mcelog_memory_rec_t *memory_record) {
/* Got empty line or "done" */
if ((!strncmp("\n", buf, strlen(buf))) ||
(!strncmp(buf, "done\n", strlen(buf))))
/* Got empty line or "done" */
if ((!strncmp("\n", buf, strlen(buf))) ||
(!strncmp(buf, "done\n", strlen(buf))))
if (strlen(buf) < 5)
continue;
if (!strncmp(buf, MCELOG_SOCKET_STR, strlen(MCELOG_SOCKET_STR))) {
if (strlen(buf) < 5)
continue;
if (!strncmp(buf, MCELOG_SOCKET_STR, strlen(MCELOG_SOCKET_STR))) {
memset(buf, 0, sizeof(buf));
}
/* parsing definitely finished */
memset(buf, 0, sizeof(buf));
}
/* parsing definitely finished */
}
static void poll_worker_cleanup(void *arg) {
}
static void poll_worker_cleanup(void *arg) {
sstrerror(errno, errbuf, sizeof(errbuf)));
}
pthread_rwlock_unlock(&self->lock);
sstrerror(errno, errbuf, sizeof(errbuf)));
}
pthread_rwlock_unlock(&self->lock);
}
if (poll_fd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
}
if (poll_fd.revents & (POLLERR | POLLHUP | POLLNVAL)) {
.type_instance = "mcelog_status"});
}
pthread_rwlock_unlock(&self->lock);
.type_instance = "mcelog_status"});
}
pthread_rwlock_unlock(&self->lock);
}
if (!(poll_fd.revents & (POLLIN | POLLPRI))) {
INFO(MCELOG_PLUGIN ": No data to read");
pthread_rwlock_unlock(&self->lock);
}
if (!(poll_fd.revents & (POLLIN | POLLPRI))) {
INFO(MCELOG_PLUGIN ": No data to read");
pthread_rwlock_unlock(&self->lock);
}
if ((*pp_file = fdopen(dup(self->sock_fd), "r")) == NULL)
res = -1;
pthread_rwlock_unlock(&self->lock);
}
if ((*pp_file = fdopen(dup(self->sock_fd), "r")) == NULL)
res = -1;
pthread_rwlock_unlock(&self->lock);
}
static void *poll_worker(__attribute__((unused)) void *arg) {
}
static void *poll_worker(__attribute__((unused)) void *arg) {
mcelog_thread_running = 0;
pthread_cleanup_pop(1);
mcelog_thread_running = 0;
pthread_cleanup_pop(1);
}
static int mcelog_init(void) {
if (socket_adapter.reinit(&socket_adapter) != 0) {
ERROR(MCELOG_PLUGIN ": Cannot connect to client socket");
}
static int mcelog_init(void) {
if (socket_adapter.reinit(&socket_adapter) != 0) {
ERROR(MCELOG_PLUGIN ": Cannot connect to client socket");
}
if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
NULL) != 0) {
ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
}
if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
NULL) != 0) {
ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
}
static int get_memory_machine_checks(void) {
}
static int get_memory_machine_checks(void) {
ERROR(MCELOG_PLUGIN ": SENT DUMP REQUEST FAILED");
else
DEBUG(MCELOG_PLUGIN ": SENT DUMP REQUEST OK");
ERROR(MCELOG_PLUGIN ": SENT DUMP REQUEST FAILED");
else
DEBUG(MCELOG_PLUGIN ": SENT DUMP REQUEST OK");
}
static int mcelog_read(__attribute__((unused)) user_data_t *ud) {
}
static int mcelog_read(__attribute__((unused)) user_data_t *ud) {
if (get_memory_machine_checks() != 0)
ERROR(MCELOG_PLUGIN ": MACHINE CHECK INFO NOT AVAILABLE");
if (get_memory_machine_checks() != 0)
ERROR(MCELOG_PLUGIN ": MACHINE CHECK INFO NOT AVAILABLE");
}
static int mcelog_shutdown(void) {
}
static int mcelog_shutdown(void) {
ret = socket_adapter.close(&socket_adapter) || ret;
pthread_rwlock_destroy(&(socket_adapter.lock));
ret = socket_adapter.close(&socket_adapter) || ret;
pthread_rwlock_destroy(&(socket_adapter.lock));
}
void module_register(void) {
}
void module_register(void) {
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
if (strcasecmp(key, "Device") == 0) {
ignorelist_add(ignorelist, value);
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
ignorelist_set_invert(ignorelist, IS_TRUE(value) ? 0 : 1);
} else {
if (strcasecmp(key, "Device") == 0) {
ignorelist_add(ignorelist, value);
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
ignorelist_set_invert(ignorelist, IS_TRUE(value) ? 0 : 1);
} else {
}
static void md_submit(const int minor, const char *type_instance,
}
static void md_submit(const int minor, const char *type_instance,
char errbuf[1024];
WARNING("md: Unable to open %s: %s", PROC_DISKSTATS,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("md: Unable to open %s: %s", PROC_DISKSTATS,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* Iterate md devices */
}
/* Iterate md devices */
} /* int md_read */
void module_register(void) {
} /* int md_read */
void module_register(void) {
wp->memc = memcached_create(NULL);
if (wp->memc == NULL) {
ERROR("memcachec plugin: memcached_create failed.");
wp->memc = memcached_create(NULL);
if (wp->memc == NULL) {
ERROR("memcachec plugin: memcached_create failed.");
}
server = memcached_servers_parse(wp->server);
memcached_server_push(wp->memc, server);
memcached_server_list_free(server);
}
server = memcached_servers_parse(wp->server);
memcached_server_push(wp->memc, server);
memcached_server_list_free(server);
} /* }}} int cmc_page_init_memc */
static int cmc_config_add_string(const char *name, char **dest, /* {{{ */
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("memcachec plugin: `%s' needs exactly one string argument.", name);
} /* }}} int cmc_page_init_memc */
static int cmc_config_add_string(const char *name, char **dest, /* {{{ */
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("memcachec plugin: `%s' needs exactly one string argument.", name);
}
sfree(*dest);
*dest = strdup(ci->values[0].value.string);
if (*dest == NULL)
}
sfree(*dest);
*dest = strdup(ci->values[0].value.string);
if (*dest == NULL)
} /* }}} int cmc_config_add_string */
static int cmc_config_add_match_dstype(int *dstype_ret, /* {{{ */
} /* }}} int cmc_config_add_string */
static int cmc_config_add_match_dstype(int *dstype_ret, /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("memcachec plugin: `DSType' needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("memcachec plugin: `DSType' needs exactly one string argument.");
}
if (strncasecmp("Gauge", ci->values[0].value.string, strlen("Gauge")) == 0) {
}
if (strncasecmp("Gauge", ci->values[0].value.string, strlen("Gauge")) == 0) {
if (dstype == 0) {
WARNING("memcachec plugin: `%s' is not a valid argument to `DSType'.",
ci->values[0].value.string);
if (dstype == 0) {
WARNING("memcachec plugin: `%s' is not a valid argument to `DSType'.",
ci->values[0].value.string);
} /* }}} int cmc_config_add_match_dstype */
static int cmc_config_add_match(web_page_t *page, /* {{{ */
} /* }}} int cmc_config_add_match_dstype */
static int cmc_config_add_match(web_page_t *page, /* {{{ */
match = calloc(1, sizeof(*match));
if (match == NULL) {
ERROR("memcachec plugin: calloc failed.");
match = calloc(1, sizeof(*match));
if (match == NULL) {
ERROR("memcachec plugin: calloc failed.");
if (status != 0) {
cmc_web_match_free(match);
if (status != 0) {
cmc_web_match_free(match);
if (match->match == NULL) {
ERROR("memcachec plugin: match_create_simple failed.");
cmc_web_match_free(match);
if (match->match == NULL) {
ERROR("memcachec plugin: match_create_simple failed.");
cmc_web_match_free(match);
} else {
web_match_t *prev;
} else {
web_match_t *prev;
} /* }}} int cmc_config_add_match */
static int cmc_config_add_page(oconfig_item_t *ci) /* {{{ */
} /* }}} int cmc_config_add_match */
static int cmc_config_add_page(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING(
"memcachec plugin: `Page' blocks need exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING(
"memcachec plugin: `Page' blocks need exactly one string argument.");
}
page = calloc(1, sizeof(*page));
if (page == NULL) {
ERROR("memcachec plugin: calloc failed.");
}
page = calloc(1, sizeof(*page));
if (page == NULL) {
ERROR("memcachec plugin: calloc failed.");
}
page->server = NULL;
page->key = NULL;
}
page->server = NULL;
page->key = NULL;
if (page->instance == NULL) {
ERROR("memcachec plugin: strdup failed.");
sfree(page);
if (page->instance == NULL) {
ERROR("memcachec plugin: strdup failed.");
sfree(page);
}
/* Process all children */
}
/* Process all children */
if (status != 0) {
cmc_web_page_free(page);
if (status != 0) {
cmc_web_page_free(page);
}
/* Add the new page to the linked list */
}
/* Add the new page to the linked list */
} /* }}} int cmc_config_add_page */
static int cmc_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int cmc_config_add_page */
static int cmc_config(oconfig_item_t *ci) /* {{{ */
if ((success == 0) && (errors > 0)) {
ERROR("memcachec plugin: All statements failed.");
if ((success == 0) && (errors > 0)) {
ERROR("memcachec plugin: All statements failed.");
} /* }}} int cmc_config */
static int cmc_init(void) /* {{{ */
{
if (pages_g == NULL) {
INFO("memcachec plugin: No pages have been defined.");
} /* }}} int cmc_config */
static int cmc_init(void) /* {{{ */
{
if (pages_g == NULL) {
INFO("memcachec plugin: No pages have been defined.");
} /* }}} int cmc_init */
static void cmc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */
} /* }}} int cmc_init */
static void cmc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */
int status;
if (wp->memc == NULL)
int status;
if (wp->memc == NULL)
wp->buffer = memcached_get(wp->memc, wp->key, strlen(wp->key), &string_length,
&flags, &rc);
if (rc != MEMCACHED_SUCCESS) {
ERROR("memcachec plugin: memcached_get failed: %s",
memcached_strerror(wp->memc, rc));
wp->buffer = memcached_get(wp->memc, wp->key, strlen(wp->key), &string_length,
&flags, &rc);
if (rc != MEMCACHED_SUCCESS) {
ERROR("memcachec plugin: memcached_get failed: %s",
memcached_strerror(wp->memc, rc));
}
for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next) {
}
for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next) {
} /* }}} int cmc_read_page */
static int cmc_read(void) /* {{{ */
} /* }}} int cmc_read_page */
static int cmc_read(void) /* {{{ */
for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next)
cmc_read_page(wp);
for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next)
cmc_read_page(wp);
} /* }}} int cmc_read */
static int cmc_shutdown(void) /* {{{ */
} /* }}} int cmc_read */
static int cmc_shutdown(void) /* {{{ */
cmc_web_page_free(pages_g);
pages_g = NULL;
cmc_web_page_free(pages_g);
pages_g = NULL;
} /* }}} int cmc_shutdown */
void module_register(void) {
} /* }}} int cmc_shutdown */
void module_register(void) {
char errbuf[1024];
ERROR("memcached plugin: memcached_connect_unix: socket(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("memcached plugin: memcached_connect_unix: socket(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* connect to the memcached daemon */
}
/* connect to the memcached daemon */
} /* int memcached_connect_unix */
static int memcached_connect_inet(memcached_t *st) {
} /* int memcached_connect_unix */
static int memcached_connect_inet(memcached_t *st) {
st->connhost, st->connport,
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
st->connhost, st->connport,
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
} /* int memcached_connect_inet */
static int memcached_connect(memcached_t *st) {
if (st->socket != NULL)
} /* int memcached_connect_inet */
static int memcached_connect(memcached_t *st) {
if (st->socket != NULL)
- return (memcached_connect_unix(st));
+ return memcached_connect_unix(st);
- return (memcached_connect_inet(st));
+ return memcached_connect_inet(st);
}
static int memcached_query_daemon(char *buffer, size_t buffer_size,
}
static int memcached_query_daemon(char *buffer, size_t buffer_size,
sstrerror(errno, errbuf, sizeof(errbuf)));
shutdown(fd, SHUT_RDWR);
close(fd);
sstrerror(errno, errbuf, sizeof(errbuf)));
shutdown(fd, SHUT_RDWR);
close(fd);
}
/* receive data from the memcached daemon */
}
/* receive data from the memcached daemon */
sstrerror(errno, errbuf, sizeof(errbuf)));
shutdown(fd, SHUT_RDWR);
close(fd);
sstrerror(errno, errbuf, sizeof(errbuf)));
shutdown(fd, SHUT_RDWR);
close(fd);
}
buffer_fill += (size_t)status;
}
buffer_fill += (size_t)status;
shutdown(fd, SHUT_RDWR);
close(fd);
shutdown(fd, SHUT_RDWR);
close(fd);
} /* int memcached_query_daemon */
static void memcached_init_vl(value_list_t *vl, memcached_t const *st) {
} /* int memcached_query_daemon */
static void memcached_init_vl(value_list_t *vl, memcached_t const *st) {
if (st->host) {
st->connhost = strdup(st->host);
if (st->connhost == NULL)
if (st->host) {
st->connhost = strdup(st->host);
if (st->connhost == NULL)
if ((strcmp("127.0.0.1", st->host) == 0) ||
(strcmp("localhost", st->host) == 0))
if ((strcmp("127.0.0.1", st->host) == 0) ||
(strcmp("localhost", st->host) == 0))
} else {
st->connhost = strdup(MEMCACHED_DEF_HOST);
if (st->connhost == NULL)
} else {
st->connhost = strdup(MEMCACHED_DEF_HOST);
if (st->connhost == NULL)
}
}
if (st->connport == NULL) {
st->connport = strdup(MEMCACHED_DEF_PORT);
if (st->connport == NULL)
}
}
if (st->connport == NULL) {
st->connport = strdup(MEMCACHED_DEF_PORT);
if (st->connport == NULL)
}
assert(st->connhost != NULL);
}
assert(st->connhost != NULL);
.data = st, .free_func = memcached_free,
});
.data = st, .free_func = memcached_free,
});
} /* int memcached_add_read_callback */
/* Configuration handling functiions
} /* int memcached_add_read_callback */
/* Configuration handling functiions
st = calloc(1, sizeof(*st));
if (st == NULL) {
ERROR("memcached plugin: calloc failed.");
st = calloc(1, sizeof(*st));
if (st == NULL) {
ERROR("memcached plugin: calloc failed.");
if (status != 0) {
sfree(st);
if (status != 0) {
sfree(st);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
if (status != 0) {
memcached_free(st);
if (status != 0) {
memcached_free(st);
}
static int memcached_config(oconfig_item_t *ci) {
}
static int memcached_config(oconfig_item_t *ci) {
} else if (!have_instance_block) {
/* Non-instance option: Assume legacy configuration (without <Instance />
* blocks) and call config_add_instance() with the <Plugin /> block. */
} else if (!have_instance_block) {
/* Non-instance option: Assume legacy configuration (without <Instance />
* blocks) and call config_add_instance() with the <Plugin /> block. */
- return (config_add_instance(ci));
+ return config_add_instance(ci);
} else
WARNING("memcached plugin: The configuration option "
"\"%s\" is not allowed here. Did you "
} else
WARNING("memcached plugin: The configuration option "
"\"%s\" is not allowed here. Did you "
child->key);
} /* for (ci->children) */
child->key);
} /* for (ci->children) */
}
static int memcached_init(void) {
}
static int memcached_init(void) {
int status;
if (memcached_have_instances)
int status;
if (memcached_have_instances)
/* No instances were configured, lets start a default instance. */
st = calloc(1, sizeof(*st));
if (st == NULL)
/* No instances were configured, lets start a default instance. */
st = calloc(1, sizeof(*st));
if (st == NULL)
st->name = NULL;
st->host = NULL;
st->socket = NULL;
st->name = NULL;
st->host = NULL;
st->socket = NULL;
} /* int memcached_init */
void module_register(void) {
} /* int memcached_init */
void module_register(void) {
} /* }}} int memory_config */
static int memory_init(void) {
} /* }}} int memory_config */
static int memory_init(void) {
pagesize = getpagesize();
if (get_kstat(&ksp, "unix", 0, "system_pages") != 0) {
ksp = NULL;
pagesize = getpagesize();
if (get_kstat(&ksp, "unix", 0, "system_pages") != 0) {
ksp = NULL;
}
if (get_kstat(&ksz, "zfs", 0, "arcstats") != 0) {
ksz = NULL;
}
if (get_kstat(&ksz, "zfs", 0, "arcstats") != 0) {
ksz = NULL;
}
/* #endif HAVE_LIBKSTAT */
}
/* #endif HAVE_LIBKSTAT */
pagesize = getpagesize();
if (pagesize <= 0) {
ERROR("memory plugin: Invalid pagesize: %i", pagesize);
pagesize = getpagesize();
if (pagesize <= 0) {
ERROR("memory plugin: Invalid pagesize: %i", pagesize);
}
/* #endif HAVE_SYSCTL */
}
/* #endif HAVE_SYSCTL */
#elif HAVE_PERFSTAT
pagesize = getpagesize();
#endif /* HAVE_PERFSTAT */
#elif HAVE_PERFSTAT
pagesize = getpagesize();
#endif /* HAVE_PERFSTAT */
} /* int memory_init */
#define MEMORY_SUBMIT(...) \
} /* int memory_init */
#define MEMORY_SUBMIT(...) \
gauge_t free;
if (!port_host || !pagesize)
gauge_t free;
if (!port_host || !pagesize)
vm_data_len = sizeof(vm_data) / sizeof(natural_t);
if ((status = host_statistics(port_host, HOST_VM_INFO, (host_info_t)&vm_data,
&vm_data_len)) != KERN_SUCCESS) {
ERROR("memory-plugin: host_statistics failed and returned the value %i",
(int)status);
vm_data_len = sizeof(vm_data) / sizeof(natural_t);
if ((status = host_statistics(port_host, HOST_VM_INFO, (host_info_t)&vm_data,
&vm_data_len)) != KERN_SUCCESS) {
ERROR("memory-plugin: host_statistics failed and returned the value %i",
(int)status);
if ((fh = fopen("/proc/meminfo", "r")) == NULL) {
char errbuf[1024];
WARNING("memory: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if ((fh = fopen("/proc/meminfo", "r")) == NULL) {
char errbuf[1024];
WARNING("memory: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
if (mem_total < (mem_free + mem_buffered + mem_cached + mem_slab_total))
}
if (mem_total < (mem_free + mem_buffered + mem_cached + mem_slab_total))
mem_used =
mem_total - (mem_free + mem_buffered + mem_cached + mem_slab_total);
mem_used =
mem_total - (mem_free + mem_buffered + mem_cached + mem_slab_total);
long long availrmem;
if (ksp == NULL)
long long availrmem;
if (ksp == NULL)
mem_used = get_kstat_value(ksp, "pagestotal");
mem_free = get_kstat_value(ksp, "pagesfree");
mem_used = get_kstat_value(ksp, "pagestotal");
mem_free = get_kstat_value(ksp, "pagesfree");
if ((mem_used < 0LL) || (mem_free < 0LL) || (mem_lock < 0LL)) {
WARNING("memory plugin: one of used, free or locked is negative.");
if ((mem_used < 0LL) || (mem_free < 0LL) || (mem_lock < 0LL)) {
WARNING("memory plugin: one of used, free or locked is negative.");
}
mem_unus = physmem - mem_used;
}
mem_unus = physmem - mem_used;
char errbuf[1024];
WARNING("memory plugin: sysctl failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("memory plugin: sysctl failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
ios = sg_get_mem_stats();
if (ios == NULL)
ios = sg_get_mem_stats();
if (ios == NULL)
MEMORY_SUBMIT("used", (gauge_t)ios->used, "cached", (gauge_t)ios->cache,
"free", (gauge_t)ios->free);
MEMORY_SUBMIT("used", (gauge_t)ios->used, "cached", (gauge_t)ios->cache,
"free", (gauge_t)ios->free);
char errbuf[1024];
WARNING("memory plugin: perfstat_memory_total failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("memory plugin: perfstat_memory_total failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* Unfortunately, the AIX documentation is not very clear on how these
}
/* Unfortunately, the AIX documentation is not very clear on how these
(gauge_t)(pmemory.real_process * pagesize));
#endif /* HAVE_PERFSTAT */
(gauge_t)(pmemory.real_process * pagesize));
#endif /* HAVE_PERFSTAT */
} /* }}} int memory_read_internal */
static int memory_read(void) /* {{{ */
} /* }}} int memory_read_internal */
static int memory_read(void) /* {{{ */
sstrncpy(vl.type, "memory", sizeof(vl.type));
vl.time = cdtime();
sstrncpy(vl.type, "memory", sizeof(vl.type));
vl.time = cdtime();
- return (memory_read_internal(&vl));
+ return memory_read_internal(&vl);
} /* }}} int memory_read */
void module_register(void) {
} /* }}} int memory_read */
void module_register(void) {
U32 mic_count;
if (mic_handle)
U32 mic_count;
if (mic_handle)
mic_count = (U32)STATIC_ARRAY_SIZE(mics);
ret = MicInitAPI(&mic_handle, eTARGET_SCIF_DRIVER, mics, &mic_count);
mic_count = (U32)STATIC_ARRAY_SIZE(mics);
ret = MicInitAPI(&mic_handle, eTARGET_SCIF_DRIVER, mics, &mic_count);
if (mic_count < 0 || mic_count >= MAX_MICS) {
ERROR("mic plugin: No Intel MICs in system");
if (mic_count < 0 || mic_count >= MAX_MICS) {
ERROR("mic plugin: No Intel MICs in system");
} else {
num_mics = mic_count;
} else {
num_mics = mic_count;
if (power_ignore == NULL)
power_ignore = ignorelist_create(1);
if (temp_ignore == NULL || power_ignore == NULL)
if (power_ignore == NULL)
power_ignore = ignorelist_create(1);
if (temp_ignore == NULL || power_ignore == NULL)
if (strcasecmp("ShowCPU", key) == 0) {
show_cpu = IS_TRUE(value);
if (strcasecmp("ShowCPU", key) == 0) {
show_cpu = IS_TRUE(value);
invert = 0;
ignorelist_set_invert(power_ignore, invert);
} else {
invert = 0;
ignorelist_set_invert(power_ignore, invert);
} else {
}
static void mic_submit_memory_use(int micnumber, const char *type_instance,
}
static void mic_submit_memory_use(int micnumber, const char *type_instance,
if (ret != MIC_ACCESS_API_SUCCESS) {
ERROR("mic plugin: Problem getting Memory Utilization: %s",
MicGetErrorString(ret));
if (ret != MIC_ACCESS_API_SUCCESS) {
ERROR("mic plugin: Problem getting Memory Utilization: %s",
MicGetErrorString(ret));
}
mic_submit_memory_use(mic, "free", mem_free);
mic_submit_memory_use(mic, "used", mem_total - mem_free - mem_bufs);
mic_submit_memory_use(mic, "buffered", mem_bufs);
DEBUG("mic plugin: Memory Read: %u %u %u", mem_total, mem_free, mem_bufs);
}
mic_submit_memory_use(mic, "free", mem_free);
mic_submit_memory_use(mic, "used", mem_total - mem_free - mem_bufs);
mic_submit_memory_use(mic, "buffered", mem_bufs);
DEBUG("mic plugin: Memory Read: %u %u %u", mem_total, mem_free, mem_bufs);
}
static void mic_submit_temp(int micnumber, const char *type, gauge_t value) {
}
static void mic_submit_temp(int micnumber, const char *type, gauge_t value) {
ERROR("mic plugin: Error reading temperature \"%s\": "
"%s",
name, MicGetErrorString(status));
ERROR("mic plugin: Error reading temperature \"%s\": "
"%s",
name, MicGetErrorString(status));
}
mic_submit_temp(mic, name, temp_buffer);
}
}
mic_submit_temp(mic, name, temp_buffer);
}
}
static void mic_submit_cpu(int micnumber, const char *type_instance, int core,
}
static void mic_submit_cpu(int micnumber, const char *type_instance, int core,
if (status != MIC_ACCESS_API_SUCCESS) {
ERROR("mic plugin: Problem getting CPU utilization: %s",
MicGetErrorString(status));
if (status != MIC_ACCESS_API_SUCCESS) {
ERROR("mic plugin: Problem getting CPU utilization: %s",
MicGetErrorString(status));
mic_submit_cpu(mic, "idle", j, core_jiffs[j].idle);
}
}
mic_submit_cpu(mic, "idle", j, core_jiffs[j].idle);
}
}
}
static void mic_submit_power(int micnumber, const char *type,
}
static void mic_submit_power(int micnumber, const char *type,
if (ret != MIC_ACCESS_API_SUCCESS) {
ERROR("mic plugin: Problem getting Power Usage: %s",
MicGetErrorString(ret));
if (ret != MIC_ACCESS_API_SUCCESS) {
ERROR("mic plugin: Problem getting Power Usage: %s",
MicGetErrorString(ret));
}
/* power is in uWatts, current in mA, voltage in uVolts.. convert to
}
/* power is in uWatts, current in mA, voltage in uVolts.. convert to
SUB_VOLTS(vddg);
SUB_VOLTS(vddq);
SUB_VOLTS(vddg);
SUB_VOLTS(vddq);
}
static int mic_read(void) {
}
static int mic_read(void) {
MicCloseAPI(&mic_handle);
mic_handle = NULL;
MicCloseAPI(&mic_handle);
mic_handle = NULL;
}
void module_register(void) {
}
void module_register(void) {
static mb_data_t *data_get_by_name(mb_data_t *src, /* {{{ */
const char *name) {
if (name == NULL)
static mb_data_t *data_get_by_name(mb_data_t *src, /* {{{ */
const char *name) {
if (name == NULL)
for (mb_data_t *ptr = src; ptr != NULL; ptr = ptr->next)
if (strcasecmp(ptr->name, name) == 0)
for (mb_data_t *ptr = src; ptr != NULL; ptr = ptr->next)
if (strcasecmp(ptr->name, name) == 0)
} /* }}} mb_data_t *data_get_by_name */
static int data_append(mb_data_t **dst, mb_data_t *src) /* {{{ */
} /* }}} mb_data_t *data_get_by_name */
static int data_append(mb_data_t **dst, mb_data_t *src) /* {{{ */
mb_data_t *ptr;
if ((dst == NULL) || (src == NULL))
mb_data_t *ptr;
if ((dst == NULL) || (src == NULL))
ptr = *dst;
if (ptr == NULL) {
*dst = src;
ptr = *dst;
if (ptr == NULL) {
*dst = src;
}
while (ptr->next != NULL)
}
while (ptr->next != NULL)
} /* }}} int data_append */
/* Copy a single mb_data_t and append it to another list. */
} /* }}} int data_append */
/* Copy a single mb_data_t and append it to another list. */
int status;
if ((dst == NULL) || (src == NULL))
int status;
if ((dst == NULL) || (src == NULL))
tmp = malloc(sizeof(*tmp));
if (tmp == NULL)
tmp = malloc(sizeof(*tmp));
if (tmp == NULL)
memcpy(tmp, src, sizeof(*tmp));
tmp->name = NULL;
tmp->next = NULL;
memcpy(tmp, src, sizeof(*tmp));
tmp->name = NULL;
tmp->next = NULL;
tmp->name = strdup(src->name);
if (tmp->name == NULL) {
sfree(tmp);
tmp->name = strdup(src->name);
if (tmp->name == NULL) {
sfree(tmp);
}
status = data_append(dst, tmp);
if (status != 0) {
sfree(tmp->name);
sfree(tmp);
}
status = data_append(dst, tmp);
if (status != 0) {
sfree(tmp->name);
sfree(tmp);
} /* }}} int data_copy */
/* Lookup a single mb_data_t instance, copy it and append the copy to another
} /* }}} int data_copy */
/* Lookup a single mb_data_t instance, copy it and append the copy to another
mb_data_t *ptr;
if ((dst == NULL) || (src == NULL) || (name == NULL))
mb_data_t *ptr;
if ((dst == NULL) || (src == NULL) || (name == NULL))
ptr = data_get_by_name(src, name);
if (ptr == NULL)
ptr = data_get_by_name(src, name);
if (ptr == NULL)
- return (data_copy(dst, ptr));
+ return data_copy(dst, ptr);
} /* }}} int data_copy_by_name */
/* Read functions */
} /* }}} int data_copy_by_name */
/* Read functions */
value_list_t vl = VALUE_LIST_INIT;
if ((host == NULL) || (slave == NULL) || (data == NULL))
value_list_t vl = VALUE_LIST_INIT;
if ((host == NULL) || (slave == NULL) || (data == NULL))
if (host->interval == 0)
host->interval = plugin_get_interval();
if (host->interval == 0)
host->interval = plugin_get_interval();
sstrncpy(vl.type, data->type, sizeof(vl.type));
sstrncpy(vl.type_instance, data->instance, sizeof(vl.type_instance));
sstrncpy(vl.type, data->type, sizeof(vl.type));
sstrncpy(vl.type_instance, data->instance, sizeof(vl.type_instance));
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
} /* }}} int mb_submit */
static float mb_register_to_float(uint16_t hi, uint16_t lo) /* {{{ */
} /* }}} int mb_submit */
static float mb_register_to_float(uint16_t hi, uint16_t lo) /* {{{ */
conv.b[0] = (hi >> 8) & 0x00ff;
#endif
conv.b[0] = (hi >> 8) & 0x00ff;
#endif
} /* }}} float mb_register_to_float */
#if LEGACY_LIBMODBUS
} /* }}} float mb_register_to_float */
#if LEGACY_LIBMODBUS
int status;
if (host == NULL)
int status;
if (host == NULL)
#if COLLECT_DEBUG
modbus_set_debug(&host->connection, 1);
#if COLLECT_DEBUG
modbus_set_debug(&host->connection, 1);
if (status != 0) {
ERROR("Modbus plugin: modbus_connect (%s, %i) failed with status %i.",
host->node, host->port ? host->port : host->baudrate, status);
if (status != 0) {
ERROR("Modbus plugin: modbus_connect (%s, %i) failed with status %i.",
host->node, host->port ? host->port : host->baudrate, status);
}
host->is_connected = 1;
}
host->is_connected = 1;
} /* }}} int mb_init_connection */
/* #endif LEGACY_LIBMODBUS */
} /* }}} int mb_init_connection */
/* #endif LEGACY_LIBMODBUS */
int status;
if (host == NULL)
int status;
if (host == NULL)
if (host->connection != NULL)
if (host->connection != NULL)
if (host->conntype == MBCONN_TCP) {
if ((host->port < 1) || (host->port > 65535))
if (host->conntype == MBCONN_TCP) {
if ((host->port < 1) || (host->port > 65535))
host->connection = modbus_new_tcp(host->node, host->port);
if (host->connection == NULL) {
ERROR("Modbus plugin: Creating new Modbus/TCP object failed.");
host->connection = modbus_new_tcp(host->node, host->port);
if (host->connection == NULL) {
ERROR("Modbus plugin: Creating new Modbus/TCP object failed.");
}
} else {
DEBUG("Modbus plugin: Trying to connect to \"%s\", baudrate %i.",
}
} else {
DEBUG("Modbus plugin: Trying to connect to \"%s\", baudrate %i.",
host->connection = modbus_new_rtu(host->node, host->baudrate, 'N', 8, 1);
if (host->connection == NULL) {
ERROR("Modbus plugin: Creating new Modbus/RTU object failed.");
host->connection = modbus_new_rtu(host->node, host->baudrate, 'N', 8, 1);
if (host->connection == NULL) {
ERROR("Modbus plugin: Creating new Modbus/RTU object failed.");
host->node, host->port ? host->port : host->baudrate, status);
modbus_free(host->connection);
host->connection = NULL;
host->node, host->port ? host->port : host->baudrate, status);
modbus_free(host->connection);
host->connection = NULL;
} /* }}} int mb_init_connection */
#endif /* !LEGACY_LIBMODBUS */
} /* }}} int mb_init_connection */
#endif /* !LEGACY_LIBMODBUS */
int status = 0;
if ((host == NULL) || (slave == NULL) || (data == NULL))
int status = 0;
if ((host == NULL) || (slave == NULL) || (data == NULL))
ds = plugin_get_ds(data->type);
if (ds == NULL) {
ERROR("Modbus plugin: Type \"%s\" is not defined.", data->type);
ds = plugin_get_ds(data->type);
if (ds == NULL) {
ERROR("Modbus plugin: Type \"%s\" is not defined.", data->type);
}
if (ds->ds_num != 1) {
ERROR("Modbus plugin: The type \"%s\" has %zu data sources. "
"I can only handle data sets with only one data source.",
data->type, ds->ds_num);
}
if (ds->ds_num != 1) {
ERROR("Modbus plugin: The type \"%s\" has %zu data sources. "
"I can only handle data sets with only one data source.",
data->type, ds->ds_num);
}
if ((ds->ds[0].type != DS_TYPE_GAUGE) &&
}
if ((ds->ds[0].type != DS_TYPE_GAUGE) &&
host->node);
host->is_connected = 0;
host->connection = NULL;
host->node);
host->is_connected = 0;
host->connection = NULL;
}
} else if (status != 0) {
#if LEGACY_LIBMODBUS
}
} else if (status != 0) {
#if LEGACY_LIBMODBUS
if (status != 0) {
ERROR("Modbus plugin: modbus_set_slave (%i) failed with status %i.",
slave->id, status);
if (status != 0) {
ERROR("Modbus plugin: modbus_set_slave (%i) failed with status %i.",
slave->id, status);
}
#endif
if (data->modbus_register_type == MREG_INPUT) {
}
#endif
if (data->modbus_register_type == MREG_INPUT) {
modbus_free(host->connection);
#endif
host->connection = NULL;
modbus_free(host->connection);
#endif
host->connection = NULL;
}
DEBUG("Modbus plugin: mb_read_data: Success! "
}
DEBUG("Modbus plugin: mb_read_data: Success! "
mb_submit(host, slave, data, vt);
}
mb_submit(host, slave, data, vt);
}
} /* }}} int mb_read_data */
static int mb_read_slave(mb_host_t *host, mb_slave_t *slave) /* {{{ */
} /* }}} int mb_read_data */
static int mb_read_slave(mb_host_t *host, mb_slave_t *slave) /* {{{ */
int status;
if ((host == NULL) || (slave == NULL))
int status;
if ((host == NULL) || (slave == NULL))
success = 0;
for (mb_data_t *data = slave->collect; data != NULL; data = data->next) {
success = 0;
for (mb_data_t *data = slave->collect; data != NULL; data = data->next) {
} /* }}} int mb_read_slave */
static int mb_read(user_data_t *user_data) /* {{{ */
} /* }}} int mb_read_slave */
static int mb_read(user_data_t *user_data) /* {{{ */
int status;
if ((user_data == NULL) || (user_data->data == NULL))
int status;
if ((user_data == NULL) || (user_data->data == NULL))
} /* }}} int mb_read */
/* Free functions */
} /* }}} int mb_read */
/* Free functions */
status = cf_util_get_string(ci, &data.name);
if (status != 0)
status = cf_util_get_string(ci, &data.name);
if (status != 0)
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
} /* }}} int mb_config_add_data */
static int mb_config_set_host_address(mb_host_t *host, /* {{{ */
} /* }}} int mb_config_add_data */
static int mb_config_set_host_address(mb_host_t *host, /* {{{ */
int status;
if ((host == NULL) || (address == NULL))
int status;
if ((host == NULL) || (address == NULL))
struct addrinfo ai_hints = {
/* XXX: libmodbus can only handle IPv4 addresses. */
struct addrinfo ai_hints = {
/* XXX: libmodbus can only handle IPv4 addresses. */
ERROR("Modbus plugin: getaddrinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
ERROR("Modbus plugin: getaddrinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
} /* }}} int mb_config_set_host_address */
static int mb_config_add_slave(mb_host_t *host, oconfig_item_t *ci) /* {{{ */
} /* }}} int mb_config_set_host_address */
static int mb_config_add_slave(mb_host_t *host, oconfig_item_t *ci) /* {{{ */
int status;
if ((host == NULL) || (ci == NULL))
int status;
if ((host == NULL) || (ci == NULL))
slave = realloc(host->slaves, sizeof(*slave) * (host->slaves_num + 1));
if (slave == NULL)
slave = realloc(host->slaves, sizeof(*slave) * (host->slaves_num + 1));
if (slave == NULL)
host->slaves = slave;
slave = host->slaves + host->slaves_num;
memset(slave, 0, sizeof(*slave));
host->slaves = slave;
slave = host->slaves + host->slaves_num;
memset(slave, 0, sizeof(*slave));
status = cf_util_get_int(ci, &slave->id);
if (status != 0)
status = cf_util_get_int(ci, &slave->id);
if (status != 0)
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
else /* if (status != 0) */
data_free_all(slave->collect);
else /* if (status != 0) */
data_free_all(slave->collect);
} /* }}} int mb_config_add_slave */
static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */
} /* }}} int mb_config_add_slave */
static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */
host = calloc(1, sizeof(*host));
if (host == NULL)
host = calloc(1, sizeof(*host));
if (host == NULL)
host->slaves = NULL;
status = cf_util_get_string_buffer(ci, host->host, sizeof(host->host));
if (status != 0) {
sfree(host);
host->slaves = NULL;
status = cf_util_get_string_buffer(ci, host->host, sizeof(host->host));
if (status != 0) {
sfree(host);
}
if (host->host[0] == 0) {
sfree(host);
}
if (host->host[0] == 0) {
sfree(host);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
} /* }}} int mb_config_add_host */
static int mb_config(oconfig_item_t *ci) /* {{{ */
{
if (ci == NULL)
} /* }}} int mb_config_add_host */
static int mb_config(oconfig_item_t *ci) /* {{{ */
{
if (ci == NULL)
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
ERROR("Modbus plugin: Unknown configuration option: %s", child->key);
}
ERROR("Modbus plugin: Unknown configuration option: %s", child->key);
}
} /* }}} int mb_config */
/* ========= */
} /* }}} int mb_config */
/* ========= */
data_free_all(data_definitions);
data_definitions = NULL;
data_free_all(data_definitions);
data_definitions = NULL;
} /* }}} int mb_shutdown */
void module_register(void) {
} /* }}} int mb_shutdown */
void module_register(void) {
while (num > 2) {
char *tmp = strchr(topic, '/');
if (tmp == NULL)
while (num > 2) {
char *tmp = strchr(topic, '/');
if (tmp == NULL)
topic = tmp + 1;
num--;
}
topic = tmp + 1;
num--;
}
}
static void on_message(
}
static void on_message(
int status;
if (conf->connected)
int status;
if (conf->connected)
status = mosquitto_reconnect(conf->mosq);
if (status != MOSQ_ERR_SUCCESS) {
status = mosquitto_reconnect(conf->mosq);
if (status != MOSQ_ERR_SUCCESS) {
ERROR("mqtt_connect_broker: mosquitto_connect failed: %s",
(status == MOSQ_ERR_ERRNO) ? sstrerror(errno, errbuf, sizeof(errbuf))
: mosquitto_strerror(status));
ERROR("mqtt_connect_broker: mosquitto_connect failed: %s",
(status == MOSQ_ERR_ERRNO) ? sstrerror(errno, errbuf, sizeof(errbuf))
: mosquitto_strerror(status));
"mqtt plugin: successfully reconnected to broker \"%s:%d\"",
conf->host, conf->port);
"mqtt plugin: successfully reconnected to broker \"%s:%d\"",
conf->host, conf->port);
} /* mqtt_reconnect */
/* must hold conf->lock when calling. */
} /* mqtt_reconnect */
/* must hold conf->lock when calling. */
#endif
if (conf->mosq == NULL) {
ERROR("mqtt plugin: mosquitto_new failed");
#endif
if (conf->mosq == NULL) {
ERROR("mqtt plugin: mosquitto_new failed");
}
#if LIBMOSQUITTO_MAJOR != 0
}
#if LIBMOSQUITTO_MAJOR != 0
mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
}
status = mosquitto_tls_opts_set(conf->mosq, SSL_VERIFY_PEER,
}
status = mosquitto_tls_opts_set(conf->mosq, SSL_VERIFY_PEER,
mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
}
status = mosquitto_tls_insecure_set(conf->mosq, false);
}
status = mosquitto_tls_insecure_set(conf->mosq, false);
mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_strerror(status));
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_disconnect(conf->mosq);
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
mosquitto_disconnect(conf->mosq);
mosquitto_destroy(conf->mosq);
conf->mosq = NULL;
} /* mqtt_connect */
static void *subscribers_thread(void *arg) {
} /* mqtt_connect */
static void *subscribers_thread(void *arg) {
if (status != 0) {
pthread_mutex_unlock(&conf->lock);
ERROR("mqtt plugin: unable to reconnect to broker");
if (status != 0) {
pthread_mutex_unlock(&conf->lock);
ERROR("mqtt plugin: unable to reconnect to broker");
}
status = mosquitto_publish(conf->mosq, /* message_id */ NULL, topic,
}
status = mosquitto_publish(conf->mosq, /* message_id */ NULL, topic,
mosquitto_disconnect(conf->mosq);
pthread_mutex_unlock(&conf->lock);
mosquitto_disconnect(conf->mosq);
pthread_mutex_unlock(&conf->lock);
}
pthread_mutex_unlock(&conf->lock);
}
pthread_mutex_unlock(&conf->lock);
} /* int publish */
static int format_topic(char *buf, size_t buf_len, data_set_t const *ds,
} /* int publish */
static int format_topic(char *buf, size_t buf_len, data_set_t const *ds,
char *c;
if ((conf->topic_prefix == NULL) || (conf->topic_prefix[0] == 0))
char *c;
if ((conf->topic_prefix == NULL) || (conf->topic_prefix[0] == 0))
- return (FORMAT_VL(buf, buf_len, vl));
+ return FORMAT_VL(buf, buf_len, vl);
status = FORMAT_VL(name, sizeof(name), vl);
if (status != 0)
status = FORMAT_VL(name, sizeof(name), vl);
if (status != 0)
status = ssnprintf(buf, buf_len, "%s/%s", conf->topic_prefix, name);
if ((status < 0) || (((size_t)status) >= buf_len))
status = ssnprintf(buf, buf_len, "%s/%s", conf->topic_prefix, name);
if ((status < 0) || (((size_t)status) >= buf_len))
while((c = strchr(buf, '#')) || (c = strchr(buf, '+'))) {
*c = '_';
}
while((c = strchr(buf, '#')) || (c = strchr(buf, '+'))) {
*c = '_';
}
} /* int format_topic */
static int mqtt_write(const data_set_t *ds, const value_list_t *vl,
} /* int format_topic */
static int mqtt_write(const data_set_t *ds, const value_list_t *vl,
int status = 0;
if ((user_data == NULL) || (user_data->data == NULL))
int status = 0;
if ((user_data == NULL) || (user_data->data == NULL))
conf = user_data->data;
status = format_topic(topic, sizeof(topic), ds, vl, conf);
if (status != 0) {
ERROR("mqtt plugin: format_topic failed with status %d.", status);
conf = user_data->data;
status = format_topic(topic, sizeof(topic), ds, vl, conf);
if (status != 0) {
ERROR("mqtt plugin: format_topic failed with status %d.", status);
}
status = format_values(payload, sizeof(payload), ds, vl, conf->store_rates);
if (status != 0) {
ERROR("mqtt plugin: format_values failed with status %d.", status);
}
status = format_values(payload, sizeof(payload), ds, vl, conf->store_rates);
if (status != 0) {
ERROR("mqtt plugin: format_values failed with status %d.", status);
}
status = publish(conf, topic, payload, strlen(payload) + 1);
if (status != 0) {
ERROR("mqtt plugin: publish failed: %s", mosquitto_strerror(status));
}
status = publish(conf, topic, payload, strlen(payload) + 1);
if (status != 0) {
ERROR("mqtt plugin: publish failed: %s", mosquitto_strerror(status));
conf = calloc(1, sizeof(*conf));
if (conf == NULL) {
ERROR("mqtt plugin: calloc failed.");
conf = calloc(1, sizeof(*conf));
if (conf == NULL) {
ERROR("mqtt plugin: calloc failed.");
status = cf_util_get_string(ci, &conf->name);
if (status != 0) {
mqtt_free(conf);
status = cf_util_get_string(ci, &conf->name);
if (status != 0) {
mqtt_free(conf);
}
conf->host = strdup(MQTT_DEFAULT_HOST);
}
conf->host = strdup(MQTT_DEFAULT_HOST);
status = pthread_mutex_init(&conf->lock, NULL);
if (status != 0) {
mqtt_free(conf);
status = pthread_mutex_init(&conf->lock, NULL);
if (status != 0) {
mqtt_free(conf);
}
C_COMPLAIN_INIT(&conf->complaint_cantpublish);
}
C_COMPLAIN_INIT(&conf->complaint_cantpublish);
plugin_register_write(cb_name, mqtt_write, &(user_data_t){
.data = conf,
});
plugin_register_write(cb_name, mqtt_write, &(user_data_t){
.data = conf,
});
} /* mqtt_config_publisher */
/*
} /* mqtt_config_publisher */
/*
conf = calloc(1, sizeof(*conf));
if (conf == NULL) {
ERROR("mqtt plugin: calloc failed.");
conf = calloc(1, sizeof(*conf));
if (conf == NULL) {
ERROR("mqtt plugin: calloc failed.");
status = cf_util_get_string(ci, &conf->name);
if (status != 0) {
mqtt_free(conf);
status = cf_util_get_string(ci, &conf->name);
if (status != 0) {
mqtt_free(conf);
}
conf->host = strdup(MQTT_DEFAULT_HOST);
}
conf->host = strdup(MQTT_DEFAULT_HOST);
status = pthread_mutex_init(&conf->lock, NULL);
if (status != 0) {
mqtt_free(conf);
status = pthread_mutex_init(&conf->lock, NULL);
if (status != 0) {
mqtt_free(conf);
}
C_COMPLAIN_INIT(&conf->complaint_cantpublish);
}
C_COMPLAIN_INIT(&conf->complaint_cantpublish);
if (tmp == NULL) {
ERROR("mqtt plugin: realloc failed.");
mqtt_free(conf);
if (tmp == NULL) {
ERROR("mqtt plugin: realloc failed.");
mqtt_free(conf);
}
subscribers = tmp;
subscribers[subscribers_num] = conf;
subscribers_num++;
}
subscribers = tmp;
subscribers[subscribers_num] = conf;
subscribers_num++;
} /* mqtt_config_subscriber */
/*
} /* mqtt_config_subscriber */
/*
ERROR("mqtt plugin: Unknown config option: %s", child->key);
}
ERROR("mqtt plugin: Unknown config option: %s", child->key);
}
} /* int mqtt_config */
static int mqtt_init(void) {
} /* int mqtt_config */
static int mqtt_init(void) {
} /* mqtt_init */
void module_register(void) {
} /* mqtt_init */
void module_register(void) {
char errbuf[1024];
ERROR("multimeter plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("multimeter plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
status = swrite(fd, "D", 1);
if (status < 0) {
ERROR("multimeter plugin: swrite failed.");
status = swrite(fd, "D", 1);
if (status < 0) {
ERROR("multimeter plugin: swrite failed.");
ERROR("multimeter plugin: "
"gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("multimeter plugin: "
"gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (timeval_cmp(time_end, time_now, &timeout) < 0)
break;
}
if (timeval_cmp(time_end, time_now, &timeout) < 0)
break;
- return (-1); /* Overflow */
+ return -1; /* Overflow */
- return (0); /* value received */
+ return 0; /* value received */
} else
break;
} else if (!status) /* Timeout */
} else
break;
} else if (!status) /* Timeout */
- return (-2); /* no value received */
+ return -2; /* no value received */
} /* int multimeter_read_value */
static int multimeter_init(void) {
} /* int multimeter_read_value */
static int multimeter_init(void) {
INFO("multimeter plugin: Device "
"found at %s",
device);
INFO("multimeter plugin: Device "
"found at %s",
device);
}
}
}
ERROR("multimeter plugin: No device found");
}
}
}
ERROR("multimeter plugin: No device found");
double value;
if (fd < 0)
double value;
if (fd < 0)
if (multimeter_read_value(&value) != 0)
if (multimeter_read_value(&value) != 0)
multimeter_submit(value);
multimeter_submit(value);
} /* int multimeter_read */
static int multimeter_shutdown(void) {
} /* int multimeter_read */
static int multimeter_shutdown(void) {
}
void module_register(void) {
}
void module_register(void) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("mysql plugin: The `Database' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("mysql plugin: The `Database' block "
"needs exactly one string argument.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("mysql plugin: calloc failed.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("mysql plugin: calloc failed.");
}
/* initialize all the pointers */
}
/* initialize all the pointers */
status = cf_util_get_string(ci, &db->instance);
if (status != 0) {
sfree(db);
status = cf_util_get_string(ci, &db->instance);
if (status != 0) {
sfree(db);
}
assert(db->instance != NULL);
}
assert(db->instance != NULL);
});
} else {
mysql_database_free(db);
});
} else {
mysql_database_free(db);
} /* }}} int mysql_config_database */
static int mysql_config(oconfig_item_t *ci) /* {{{ */
{
if (ci == NULL)
} /* }}} int mysql_config_database */
static int mysql_config(oconfig_item_t *ci) /* {{{ */
{
if (ci == NULL)
/* Fill the `mysql_database_t' structure.. */
for (int i = 0; i < ci->children_num; i++) {
/* Fill the `mysql_database_t' structure.. */
for (int i = 0; i < ci->children_num; i++) {
WARNING("mysql plugin: Option \"%s\" not allowed here.", child->key);
}
WARNING("mysql plugin: Option \"%s\" not allowed here.", child->key);
}
} /* }}} int mysql_config */
/* }}} End of configuration handling functions */
} /* }}} int mysql_config */
/* }}} End of configuration handling functions */
status = mysql_ping(db->con);
if (status == 0)
status = mysql_ping(db->con);
if (status == 0)
WARNING("mysql plugin: Lost connection to instance \"%s\": %s",
db->instance, mysql_error(db->con));
WARNING("mysql plugin: Lost connection to instance \"%s\": %s",
db->instance, mysql_error(db->con));
db->con = mysql_init(NULL);
if (db->con == NULL) {
ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con));
db->con = mysql_init(NULL);
if (db->con == NULL) {
ERROR("mysql plugin: mysql_init failed: %s", mysql_error(db->con));
"at server %s: %s",
(db->database != NULL) ? db->database : "<none>",
(db->host != NULL) ? db->host : "localhost", mysql_error(db->con));
"at server %s: %s",
(db->database != NULL) ? db->database : "<none>",
(db->host != NULL) ? db->host : "localhost", mysql_error(db->con));
}
cipher = mysql_get_ssl_cipher(db->con);
}
cipher = mysql_get_ssl_cipher(db->con);
mysql_get_server_info(db->con), mysql_get_proto_info(db->con));
db->is_connected = 1;
mysql_get_server_info(db->con), mysql_get_proto_info(db->con));
db->is_connected = 1;
} /* static MYSQL *getconnection (mysql_database_t *db) */
static void set_host(mysql_database_t *db, char *buf, size_t buflen) {
} /* static MYSQL *getconnection (mysql_database_t *db) */
static void set_host(mysql_database_t *db, char *buf, size_t buflen) {
if (mysql_real_query(con, query, query_len)) {
ERROR("mysql plugin: Failed to execute query: %s", mysql_error(con));
INFO("mysql plugin: SQL query was: %s", query);
if (mysql_real_query(con, query, query_len)) {
ERROR("mysql plugin: Failed to execute query: %s", mysql_error(con));
INFO("mysql plugin: SQL query was: %s", query);
}
res = mysql_store_result(con);
if (res == NULL) {
ERROR("mysql plugin: Failed to store query result: %s", mysql_error(con));
INFO("mysql plugin: SQL query was: %s", query);
}
res = mysql_store_result(con);
if (res == NULL) {
ERROR("mysql plugin: Failed to store query result: %s", mysql_error(con));
INFO("mysql plugin: SQL query was: %s", query);
} /* exec_query */
static int mysql_read_master_stats(mysql_database_t *db, MYSQL *con) {
} /* exec_query */
static int mysql_read_master_stats(mysql_database_t *db, MYSQL *con) {
res = exec_query(con, query);
if (res == NULL)
res = exec_query(con, query);
if (res == NULL)
row = mysql_fetch_row(res);
if (row == NULL) {
row = mysql_fetch_row(res);
if (row == NULL) {
"`%s' did not return any rows.",
query);
mysql_free_result(res);
"`%s' did not return any rows.",
query);
mysql_free_result(res);
}
field_num = mysql_num_fields(res);
}
field_num = mysql_num_fields(res);
"`%s' returned less than two columns.",
query);
mysql_free_result(res);
"`%s' returned less than two columns.",
query);
mysql_free_result(res);
}
position = atoll(row[1]);
}
position = atoll(row[1]);
} /* mysql_read_master_stats */
static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) {
} /* mysql_read_master_stats */
static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) {
res = exec_query(con, query);
if (res == NULL)
res = exec_query(con, query);
if (res == NULL)
row = mysql_fetch_row(res);
if (row == NULL) {
row = mysql_fetch_row(res);
if (row == NULL) {
"`%s' did not return any rows.",
query);
mysql_free_result(res);
"`%s' did not return any rows.",
query);
mysql_free_result(res);
}
field_num = mysql_num_fields(res);
}
field_num = mysql_num_fields(res);
"`%s' returned less than 33 columns.",
query);
mysql_free_result(res);
"`%s' returned less than 33 columns.",
query);
mysql_free_result(res);
} /* mysql_read_slave_stats */
static int mysql_read_innodb_stats(mysql_database_t *db, MYSQL *con) {
} /* mysql_read_slave_stats */
static int mysql_read_innodb_stats(mysql_database_t *db, MYSQL *con) {
res = exec_query(con, query);
if (res == NULL)
res = exec_query(con, query);
if (res == NULL)
while ((row = mysql_fetch_row(res))) {
int i;
while ((row = mysql_fetch_row(res))) {
int i;
}
mysql_free_result(res);
}
mysql_free_result(res);
}
static int mysql_read_wsrep_stats(mysql_database_t *db, MYSQL *con) {
}
static int mysql_read_wsrep_stats(mysql_database_t *db, MYSQL *con) {
res = exec_query(con, query);
if (res == NULL)
res = exec_query(con, query);
if (res == NULL)
row = mysql_fetch_row(res);
if (row == NULL) {
row = mysql_fetch_row(res);
if (row == NULL) {
"`%s' did not return any rows.",
query);
mysql_free_result(res);
"`%s' did not return any rows.",
query);
mysql_free_result(res);
}
while ((row = mysql_fetch_row(res))) {
}
while ((row = mysql_fetch_row(res))) {
}
mysql_free_result(res);
}
mysql_free_result(res);
} /* mysql_read_wsrep_stats */
static int mysql_read(user_data_t *ud) {
} /* mysql_read_wsrep_stats */
static int mysql_read(user_data_t *ud) {
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("mysql plugin: mysql_database_read: Invalid user data.");
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("mysql plugin: mysql_database_read: Invalid user data.");
}
db = (mysql_database_t *)ud->data;
/* An error message will have been printed in this case */
if ((con = getconnection(db)) == NULL)
}
db = (mysql_database_t *)ud->data;
/* An error message will have been printed in this case */
if ((con = getconnection(db)) == NULL)
mysql_version = mysql_get_server_version(con);
mysql_version = mysql_get_server_version(con);
res = exec_query(con, query);
if (res == NULL)
res = exec_query(con, query);
if (res == NULL)
while ((row = mysql_fetch_row(res))) {
char *key;
while ((row = mysql_fetch_row(res))) {
char *key;
if (db->wsrep_stats)
mysql_read_wsrep_stats(db, con);
if (db->wsrep_stats)
mysql_read_wsrep_stats(db, con);
} /* int mysql_read */
void module_register(void) {
} /* int mysql_read */
void module_register(void) {
disk_t *d;
if ((cd == NULL) || (name == NULL))
disk_t *d;
if ((cd == NULL) || (name == NULL))
for (d = cd->disks; d != NULL; d = d->next) {
if (strcmp(d->name, name) == 0)
for (d = cd->disks; d != NULL; d = d->next) {
if (strcmp(d->name, name) == 0)
d = calloc(1, sizeof(*d));
if (d == NULL)
d = calloc(1, sizeof(*d));
if (d == NULL)
d->next = NULL;
d->name = strdup(name);
if (d->name == NULL) {
sfree(d);
d->next = NULL;
d->name = strdup(name);
if (d->name == NULL) {
sfree(d);
int ignore_snapshot = 0;
if ((cvu == NULL) || (name == NULL))
int ignore_snapshot = 0;
if ((cvu == NULL) || (name == NULL))
last = cvu->volumes;
while (last != NULL) {
if (strcmp(last->name, name) == 0)
last = cvu->volumes;
while (last != NULL) {
if (strcmp(last->name, name) == 0)
if (last->next == NULL)
break;
if (last->next == NULL)
break;
ignore_capacity = ignorelist_match(cvu->il_capacity, name);
ignore_snapshot = ignorelist_match(cvu->il_snapshot, name);
if ((ignore_capacity != 0) && (ignore_snapshot != 0))
ignore_capacity = ignorelist_match(cvu->il_capacity, name);
ignore_snapshot = ignorelist_match(cvu->il_snapshot, name);
if ((ignore_capacity != 0) && (ignore_snapshot != 0))
/* Not found: allocate. */
new = calloc(1, sizeof(*new));
if (new == NULL)
/* Not found: allocate. */
new = calloc(1, sizeof(*new));
if (new == NULL)
new->next = NULL;
new->name = strdup(name);
if (new->name == NULL) {
sfree(new);
new->next = NULL;
new->name = strdup(name);
if (new->name == NULL) {
sfree(new);
}
if (ignore_capacity == 0)
}
if (ignore_capacity == 0)
} /* }}} data_volume_usage_t *get_volume_usage */
static data_volume_perf_t *get_volume_perf(cfg_volume_perf_t *cvp, /* {{{ */
} /* }}} data_volume_usage_t *get_volume_usage */
static data_volume_perf_t *get_volume_perf(cfg_volume_perf_t *cvp, /* {{{ */
int ignore_latency = 0;
if ((cvp == NULL) || (name == NULL))
int ignore_latency = 0;
if ((cvp == NULL) || (name == NULL))
last = cvp->volumes;
while (last != NULL) {
if (strcmp(last->name, name) == 0)
last = cvp->volumes;
while (last != NULL) {
if (strcmp(last->name, name) == 0)
if (last->next == NULL)
break;
if (last->next == NULL)
break;
ignore_operations = ignorelist_match(cvp->il_operations, name);
ignore_latency = ignorelist_match(cvp->il_latency, name);
if ((ignore_octets != 0) || (ignore_operations != 0) || (ignore_latency != 0))
ignore_operations = ignorelist_match(cvp->il_operations, name);
ignore_latency = ignorelist_match(cvp->il_latency, name);
if ((ignore_octets != 0) || (ignore_operations != 0) || (ignore_latency != 0))
/* Not found: allocate. */
new = calloc(1, sizeof(*new));
if (new == NULL)
/* Not found: allocate. */
new = calloc(1, sizeof(*new));
if (new == NULL)
new->next = NULL;
new->name = strdup(name);
if (new->name == NULL) {
sfree(new);
new->next = NULL;
new->name = strdup(name);
if (new->name == NULL) {
sfree(new);
}
if (ignore_octets == 0)
}
if (ignore_octets == 0)
} /* }}} data_volume_perf_t *get_volume_perf */
/*
} /* }}} data_volume_perf_t *get_volume_perf */
/*
if (type_inst != NULL)
sstrncpy(vl.type_instance, type_inst, sizeof(vl.type_instance));
if (type_inst != NULL)
sstrncpy(vl.type_instance, type_inst, sizeof(vl.type_instance));
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
} /* }}} int submit_uint64 */
static int submit_two_derive(const char *host,
} /* }}} int submit_uint64 */
static int submit_two_derive(const char *host,
{.derive = val0}, {.derive = val1},
};
{.derive = val0}, {.derive = val1},
};
- return (submit_values(host, plugin_inst, type, type_inst, values,
- STATIC_ARRAY_SIZE(values), timestamp, interval));
+ return submit_values(host, plugin_inst, type, type_inst, values,
+ STATIC_ARRAY_SIZE(values), timestamp, interval);
} /* }}} int submit_two_derive */
static int submit_derive(const char *host, const char *plugin_inst, /* {{{ */
const char *type, const char *type_inst,
derive_t counter, cdtime_t timestamp,
cdtime_t interval) {
} /* }}} int submit_two_derive */
static int submit_derive(const char *host, const char *plugin_inst, /* {{{ */
const char *type, const char *type_inst,
derive_t counter, cdtime_t timestamp,
cdtime_t interval) {
- return (submit_values(host, plugin_inst, type, type_inst,
- &(value_t){.derive = counter}, 1, timestamp, interval));
+ return submit_values(host, plugin_inst, type, type_inst, &(value_t){
+ .derive=counter,
+ }, 1, timestamp, interval);
} /* }}} int submit_derive */
static int submit_two_gauge(const char *host, const char *plugin_inst, /* {{{ */
} /* }}} int submit_derive */
static int submit_two_gauge(const char *host, const char *plugin_inst, /* {{{ */
{.gauge = val0}, {.gauge = val1},
};
{.gauge = val0}, {.gauge = val1},
};
- return (submit_values(host, plugin_inst, type, type_inst, values,
- STATIC_ARRAY_SIZE(values), timestamp, interval));
+ return submit_values(host, plugin_inst, type, type_inst, values,
+ STATIC_ARRAY_SIZE(values), timestamp, interval);
} /* }}} int submit_two_gauge */
static int submit_double(const char *host, const char *plugin_inst, /* {{{ */
const char *type, const char *type_inst, double d,
cdtime_t timestamp, cdtime_t interval) {
} /* }}} int submit_two_gauge */
static int submit_double(const char *host, const char *plugin_inst, /* {{{ */
const char *type, const char *type_inst, double d,
cdtime_t timestamp, cdtime_t interval) {
- return (submit_values(host, plugin_inst, type, type_inst,
- &(value_t){.gauge = d}, 1, timestamp, interval));
+ return submit_values(host, plugin_inst, type, type_inst, &(value_t){
+ .gauge=d,
+ }, 1, timestamp, interval);
} /* }}} int submit_uint64 */
/* Calculate hit ratio from old and new counters and submit the resulting
} /* }}} int submit_uint64 */
/* Calculate hit ratio from old and new counters and submit the resulting
v.gauge = 100.0 * ((gauge_t)hits) / ((gauge_t)(hits + misses));
}
v.gauge = 100.0 * ((gauge_t)hits) / ((gauge_t)(hits + misses));
}
- return (submit_values(host, plugin_inst, "cache_ratio", type_inst, &v, 1,
- timestamp, interval));
+ return submit_values(host, plugin_inst, "cache_ratio", type_inst, &v, 1,
+ timestamp, interval);
} /* }}} int submit_cache_ratio */
/* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
} /* }}} int submit_cache_ratio */
/* Submits all the caches used by WAFL. Uses "submit_cache_ratio". */
/* Copy HAVE_* flags */
old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
/* Copy HAVE_* flags */
old_data->flags |= (new_data->flags & HAVE_WAFL_ALL);
} /* }}} int submit_wafl_data */
/* Submits volume performance data to the daemon, taking care to honor and
} /* }}} int submit_wafl_data */
/* Submits volume performance data to the daemon, taking care to honor and
char plugin_instance[DATA_MAX_NAME_LEN];
if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
char plugin_instance[DATA_MAX_NAME_LEN];
if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
old_data->name);
ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
old_data->name);
/* Copy the HAVE_* flags */
old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
/* Copy the HAVE_* flags */
old_data->flags |= (new_data->flags & HAVE_VOLUME_PERF_ALL);
} /* }}} int submit_volume_perf_data */
static cdtime_t cna_child_get_cdtime(na_elem_t *data) /* {{{ */
} /* }}} int submit_volume_perf_data */
static cdtime_t cna_child_get_cdtime(na_elem_t *data) /* {{{ */
t = (time_t)na_child_get_uint64(data, "timestamp", /* default = */ 0);
t = (time_t)na_child_get_uint64(data, "timestamp", /* default = */ 0);
- return (TIME_T_TO_CDTIME_T(t));
+ return TIME_T_TO_CDTIME_T(t);
} /* }}} cdtime_t cna_child_get_cdtime */
/*
} /* }}} cdtime_t cna_child_get_cdtime */
/*
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
}
plugin_inst = na_child_get_string(instances, "name");
}
plugin_inst = na_child_get_string(instances, "name");
"na_child_get_string (\"name\") failed "
"for host %s.",
hostname);
"na_child_get_string (\"name\") failed "
"for host %s.",
hostname);
}
/* Iterate over all counters */
}
/* Iterate over all counters */
- return (
- submit_wafl_data(hostname, plugin_inst, cfg_wafl, &perf_data, interval));
+ return submit_wafl_data(hostname, plugin_inst, cfg_wafl, &perf_data,
+ interval);
} /* }}} void cna_handle_wafl_data */
static int cna_setup_wafl(cfg_wafl_t *cw) /* {{{ */
} /* }}} void cna_handle_wafl_data */
static int cna_setup_wafl(cfg_wafl_t *cw) /* {{{ */
na_elem_t *e;
if (cw == NULL)
na_elem_t *e;
if (cw == NULL)
cw->query = na_elem_new("perf-object-get-instances");
if (cw->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
cw->query = na_elem_new("perf-object-get-instances");
if (cw->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
}
na_child_add_string(cw->query, "objectname", "wafl");
}
na_child_add_string(cw->query, "objectname", "wafl");
na_elem_free(cw->query);
cw->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
na_elem_free(cw->query);
cw->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
}
na_child_add_string(e, "counter", "name_cache_hit");
na_child_add_string(e, "counter", "name_cache_miss");
}
na_child_add_string(e, "counter", "name_cache_hit");
na_child_add_string(e, "counter", "name_cache_miss");
na_child_add(cw->query, e);
na_child_add(cw->query, e);
} /* }}} int cna_setup_wafl */
static int cna_query_wafl(host_config_t *host) /* {{{ */
} /* }}} int cna_setup_wafl */
static int cna_query_wafl(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
cdtime_t now;
if (host == NULL)
/* If WAFL was not configured, return without doing anything. */
if (host->cfg_wafl == NULL)
/* If WAFL was not configured, return without doing anything. */
if (host->cfg_wafl == NULL)
now = cdtime();
if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) >
now)
now = cdtime();
if ((host->cfg_wafl->interval.interval + host->cfg_wafl->interval.last_read) >
now)
status = cna_setup_wafl(host->cfg_wafl);
if (status != 0)
status = cna_setup_wafl(host->cfg_wafl);
if (status != 0)
assert(host->cfg_wafl->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
assert(host->cfg_wafl->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_wafl->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
}
status = cna_handle_wafl_data(host->name, host->cfg_wafl, data,
}
status = cna_handle_wafl_data(host->name, host->cfg_wafl, data,
host->cfg_wafl->interval.last_read = now;
na_elem_free(data);
host->cfg_wafl->interval.last_read = now;
na_elem_free(data);
} /* }}} int cna_query_wafl */
/* Data corresponding to <Disks /> */
} /* }}} int cna_query_wafl */
/* Data corresponding to <Disks /> */
disk_t *worst_disk = NULL;
if ((cfg_disk == NULL) || (data == NULL))
disk_t *worst_disk = NULL;
if ((cfg_disk == NULL) || (data == NULL))
timestamp = cna_child_get_cdtime(data);
timestamp = cna_child_get_cdtime(data);
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
}
/* Iterate over all children */
}
/* Iterate over all children */
submit_double(hostname, "system", "percent", "disk_busy",
worst_disk->disk_busy_percent, timestamp, interval);
submit_double(hostname, "system", "percent", "disk_busy",
worst_disk->disk_busy_percent, timestamp, interval);
} /* }}} int cna_handle_disk_data */
static int cna_setup_disk(cfg_disk_t *cd) /* {{{ */
} /* }}} int cna_handle_disk_data */
static int cna_setup_disk(cfg_disk_t *cd) /* {{{ */
na_elem_t *e;
if (cd == NULL)
na_elem_t *e;
if (cd == NULL)
cd->query = na_elem_new("perf-object-get-instances");
if (cd->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
cd->query = na_elem_new("perf-object-get-instances");
if (cd->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
}
na_child_add_string(cd->query, "objectname", "disk");
}
na_child_add_string(cd->query, "objectname", "disk");
na_elem_free(cd->query);
cd->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
na_elem_free(cd->query);
cd->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
}
na_child_add_string(e, "counter", "disk_busy");
na_child_add_string(e, "counter", "base_for_disk_busy");
na_child_add(cd->query, e);
}
na_child_add_string(e, "counter", "disk_busy");
na_child_add_string(e, "counter", "base_for_disk_busy");
na_child_add(cd->query, e);
} /* }}} int cna_setup_disk */
static int cna_query_disk(host_config_t *host) /* {{{ */
} /* }}} int cna_setup_disk */
static int cna_query_disk(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
cdtime_t now;
if (host == NULL)
/* If the user did not configure disk statistics, return without doing
* anything. */
if (host->cfg_disk == NULL)
/* If the user did not configure disk statistics, return without doing
* anything. */
if (host->cfg_disk == NULL)
now = cdtime();
if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) >
now)
now = cdtime();
if ((host->cfg_disk->interval.interval + host->cfg_disk->interval.last_read) >
now)
status = cna_setup_disk(host->cfg_disk);
if (status != 0)
status = cna_setup_disk(host->cfg_disk);
if (status != 0)
assert(host->cfg_disk->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
assert(host->cfg_disk->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_disk->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
}
status = cna_handle_disk_data(host->name, host->cfg_disk, data,
}
status = cna_handle_disk_data(host->name, host->cfg_disk, data,
host->cfg_disk->interval.last_read = now;
na_elem_free(data);
host->cfg_disk->interval.last_read = now;
na_elem_free(data);
} /* }}} int cna_query_disk */
/* Data corresponding to <VolumePerf /> */
} /* }}} int cna_query_disk */
/* Data corresponding to <VolumePerf /> */
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
}
iter_instances = na_child_iterator(elem_instances);
}
iter_instances = na_child_iterator(elem_instances);
submit_volume_perf_data(hostname, v, &perf_data, interval);
} /* for (volume) */
submit_volume_perf_data(hostname, v, &perf_data, interval);
} /* for (volume) */
} /* }}} int cna_handle_volume_perf_data */
static int cna_setup_volume_perf(cfg_volume_perf_t *cd) /* {{{ */
} /* }}} int cna_handle_volume_perf_data */
static int cna_setup_volume_perf(cfg_volume_perf_t *cd) /* {{{ */
na_elem_t *e;
if (cd == NULL)
na_elem_t *e;
if (cd == NULL)
cd->query = na_elem_new("perf-object-get-instances");
if (cd->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
cd->query = na_elem_new("perf-object-get-instances");
if (cd->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
}
na_child_add_string(cd->query, "objectname", "volume");
}
na_child_add_string(cd->query, "objectname", "volume");
na_elem_free(cd->query);
cd->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
na_elem_free(cd->query);
cd->query = NULL;
ERROR("netapp plugin: na_elem_new failed.");
}
na_child_add_string(e, "counter", "read_ops");
na_child_add_string(e, "counter", "write_ops");
}
na_child_add_string(e, "counter", "read_ops");
na_child_add_string(e, "counter", "write_ops");
na_child_add_string(e, "counter", "write_latency");
na_child_add(cd->query, e);
na_child_add_string(e, "counter", "write_latency");
na_child_add(cd->query, e);
} /* }}} int cna_setup_volume_perf */
static int cna_query_volume_perf(host_config_t *host) /* {{{ */
} /* }}} int cna_setup_volume_perf */
static int cna_query_volume_perf(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
cdtime_t now;
if (host == NULL)
/* If the user did not configure volume performance statistics, return
* without doing anything. */
if (host->cfg_volume_perf == NULL)
/* If the user did not configure volume performance statistics, return
* without doing anything. */
if (host->cfg_volume_perf == NULL)
now = cdtime();
if ((host->cfg_volume_perf->interval.interval +
host->cfg_volume_perf->interval.last_read) > now)
now = cdtime();
if ((host->cfg_volume_perf->interval.interval +
host->cfg_volume_perf->interval.last_read) > now)
status = cna_setup_volume_perf(host->cfg_volume_perf);
if (status != 0)
status = cna_setup_volume_perf(host->cfg_volume_perf);
if (status != 0)
assert(host->cfg_volume_perf->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_volume_perf->query);
assert(host->cfg_volume_perf->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_volume_perf->query);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
host->cfg_volume_perf->interval.last_read = now;
na_elem_free(data);
host->cfg_volume_perf->interval.last_read = now;
na_elem_free(data);
} /* }}} int cna_query_volume_perf */
/* Data corresponding to <VolumeUsage /> */
} /* }}} int cna_query_volume_perf */
/* Data corresponding to <VolumeUsage /> */
v->flags &= ~HAVE_VOLUME_USAGE_ALL;
} /* for (v = cfg_volume->volumes) */
v->flags &= ~HAVE_VOLUME_USAGE_ALL;
} /* for (v = cfg_volume->volumes) */
} /* }}} int cna_submit_volume_usage_data */
/* Switch the state of a volume between online and offline and send out a
} /* }}} int cna_submit_volume_usage_data */
/* Switch the state of a volume between online and offline and send out a
v->flags |= IS_VOLUME_USAGE_OFFLINE;
}
v->flags |= IS_VOLUME_USAGE_OFFLINE;
}
- return (plugin_dispatch_notification(&n));
+ return plugin_dispatch_notification(&n);
} /* }}} int cna_change_volume_status */
static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
} /* }}} int cna_change_volume_status */
static void cna_handle_volume_snap_usage(const host_config_t *host, /* {{{ */
"na_elem_child (\"volumes\") failed "
"for host %s.",
host->name);
"na_elem_child (\"volumes\") failed "
"for host %s.",
host->name);
}
iter_volume = na_child_iterator(elem_volumes);
}
iter_volume = na_child_iterator(elem_volumes);
}
} /* for (elem_volume) */
}
} /* for (elem_volume) */
- return (cna_submit_volume_usage_data(
- host->name, cfg_volume, host->cfg_volume_usage->interval.interval));
+ return cna_submit_volume_usage_data(host->name, cfg_volume,
+ host->cfg_volume_usage->interval.interval);
} /* }}} int cna_handle_volume_usage_data */
static int cna_setup_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
{
if (cvu == NULL)
} /* }}} int cna_handle_volume_usage_data */
static int cna_setup_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
{
if (cvu == NULL)
cvu->query = na_elem_new("volume-list-info");
if (cvu->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
cvu->query = na_elem_new("volume-list-info");
if (cvu->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
} /* }}} int cna_setup_volume_usage */
static int cna_query_volume_usage(host_config_t *host) /* {{{ */
} /* }}} int cna_setup_volume_usage */
static int cna_query_volume_usage(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
cdtime_t now;
if (host == NULL)
/* If the user did not configure volume_usage statistics, return without
* doing anything. */
if (host->cfg_volume_usage == NULL)
/* If the user did not configure volume_usage statistics, return without
* doing anything. */
if (host->cfg_volume_usage == NULL)
now = cdtime();
if ((host->cfg_volume_usage->interval.interval +
host->cfg_volume_usage->interval.last_read) > now)
now = cdtime();
if ((host->cfg_volume_usage->interval.interval +
host->cfg_volume_usage->interval.last_read) > now)
status = cna_setup_volume_usage(host->cfg_volume_usage);
if (status != 0)
status = cna_setup_volume_usage(host->cfg_volume_usage);
if (status != 0)
assert(host->cfg_volume_usage->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
assert(host->cfg_volume_usage->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_volume_usage->query);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
}
status = cna_handle_volume_usage_data(host, host->cfg_volume_usage, data);
}
status = cna_handle_volume_usage_data(host, host->cfg_volume_usage, data);
host->cfg_volume_usage->interval.last_read = now;
na_elem_free(data);
host->cfg_volume_usage->interval.last_read = now;
na_elem_free(data);
} /* }}} int cna_query_volume_usage */
/* Data corresponding to <Quota /> */
} /* }}} int cna_query_volume_usage */
/* Data corresponding to <Quota /> */
"na_elem_child (\"quotas\") failed "
"for host %s.",
host->name);
"na_elem_child (\"quotas\") failed "
"for host %s.",
host->name);
}
iter_quota = na_child_iterator(elem_quotas);
}
iter_quota = na_child_iterator(elem_quotas);
}
} /* for (elem_quota) */
}
} /* for (elem_quota) */
} /* }}} int cna_handle_volume_usage_data */
static int cna_setup_quota(cfg_quota_t *cq) /* {{{ */
{
if (cq == NULL)
} /* }}} int cna_handle_volume_usage_data */
static int cna_setup_quota(cfg_quota_t *cq) /* {{{ */
{
if (cq == NULL)
cq->query = na_elem_new("quota-report");
if (cq->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
cq->query = na_elem_new("quota-report");
if (cq->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
} /* }}} int cna_setup_quota */
static int cna_query_quota(host_config_t *host) /* {{{ */
} /* }}} int cna_setup_quota */
static int cna_query_quota(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
cdtime_t now;
if (host == NULL)
/* If the user did not configure quota statistics, return without
* doing anything. */
if (host->cfg_quota == NULL)
/* If the user did not configure quota statistics, return without
* doing anything. */
if (host->cfg_quota == NULL)
now = cdtime();
if ((host->cfg_quota->interval.interval +
host->cfg_quota->interval.last_read) > now)
now = cdtime();
if ((host->cfg_quota->interval.interval +
host->cfg_quota->interval.last_read) > now)
status = cna_setup_quota(host->cfg_quota);
if (status != 0)
status = cna_setup_quota(host->cfg_quota);
if (status != 0)
assert(host->cfg_quota->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_quota->query);
assert(host->cfg_quota->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_quota->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
}
status = cna_handle_quota_data(host, host->cfg_quota, data);
}
status = cna_handle_quota_data(host, host->cfg_quota, data);
host->cfg_quota->interval.last_read = now;
na_elem_free(data);
host->cfg_quota->interval.last_read = now;
na_elem_free(data);
} /* }}} int cna_query_quota */
/* Data corresponding to <SnapVault /> */
} /* }}} int cna_query_quota */
/* Data corresponding to <SnapVault /> */
na_elem_t *status_list = na_elem_child(data, "status-list");
if (status_list == NULL) {
ERROR("netapp plugin: SnapVault status record missing status-list");
na_elem_t *status_list = na_elem_child(data, "status-list");
if (status_list == NULL) {
ERROR("netapp plugin: SnapVault status record missing status-list");
}
na_elem_iter_t status_iter = na_child_iterator(status_list);
}
na_elem_iter_t status_iter = na_child_iterator(status_list);
} /* }}} int cna_handle_snapvault_data */
static int cna_handle_snapvault_iter(host_config_t *host, /* {{{ */
} /* }}} int cna_handle_snapvault_data */
static int cna_handle_snapvault_iter(host_config_t *host, /* {{{ */
"na_server_invoke failed for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(elem);
"na_server_invoke failed for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(elem);
}
cna_handle_snapvault_data(host->name, host->cfg_snapvault, elem,
}
cna_handle_snapvault_data(host->name, host->cfg_snapvault, elem,
na_elem_free(na_server_invoke(
host->srv, "snapvault-secondary-relationship-status-list-iter-end", "tag",
tag, NULL));
na_elem_free(na_server_invoke(
host->srv, "snapvault-secondary-relationship-status-list-iter-end", "tag",
tag, NULL));
} /* }}} int cna_handle_snapvault_iter */
static int cna_setup_snapvault(cfg_snapvault_t *sv) /* {{{ */
{
if (sv == NULL)
} /* }}} int cna_handle_snapvault_iter */
static int cna_setup_snapvault(cfg_snapvault_t *sv) /* {{{ */
{
if (sv == NULL)
sv->query =
na_elem_new("snapvault-secondary-relationship-status-list-iter-start");
if (sv->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
sv->query =
na_elem_new("snapvault-secondary-relationship-status-list-iter-start");
if (sv->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
} /* }}} int cna_setup_snapvault */
static int cna_query_snapvault(host_config_t *host) /* {{{ */
} /* }}} int cna_setup_snapvault */
static int cna_query_snapvault(host_config_t *host) /* {{{ */
now = cdtime();
if ((host->cfg_snapvault->interval.interval +
host->cfg_snapvault->interval.last_read) > now)
now = cdtime();
if ((host->cfg_snapvault->interval.interval +
host->cfg_snapvault->interval.last_read) > now)
status = cna_setup_snapvault(host->cfg_snapvault);
if (status != 0)
status = cna_setup_snapvault(host->cfg_snapvault);
if (status != 0)
assert(host->cfg_snapvault->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_snapvault->query);
assert(host->cfg_snapvault->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_snapvault->query);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
"for host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
}
status = cna_handle_snapvault_iter(host, data);
}
status = cna_handle_snapvault_iter(host, data);
host->cfg_snapvault->interval.last_read = now;
na_elem_free(data);
host->cfg_snapvault->interval.last_read = now;
na_elem_free(data);
} /* }}} int cna_query_snapvault */
/* Data corresponding to <System /> */
} /* }}} int cna_query_snapvault */
/* Data corresponding to <System /> */
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
"na_elem_child (\"instances\") failed "
"for host %s.",
hostname);
}
instance = na_child_get_string(instances, "name");
}
instance = na_child_get_string(instances, "name");
"na_child_get_string (\"name\") failed "
"for host %s.",
hostname);
"na_child_get_string (\"name\") failed "
"for host %s.",
hostname);
}
counter_iter = na_child_iterator(na_elem_child(instances, "counters"));
}
counter_iter = na_child_iterator(na_elem_child(instances, "counters"));
} /* }}} int cna_handle_system_data */
static int cna_setup_system(cfg_system_t *cs) /* {{{ */
{
if (cs == NULL)
} /* }}} int cna_handle_system_data */
static int cna_setup_system(cfg_system_t *cs) /* {{{ */
{
if (cs == NULL)
cs->query = na_elem_new("perf-object-get-instances");
if (cs->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
cs->query = na_elem_new("perf-object-get-instances");
if (cs->query == NULL) {
ERROR("netapp plugin: na_elem_new failed.");
}
na_child_add_string(cs->query, "objectname", "system");
}
na_child_add_string(cs->query, "objectname", "system");
} /* }}} int cna_setup_system */
static int cna_query_system(host_config_t *host) /* {{{ */
} /* }}} int cna_setup_system */
static int cna_query_system(host_config_t *host) /* {{{ */
cdtime_t now;
if (host == NULL)
cdtime_t now;
if (host == NULL)
/* If system statistics were not configured, return without doing anything. */
if (host->cfg_system == NULL)
/* If system statistics were not configured, return without doing anything. */
if (host->cfg_system == NULL)
now = cdtime();
if ((host->cfg_system->interval.interval +
host->cfg_system->interval.last_read) > now)
now = cdtime();
if ((host->cfg_system->interval.interval +
host->cfg_system->interval.last_read) > now)
status = cna_setup_system(host->cfg_system);
if (status != 0)
status = cna_setup_system(host->cfg_system);
if (status != 0)
assert(host->cfg_system->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_system->query);
assert(host->cfg_system->query != NULL);
data = na_server_invoke_elem(host->srv, host->cfg_system->query);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
"host %s: %s",
host->name, na_results_reason(data));
na_elem_free(data);
}
status = cna_handle_system_data(host->name, host->cfg_system, data,
}
status = cna_handle_system_data(host->name, host->cfg_system, data,
host->cfg_system->interval.last_read = now;
na_elem_free(data);
host->cfg_system->interval.last_read = now;
na_elem_free(data);
} /* }}} int cna_query_system */
/*
} /* }}} int cna_query_system */
/*
static int cna_config_bool_to_flag(const oconfig_item_t *ci, /* {{{ */
uint32_t *flags, uint32_t flag) {
if ((ci == NULL) || (flags == NULL))
static int cna_config_bool_to_flag(const oconfig_item_t *ci, /* {{{ */
uint32_t *flags, uint32_t flag) {
if ((ci == NULL) || (flags == NULL))
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
WARNING("netapp plugin: The %s option needs exactly one boolean argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
WARNING("netapp plugin: The %s option needs exactly one boolean argument.",
ci->key);
}
if (ci->values[0].value.boolean)
}
if (ci->values[0].value.boolean)
} /* }}} int cna_config_bool_to_flag */
/* Handling of the "Interval" option which is allowed in every block. */
} /* }}} int cna_config_bool_to_flag */
/* Handling of the "Interval" option which is allowed in every block. */
status = cf_util_get_cdtime(ci, &tmp);
if (status != 0)
status = cf_util_get_cdtime(ci, &tmp);
if (status != 0)
out_interval->interval = tmp;
out_interval->last_read = 0;
out_interval->interval = tmp;
out_interval->last_read = 0;
} /* }}} int cna_config_get_interval */
/* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
} /* }}} int cna_config_get_interval */
/* Handling of the "GetIO", "GetOps" and "GetLatency" options within a
cfg_volume_perf_t *cfg_volume_perf;
if ((host == NULL) || (ci == NULL))
cfg_volume_perf_t *cfg_volume_perf;
if ((host == NULL) || (ci == NULL))
if (host->cfg_volume_perf == NULL) {
cfg_volume_perf = calloc(1, sizeof(*cfg_volume_perf));
if (cfg_volume_perf == NULL)
if (host->cfg_volume_perf == NULL) {
cfg_volume_perf = calloc(1, sizeof(*cfg_volume_perf));
if (cfg_volume_perf == NULL)
/* Set default flags */
cfg_volume_perf->query = NULL;
/* Set default flags */
cfg_volume_perf->query = NULL;
cfg_volume_perf->il_octets = ignorelist_create(/* invert = */ 1);
if (cfg_volume_perf->il_octets == NULL) {
sfree(cfg_volume_perf);
cfg_volume_perf->il_octets = ignorelist_create(/* invert = */ 1);
if (cfg_volume_perf->il_octets == NULL) {
sfree(cfg_volume_perf);
}
cfg_volume_perf->il_operations = ignorelist_create(/* invert = */ 1);
if (cfg_volume_perf->il_operations == NULL) {
ignorelist_free(cfg_volume_perf->il_octets);
sfree(cfg_volume_perf);
}
cfg_volume_perf->il_operations = ignorelist_create(/* invert = */ 1);
if (cfg_volume_perf->il_operations == NULL) {
ignorelist_free(cfg_volume_perf->il_octets);
sfree(cfg_volume_perf);
}
cfg_volume_perf->il_latency = ignorelist_create(/* invert = */ 1);
}
cfg_volume_perf->il_latency = ignorelist_create(/* invert = */ 1);
ignorelist_free(cfg_volume_perf->il_octets);
ignorelist_free(cfg_volume_perf->il_operations);
sfree(cfg_volume_perf);
ignorelist_free(cfg_volume_perf->il_octets);
ignorelist_free(cfg_volume_perf->il_operations);
sfree(cfg_volume_perf);
}
host->cfg_volume_perf = cfg_volume_perf;
}
host->cfg_volume_perf = cfg_volume_perf;
} /* }}} int cna_config_volume_performance */
/* Handling of the "GetCapacity" and "GetSnapshot" options within a
} /* }}} int cna_config_volume_performance */
/* Handling of the "GetCapacity" and "GetSnapshot" options within a
cfg_quota_t *cfg_quota;
if ((host == NULL) || (ci == NULL))
cfg_quota_t *cfg_quota;
if ((host == NULL) || (ci == NULL))
if (host->cfg_quota == NULL) {
cfg_quota = calloc(1, sizeof(*cfg_quota));
if (cfg_quota == NULL)
if (host->cfg_quota == NULL) {
cfg_quota = calloc(1, sizeof(*cfg_quota));
if (cfg_quota == NULL)
cfg_quota->query = NULL;
host->cfg_quota = cfg_quota;
cfg_quota->query = NULL;
host->cfg_quota = cfg_quota;
} /* }}} int cna_config_quota */
/* Corresponds to a <Disks /> block */
} /* }}} int cna_config_quota */
/* Corresponds to a <Disks /> block */
cfg_disk_t *cfg_disk;
if ((host == NULL) || (ci == NULL))
cfg_disk_t *cfg_disk;
if ((host == NULL) || (ci == NULL))
if (host->cfg_disk == NULL) {
cfg_disk = calloc(1, sizeof(*cfg_disk));
if (cfg_disk == NULL)
if (host->cfg_disk == NULL) {
cfg_disk = calloc(1, sizeof(*cfg_disk));
if (cfg_disk == NULL)
/* Set default flags */
cfg_disk->flags = CFG_DISK_ALL;
/* Set default flags */
cfg_disk->flags = CFG_DISK_ALL;
} /* }}} int cna_config_disk */
/* Corresponds to a <WAFL /> block */
} /* }}} int cna_config_disk */
/* Corresponds to a <WAFL /> block */
cfg_wafl_t *cfg_wafl;
if ((host == NULL) || (ci == NULL))
cfg_wafl_t *cfg_wafl;
if ((host == NULL) || (ci == NULL))
if (host->cfg_wafl == NULL) {
cfg_wafl = calloc(1, sizeof(*cfg_wafl));
if (cfg_wafl == NULL)
if (host->cfg_wafl == NULL) {
cfg_wafl = calloc(1, sizeof(*cfg_wafl));
if (cfg_wafl == NULL)
/* Set default flags */
cfg_wafl->flags = CFG_WAFL_ALL;
/* Set default flags */
cfg_wafl->flags = CFG_WAFL_ALL;
} /* }}} int cna_config_wafl */
/*
} /* }}} int cna_config_wafl */
/*
cfg_volume_usage_t *cfg_volume_usage;
if ((host == NULL) || (ci == NULL))
cfg_volume_usage_t *cfg_volume_usage;
if ((host == NULL) || (ci == NULL))
if (host->cfg_volume_usage == NULL) {
cfg_volume_usage = calloc(1, sizeof(*cfg_volume_usage));
if (cfg_volume_usage == NULL)
if (host->cfg_volume_usage == NULL) {
cfg_volume_usage = calloc(1, sizeof(*cfg_volume_usage));
if (cfg_volume_usage == NULL)
/* Set default flags */
cfg_volume_usage->query = NULL;
/* Set default flags */
cfg_volume_usage->query = NULL;
cfg_volume_usage->il_capacity = ignorelist_create(/* invert = */ 1);
if (cfg_volume_usage->il_capacity == NULL) {
sfree(cfg_volume_usage);
cfg_volume_usage->il_capacity = ignorelist_create(/* invert = */ 1);
if (cfg_volume_usage->il_capacity == NULL) {
sfree(cfg_volume_usage);
}
cfg_volume_usage->il_snapshot = ignorelist_create(/* invert = */ 1);
if (cfg_volume_usage->il_snapshot == NULL) {
ignorelist_free(cfg_volume_usage->il_capacity);
sfree(cfg_volume_usage);
}
cfg_volume_usage->il_snapshot = ignorelist_create(/* invert = */ 1);
if (cfg_volume_usage->il_snapshot == NULL) {
ignorelist_free(cfg_volume_usage->il_capacity);
sfree(cfg_volume_usage);
}
host->cfg_volume_usage = cfg_volume_usage;
}
host->cfg_volume_usage = cfg_volume_usage;
} /* }}} int cna_config_volume_usage */
/* Corresponds to a <SnapVault /> block */
} /* }}} int cna_config_volume_usage */
/* Corresponds to a <SnapVault /> block */
cfg_system_t *cfg_system;
if ((host == NULL) || (ci == NULL))
cfg_system_t *cfg_system;
if ((host == NULL) || (ci == NULL))
if (host->cfg_system == NULL) {
cfg_system = calloc(1, sizeof(*cfg_system));
if (cfg_system == NULL)
if (host->cfg_system == NULL) {
cfg_system = calloc(1, sizeof(*cfg_system));
if (cfg_system == NULL)
/* Set default flags */
cfg_system->flags = CFG_SYSTEM_ALL;
/* Set default flags */
cfg_system->flags = CFG_SYSTEM_ALL;
host->cfg_system = NULL;
}
host->cfg_system = NULL;
}
} /* }}} int cna_config_system */
/* Corresponds to a <Host /> block. */
} /* }}} int cna_config_system */
/* Corresponds to a <Host /> block. */
host = calloc(1, sizeof(*host));
if (host == NULL)
host = calloc(1, sizeof(*host));
if (host == NULL)
host->name = NULL;
host->protocol = NA_SERVER_TRANSPORT_HTTPS;
host->name = NULL;
host->protocol = NA_SERVER_TRANSPORT_HTTPS;
host->cfg_snapvault = NULL;
host->cfg_system = NULL;
host->cfg_snapvault = NULL;
host->cfg_system = NULL;
} /* }}} host_config_t *cna_alloc_host */
static host_config_t *cna_shallow_clone_host(host_config_t *host) /* {{{ */
} /* }}} host_config_t *cna_alloc_host */
static host_config_t *cna_shallow_clone_host(host_config_t *host) /* {{{ */
host_config_t *clone;
if (host == NULL)
host_config_t *clone;
if (host == NULL)
clone = cna_alloc_host();
if (clone == NULL)
clone = cna_alloc_host();
if (clone == NULL)
if (host->name != NULL) {
clone->name = strdup(host->name);
if (host->name != NULL) {
clone->name = strdup(host->name);
clone->interval = host->interval;
clone->interval = host->interval;
} /* }}} host_config_t *cna_shallow_clone_host */
static int cna_read(user_data_t *ud);
} /* }}} host_config_t *cna_shallow_clone_host */
static int cna_read(user_data_t *ud);
.data = host, .free_func = (void *)free_host_config,
});
.data = host, .free_func = (void *)free_host_config,
});
} /* }}} int cna_register_host */
static int cna_config_host(host_config_t *host, /* {{{ */
} /* }}} int cna_register_host */
static int cna_config_host(host_config_t *host, /* {{{ */
WARNING("netapp plugin: \"%s\" needs exactly one string argument. Ignoring "
"host block.",
ci->key);
WARNING("netapp plugin: \"%s\" needs exactly one string argument. Ignoring "
"host block.",
ci->key);
}
status = cf_util_get_string(ci, &host->name);
if (status != 0)
}
status = cf_util_get_string(ci, &host->name);
if (status != 0)
for (int i = 0; i < ci->children_num; ++i) {
item = ci->children + i;
for (int i = 0; i < ci->children_num; ++i) {
item = ci->children + i;
WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or "
"\"https\". Ignoring host block \"%s\".",
ci->values[0].value.string);
WARNING("netapp plugin: \"Protocol\" needs to be either \"http\" or "
"\"https\". Ignoring host block \"%s\".",
ci->values[0].value.string);
}
if (!strcasecmp(item->values[0].value.string, "http"))
host->protocol = NA_SERVER_TRANSPORT_HTTP;
}
if (!strcasecmp(item->values[0].value.string, "http"))
host->protocol = NA_SERVER_TRANSPORT_HTTP;
if (status != 0)
return status;
if (status != 0)
return status;
} /* }}} host_config_t *cna_config_host */
/*
} /* }}} host_config_t *cna_config_host */
/*
int major_version = 1, minor_version = 1;
if (host == NULL)
int major_version = 1, minor_version = 1;
if (host == NULL)
if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
minor_version = 7;
if (host->vfiler != NULL) /* Request version 1.7 of the ONTAP API */
minor_version = 7;
host->srv = na_server_open(host->host, major_version, minor_version);
if (host->srv == NULL) {
ERROR("netapp plugin: na_server_open (%s) failed.", host->host);
host->srv = na_server_open(host->host, major_version, minor_version);
if (host->srv == NULL) {
ERROR("netapp plugin: na_server_open (%s) failed.", host->host);
}
na_server_set_transport_type(host->srv, host->protocol,
}
na_server_set_transport_type(host->srv, host->protocol,
if (!na_server_set_vfiler(host->srv, host->vfiler)) {
ERROR("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
host->vfiler, host->host);
if (!na_server_set_vfiler(host->srv, host->vfiler)) {
ERROR("netapp plugin: Failed to connect to VFiler '%s' on host '%s'.",
host->vfiler, host->host);
} else {
INFO("netapp plugin: Connected to VFiler '%s' on host '%s'.",
host->vfiler, host->host);
}
}
} else {
INFO("netapp plugin: Connected to VFiler '%s' on host '%s'.",
host->vfiler, host->host);
}
}
} /* }}} int cna_init_host */
static int cna_init(void) /* {{{ */
} /* }}} int cna_init_host */
static int cna_init(void) /* {{{ */
} /* }}} cna_init */
static int cna_read_internal(host_config_t *host) { /* {{{ */
} /* }}} cna_init */
static int cna_read_internal(host_config_t *host) { /* {{{ */
status = cna_query_wafl(host);
if (status != 0)
status = cna_query_wafl(host);
if (status != 0)
status = cna_query_disk(host);
if (status != 0)
status = cna_query_disk(host);
if (status != 0)
status = cna_query_volume_perf(host);
if (status != 0)
status = cna_query_volume_perf(host);
if (status != 0)
status = cna_query_volume_usage(host);
if (status != 0)
status = cna_query_volume_usage(host);
if (status != 0)
status = cna_query_quota(host);
if (status != 0)
status = cna_query_quota(host);
if (status != 0)
status = cna_query_snapvault(host);
if (status != 0)
status = cna_query_snapvault(host);
if (status != 0)
status = cna_query_system(host);
if (status != 0)
status = cna_query_system(host);
if (status != 0)
return 0;
} /* }}} int cna_read_internal */
return 0;
} /* }}} int cna_read_internal */
int status;
if ((ud == NULL) || (ud->data == NULL))
int status;
if ((ud == NULL) || (ud->data == NULL))
host = ud->data;
status = cna_init_host(host);
if (status != 0)
host = ud->data;
status = cna_init_host(host);
if (status != 0)
status = cna_read_internal(host);
if (status != 0) {
status = cna_read_internal(host);
if (status != 0) {
/* Clean up system resources and stuff. */
na_shutdown();
/* Clean up system resources and stuff. */
na_shutdown();
} /* }}} int cna_shutdown */
void module_register(void) {
} /* }}} int cna_shutdown */
void module_register(void) {
entry = calloc(1, sizeof(*entry));
if (entry == NULL)
entry = calloc(1, sizeof(*entry));
if (entry == NULL)
if (strcasecmp(dev, "All") != 0) {
entry->device = strdup(dev);
if (entry->device == NULL) {
sfree(entry);
if (strcasecmp(dev, "All") != 0) {
entry->device = strdup(dev);
if (entry->device == NULL) {
sfree(entry);
if (entry->type == NULL) {
sfree(entry->device);
sfree(entry);
if (entry->type == NULL) {
sfree(entry->device);
sfree(entry);
sfree(entry->type);
sfree(entry->device);
sfree(entry);
sfree(entry->type);
sfree(entry->device);
sfree(entry);
}
}
entry->next = ir_ignorelist_head;
ir_ignorelist_head = entry;
}
}
entry->next = ir_ignorelist_head;
ir_ignorelist_head = entry;
} /* int add_ignorelist */
/*
} /* int add_ignorelist */
/*
assert((dev != NULL) && (type != NULL));
if (ir_ignorelist_head == NULL)
assert((dev != NULL) && (type != NULL));
if (ir_ignorelist_head == NULL)
- return (ir_ignorelist_invert ? 0 : 1);
+ return ir_ignorelist_invert ? 0 : 1;
for (ir_ignorelist_t *i = ir_ignorelist_head; i != NULL; i = i->next) {
/* i->device == NULL => match all devices */
for (ir_ignorelist_t *i = ir_ignorelist_head; i != NULL; i = i->next) {
/* i->device == NULL => match all devices */
i->device == NULL ? "(nil)" : i->device, i->type,
i->inst == NULL ? "(nil)" : i->inst);
i->device == NULL ? "(nil)" : i->device, i->type,
i->inst == NULL ? "(nil)" : i->inst);
- return (ir_ignorelist_invert ? 0 : 1);
+ return ir_ignorelist_invert ? 0 : 1;
- return (ir_ignorelist_invert);
+ return ir_ignorelist_invert;
} /* int check_ignorelist */
static void submit_one(const char *dev, const char *type,
} /* int check_ignorelist */
static void submit_one(const char *dev, const char *type,
temp = realloc(iflist, (msg->ifi_index + 1) * sizeof(char *));
if (temp == NULL) {
ERROR("netlink plugin: update_iflist: realloc failed.");
temp = realloc(iflist, (msg->ifi_index + 1) * sizeof(char *));
if (temp == NULL) {
ERROR("netlink plugin: update_iflist: realloc failed.");
}
memset(temp + iflist_len, '\0',
}
memset(temp + iflist_len, '\0',
iflist[msg->ifi_index] = strdup(dev);
}
iflist[msg->ifi_index] = strdup(dev);
}
} /* int update_iflist */
static void check_ignorelist_and_submit(const char *dev,
} /* int update_iflist */
static void check_ignorelist_and_submit(const char *dev,
if (kind == NULL) {
ERROR("netlink plugin: qos_filter_cb: kind == NULL");
if (kind == NULL) {
ERROR("netlink plugin: qos_filter_cb: kind == NULL");
new_val = strdup(value);
if (new_val == NULL)
new_val = strdup(value);
if (new_val == NULL)
fields_num = strsplit(new_val, fields, STATIC_ARRAY_SIZE(fields));
if ((fields_num < 1) || (fields_num > 8)) {
sfree(new_val);
fields_num = strsplit(new_val, fields, STATIC_ARRAY_SIZE(fields));
if ((fields_num < 1) || (fields_num > 8)) {
sfree(new_val);
}
if ((strcasecmp(key, "Interface") == 0) ||
}
if ((strcasecmp(key, "Interface") == 0) ||
ERROR("netlink plugin: Invalid number of fields for option "
"`%s'. Got %i, expected 1 or 2.",
key, fields_num);
ERROR("netlink plugin: Invalid number of fields for option "
"`%s'. Got %i, expected 1 or 2.",
key, fields_num);
} else {
add_ignorelist(fields[0], key, (fields_num == 2) ? fields[1] : NULL);
status = 0;
} else {
add_ignorelist(fields[0], key, (fields_num == 2) ? fields[1] : NULL);
status = 0;
} /* int ir_config */
static int ir_init(void) {
nl = mnl_socket_open(NETLINK_ROUTE);
if (nl == NULL) {
ERROR("netlink plugin: ir_init: mnl_socket_open failed.");
} /* int ir_config */
static int ir_init(void) {
nl = mnl_socket_open(NETLINK_ROUTE);
if (nl == NULL) {
ERROR("netlink plugin: ir_init: mnl_socket_open failed.");
}
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
ERROR("netlink plugin: ir_init: mnl_socket_bind failed.");
}
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
ERROR("netlink plugin: ir_init: mnl_socket_bind failed.");
} /* int ir_init */
static int ir_read(void) {
} /* int ir_init */
static int ir_read(void) {
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
ERROR("netlink plugin: ir_read: rtnl_wilddump_request failed.");
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
ERROR("netlink plugin: ir_read: rtnl_wilddump_request failed.");
}
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
}
if (ret < 0) {
ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed.");
}
if (ret < 0) {
ERROR("netlink plugin: ir_read: mnl_socket_recvfrom failed.");
}
/* `link_filter_cb' will update `iflist' which is used here to iterate
}
/* `link_filter_cb' will update `iflist' which is used here to iterate
} /* for (type_index) */
} /* for (if_index) */
} /* for (type_index) */
} /* for (if_index) */
} /* int ir_read */
static int ir_shutdown(void) {
} /* int ir_read */
static int ir_shutdown(void) {
} /* int ir_shutdown */
void module_register(void) {
} /* int ir_shutdown */
void module_register(void) {
/* This is a value we already sent. Don't allow it to be received again in
* order to avoid looping. */
if ((status == 0) && (time_sent >= ((uint64_t)vl->time)))
/* This is a value we already sent. Don't allow it to be received again in
* order to avoid looping. */
if ((status == 0) && (time_sent >= ((uint64_t)vl->time)))
} /* }}} _Bool check_receive_okay */
static _Bool check_send_okay(const value_list_t *vl) /* {{{ */
} /* }}} _Bool check_receive_okay */
static _Bool check_send_okay(const value_list_t *vl) /* {{{ */
int status;
if (network_config_forward)
int status;
if (network_config_forward)
status = meta_data_get_boolean(vl->meta, "network:received", &received);
if (status == -ENOENT)
status = meta_data_get_boolean(vl->meta, "network:received", &received);
if (status == -ENOENT)
else if (status != 0) {
ERROR("network plugin: check_send_okay: meta_data_get_boolean failed "
"with status %i.",
status);
else if (status != 0) {
ERROR("network plugin: check_send_okay: meta_data_get_boolean failed "
"with status %i.",
status);
}
/* By default, only *send* value lists that were not *received* by the
* network plugin. */
}
/* By default, only *send* value lists that were not *received* by the
* network plugin. */
} /* }}} _Bool check_send_okay */
static _Bool check_notify_received(const notification_t *n) /* {{{ */
} /* }}} _Bool check_send_okay */
static _Bool check_notify_received(const notification_t *n) /* {{{ */
for (notification_meta_t *ptr = n->meta; ptr != NULL; ptr = ptr->next)
if ((strcmp("network:received", ptr->name) == 0) &&
(ptr->type == NM_TYPE_BOOLEAN))
for (notification_meta_t *ptr = n->meta; ptr != NULL; ptr = ptr->next)
if ((strcmp("network:received", ptr->name) == 0) &&
(ptr->type == NM_TYPE_BOOLEAN))
- return ((_Bool)ptr->nm_value.nm_boolean);
+ return (_Bool)ptr->nm_value.nm_boolean;
} /* }}} _Bool check_notify_received */
static _Bool check_send_notify_okay(const notification_t *n) /* {{{ */
} /* }}} _Bool check_notify_received */
static _Bool check_send_notify_okay(const notification_t *n) /* {{{ */
_Bool received = 0;
if (n->meta == NULL)
_Bool received = 0;
if (n->meta == NULL)
received = check_notify_received(n);
received = check_notify_received(n);
/* By default, only *send* value lists that were not *received* by the
* network plugin. */
/* By default, only *send* value lists that were not *received* by the
* network plugin. */
} /* }}} _Bool check_send_notify_okay */
static int network_dispatch_values(value_list_t *vl, /* {{{ */
} /* }}} _Bool check_send_notify_okay */
static int network_dispatch_values(value_list_t *vl, /* {{{ */
if ((vl->time == 0) || (strlen(vl->host) == 0) || (strlen(vl->plugin) == 0) ||
(strlen(vl->type) == 0))
if ((vl->time == 0) || (strlen(vl->host) == 0) || (strlen(vl->plugin) == 0) ||
(strlen(vl->type) == 0))
if (!check_receive_okay(vl)) {
#if COLLECT_DEBUG
if (!check_receive_okay(vl)) {
#if COLLECT_DEBUG
name);
#endif
stats_values_not_dispatched++;
name);
#endif
stats_values_not_dispatched++;
}
assert(vl->meta == NULL);
}
assert(vl->meta == NULL);
vl->meta = meta_data_create();
if (vl->meta == NULL) {
ERROR("network plugin: meta_data_create failed.");
vl->meta = meta_data_create();
if (vl->meta == NULL) {
ERROR("network plugin: meta_data_create failed.");
}
status = meta_data_add_boolean(vl->meta, "network:received", 1);
}
status = meta_data_add_boolean(vl->meta, "network:received", 1);
ERROR("network plugin: meta_data_add_boolean failed.");
meta_data_destroy(vl->meta);
vl->meta = NULL;
ERROR("network plugin: meta_data_add_boolean failed.");
meta_data_destroy(vl->meta);
vl->meta = NULL;
}
if (username != NULL) {
}
if (username != NULL) {
ERROR("network plugin: meta_data_add_string failed.");
meta_data_destroy(vl->meta);
vl->meta = NULL;
ERROR("network plugin: meta_data_add_string failed.");
meta_data_destroy(vl->meta);
vl->meta = NULL;
meta_data_destroy(vl->meta);
vl->meta = NULL;
meta_data_destroy(vl->meta);
vl->meta = NULL;
} /* }}} int network_dispatch_values */
static int network_dispatch_notification(notification_t *n) /* {{{ */
} /* }}} int network_dispatch_values */
static int network_dispatch_notification(notification_t *n) /* {{{ */
ERROR("network plugin: plugin_notification_meta_add_boolean failed.");
plugin_notification_meta_free(n->meta);
n->meta = NULL;
ERROR("network plugin: plugin_notification_meta_add_boolean failed.");
plugin_notification_meta_free(n->meta);
n->meta = NULL;
}
status = plugin_dispatch_notification(n);
}
status = plugin_dispatch_notification(n);
plugin_notification_meta_free(n->meta);
n->meta = NULL;
plugin_notification_meta_free(n->meta);
n->meta = NULL;
} /* }}} int network_dispatch_notification */
#if HAVE_GCRYPT_H
} /* }}} int network_dispatch_notification */
#if HAVE_GCRYPT_H
* Because you can't know in a library whether another library has
* already initialized the library */
if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P))
* Because you can't know in a library whether another library has
* already initialized the library */
if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P))
/* http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html
* To ensure thread-safety, it's important to set GCRYCTL_SET_THREAD_CBS
/* http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html
* To ensure thread-safety, it's important to set GCRYCTL_SET_THREAD_CBS
if (err) {
ERROR("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s",
gcry_strerror(err));
if (err) {
ERROR("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s",
gcry_strerror(err));
if (err) {
ERROR("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s",
gcry_strerror(err));
if (err) {
ERROR("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s",
gcry_strerror(err));
}
gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
}
gcry_control(GCRYCTL_INITIALIZATION_FINISHED);
} /* }}} int network_init_gcrypt */
static gcry_cipher_hd_t network_get_aes256_cypher(sockent_t *se, /* {{{ */
} /* }}} int network_init_gcrypt */
static gcry_cipher_hd_t network_get_aes256_cypher(sockent_t *se, /* {{{ */
cyper_ptr = &se->data.server.cypher;
if (username == NULL)
cyper_ptr = &se->data.server.cypher;
if (username == NULL)
secret = fbh_get(se->data.server.userdb, username);
if (secret == NULL)
secret = fbh_get(se->data.server.userdb, username);
if (secret == NULL)
gcry_md_hash_buffer(GCRY_MD_SHA256, password_hash, secret, strlen(secret));
gcry_md_hash_buffer(GCRY_MD_SHA256, password_hash, secret, strlen(secret));
ERROR("network plugin: gcry_cipher_open returned: %s",
gcry_strerror(err));
*cyper_ptr = NULL;
ERROR("network plugin: gcry_cipher_open returned: %s",
gcry_strerror(err));
*cyper_ptr = NULL;
}
} else {
gcry_cipher_reset(*cyper_ptr);
}
} else {
gcry_cipher_reset(*cyper_ptr);
gcry_strerror(err));
gcry_cipher_close(*cyper_ptr);
*cyper_ptr = NULL;
gcry_strerror(err));
gcry_cipher_close(*cyper_ptr);
*cyper_ptr = NULL;
}
err = gcry_cipher_setiv(*cyper_ptr, iv, iv_size);
}
err = gcry_cipher_setiv(*cyper_ptr, iv, iv_size);
gcry_strerror(err));
gcry_cipher_close(*cyper_ptr);
*cyper_ptr = NULL;
gcry_strerror(err));
gcry_cipher_close(*cyper_ptr);
*cyper_ptr = NULL;
} /* }}} int network_get_aes256_cypher */
#endif /* HAVE_GCRYPT_H */
} /* }}} int network_get_aes256_cypher */
#endif /* HAVE_GCRYPT_H */
(num_values * sizeof(uint8_t)) + (num_values * sizeof(value_t));
if (*ret_buffer_len < packet_len)
(num_values * sizeof(uint8_t)) + (num_values * sizeof(value_t));
if (*ret_buffer_len < packet_len)
pkg_values_types = malloc(num_values * sizeof(*pkg_values_types));
if (pkg_values_types == NULL) {
ERROR("network plugin: write_part_values: malloc failed.");
pkg_values_types = malloc(num_values * sizeof(*pkg_values_types));
if (pkg_values_types == NULL) {
ERROR("network plugin: write_part_values: malloc failed.");
}
pkg_values = malloc(num_values * sizeof(*pkg_values));
if (pkg_values == NULL) {
free(pkg_values_types);
ERROR("network plugin: write_part_values: malloc failed.");
}
pkg_values = malloc(num_values * sizeof(*pkg_values));
if (pkg_values == NULL) {
free(pkg_values_types);
ERROR("network plugin: write_part_values: malloc failed.");
}
pkg_ph.type = htons(TYPE_VALUES);
}
pkg_ph.type = htons(TYPE_VALUES);
ERROR("network plugin: write_part_values: "
"Unknown data source type: %i",
ds->ds[i].type);
ERROR("network plugin: write_part_values: "
"Unknown data source type: %i",
ds->ds[i].type);
} /* switch (ds->ds[i].type) */
} /* for (num_values) */
} /* switch (ds->ds[i].type) */
} /* for (num_values) */
free(pkg_values_types);
free(pkg_values);
free(pkg_values_types);
free(pkg_values);
} /* int write_part_values */
static int write_part_number(char **ret_buffer, size_t *ret_buffer_len,
} /* int write_part_values */
static int write_part_number(char **ret_buffer, size_t *ret_buffer_len,
packet_len = sizeof(pkg_head) + sizeof(pkg_value);
if (*ret_buffer_len < packet_len)
packet_len = sizeof(pkg_head) + sizeof(pkg_value);
if (*ret_buffer_len < packet_len)
pkg_head.type = htons(type);
pkg_head.length = htons(packet_len);
pkg_head.type = htons(type);
pkg_head.length = htons(packet_len);
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
*ret_buffer = packet_ptr + packet_len;
*ret_buffer_len -= packet_len;
} /* int write_part_number */
static int write_part_string(char **ret_buffer, size_t *ret_buffer_len,
} /* int write_part_number */
static int write_part_string(char **ret_buffer, size_t *ret_buffer_len,
buffer_len = 2 * sizeof(uint16_t) + str_len + 1;
if (*ret_buffer_len < buffer_len)
buffer_len = 2 * sizeof(uint16_t) + str_len + 1;
if (*ret_buffer_len < buffer_len)
pkg_type = htons(type);
pkg_length = htons(buffer_len);
pkg_type = htons(type);
pkg_length = htons(buffer_len);
*ret_buffer = buffer + buffer_len;
*ret_buffer_len -= buffer_len;
*ret_buffer = buffer + buffer_len;
*ret_buffer_len -= buffer_len;
} /* int write_part_string */
static int parse_part_values(void **ret_buffer, size_t *ret_buffer_len,
} /* int write_part_string */
static int parse_part_values(void **ret_buffer, size_t *ret_buffer_len,
NOTICE("network plugin: packet is too short: "
"buffer_len = %zu",
buffer_len);
NOTICE("network plugin: packet is too short: "
"buffer_len = %zu",
buffer_len);
}
memcpy((void *)&tmp16, buffer, sizeof(tmp16));
}
memcpy((void *)&tmp16, buffer, sizeof(tmp16));
"Chunk of size %zu expected, "
"but buffer has only %zu bytes left.",
exp_size, buffer_len);
"Chunk of size %zu expected, "
"but buffer has only %zu bytes left.",
exp_size, buffer_len);
}
assert(pkg_numval <= ((buffer_len - 6) / 9));
}
assert(pkg_numval <= ((buffer_len - 6) / 9));
WARNING("network plugin: parse_part_values: "
"Length and number of values "
"in the packet don't match.");
WARNING("network plugin: parse_part_values: "
"Length and number of values "
"in the packet don't match.");
}
pkg_types = calloc(pkg_numval, sizeof(*pkg_types));
}
pkg_types = calloc(pkg_numval, sizeof(*pkg_types));
sfree(pkg_types);
sfree(pkg_values);
ERROR("network plugin: parse_part_values: calloc failed.");
sfree(pkg_types);
sfree(pkg_values);
ERROR("network plugin: parse_part_values: calloc failed.");
}
memcpy(pkg_types, buffer, pkg_numval * sizeof(*pkg_types));
}
memcpy(pkg_types, buffer, pkg_numval * sizeof(*pkg_types));
pkg_types[i]);
sfree(pkg_types);
sfree(pkg_values);
pkg_types[i]);
sfree(pkg_types);
sfree(pkg_values);
} /* switch (pkg_types[i]) */
}
} /* switch (pkg_types[i]) */
}
} /* int parse_part_values */
static int parse_part_number(void **ret_buffer, size_t *ret_buffer_len,
} /* int parse_part_values */
static int parse_part_number(void **ret_buffer, size_t *ret_buffer_len,
"Chunk of size %zu expected, "
"but buffer has only %zu bytes left.",
exp_size, buffer_len);
"Chunk of size %zu expected, "
"but buffer has only %zu bytes left.",
exp_size, buffer_len);
}
memcpy((void *)&tmp16, buffer, sizeof(tmp16));
}
memcpy((void *)&tmp16, buffer, sizeof(tmp16));
*ret_buffer = buffer;
*ret_buffer_len = buffer_len - pkg_length;
*ret_buffer = buffer;
*ret_buffer_len = buffer_len - pkg_length;
} /* int parse_part_number */
static int parse_part_string(void **ret_buffer, size_t *ret_buffer_len,
} /* int parse_part_number */
static int parse_part_string(void **ret_buffer, size_t *ret_buffer_len,
size_t payload_size;
if (output_len == 0)
size_t payload_size;
if (output_len == 0)
if (buffer_len < header_size) {
WARNING("network plugin: parse_part_string: "
if (buffer_len < header_size) {
WARNING("network plugin: parse_part_string: "
"Chunk of at least size %zu expected, "
"but buffer has only %zu bytes left.",
header_size, buffer_len);
"Chunk of at least size %zu expected, "
"but buffer has only %zu bytes left.",
header_size, buffer_len);
}
memcpy((void *)&tmp16, buffer, sizeof(tmp16));
}
memcpy((void *)&tmp16, buffer, sizeof(tmp16));
"Chunk of size %" PRIu16 " received, "
"but buffer has only %zu bytes left.",
pkg_length, buffer_len);
"Chunk of size %" PRIu16 " received, "
"but buffer has only %zu bytes left.",
pkg_length, buffer_len);
}
/* Check that pkg_length is in the valid range */
}
/* Check that pkg_length is in the valid range */
"Header claims this packet is only %hu "
"bytes long.",
pkg_length);
"Header claims this packet is only %hu "
"bytes long.",
pkg_length);
}
/* Check that the package data fits into the output buffer.
}
/* Check that the package data fits into the output buffer.
"which is too small to hold the received "
"%zu byte string.",
output_len, payload_size);
"which is too small to hold the received "
"%zu byte string.",
output_len, payload_size);
}
/* All sanity checks successfull, let's copy the data over */
}
/* All sanity checks successfull, let's copy the data over */
WARNING("network plugin: parse_part_string: "
"Received string does not end "
"with a NULL-byte.");
WARNING("network plugin: parse_part_string: "
"Received string does not end "
"with a NULL-byte.");
}
*ret_buffer = buffer;
*ret_buffer_len = buffer_len - pkg_length;
}
*ret_buffer = buffer;
*ret_buffer_len = buffer_len - pkg_length;
} /* int parse_part_string */
/* Forward declaration: parse_part_sign_sha256 and parse_part_encr_aes256 call
} /* int parse_part_string */
/* Forward declaration: parse_part_sign_sha256 and parse_part_encr_aes256 call
/* Check if the buffer has enough data for this structure. */
if (buffer_len <= PART_SIGNATURE_SHA256_SIZE)
/* Check if the buffer has enough data for this structure. */
if (buffer_len <= PART_SIGNATURE_SHA256_SIZE)
/* Read type and length header */
BUFFER_READ(&pss.head.type, sizeof(pss.head.type));
/* Read type and length header */
BUFFER_READ(&pss.head.type, sizeof(pss.head.type));
if ((pss_head_length <= PART_SIGNATURE_SHA256_SIZE) ||
(pss_head_length > buffer_len)) {
ERROR("network plugin: HMAC-SHA-256 with invalid length received.");
if ((pss_head_length <= PART_SIGNATURE_SHA256_SIZE) ||
(pss_head_length > buffer_len)) {
ERROR("network plugin: HMAC-SHA-256 with invalid length received.");
}
if (se->data.server.userdb == NULL) {
}
if (se->data.server.userdb == NULL) {
*ret_buffer = buffer + pss_head_length;
*ret_buffer_len -= pss_head_length;
*ret_buffer = buffer + pss_head_length;
*ret_buffer_len -= pss_head_length;
username_len = pss_head_length - PART_SIGNATURE_SHA256_SIZE;
pss.username = malloc(username_len + 1);
if (pss.username == NULL)
username_len = pss_head_length - PART_SIGNATURE_SHA256_SIZE;
pss.username = malloc(username_len + 1);
if (pss.username == NULL)
/* Read the username */
BUFFER_READ(pss.username, username_len);
/* Read the username */
BUFFER_READ(pss.username, username_len);
if (secret == NULL) {
ERROR("network plugin: Unknown user: %s", pss.username);
sfree(pss.username);
if (secret == NULL) {
ERROR("network plugin: Unknown user: %s", pss.username);
sfree(pss.username);
}
/* Create a hash device and check the HMAC */
}
/* Create a hash device and check the HMAC */
gcry_strerror(err));
sfree(secret);
sfree(pss.username);
gcry_strerror(err));
sfree(secret);
sfree(pss.username);
}
err = gcry_md_setkey(hd, secret, strlen(secret));
}
err = gcry_md_setkey(hd, secret, strlen(secret));
gcry_md_close(hd);
sfree(secret);
sfree(pss.username);
gcry_md_close(hd);
sfree(secret);
sfree(pss.username);
}
gcry_md_write(hd, buffer + PART_SIGNATURE_SHA256_SIZE,
}
gcry_md_write(hd, buffer + PART_SIGNATURE_SHA256_SIZE,
gcry_md_close(hd);
sfree(secret);
sfree(pss.username);
gcry_md_close(hd);
sfree(secret);
sfree(pss.username);
}
memcpy(hash, hash_ptr, sizeof(hash));
}
memcpy(hash, hash_ptr, sizeof(hash));
*ret_buffer = buffer + buffer_len;
*ret_buffer_len = 0;
*ret_buffer = buffer + buffer_len;
*ret_buffer_len = 0;
} /* }}} int parse_part_sign_sha256 */
/* #endif HAVE_GCRYPT_H */
} /* }}} int parse_part_sign_sha256 */
/* #endif HAVE_GCRYPT_H */
buffer_offset = 0;
if (buffer_size <= PART_SIGNATURE_SHA256_SIZE)
buffer_offset = 0;
if (buffer_size <= PART_SIGNATURE_SHA256_SIZE)
BUFFER_READ(&pss.head.type, sizeof(pss.head.type));
BUFFER_READ(&pss.head.length, sizeof(pss.head.length));
part_len = ntohs(pss.head.length);
if ((part_len <= PART_SIGNATURE_SHA256_SIZE) || (part_len > buffer_size))
BUFFER_READ(&pss.head.type, sizeof(pss.head.type));
BUFFER_READ(&pss.head.length, sizeof(pss.head.length));
part_len = ntohs(pss.head.length);
if ((part_len <= PART_SIGNATURE_SHA256_SIZE) || (part_len > buffer_size))
if (warning_has_been_printed == 0) {
WARNING("network plugin: Received signed packet, but the network "
if (warning_has_been_printed == 0) {
WARNING("network plugin: Received signed packet, but the network "
*ret_buffer = buffer + buffer_size;
*ret_buffer_size = 0;
*ret_buffer = buffer + buffer_size;
*ret_buffer_size = 0;
} /* }}} int parse_part_sign_sha256 */
#endif /* !HAVE_GCRYPT_H */
} /* }}} int parse_part_sign_sha256 */
#endif /* !HAVE_GCRYPT_H */
if (buffer_len <= PART_ENCRYPTION_AES256_SIZE) {
NOTICE("network plugin: parse_part_encr_aes256: "
"Discarding short packet.");
if (buffer_len <= PART_ENCRYPTION_AES256_SIZE) {
NOTICE("network plugin: parse_part_encr_aes256: "
"Discarding short packet.");
if ((part_size <= PART_ENCRYPTION_AES256_SIZE) || (part_size > buffer_len)) {
NOTICE("network plugin: parse_part_encr_aes256: "
"Discarding part with invalid size.");
if ((part_size <= PART_ENCRYPTION_AES256_SIZE) || (part_size > buffer_len)) {
NOTICE("network plugin: parse_part_encr_aes256: "
"Discarding part with invalid size.");
}
/* Read the username */
}
/* Read the username */
(username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1)))) {
NOTICE("network plugin: parse_part_encr_aes256: "
"Discarding part with invalid username length.");
(username_len > (part_size - (PART_ENCRYPTION_AES256_SIZE + 1)))) {
NOTICE("network plugin: parse_part_encr_aes256: "
"Discarding part with invalid username length.");
}
assert(username_len > 0);
pea.username = malloc(username_len + 1);
if (pea.username == NULL)
}
assert(username_len > 0);
pea.username = malloc(username_len + 1);
if (pea.username == NULL)
BUFFER_READ(pea.username, username_len);
pea.username[username_len] = 0;
BUFFER_READ(pea.username, username_len);
pea.username[username_len] = 0;
if (cypher == NULL) {
ERROR("network plugin: Failed to get cypher. Username: %s", pea.username);
sfree(pea.username);
if (cypher == NULL) {
ERROR("network plugin: Failed to get cypher. Username: %s", pea.username);
sfree(pea.username);
}
payload_len = part_size - (PART_ENCRYPTION_AES256_SIZE + username_len);
}
payload_len = part_size - (PART_ENCRYPTION_AES256_SIZE + username_len);
sfree(pea.username);
ERROR("network plugin: gcry_cipher_decrypt returned: %s. Username: %s",
gcry_strerror(err), pea.username);
sfree(pea.username);
ERROR("network plugin: gcry_cipher_decrypt returned: %s. Username: %s",
gcry_strerror(err), pea.username);
if (memcmp(hash, pea.hash, sizeof(hash)) != 0) {
ERROR("network plugin: Checksum mismatch. Username: %s", pea.username);
sfree(pea.username);
if (memcmp(hash, pea.hash, sizeof(hash)) != 0) {
ERROR("network plugin: Checksum mismatch. Username: %s", pea.username);
sfree(pea.username);
}
parse_packet(se, buffer + buffer_offset, payload_len, flags | PP_ENCRYPTED,
}
parse_packet(se, buffer + buffer_offset, payload_len, flags | PP_ENCRYPTED,
} /* }}} int parse_part_encr_aes256 */
/* #endif HAVE_GCRYPT_H */
} /* }}} int parse_part_encr_aes256 */
/* #endif HAVE_GCRYPT_H */
if ((ph_length <= PART_ENCRYPTION_AES256_SIZE) || (ph_length > buffer_size)) {
ERROR("network plugin: AES-256 encrypted part "
"with invalid length received.");
if ((ph_length <= PART_ENCRYPTION_AES256_SIZE) || (ph_length > buffer_size)) {
ERROR("network plugin: AES-256 encrypted part "
"with invalid length received.");
}
if (warning_has_been_printed == 0) {
}
if (warning_has_been_printed == 0) {
*ret_buffer = (void *)(((char *)*ret_buffer) + ph_length);
*ret_buffer_size -= ph_length;
*ret_buffer = (void *)(((char *)*ret_buffer) + ph_length);
*ret_buffer_size -= ph_length;
} /* }}} int parse_part_encr_aes256 */
#endif /* !HAVE_GCRYPT_H */
} /* }}} int parse_part_encr_aes256 */
#endif /* !HAVE_GCRYPT_H */
WARNING("network plugin: parse_packet: Received truncated "
"packet, try increasing `MaxPacketSize'");
WARNING("network plugin: parse_packet: Received truncated "
"packet, try increasing `MaxPacketSize'");
} /* }}} int parse_packet */
static void free_sockent_client(struct sockent_client *sec) /* {{{ */
} /* }}} int parse_packet */
static void free_sockent_client(struct sockent_client *sec) /* {{{ */
assert(se->type == SOCKENT_TYPE_CLIENT);
if ((network_config_ttl < 1) || (network_config_ttl > 255))
assert(se->type == SOCKENT_TYPE_CLIENT);
if ((network_config_ttl < 1) || (network_config_ttl > 255))
if (ai->ai_family == AF_INET) {
struct sockaddr_in *addr = (struct sockaddr_in *)ai->ai_addr;
if (ai->ai_family == AF_INET) {
struct sockaddr_in *addr = (struct sockaddr_in *)ai->ai_addr;
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv4-ttl): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv4-ttl): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
} else if (ai->ai_family == AF_INET6) {
/* Useful example:
}
} else if (ai->ai_family == AF_INET6) {
/* Useful example:
char errbuf[1024];
ERROR("network plugin: setsockopt(ipv6-ttl): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt(ipv6-ttl): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
} /* int network_set_ttl */
static int network_set_interface(const sockent_t *se,
} /* int network_set_ttl */
static int network_set_interface(const sockent_t *se,
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv4-multicast-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv4-multicast-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
} else if (ai->ai_family == AF_INET6) {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)ai->ai_addr;
}
} else if (ai->ai_family == AF_INET6) {
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)ai->ai_addr;
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv6-multicast-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv6-multicast-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char interface_name[IFNAMSIZ];
if (if_indextoname(se->interface, interface_name) == NULL)
char interface_name[IFNAMSIZ];
if (if_indextoname(se->interface, interface_name) == NULL)
DEBUG("network plugin: Binding socket to interface %s", interface_name);
DEBUG("network plugin: Binding socket to interface %s", interface_name);
char errbuf[1024];
ERROR("network plugin: setsockopt (bind-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (bind-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* #endif HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
}
/* #endif HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
} /* }}} network_set_interface */
static int network_bind_socket(int fd, const struct addrinfo *ai,
} /* }}} network_set_interface */
static int network_bind_socket(int fd, const struct addrinfo *ai,
char errbuf[1024];
ERROR("network plugin: setsockopt (reuseaddr): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (reuseaddr): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
DEBUG("fd = %i; calling `bind'", fd);
}
DEBUG("fd = %i; calling `bind'", fd);
if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) {
char errbuf[1024];
ERROR("bind: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if (bind(fd, ai->ai_addr, ai->ai_addrlen) == -1) {
char errbuf[1024];
ERROR("bind: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (ai->ai_family == AF_INET) {
}
if (ai->ai_family == AF_INET) {
char errbuf[1024];
ERROR("network plugin: setsockopt (multicast-loop): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (multicast-loop): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) ==
}
if (setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) ==
char errbuf[1024];
ERROR("network plugin: setsockopt (add-membership): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (add-membership): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
} else if (ai->ai_family == AF_INET6) {
/* Useful example:
}
} else if (ai->ai_family == AF_INET6) {
/* Useful example:
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv6-multicast-loop): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv6-multicast-loop): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq,
}
if (setsockopt(fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq,
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv6-add-membership): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (ipv6-add-membership): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char interface_name[IFNAMSIZ];
if (if_indextoname(interface_idx, interface_name) == NULL)
char interface_name[IFNAMSIZ];
if (if_indextoname(interface_idx, interface_name) == NULL)
DEBUG("fd = %i; Binding socket to interface %s", fd, interface_name);
DEBUG("fd = %i; Binding socket to interface %s", fd, interface_name);
char errbuf[1024];
ERROR("network plugin: setsockopt (bind-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("network plugin: setsockopt (bind-if): %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
}
#endif /* HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
}
}
#endif /* HAVE_IF_INDEXTONAME && SO_BINDTODEVICE */
} /* int network_bind_socket */
/* Initialize a sockent structure. `type' must be either `SOCKENT_TYPE_CLIENT'
} /* int network_bind_socket */
/* Initialize a sockent structure. `type' must be either `SOCKENT_TYPE_CLIENT'
sockent_t *se;
if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER))
sockent_t *se;
if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER))
se = calloc(1, sizeof(*se));
if (se == NULL)
se = calloc(1, sizeof(*se));
if (se == NULL)
se->type = type;
se->node = NULL;
se->type = type;
se->node = NULL;
} /* }}} sockent_t *sockent_create */
static int sockent_init_crypto(sockent_t *se) /* {{{ */
} /* }}} sockent_t *sockent_create */
static int sockent_init_crypto(sockent_t *se) /* {{{ */
if (network_init_gcrypt() < 0) {
ERROR("network plugin: Cannot configure client socket with "
"security: Failed to initialize crypto library.");
if (network_init_gcrypt() < 0) {
ERROR("network plugin: Cannot configure client socket with "
"security: Failed to initialize crypto library.");
}
if ((se->data.client.username == NULL) ||
}
if ((se->data.client.username == NULL) ||
ERROR("network plugin: Client socket with "
"security requested, but no "
"credentials are configured.");
ERROR("network plugin: Client socket with "
"security requested, but no "
"credentials are configured.");
}
gcry_md_hash_buffer(GCRY_MD_SHA256, se->data.client.password_hash,
se->data.client.password,
}
gcry_md_hash_buffer(GCRY_MD_SHA256, se->data.client.password_hash,
se->data.client.password,
(se->data.server.auth_file == NULL)) {
ERROR("network plugin: Server socket with security requested, "
"but no \"AuthFile\" is configured.");
(se->data.server.auth_file == NULL)) {
ERROR("network plugin: Server socket with security requested, "
"but no \"AuthFile\" is configured.");
}
if (se->data.server.auth_file != NULL) {
if (network_init_gcrypt() < 0) {
ERROR("network plugin: Cannot configure server socket with security: "
"Failed to initialize crypto library.");
}
if (se->data.server.auth_file != NULL) {
if (network_init_gcrypt() < 0) {
ERROR("network plugin: Cannot configure server socket with security: "
"Failed to initialize crypto library.");
}
se->data.server.userdb = fbh_create(se->data.server.auth_file);
if (se->data.server.userdb == NULL) {
ERROR("network plugin: Reading password file \"%s\" failed.",
se->data.server.auth_file);
}
se->data.server.userdb = fbh_create(se->data.server.auth_file);
if (se->data.server.userdb == NULL) {
ERROR("network plugin: Reading password file \"%s\" failed.",
se->data.server.auth_file);
}
}
}
#endif /* }}} HAVE_GCRYPT_H */
}
}
}
#endif /* }}} HAVE_GCRYPT_H */
} /* }}} int sockent_init_crypto */
static int sockent_client_disconnect(sockent_t *se) /* {{{ */
} /* }}} int sockent_init_crypto */
static int sockent_client_disconnect(sockent_t *se) /* {{{ */
struct sockent_client *client;
if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
struct sockent_client *client;
if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
client = &se->data.client;
if (client->fd >= 0) /* connected */
client = &se->data.client;
if (client->fd >= 0) /* connected */
sfree(client->addr);
client->addrlen = 0;
sfree(client->addr);
client->addrlen = 0;
} /* }}} int sockent_client_disconnect */
static int sockent_client_connect(sockent_t *se) /* {{{ */
} /* }}} int sockent_client_disconnect */
static int sockent_client_connect(sockent_t *se) /* {{{ */
cdtime_t now;
if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
cdtime_t now;
if ((se == NULL) || (se->type != SOCKENT_TYPE_CLIENT))
client = &se->data.client;
client = &se->data.client;
}
if (client->fd >= 0 && !reconnect) /* already connected and not stale*/
}
if (client->fd >= 0 && !reconnect) /* already connected and not stale*/
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG,
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC,
.ai_flags = AI_ADDRCONFIG,
LOG_ERR, &complaint, "network plugin: getaddrinfo (%s, %s) failed: %s",
(se->node == NULL) ? "(null)" : se->node,
(se->service == NULL) ? "(null)" : se->service, gai_strerror(status));
LOG_ERR, &complaint, "network plugin: getaddrinfo (%s, %s) failed: %s",
(se->node == NULL) ? "(null)" : se->node,
(se->service == NULL) ? "(null)" : se->service, gai_strerror(status));
} else {
c_release(LOG_NOTICE, &complaint,
"network plugin: Successfully resolved \"%s\".", se->node);
} else {
c_release(LOG_NOTICE, &complaint,
"network plugin: Successfully resolved \"%s\".", se->node);
freeaddrinfo(ai_list);
if (client->fd < 0)
freeaddrinfo(ai_list);
if (client->fd < 0)
if (client->resolve_interval > 0)
client->next_resolve_reconnect = now + client->resolve_interval;
if (client->resolve_interval > 0)
client->next_resolve_reconnect = now + client->resolve_interval;
} /* }}} int sockent_client_connect */
/* Open the file descriptors for a initialized sockent structure. */
} /* }}} int sockent_client_connect */
/* Open the file descriptors for a initialized sockent structure. */
const char *service;
if (se == NULL)
const char *service;
if (se == NULL)
assert(se->data.server.fd == NULL);
assert(se->data.server.fd_num == 0);
assert(se->data.server.fd == NULL);
assert(se->data.server.fd_num == 0);
ERROR("network plugin: getaddrinfo (%s, %s) failed: %s",
(se->node == NULL) ? "(null)" : se->node,
(se->service == NULL) ? "(null)" : se->service, gai_strerror(status));
ERROR("network plugin: getaddrinfo (%s, %s) failed: %s",
(se->node == NULL) ? "(null)" : se->node,
(se->service == NULL) ? "(null)" : se->service, gai_strerror(status));
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
freeaddrinfo(ai_list);
if (se->data.server.fd_num == 0)
freeaddrinfo(ai_list);
if (se->data.server.fd_num == 0)
- return (-1);
- return (0);
} /* }}} int sockent_server_listen */
/* Add a sockent to the global list of sockets */
} /* }}} int sockent_server_listen */
/* Add a sockent to the global list of sockets */
sockent_t *last_ptr;
if (se == NULL)
sockent_t *last_ptr;
if (se == NULL)
if (se->type == SOCKENT_TYPE_SERVER) {
struct pollfd *tmp;
if (se->type == SOCKENT_TYPE_SERVER) {
struct pollfd *tmp;
sizeof(*tmp) * (listen_sockets_num + se->data.server.fd_num));
if (tmp == NULL) {
ERROR("network plugin: realloc failed.");
sizeof(*tmp) * (listen_sockets_num + se->data.server.fd_num));
if (tmp == NULL) {
ERROR("network plugin: realloc failed.");
}
listen_sockets_pollfd = tmp;
tmp = listen_sockets_pollfd + listen_sockets_num;
}
listen_sockets_pollfd = tmp;
tmp = listen_sockets_pollfd + listen_sockets_num;
if (listen_sockets == NULL) {
listen_sockets = se;
if (listen_sockets == NULL) {
listen_sockets = se;
}
last_ptr = listen_sockets;
} else /* if (se->type == SOCKENT_TYPE_CLIENT) */
{
if (sending_sockets == NULL) {
sending_sockets = se;
}
last_ptr = listen_sockets;
} else /* if (se->type == SOCKENT_TYPE_CLIENT) */
{
if (sending_sockets == NULL) {
sending_sockets = se;
}
last_ptr = sending_sockets;
}
}
last_ptr = sending_sockets;
}
last_ptr = last_ptr->next;
last_ptr->next = se;
last_ptr = last_ptr->next;
last_ptr->next = se;
} /* }}} int sockent_add */
static void *dispatch_thread(void __attribute__((unused)) * arg) /* {{{ */
} /* }}} int sockent_add */
static void *dispatch_thread(void __attribute__((unused)) * arg) /* {{{ */
sfree(ent);
} /* while (42) */
sfree(ent);
} /* while (42) */
} /* }}} void *dispatch_thread */
static int network_receive(void) /* {{{ */
} /* }}} void *dispatch_thread */
static int network_receive(void) /* {{{ */
pthread_mutex_unlock(&receive_list_lock);
}
pthread_mutex_unlock(&receive_list_lock);
}
} /* }}} int network_receive */
static void *receive_thread(void __attribute__((unused)) * arg) {
} /* }}} int network_receive */
static void *receive_thread(void __attribute__((unused)) * arg) {
- return (network_receive() ? (void *)1 : (void *)0);
+ return network_receive() ? (void *)1 : (void *)0;
} /* void *receive_thread */
static void network_init_buffer(void) {
} /* void *receive_thread */
static void network_init_buffer(void) {
if (strcmp(vl_def->host, vl->host) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_HOST, vl->host,
strlen(vl->host)) != 0)
if (strcmp(vl_def->host, vl->host) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_HOST, vl->host,
strlen(vl->host)) != 0)
sstrncpy(vl_def->host, vl->host, sizeof(vl_def->host));
}
if (vl_def->time != vl->time) {
if (write_part_number(&buffer, &buffer_size, TYPE_TIME_HR,
(uint64_t)vl->time))
sstrncpy(vl_def->host, vl->host, sizeof(vl_def->host));
}
if (vl_def->time != vl->time) {
if (write_part_number(&buffer, &buffer_size, TYPE_TIME_HR,
(uint64_t)vl->time))
vl_def->time = vl->time;
}
if (vl_def->interval != vl->interval) {
if (write_part_number(&buffer, &buffer_size, TYPE_INTERVAL_HR,
(uint64_t)vl->interval))
vl_def->time = vl->time;
}
if (vl_def->interval != vl->interval) {
if (write_part_number(&buffer, &buffer_size, TYPE_INTERVAL_HR,
(uint64_t)vl->interval))
vl_def->interval = vl->interval;
}
if (strcmp(vl_def->plugin, vl->plugin) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_PLUGIN, vl->plugin,
strlen(vl->plugin)) != 0)
vl_def->interval = vl->interval;
}
if (strcmp(vl_def->plugin, vl->plugin) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_PLUGIN, vl->plugin,
strlen(vl->plugin)) != 0)
sstrncpy(vl_def->plugin, vl->plugin, sizeof(vl_def->plugin));
}
sstrncpy(vl_def->plugin, vl->plugin, sizeof(vl_def->plugin));
}
if (write_part_string(&buffer, &buffer_size, TYPE_PLUGIN_INSTANCE,
vl->plugin_instance,
strlen(vl->plugin_instance)) != 0)
if (write_part_string(&buffer, &buffer_size, TYPE_PLUGIN_INSTANCE,
vl->plugin_instance,
strlen(vl->plugin_instance)) != 0)
sstrncpy(vl_def->plugin_instance, vl->plugin_instance,
sizeof(vl_def->plugin_instance));
}
sstrncpy(vl_def->plugin_instance, vl->plugin_instance,
sizeof(vl_def->plugin_instance));
}
if (strcmp(vl_def->type, vl->type) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_TYPE, vl->type,
strlen(vl->type)) != 0)
if (strcmp(vl_def->type, vl->type) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_TYPE, vl->type,
strlen(vl->type)) != 0)
sstrncpy(vl_def->type, ds->type, sizeof(vl_def->type));
}
if (strcmp(vl_def->type_instance, vl->type_instance) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_TYPE_INSTANCE,
vl->type_instance, strlen(vl->type_instance)) != 0)
sstrncpy(vl_def->type, ds->type, sizeof(vl_def->type));
}
if (strcmp(vl_def->type_instance, vl->type_instance) != 0) {
if (write_part_string(&buffer, &buffer_size, TYPE_TYPE_INSTANCE,
vl->type_instance, strlen(vl->type_instance)) != 0)
sstrncpy(vl_def->type_instance, vl->type_instance,
sizeof(vl_def->type_instance));
}
if (write_part_values(&buffer, &buffer_size, ds, vl) != 0)
sstrncpy(vl_def->type_instance, vl->type_instance,
sizeof(vl_def->type_instance));
}
if (write_part_values(&buffer, &buffer_size, ds, vl) != 0)
- return (buffer - buffer_orig);
+ return buffer - buffer_orig;
} /* }}} int add_to_buffer */
static void flush_buffer(void) {
} /* }}} int add_to_buffer */
static void flush_buffer(void) {
pthread_mutex_lock(&stats_lock);
stats_values_not_sent++;
pthread_mutex_unlock(&stats_lock);
pthread_mutex_lock(&stats_lock);
stats_values_not_sent++;
pthread_mutex_unlock(&stats_lock);
}
uc_meta_data_add_unsigned_int(vl, "network:time_sent", (uint64_t)vl->time);
}
uc_meta_data_add_unsigned_int(vl, "network:time_sent", (uint64_t)vl->time);
pthread_mutex_unlock(&send_buffer_lock);
pthread_mutex_unlock(&send_buffer_lock);
- return ((status < 0) ? -1 : 0);
+ return (status < 0) ? -1 : 0;
} /* int network_write */
static int network_config_set_ttl(const oconfig_item_t *ci) /* {{{ */
} /* int network_write */
static int network_config_set_ttl(const oconfig_item_t *ci) /* {{{ */
int tmp = 0;
if (cf_util_get_int(ci, &tmp) != 0)
int tmp = 0;
if (cf_util_get_int(ci, &tmp) != 0)
else if ((tmp > 0) && (tmp <= 255))
network_config_ttl = tmp;
else {
WARNING("network plugin: The `TimeToLive' must be between 1 and 255.");
else if ((tmp > 0) && (tmp <= 255))
network_config_ttl = tmp;
else {
WARNING("network plugin: The `TimeToLive' must be between 1 and 255.");
} /* }}} int network_config_set_ttl */
static int network_config_set_interface(const oconfig_item_t *ci, /* {{{ */
} /* }}} int network_config_set_ttl */
static int network_config_set_interface(const oconfig_item_t *ci, /* {{{ */
char if_name[256];
if (cf_util_get_string_buffer(ci, if_name, sizeof(if_name)) != 0)
char if_name[256];
if (cf_util_get_string_buffer(ci, if_name, sizeof(if_name)) != 0)
*interface = if_nametoindex(if_name);
*interface = if_nametoindex(if_name);
} /* }}} int network_config_set_interface */
static int network_config_set_buffer_size(const oconfig_item_t *ci) /* {{{ */
} /* }}} int network_config_set_interface */
static int network_config_set_buffer_size(const oconfig_item_t *ci) /* {{{ */
int tmp = 0;
if (cf_util_get_int(ci, &tmp) != 0)
int tmp = 0;
if (cf_util_get_int(ci, &tmp) != 0)
else if ((tmp >= 1024) && (tmp <= 65535))
network_config_packet_size = tmp;
else {
WARNING(
"network plugin: The `MaxPacketSize' must be between 1024 and 65535.");
else if ((tmp >= 1024) && (tmp <= 65535))
network_config_packet_size = tmp;
else {
WARNING(
"network plugin: The `MaxPacketSize' must be between 1024 and 65535.");
} /* }}} int network_config_set_buffer_size */
#if HAVE_GCRYPT_H
} /* }}} int network_config_set_buffer_size */
#if HAVE_GCRYPT_H
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("network plugin: The `SecurityLevel' config option needs exactly "
"one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("network plugin: The `SecurityLevel' config option needs exactly "
"one string argument.");
}
str = ci->values[0].value.string;
}
str = ci->values[0].value.string;
*retval = SECURITY_LEVEL_NONE;
else {
WARNING("network plugin: Unknown security level: %s.", str);
*retval = SECURITY_LEVEL_NONE;
else {
WARNING("network plugin: Unknown security level: %s.", str);
} /* }}} int network_config_set_security_level */
#endif /* HAVE_GCRYPT_H */
} /* }}} int network_config_set_security_level */
#endif /* HAVE_GCRYPT_H */
ERROR("network plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
ERROR("network plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
}
se = sockent_create(SOCKENT_TYPE_SERVER);
if (se == NULL) {
ERROR("network plugin: sockent_create failed.");
}
se = sockent_create(SOCKENT_TYPE_SERVER);
if (se == NULL) {
ERROR("network plugin: sockent_create failed.");
}
se->node = strdup(ci->values[0].value.string);
}
se->node = strdup(ci->values[0].value.string);
"requested, but no AuthFile option was given. Cowardly refusing to "
"open this socket!");
sockent_destroy(se);
"requested, but no AuthFile option was given. Cowardly refusing to "
"open this socket!");
sockent_destroy(se);
}
#endif /* HAVE_GCRYPT_H */
}
#endif /* HAVE_GCRYPT_H */
ERROR("network plugin: network_config_add_listen: sockent_init_crypto() "
"failed.");
sockent_destroy(se);
ERROR("network plugin: network_config_add_listen: sockent_init_crypto() "
"failed.");
sockent_destroy(se);
}
status = sockent_server_listen(se);
}
status = sockent_server_listen(se);
ERROR("network plugin: network_config_add_listen: sockent_server_listen "
"failed.");
sockent_destroy(se);
ERROR("network plugin: network_config_add_listen: sockent_server_listen "
"failed.");
sockent_destroy(se);
}
status = sockent_add(se);
if (status != 0) {
ERROR("network plugin: network_config_add_listen: sockent_add failed.");
sockent_destroy(se);
}
status = sockent_add(se);
if (status != 0) {
ERROR("network plugin: network_config_add_listen: sockent_add failed.");
sockent_destroy(se);
} /* }}} int network_config_add_listen */
static int network_config_add_server(const oconfig_item_t *ci) /* {{{ */
} /* }}} int network_config_add_listen */
static int network_config_add_server(const oconfig_item_t *ci) /* {{{ */
ERROR("network plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
ERROR("network plugin: The `%s' config option needs "
"one or two string arguments.",
ci->key);
}
se = sockent_create(SOCKENT_TYPE_CLIENT);
if (se == NULL) {
ERROR("network plugin: sockent_create failed.");
}
se = sockent_create(SOCKENT_TYPE_CLIENT);
if (se == NULL) {
ERROR("network plugin: sockent_create failed.");
}
se->node = strdup(ci->values[0].value.string);
}
se->node = strdup(ci->values[0].value.string);
"requested, but no Username or Password option was given. "
"Cowardly refusing to open this socket!");
sockent_destroy(se);
"requested, but no Username or Password option was given. "
"Cowardly refusing to open this socket!");
sockent_destroy(se);
}
#endif /* HAVE_GCRYPT_H */
}
#endif /* HAVE_GCRYPT_H */
ERROR("network plugin: network_config_add_server: sockent_init_crypto() "
"failed.");
sockent_destroy(se);
ERROR("network plugin: network_config_add_server: sockent_init_crypto() "
"failed.");
sockent_destroy(se);
}
/* No call to sockent_client_connect() here -- it is called from
}
/* No call to sockent_client_connect() here -- it is called from
if (status != 0) {
ERROR("network plugin: network_config_add_server: sockent_add failed.");
sockent_destroy(se);
if (status != 0) {
ERROR("network plugin: network_config_add_server: sockent_add failed.");
sockent_destroy(se);
} /* }}} int network_config_add_server */
static int network_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int network_config_add_server */
static int network_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int network_config */
static int network_notification(const notification_t *n,
} /* }}} int network_config */
static int network_notification(const notification_t *n,
int status;
if (!check_send_notify_okay(n))
int status;
if (!check_send_notify_okay(n))
memset(buffer, 0, sizeof(buffer));
status = write_part_number(&buffer_ptr, &buffer_free, TYPE_TIME_HR,
(uint64_t)n->time);
if (status != 0)
memset(buffer, 0, sizeof(buffer));
status = write_part_number(&buffer_ptr, &buffer_free, TYPE_TIME_HR,
(uint64_t)n->time);
if (status != 0)
status = write_part_number(&buffer_ptr, &buffer_free, TYPE_SEVERITY,
(uint64_t)n->severity);
if (status != 0)
status = write_part_number(&buffer_ptr, &buffer_free, TYPE_SEVERITY,
(uint64_t)n->severity);
if (status != 0)
if (strlen(n->host) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_HOST, n->host,
strlen(n->host));
if (status != 0)
if (strlen(n->host) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_HOST, n->host,
strlen(n->host));
if (status != 0)
}
if (strlen(n->plugin) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_PLUGIN,
n->plugin, strlen(n->plugin));
if (status != 0)
}
if (strlen(n->plugin) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_PLUGIN,
n->plugin, strlen(n->plugin));
if (status != 0)
}
if (strlen(n->plugin_instance) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_PLUGIN_INSTANCE,
n->plugin_instance, strlen(n->plugin_instance));
if (status != 0)
}
if (strlen(n->plugin_instance) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_PLUGIN_INSTANCE,
n->plugin_instance, strlen(n->plugin_instance));
if (status != 0)
}
if (strlen(n->type) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_TYPE, n->type,
strlen(n->type));
if (status != 0)
}
if (strlen(n->type) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_TYPE, n->type,
strlen(n->type));
if (status != 0)
}
if (strlen(n->type_instance) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_TYPE_INSTANCE,
n->type_instance, strlen(n->type_instance));
if (status != 0)
}
if (strlen(n->type_instance) > 0) {
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_TYPE_INSTANCE,
n->type_instance, strlen(n->type_instance));
if (status != 0)
}
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_MESSAGE,
n->message, strlen(n->message));
if (status != 0)
}
status = write_part_string(&buffer_ptr, &buffer_free, TYPE_MESSAGE,
n->message, strlen(n->message));
if (status != 0)
network_send_buffer(buffer, sizeof(buffer) - buffer_free);
network_send_buffer(buffer, sizeof(buffer) - buffer_free);
} /* int network_notification */
static int network_shutdown(void) {
} /* int network_notification */
static int network_shutdown(void) {
plugin_unregister_write("network");
plugin_unregister_shutdown("network");
plugin_unregister_write("network");
plugin_unregister_shutdown("network");
} /* int network_shutdown */
static int network_stats_read(void) /* {{{ */
} /* int network_shutdown */
static int network_stats_read(void) /* {{{ */
vl.type_instance[0] = 0;
plugin_dispatch_values(&vl);
vl.type_instance[0] = 0;
plugin_dispatch_values(&vl);
} /* }}} int network_stats_read */
static int network_init(void) {
} /* }}} int network_stats_read */
static int network_init(void) {
/* Check if we were already initialized. If so, just return - there's
* nothing more to do (for now, that is). */
if (have_init)
/* Check if we were already initialized. If so, just return - there's
* nothing more to do (for now, that is). */
if (have_init)
have_init = 1;
if (network_config_stats)
have_init = 1;
if (network_config_stats)
send_buffer = malloc(network_config_packet_size);
if (send_buffer == NULL) {
ERROR("network plugin: malloc failed.");
send_buffer = malloc(network_config_packet_size);
if (send_buffer == NULL) {
ERROR("network plugin: malloc failed.");
/* If no threads need to be started, return here. */
if ((listen_sockets_num == 0) ||
((dispatch_thread_running != 0) && (receive_thread_running != 0)))
/* If no threads need to be started, return here. */
if ((listen_sockets_num == 0) ||
((dispatch_thread_running != 0) && (receive_thread_running != 0)))
if (dispatch_thread_running == 0) {
int status;
if (dispatch_thread_running == 0) {
int status;
} /* int network_init */
/*
} /* int network_init */
/*
cdtime_t now = cdtime();
if ((send_buffer_last_update + timeout) > now) {
pthread_mutex_unlock(&send_buffer_lock);
cdtime_t now = cdtime();
if ((send_buffer_last_update + timeout) > now) {
pthread_mutex_unlock(&send_buffer_lock);
}
}
flush_buffer();
}
pthread_mutex_unlock(&send_buffer_lock);
}
}
flush_buffer();
}
pthread_mutex_unlock(&send_buffer_lock);
} /* int network_flush */
void module_register(void) {
} /* int network_flush */
void module_register(void) {
-static int nfs_init(void) { return (0); }
+static int nfs_init(void) { return 0; }
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
nfs4_ksp_server = NULL;
if (kc == NULL)
nfs4_ksp_server = NULL;
if (kc == NULL)
for (kstat_t *ksp_chain = kc->kc_chain; ksp_chain != NULL;
ksp_chain = ksp_chain->ks_next) {
for (kstat_t *ksp_chain = kc->kc_chain; ksp_chain != NULL;
ksp_chain = ksp_chain->ks_next) {
nfs4_ksp_client = ksp_chain;
}
nfs4_ksp_client = ksp_chain;
}
} /* int nfs_init */
#endif
} /* int nfs_init */
#endif
WARNING("nfs plugin: Wrong number of fields for "
"NFSv%i %s statistics. Expected %zu, got %zu.",
nfs_version, instance, proc_names_num, fields_num);
WARNING("nfs plugin: Wrong number of fields for "
"NFSv%i %s statistics. Expected %zu, got %zu.",
nfs_version, instance, proc_names_num, fields_num);
}
nfs_submit_fields(nfs_version, instance, fields, fields_num, proc_names);
}
nfs_submit_fields(nfs_version, instance, fields, fields_num, proc_names);
}
static int nfs_submit_nfs4_server(const char *instance, char **fields,
}
static int nfs_submit_nfs4_server(const char *instance, char **fields,
fields_num = NFS4_SERVER_MAX_PROC;
suppress_warning = 1;
} else {
fields_num = NFS4_SERVER_MAX_PROC;
suppress_warning = 1;
} else {
nfs4_server41_procedures_names);
}
nfs4_server41_procedures_names);
}
}
static int nfs_submit_nfs4_client(const char *instance, char **fields,
}
static int nfs_submit_nfs4_client(const char *instance, char **fields,
suppress_warning = 1;
} else {
suppress_warning = 1;
} else {
nfs4_client41_procedures_names);
}
nfs4_client41_procedures_names);
}
}
static void nfs_read_linux(FILE *fh, const char *inst) {
}
static void nfs_read_linux(FILE *fh, const char *inst) {
value_t values[proc_names_num];
if (ksp == NULL)
value_t values[proc_names_num];
if (ksp == NULL)
ssnprintf(plugin_instance, sizeof(plugin_instance), "v%i%s", nfs_version,
inst);
ssnprintf(plugin_instance, sizeof(plugin_instance), "v%i%s", nfs_version,
inst);
}
nfs_procedures_submit(plugin_instance, proc_names, values, proc_names_num);
}
nfs_procedures_submit(plugin_instance, proc_names, values, proc_names_num);
}
/* #endif KERNEL_LINUX */
}
/* #endif KERNEL_LINUX */
nfs_read_kstat(nfs4_ksp_server, /* version = */ 4, "server",
nfs4_procedures_names, nfs4_procedures_names_num);
nfs_read_kstat(nfs4_ksp_server, /* version = */ 4, "server",
nfs4_procedures_names, nfs4_procedures_names_num);
}
#endif /* HAVE_LIBKSTAT */
}
#endif /* HAVE_LIBKSTAT */
memcpy(&nginx_buffer[nginx_buffer_len], buf, len);
nginx_buffer_len += len;
nginx_buffer[nginx_buffer_len] = 0;
memcpy(&nginx_buffer[nginx_buffer_len], buf, len);
nginx_buffer_len += len;
nginx_buffer[nginx_buffer_len] = 0;
}
static int config_set(char **var, const char *value) {
}
static int config_set(char **var, const char *value) {
}
if ((*var = strdup(value)) == NULL)
}
if ((*var = strdup(value)) == NULL)
}
static int config(const char *key, const char *value) {
if (strcasecmp(key, "url") == 0)
}
static int config(const char *key, const char *value) {
if (strcasecmp(key, "url") == 0)
- return (config_set(&url, value));
+ return config_set(&url, value);
else if (strcasecmp(key, "user") == 0)
else if (strcasecmp(key, "user") == 0)
- return (config_set(&user, value));
+ return config_set(&user, value);
else if (strcasecmp(key, "password") == 0)
else if (strcasecmp(key, "password") == 0)
- return (config_set(&pass, value));
+ return config_set(&pass, value);
else if (strcasecmp(key, "verifypeer") == 0)
else if (strcasecmp(key, "verifypeer") == 0)
- return (config_set(&verify_peer, value));
+ return config_set(&verify_peer, value);
else if (strcasecmp(key, "verifyhost") == 0)
else if (strcasecmp(key, "verifyhost") == 0)
- return (config_set(&verify_host, value));
+ return config_set(&verify_host, value);
else if (strcasecmp(key, "cacert") == 0)
else if (strcasecmp(key, "cacert") == 0)
- return (config_set(&cacert, value));
+ return config_set(&cacert, value);
else if (strcasecmp(key, "timeout") == 0)
else if (strcasecmp(key, "timeout") == 0)
- return (config_set(&timeout, value));
+ return config_set(&timeout, value);
} /* int config */
static int init(void) {
} /* int config */
static int init(void) {
if ((curl = curl_easy_init()) == NULL) {
ERROR("nginx plugin: curl_easy_init failed.");
if ((curl = curl_easy_init()) == NULL) {
ERROR("nginx plugin: curl_easy_init failed.");
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
pass == NULL ? "" : pass);
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("nginx plugin: Credentials would have been truncated.");
pass == NULL ? "" : pass);
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("nginx plugin: Credentials would have been truncated.");
}
curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
}
curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
} /* void init */
static void submit(const char *type, const char *inst, long long value) {
} /* void init */
static void submit(const char *type, const char *inst, long long value) {
int fields_num;
if (curl == NULL)
int fields_num;
if (curl == NULL)
nginx_buffer_len = 0;
if (curl_easy_perform(curl) != CURLE_OK) {
WARNING("nginx plugin: curl_easy_perform failed: %s", nginx_curl_error);
nginx_buffer_len = 0;
if (curl_easy_perform(curl) != CURLE_OK) {
WARNING("nginx plugin: curl_easy_perform failed: %s", nginx_curl_error);
} /* int nginx_read */
void module_register(void) {
} /* int nginx_read */
void module_register(void) {
if (session == NULL) {
pthread_mutex_unlock(&session_lock);
ERROR("notify_email plugin: cannot create SMTP session");
if (session == NULL) {
pthread_mutex_unlock(&session_lock);
ERROR("notify_email plugin: cannot create SMTP session");
}
smtp_set_monitorcb(session, monitor_cb, NULL, 1);
}
smtp_set_monitorcb(session, monitor_cb, NULL, 1);
if (!smtp_auth_set_context(session, authctx)) {
pthread_mutex_unlock(&session_lock);
ERROR("notify_email plugin: cannot set SMTP auth context");
if (!smtp_auth_set_context(session, authctx)) {
pthread_mutex_unlock(&session_lock);
ERROR("notify_email plugin: cannot set SMTP auth context");
}
pthread_mutex_unlock(&session_lock);
}
pthread_mutex_unlock(&session_lock);
} /* int notify_email_init */
static int notify_email_shutdown(void) {
} /* int notify_email_init */
static int notify_email_shutdown(void) {
auth_client_exit();
pthread_mutex_unlock(&session_lock);
auth_client_exit();
pthread_mutex_unlock(&session_lock);
} /* int notify_email_shutdown */
static int notify_email_config(const char *key, const char *value) {
} /* int notify_email_shutdown */
static int notify_email_config(const char *key, const char *value) {
tmp = realloc(recipients, (recipients_len + 1) * sizeof(char *));
if (tmp == NULL) {
ERROR("notify_email: realloc failed.");
tmp = realloc(recipients, (recipients_len + 1) * sizeof(char *));
if (tmp == NULL) {
ERROR("notify_email: realloc failed.");
}
recipients = tmp;
recipients[recipients_len] = strdup(value);
if (recipients[recipients_len] == NULL) {
ERROR("notify_email: strdup failed.");
}
recipients = tmp;
recipients[recipients_len] = strdup(value);
if (recipients[recipients_len] == NULL) {
ERROR("notify_email: strdup failed.");
}
recipients_len++;
} else if (0 == strcasecmp(key, "SMTPServer")) {
}
recipients_len++;
} else if (0 == strcasecmp(key, "SMTPServer")) {
int port_tmp = atoi(value);
if (port_tmp < 1 || port_tmp > 65535) {
WARNING("notify_email plugin: Invalid SMTP port: %i", port_tmp);
int port_tmp = atoi(value);
if (port_tmp < 1 || port_tmp > 65535) {
WARNING("notify_email plugin: Invalid SMTP port: %i", port_tmp);
}
smtp_port = port_tmp;
} else if (0 == strcasecmp(key, "SMTPUser")) {
}
smtp_port = port_tmp;
} else if (0 == strcasecmp(key, "SMTPUser")) {
if (session == NULL) {
/* Initialization failed or we're in the process of shutting down. */
pthread_mutex_unlock(&session_lock);
if (session == NULL) {
/* Initialization failed or we're in the process of shutting down. */
pthread_mutex_unlock(&session_lock);
}
if (!(message = smtp_add_message(session))) {
pthread_mutex_unlock(&session_lock);
ERROR("notify_email plugin: cannot set SMTP message");
}
if (!(message = smtp_add_message(session))) {
pthread_mutex_unlock(&session_lock);
ERROR("notify_email plugin: cannot set SMTP message");
}
smtp_set_reverse_path(message, email_from);
smtp_set_header(message, "To", NULL, NULL);
}
smtp_set_reverse_path(message, email_from);
smtp_set_header(message, "To", NULL, NULL);
ERROR("notify_email plugin: SMTP server problem: %s",
smtp_strerror(smtp_errno(), buf, sizeof buf));
pthread_mutex_unlock(&session_lock);
ERROR("notify_email plugin: SMTP server problem: %s",
smtp_strerror(smtp_errno(), buf, sizeof buf));
pthread_mutex_unlock(&session_lock);
} else {
#if COLLECT_DEBUG
const smtp_status_t *status;
} else {
#if COLLECT_DEBUG
const smtp_status_t *status;
}
pthread_mutex_unlock(&session_lock);
}
pthread_mutex_unlock(&session_lock);
} /* int notify_email_notification */
void module_register(void) {
} /* int notify_email_notification */
void module_register(void) {
if (ntpd_host != NULL)
free(ntpd_host);
if ((ntpd_host = strdup(value)) == NULL)
if (ntpd_host != NULL)
free(ntpd_host);
if ((ntpd_host = strdup(value)) == NULL)
} else if (strcasecmp(key, "Port") == 0) {
int port = (int)(atof(value));
if ((port > 0) && (port <= 65535))
} else if (strcasecmp(key, "Port") == 0) {
int port = (int)(atof(value));
if ((port > 0) && (port <= 65535))
else
include_unit_id = 0;
} else {
else
include_unit_id = 0;
} else {
}
static void ntpd_submit(const char *type, const char *type_inst,
}
static void ntpd_submit(const char *type, const char *type_inst,
int status;
if (sock_descr >= 0)
int status;
if (sock_descr >= 0)
DEBUG("Opening a new socket");
DEBUG("Opening a new socket");
ERROR("ntpd plugin: getaddrinfo (%s, %s): %s", host, port,
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
ERROR("ntpd plugin: getaddrinfo (%s, %s): %s", host, port,
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
ERROR("ntpd plugin: Unable to connect to server.");
}
ERROR("ntpd plugin: Unable to connect to server.");
}
}
/* For a description of the arguments see `ntpd_do_query' below. */
}
/* For a description of the arguments see `ntpd_do_query' below. */
ssize_t pkt_padding; /* Padding in this packet */
if ((sd = ntpd_connect()) < 0)
ssize_t pkt_padding; /* Padding in this packet */
if ((sd = ntpd_connect()) < 0)
items = NULL;
items_num = 0;
items = NULL;
items_num = 0;
char errbuf[1024];
ERROR("ntpd plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("ntpd plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
time_end.tv_sec++; /* wait for a most one second */
}
time_end.tv_sec++; /* wait for a most one second */
char errbuf[1024];
ERROR("ntpd plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("ntpd plugin: gettimeofday failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (timeval_cmp(time_end, time_now, &time_left) <= 0)
}
if (timeval_cmp(time_end, time_now, &time_left) <= 0)
char errbuf[1024];
ERROR("ntpd plugin: poll failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("ntpd plugin: poll failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (status == 0) /* timeout */
}
if (status == 0) /* timeout */
DEBUG("Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
DEBUG("Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
}
DEBUG("recv'd %i bytes", status);
}
DEBUG("recv'd %i bytes", status);
if (INFO_ERR(res.err_nitems) != 0) {
ERROR("ntpd plugin: Received error code %i",
(int)INFO_ERR(res.err_nitems));
if (INFO_ERR(res.err_nitems) != 0) {
ERROR("ntpd plugin: Received error code %i",
(int)INFO_ERR(res.err_nitems));
- return ((int)INFO_ERR(res.err_nitems));
+ return (int)INFO_ERR(res.err_nitems);
}
/* extract number of items in this packet and the size of these items */
}
/* extract number of items in this packet and the size of these items */
done = 1;
} /* while (done == 0) */
done = 1;
} /* while (done == 0) */
} /* int ntpd_receive_response */
/* For a description of the arguments see `ntpd_do_query' below. */
} /* int ntpd_receive_response */
/* For a description of the arguments see `ntpd_do_query' below. */
assert(req_size >= 0);
if ((sd = ntpd_connect()) < 0)
assert(req_size >= 0);
if ((sd = ntpd_connect()) < 0)
req.rm_vn_mode = RM_VN_MODE(0, 0, 0);
req.auth_seq = AUTH_SEQ(0, 0);
req.rm_vn_mode = RM_VN_MODE(0, 0, 0);
req.auth_seq = AUTH_SEQ(0, 0);
DEBUG("`swrite' failed. Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
DEBUG("`swrite' failed. Closing socket #%i", sd);
close(sd);
sock_descr = sd = -1;
status = ntpd_send_request(req_code, req_items, req_size, req_data);
if (status != 0)
status = ntpd_send_request(req_code, req_items, req_size, req_data);
if (status != 0)
status = ntpd_receive_response(res_items, res_size, res_data, res_item_size);
status = ntpd_receive_response(res_items, res_size, res_data, res_item_size);
}
static double ntpd_read_fp(int32_t val_int) {
}
static double ntpd_read_fp(int32_t val_int) {
val_int = ntohl(val_int);
val_double = ((double)val_int) / FP_FRAC;
val_int = ntohl(val_int);
val_double = ((double)val_int) / FP_FRAC;
uint32_t addr = ntohl(peer_info->srcadr);
uint32_t refclock_id = (addr >> 8) & 0x00FF;
uint32_t addr = ntohl(peer_info->srcadr);
uint32_t refclock_id = (addr >> 8) & 0x00FF;
}
static int ntpd_get_name_from_address(char *buffer, size_t buffer_size,
}
static int ntpd_get_name_from_address(char *buffer, size_t buffer_size,
ERROR("ntpd plugin: getnameinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
ERROR("ntpd plugin: getnameinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
} /* ntpd_get_name_from_address */
static int ntpd_get_name_refclock(char *buffer, size_t buffer_size,
} /* ntpd_get_name_from_address */
static int ntpd_get_name_refclock(char *buffer, size_t buffer_size,
uint32_t unit_id = ntohl(peer_info->srcadr) & 0x00FF;
if (((size_t)refclock_id) >= refclock_names_num)
uint32_t unit_id = ntohl(peer_info->srcadr) & 0x00FF;
if (((size_t)refclock_id) >= refclock_names_num)
- return (ntpd_get_name_from_address(buffer, buffer_size, peer_info,
- /* do_reverse_lookup = */ 0));
+ return ntpd_get_name_from_address(buffer, buffer_size, peer_info, 0);
if (include_unit_id)
ssnprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
if (include_unit_id)
ssnprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
else
sstrncpy(buffer, refclock_names[refclock_id], buffer_size);
else
sstrncpy(buffer, refclock_names[refclock_id], buffer_size);
} /* int ntpd_get_name_refclock */
static int ntpd_get_name(char *buffer, size_t buffer_size,
} /* int ntpd_get_name_refclock */
static int ntpd_get_name(char *buffer, size_t buffer_size,
uint32_t addr = ntohl(peer_info->srcadr);
if (!peer_info->v6_flag && ((addr & REFCLOCK_MASK) == REFCLOCK_ADDR))
uint32_t addr = ntohl(peer_info->srcadr);
if (!peer_info->v6_flag && ((addr & REFCLOCK_MASK) == REFCLOCK_ADDR))
- return (ntpd_get_name_refclock(buffer, buffer_size, peer_info));
+ return ntpd_get_name_refclock(buffer, buffer_size, peer_info);
- return (ntpd_get_name_from_address(buffer, buffer_size, peer_info,
- do_reverse_lookups));
+ return ntpd_get_name_from_address(buffer, buffer_size, peer_info,
+ do_reverse_lookups);
} /* int ntpd_addr_to_name */
static int ntpd_read(void) {
} /* int ntpd_addr_to_name */
static int ntpd_read(void) {
if (status != 0) {
ERROR("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i",
status);
if (status != 0) {
ERROR("ntpd plugin: ntpd_do_query (REQ_GET_KERNEL) failed with status %i",
status);
} else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0)) {
ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
"(ik = %p; ik_num = %i; ik_size = %i)",
(void *)ik, ik_num, ik_size);
} else if ((ik == NULL) || (ik_num == 0) || (ik_size == 0)) {
ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
"(ik = %p; ik_num = %i; ik_size = %i)",
(void *)ik, ik_num, ik_size);
}
if (ntohs(ik->status) & STA_NANO) {
}
if (ntohs(ik->status) & STA_NANO) {
ERROR(
"ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i",
status);
ERROR(
"ntpd plugin: ntpd_do_query (REQ_PEER_LIST_SUM) failed with status %i",
status);
} else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0)) {
ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
"(ps = %p; ps_num = %i; ps_size = %i)",
(void *)ps, ps_num, ps_size);
} else if ((ps == NULL) || (ps_num == 0) || (ps_size == 0)) {
ERROR("ntpd plugin: ntpd_do_query returned unexpected data. "
"(ps = %p; ps_num = %i; ps_size = %i)",
(void *)ps, ps_num, ps_size);
}
for (int i = 0; i < ps_num; i++) {
}
for (int i = 0; i < ps_num; i++) {
} /* int ntpd_read */
void module_register(void) {
} /* int ntpd_read */
void module_register(void) {
char errbuf[1024];
ERROR("numa plugin: Reading node %i failed: open(%s): %s", node, path,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("numa plugin: Reading node %i failed: open(%s): %s", node, path,
sstrerror(errno, errbuf, sizeof(errbuf)));
- return (success ? 0 : -1);
+ return success ? 0 : -1;
} /* }}} int numa_read_node */
static int numa_read(void) /* {{{ */
} /* }}} int numa_read_node */
static int numa_read(void) /* {{{ */
if (max_node < 0) {
WARNING("numa plugin: No NUMA nodes were detected.");
if (max_node < 0) {
WARNING("numa plugin: No NUMA nodes were detected.");
- return (success ? 0 : -1);
+ return success ? 0 : -1;
} /* }}} int numa_read */
static int numa_init(void) /* {{{ */
} /* }}} int numa_read */
static int numa_init(void) /* {{{ */
char errbuf[1024];
ERROR("numa plugin: stat(%s) failed: %s", path,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("numa plugin: stat(%s) failed: %s", path,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
}
DEBUG("numa plugin: Found %i nodes.", max_node + 1);
}
}
DEBUG("numa plugin: Found %i nodes.", max_node + 1);
} /* }}} int numa_init */
void module_register(void) {
} /* }}} int numa_init */
void module_register(void) {
ups = calloc(1, sizeof(*ups));
if (ups == NULL) {
ERROR("nut plugin: nut_add_ups: calloc failed.");
ups = calloc(1, sizeof(*ups));
if (ups == NULL) {
ERROR("nut plugin: nut_add_ups: calloc failed.");
}
status = upscli_splitname(name, &ups->upsname, &ups->hostname, &ups->port);
if (status != 0) {
ERROR("nut plugin: nut_add_ups: upscli_splitname (%s) failed.", name);
free_nut_ups_t(ups);
}
status = upscli_splitname(name, &ups->upsname, &ups->hostname, &ups->port);
if (status != 0) {
ERROR("nut plugin: nut_add_ups: upscli_splitname (%s) failed.", name);
free_nut_ups_t(ups);
}
if (upslist_head == NULL)
}
if (upslist_head == NULL)
} /* int nut_add_ups */
static int nut_force_ssl(const char *value) {
} /* int nut_add_ups */
static int nut_force_ssl(const char *value) {
WARNING("nut plugin: nut_force_ssl: invalid FORCESSL value "
"found. Defaulting to false.");
}
WARNING("nut plugin: nut_force_ssl: invalid FORCESSL value "
"found. Defaulting to false.");
}
} /* int nut_parse_force_ssl */
static int nut_verify_peer(const char *value) {
} /* int nut_parse_force_ssl */
static int nut_verify_peer(const char *value) {
WARNING("nut plugin: nut_verify_peer: invalid VERIFYPEER value "
"found. Defaulting to false.");
}
WARNING("nut plugin: nut_verify_peer: invalid VERIFYPEER value "
"found. Defaulting to false.");
}
} /* int nut_verify_peer */
static int nut_ca_path(const char *value) {
} /* int nut_verify_peer */
static int nut_ca_path(const char *value) {
} else {
ca_path = NULL; // Should alread be set to NULL from initialization
}
} else {
ca_path = NULL; // Should alread be set to NULL from initialization
}
} /* int nut_ca_path */
static int nut_config(const char *key, const char *value) {
if (strcasecmp(key, "UPS") == 0)
} /* int nut_ca_path */
static int nut_config(const char *key, const char *value) {
if (strcasecmp(key, "UPS") == 0)
- return (nut_add_ups(value));
+ return nut_add_ups(value);
else if (strcasecmp(key, "FORCESSL") == 0)
else if (strcasecmp(key, "FORCESSL") == 0)
- return (nut_force_ssl(value));
+ return nut_force_ssl(value);
else if (strcasecmp(key, "VERIFYPEER") == 0)
else if (strcasecmp(key, "VERIFYPEER") == 0)
- return (nut_verify_peer(value));
+ return nut_verify_peer(value);
else if (strcasecmp(key, "CAPATH") == 0)
else if (strcasecmp(key, "CAPATH") == 0)
- return (nut_ca_path(value));
+ return nut_ca_path(value);
} /* int nut_config */
static void nut_submit(nut_ups_t *ups, const char *type,
} /* int nut_config */
static void nut_submit(nut_ups_t *ups, const char *type,
if (verify_peer == 1 && ca_path == NULL) {
ERROR("nut plugin: nut_connect: VerifyPeer true but missing "
"CAPath value.");
if (verify_peer == 1 && ca_path == NULL) {
ERROR("nut plugin: nut_connect: VerifyPeer true but missing "
"CAPath value.");
}
if (verify_peer == 1) {
}
if (verify_peer == 1) {
ERROR("nut plugin: nut_connect: upscli_init (%i, %s) failed: %s",
verify_peer, ca_path, upscli_strerror(ups->conn));
upscli_cleanup();
ERROR("nut plugin: nut_connect: upscli_init (%i, %s) failed: %s",
verify_peer, ca_path, upscli_strerror(ups->conn));
upscli_cleanup();
}
} /* if (verify_peer == 1) */
}
} /* if (verify_peer == 1) */
ups->hostname, ups->port, upscli_strerror(ups->conn));
sfree(ups->conn);
upscli_cleanup();
ups->hostname, ups->port, upscli_strerror(ups->conn));
sfree(ups->conn);
upscli_cleanup();
} /* if (status != 0) */
INFO("nut plugin: Connection to (%s, %i) established.", ups->hostname,
} /* if (status != 0) */
INFO("nut plugin: Connection to (%s, %i) established.", ups->hostname,
upscli_strerror(ups->conn));
sfree(ups->conn);
upscli_cleanup();
upscli_strerror(ups->conn));
sfree(ups->conn);
upscli_cleanup();
} /* if (ssl_status == 1 && verify_peer == 1) */
} /* if (ssl_status == 1 && verify_peer == 1) */
#else /* #if HAVE_UPSCLI_INIT */
int status;
#else /* #if HAVE_UPSCLI_INIT */
int status;
ERROR("nut plugin: nut_connect: upscli_connect (%s, %i) failed: %s",
ups->hostname, ups->port, upscli_strerror(ups->conn));
sfree(ups->conn);
ERROR("nut plugin: nut_connect: upscli_connect (%s, %i) failed: %s",
ups->hostname, ups->port, upscli_strerror(ups->conn));
sfree(ups->conn);
} /* if (status != 0) */
INFO("nut plugin: Connection to (%s, %i) established.", ups->hostname,
} /* if (status != 0) */
INFO("nut plugin: Connection to (%s, %i) established.", ups->hostname,
ERROR("nut plugin: nut_connect: upscli_ssl failed: %s",
upscli_strerror(ups->conn));
sfree(ups->conn);
ERROR("nut plugin: nut_connect: upscli_ssl failed: %s",
upscli_strerror(ups->conn));
sfree(ups->conn);
} /* if (ssl_status == 1 && verify_peer == 1) */
} /* if (ssl_status == 1 && verify_peer == 1) */
ups->conn = malloc(sizeof(*ups->conn));
if (ups->conn == NULL) {
ERROR("nut plugin: malloc failed.");
ups->conn = malloc(sizeof(*ups->conn));
if (ups->conn == NULL) {
ERROR("nut plugin: malloc failed.");
}
status = nut_connect(ups);
}
status = nut_connect(ups);
#if HAVE_UPSCLI_INIT
upscli_cleanup();
#endif
#if HAVE_UPSCLI_INIT
upscli_cleanup();
#endif
}
while ((status = upscli_list_next(ups->conn, query_num, query, &answer_num,
}
while ((status = upscli_list_next(ups->conn, query_num, query, &answer_num,
}
} /* while (upscli_list_next) */
}
} /* while (upscli_list_next) */
} /* int nut_read_one */
static int nut_read(void) {
} /* int nut_read_one */
static int nut_read(void) {
pthread_mutex_unlock(&read_lock);
if (success != 0)
pthread_mutex_unlock(&read_lock);
if (success != 0)
for (nut_ups_t *ups = upslist_head; ups != NULL; ups = ups->next)
if (nut_read_one(ups) == 0)
for (nut_ups_t *ups = upslist_head; ups != NULL; ups = ups->next)
if (nut_read_one(ups) == 0)
read_busy = 0;
pthread_mutex_unlock(&read_lock);
read_busy = 0;
pthread_mutex_unlock(&read_lock);
- return ((success != 0) ? 0 : -1);
+ return (success != 0) ? 0 : -1;
} /* int nut_read */
static int nut_shutdown(void) {
} /* int nut_read */
static int nut_shutdown(void) {
} /* int nut_shutdown */
void module_register(void) {
} /* int nut_shutdown */
void module_register(void) {
static const char *olsrd_get_node(void) /* {{{ */
{
if (config_node != NULL)
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)
} /* }}} 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) /* {{{ */
} /* }}} const char *olsrd_get_service */
static void olsrd_set_node(const char *node) /* {{{ */
buffer[buffer_len] = 0;
}
buffer[buffer_len] = 0;
}
} /* }}} size_t strchomp */
static size_t strtabsplit(char *string, char **fields, size_t size) /* {{{ */
} /* }}} size_t strchomp */
static size_t strtabsplit(char *string, char **fields, size_t size) /* {{{ */
} /* }}} size_t strtabsplit */
static FILE *olsrd_connect(void) /* {{{ */
} /* }}} 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));
if (ai_return != 0) {
ERROR("olsrd plugin: getaddrinfo (%s, %s) failed: %s", olsrd_get_node(),
olsrd_get_service(), gai_strerror(ai_return));
} /* }}} FILE *olsrd_connect */
__attribute__((nonnull(2))) static void
} /* }}} FILE *olsrd_connect */
__attribute__((nonnull(2))) static void
static int olsrd_cb_ignore(int lineno, /* {{{ */
size_t fields_num, char **fields) {
static int olsrd_cb_ignore(int lineno, /* {{{ */
size_t fields_num, char **fields) {
} /* }}} int olsrd_cb_ignore */
static int olsrd_cb_links(int lineno, /* {{{ */
} /* }}} int olsrd_cb_ignore */
static int olsrd_cb_links(int lineno, /* {{{ */
char *endptr;
if (config_want_links == OLSRD_WANT_NOT)
char *endptr;
if (config_want_links == OLSRD_WANT_NOT)
/* Special handling of the first line. */
if (lineno <= 0) {
/* Special handling of the first line. */
if (lineno <= 0) {
nlq_sum = 0.0;
nlq_num = 0;
nlq_sum = 0.0;
nlq_num = 0;
}
/* Special handling of the last line. */
}
/* Special handling of the last line. */
olsrd_submit(/* p.-inst = */ "links", /* type = */ "signal_quality",
"average-nlq", nlq);
olsrd_submit(/* p.-inst = */ "links", /* type = */ "signal_quality",
"average-nlq", nlq);
} /* }}} int olsrd_cb_links */
static int olsrd_cb_routes(int lineno, /* {{{ */
} /* }}} int olsrd_cb_links */
static int olsrd_cb_routes(int lineno, /* {{{ */
char *endptr;
if (config_want_routes == OLSRD_WANT_NOT)
char *endptr;
if (config_want_routes == OLSRD_WANT_NOT)
/* Special handling of the first line */
if (lineno <= 0) {
/* Special handling of the first line */
if (lineno <= 0) {
etx_sum = 0.0;
etx_num = 0;
etx_sum = 0.0;
etx_num = 0;
}
/* Special handling after the last line */
}
/* Special handling after the last line */
olsrd_submit(/* p.-inst = */ "routes", /* type = */ "route_etx", "average",
etx);
olsrd_submit(/* p.-inst = */ "routes", /* type = */ "route_etx", "average",
etx);
} /* }}} int olsrd_cb_routes */
static int olsrd_cb_topology(int lineno, /* {{{ */
} /* }}} int olsrd_cb_routes */
static int olsrd_cb_topology(int lineno, /* {{{ */
char *endptr;
if (config_want_topology == OLSRD_WANT_NOT)
char *endptr;
if (config_want_topology == OLSRD_WANT_NOT)
/* Special handling of the first line */
if (lineno <= 0) {
/* Special handling of the first line */
if (lineno <= 0) {
lq_num = 0;
links_num = 0;
lq_num = 0;
links_num = 0;
}
/* Special handling after the last line */
}
/* Special handling after the last line */
olsrd_submit(/* p.-inst = */ "topology", /* type = */ "signal_quality",
/* t.-inst = */ "average", lq);
olsrd_submit(/* p.-inst = */ "topology", /* type = */ "signal_quality",
/* t.-inst = */ "average", lq);
} /* }}} int olsrd_cb_topology */
static int olsrd_read_table(FILE *fh, /* {{{ */
} /* }}} int olsrd_cb_topology */
static int olsrd_read_table(FILE *fh, /* {{{ */
lineno++;
} /* while (fgets) */
lineno++;
} /* while (fgets) */
} /* }}} int olsrd_read_table */
static int olsrd_config(const char *key, const char *value) /* {{{ */
} /* }}} 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);
olsrd_set_detail(&config_want_topology, value, key);
else {
ERROR("olsrd plugin: Unknown configuration option given: %s", key);
} /* }}} int olsrd_config */
static int olsrd_read(void) /* {{{ */
} /* }}} int olsrd_config */
static int olsrd_read(void) /* {{{ */
fh = olsrd_connect();
if (fh == NULL)
fh = olsrd_connect();
if (fh == NULL)
fputs("\r\n", fh);
fflush(fh);
fputs("\r\n", fh);
fflush(fh);
} /* }}} int olsrd_read */
static int olsrd_shutdown(void) /* {{{ */
} /* }}} int olsrd_read */
static int olsrd_shutdown(void) /* {{{ */
sfree(config_node);
sfree(config_service);
sfree(config_node);
sfree(config_service);
} /* }}} int olsrd_shutdown */
void module_register(void) {
} /* }}} int olsrd_shutdown */
void module_register(void) {
result->tv_sec = diff / 1000000;
result->tv_usec = diff % 1000000;
result->tv_sec = diff / 1000000;
result->tv_usec = diff % 1000000;
}
#endif /* COLLECT_DEBUG */
}
#endif /* COLLECT_DEBUG */
if (regcomp(®ex_direct, regexp_to_match, REG_EXTENDED)) {
ERROR("onewire plugin: Cannot compile regex");
direct_list_element_free(element);
if (regcomp(®ex_direct, regexp_to_match, REG_EXTENDED)) {
ERROR("onewire plugin: Cannot compile regex");
direct_list_element_free(element);
}
regex_direct_initialized = 1;
DEBUG("onewire plugin: Compiled regex!!");
}
regex_direct_initialized = 1;
DEBUG("onewire plugin: Compiled regex!!");
if (ignorelist_add(sensor_list, value)) {
ERROR("onewire plugin: Cannot add value to ignorelist.");
if (ignorelist_add(sensor_list, value)) {
ERROR("onewire plugin: Cannot add value to ignorelist.");
}
} else {
DEBUG("onewire plugin: %s is a direct access", value);
}
} else {
DEBUG("onewire plugin: %s is a direct access", value);
temp = strdup(value);
if (temp == NULL) {
ERROR("onewire plugin: strdup failed.");
temp = strdup(value);
if (temp == NULL) {
ERROR("onewire plugin: strdup failed.");
}
sfree(device_g);
device_g = temp;
}
sfree(device_g);
device_g = temp;
else
ERROR("onewire plugin: Invalid `Interval' setting: %s", value);
} else {
else
ERROR("onewire plugin: Invalid `Interval' setting: %s", value);
} else {
}
static int cow_read_values(const char *path, const char *name,
}
static int cow_read_values(const char *path, const char *name,
ERROR("onewire plugin: OW_get (%s/%s) failed. error = %s;", path,
family_info->features[i].filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("onewire plugin: OW_get (%s/%s) failed. error = %s;", path,
family_info->features[i].filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
DEBUG("Read onewire device %s as %s", file, buffer);
}
DEBUG("Read onewire device %s as %s", file, buffer);
free(buffer);
} /* for (i = 0; i < features_num; i++) */
free(buffer);
} /* for (i = 0; i < features_num; i++) */
- return ((success > 0) ? 0 : -1);
+ return (success > 0) ? 0 : -1;
} /* int cow_read_values */
/* Forward declaration so the recursion below works */
} /* int cow_read_values */
/* Forward declaration so the recursion below works */
if ((status > 0) && (status < (int)sizeof(subpath)))
cow_read_bus(subpath);
if ((status > 0) && (status < (int)sizeof(subpath)))
cow_read_bus(subpath);
} /* int cow_read_ds2409 */
static int cow_read_bus(const char *path) {
} /* int cow_read_ds2409 */
static int cow_read_bus(const char *path) {
if (status < 0) {
ERROR("onewire plugin: OW_get (%s) failed. error = %s;", path,
sstrerror(errno, errbuf, sizeof(errbuf)));
if (status < 0) {
ERROR("onewire plugin: OW_get (%s) failed. error = %s;", path,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
DEBUG("onewire plugin: OW_get (%s) returned: %s", path, buffer);
}
DEBUG("onewire plugin: OW_get (%s) returned: %s", path, buffer);
} /* while (strtok_r) */
free(buffer);
} /* while (strtok_r) */
free(buffer);
} /* int cow_read_bus */
/* ===================================================================================
} /* int cow_read_bus */
/* ===================================================================================
if (status < 0) {
ERROR("onewire plugin: OW_get (%s) failed. status = %s;", traverse->path,
sstrerror(errno, errbuf, sizeof(errbuf)));
if (status < 0) {
ERROR("onewire plugin: OW_get (%s) failed. status = %s;", traverse->path,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
DEBUG("onewire plugin: Read onewire device %s as %s", traverse->path,
buffer);
}
DEBUG("onewire plugin: Read onewire device %s as %s", traverse->path,
buffer);
regfree(®ex_direct);
}
regfree(®ex_direct);
}
} /* int cow_shutdown */
static int cow_init(void) {
} /* int cow_shutdown */
static int cow_init(void) {
if (device_g == NULL) {
ERROR("onewire plugin: cow_init: No device configured.");
if (device_g == NULL) {
ERROR("onewire plugin: cow_init: No device configured.");
}
DEBUG("onewire plugin: about to init device <%s>.", device_g);
}
DEBUG("onewire plugin: about to init device <%s>.", device_g);
if (status != 0) {
ERROR("onewire plugin: OW_init(%s) failed: %s.", device_g,
sstrerror(errno, errbuf, sizeof(errbuf)));
if (status != 0) {
ERROR("onewire plugin: OW_init(%s) failed: %s.", device_g,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
plugin_register_complex_read(/* group = */ NULL, "onewire", cow_read,
ow_interval, /* user data = */ NULL);
plugin_register_shutdown("onewire", cow_shutdown);
}
plugin_register_complex_read(/* group = */ NULL, "onewire", cow_read,
ow_interval, /* user data = */ NULL);
plugin_register_shutdown("onewire", cow_shutdown);
} /* int cow_init */
void module_register(void) {
} /* int cow_init */
void module_register(void) {
if (st->state && st->ld) {
DEBUG("openldap plugin: Already connected to %s", st->url);
if (st->state && st->ld) {
DEBUG("openldap plugin: Already connected to %s", st->url);
}
rc = ldap_initialize(&ld, st->url);
}
rc = ldap_initialize(&ld, st->url);
ERROR("openldap plugin: ldap_initialize failed: %s", ldap_err2string(rc));
st->state = 0;
ldap_unbind_ext_s(ld, NULL, NULL);
ERROR("openldap plugin: ldap_initialize failed: %s", ldap_err2string(rc));
st->state = 0;
ldap_unbind_ext_s(ld, NULL, NULL);
ldap_err2string(rc));
st->state = 0;
ldap_unbind_ext_s(st->ld, NULL, NULL);
ldap_err2string(rc));
st->state = 0;
ldap_unbind_ext_s(st->ld, NULL, NULL);
ldap_err2string(rc));
st->state = 0;
ldap_unbind_ext_s(st->ld, NULL, NULL);
ldap_err2string(rc));
st->state = 0;
ldap_unbind_ext_s(st->ld, NULL, NULL);
} else {
DEBUG("openldap plugin: Successfully connected to %s", st->url);
st->state = 1;
} else {
DEBUG("openldap plugin: Successfully connected to %s", st->url);
st->state = 1;
}
} /* }}} static cldap_init_host */
}
} /* }}} static cldap_init_host */
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("openldap plugin: cldap_read_host: Invalid user data.");
if ((ud == NULL) || (ud->data == NULL)) {
ERROR("openldap plugin: cldap_read_host: Invalid user data.");
}
st = (cldap_t *)ud->data;
status = cldap_init_host(st);
if (status != 0)
}
st = (cldap_t *)ud->data;
status = cldap_init_host(st);
if (status != 0)
rc = ldap_search_ext_s(st->ld, "cn=Monitor", LDAP_SCOPE_SUBTREE,
"(|(!(cn=* *))(cn=Database*))", attrs, 0, NULL, NULL,
rc = ldap_search_ext_s(st->ld, "cn=Monitor", LDAP_SCOPE_SUBTREE,
"(|(!(cn=* *))(cn=Database*))", attrs, 0, NULL, NULL,
ldap_msgfree(result);
st->state = 0;
ldap_unbind_ext_s(st->ld, NULL, NULL);
ldap_msgfree(result);
st->state = 0;
ldap_unbind_ext_s(st->ld, NULL, NULL);
}
for (LDAPMessage *e = ldap_first_entry(st->ld, result); e != NULL;
}
for (LDAPMessage *e = ldap_first_entry(st->ld, result); e != NULL;
} /* }}} int cldap_read_host */
/* Configuration handling functions {{{
} /* }}} int cldap_read_host */
/* Configuration handling functions {{{
st = calloc(1, sizeof(*st));
if (st == NULL) {
ERROR("openldap plugin: calloc failed.");
st = calloc(1, sizeof(*st));
if (st == NULL) {
ERROR("openldap plugin: calloc failed.");
}
status = cf_util_get_string(ci, &st->name);
if (status != 0) {
sfree(st);
}
status = cf_util_get_string(ci, &st->name);
if (status != 0) {
sfree(st);
if (status != 0) {
cldap_free(st);
if (status != 0) {
cldap_free(st);
} /* }}} int cldap_config_add */
static int cldap_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int cldap_config_add */
static int cldap_config(oconfig_item_t *ci) /* {{{ */
child->key);
} /* for (ci->children) */
child->key);
} /* for (ci->children) */
} /* }}} int cldap_config */
/* }}} End of configuration handling functions */
} /* }}} int cldap_config */
/* }}} End of configuration handling functions */
* ldap_initialize(3) */
int debug_level;
ldap_get_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level);
* ldap_initialize(3) */
int debug_level;
ldap_get_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level);
} /* }}} int cldap_init */
static int cldap_shutdown(void) /* {{{ */
} /* }}} int cldap_init */
static int cldap_shutdown(void) /* {{{ */
sfree(databases);
databases_num = 0;
sfree(databases);
databases_num = 0;
} /* }}} int cldap_shutdown */
void module_register(void) /* {{{ */
} /* }}} int cldap_shutdown */
void module_register(void) /* {{{ */
} /* int openvpn_strsplit */
/* dispatches number of users */
} /* int openvpn_strsplit */
/* dispatches number of users */
} /* int single_read */
/* for reading status version 1 */
} /* int single_read */
/* for reading status version 1 */
if (collect_user_count)
numusers_submit(name, name, sum_users);
if (collect_user_count)
numusers_submit(name, name, sum_users);
} /* int multi1_read */
/* for reading status version 2 */
} /* int multi1_read */
/* for reading status version 2 */
} /* int multi2_read */
/* for reading status version 3 */
} /* int multi2_read */
/* for reading status version 3 */
} /* int multi3_read */
/* for reading status version 4 */
} /* int multi3_read */
/* for reading status version 4 */
} /* int multi4_read */
/* read callback */
} /* int multi4_read */
/* read callback */
read = 0;
if (vpn_num == 0)
read = 0;
if (vpn_num == 0)
/* call the right read function for every status entry in the list */
for (int i = 0; i < vpn_num; i++) {
/* call the right read function for every status entry in the list */
for (int i = 0; i < vpn_num; i++) {
- return (read ? 0 : -1);
} /* int openvpn_read */
static int version_detect(const char *filename) {
} /* int openvpn_read */
static int version_detect(const char *filename) {
/* Sanity checking. We're called from the config handling routine, so
* better play it save. */
if ((filename == NULL) || (*filename == 0))
/* Sanity checking. We're called from the config handling routine, so
* better play it save. */
if ((filename == NULL) || (*filename == 0))
fh = fopen(filename, "r");
if (fh == NULL) {
char errbuf[1024];
WARNING("openvpn plugin: Unable to read \"%s\": %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
fh = fopen(filename, "r");
if (fh == NULL) {
char errbuf[1024];
WARNING("openvpn plugin: Unable to read \"%s\": %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* now search for the specific multimode data format */
}
/* now search for the specific multimode data format */
WARNING("openvpn plugin: unable to detect status version, "
"discarding status file \"%s\".",
value);
WARNING("openvpn plugin: unable to detect status version, "
"discarding status file \"%s\".",
value);
}
status_file = sstrdup(value);
}
status_file = sstrdup(value);
char errbuf[1024];
WARNING("openvpn plugin: sstrdup failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("openvpn plugin: sstrdup failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* it determines the file name as string starting at location filename + 1
}
/* it determines the file name as string starting at location filename + 1
"different one.",
status_name);
sfree(status_file);
"different one.",
status_name);
sfree(status_file);
ERROR("openvpn plugin: malloc failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(status_file);
ERROR("openvpn plugin: malloc failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(status_file);
}
temp->file = status_file;
temp->version = status_version;
}
temp->file = status_file;
temp->version = status_version;
sfree(vpn_list);
sfree(temp->file);
sfree(temp);
sfree(vpn_list);
sfree(temp->file);
sfree(temp);
collect_individual_users = 1;
} /* if (strcasecmp("CollectIndividualUsers", key) == 0) */
else {
collect_individual_users = 1;
} /* if (strcasecmp("CollectIndividualUsers", key) == 0) */
else {
} /* int openvpn_config */
/* shutdown callback */
} /* int openvpn_config */
/* shutdown callback */
} /* int openvpn_shutdown */
static int openvpn_init(void) {
} /* int openvpn_shutdown */
static int openvpn_init(void) {
WARNING("OpenVPN plugin: Neither `CollectIndividualUsers', "
"`CollectCompression', nor `CollectUserCount' is true. There's no "
"data left to collect.");
WARNING("OpenVPN plugin: Neither `CollectIndividualUsers', "
"`CollectCompression', nor `CollectUserCount' is true. There's no "
"data left to collect.");
}
plugin_register_read("openvpn", openvpn_read);
plugin_register_shutdown("openvpn", openvpn_shutdown);
}
plugin_register_read("openvpn", openvpn_read);
plugin_register_shutdown("openvpn", openvpn_shutdown);
} /* int openvpn_init */
void module_register(void) {
} /* int openvpn_init */
void module_register(void) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("oracle plugin: The `Database' block "
"needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("oracle plugin: The `Database' block "
"needs exactly one string argument.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("oracle plugin: calloc failed.");
}
db = calloc(1, sizeof(*db));
if (db == NULL) {
ERROR("oracle plugin: calloc failed.");
}
db->name = NULL;
db->host = NULL;
}
db->name = NULL;
db->host = NULL;
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
status = cf_util_get_string(ci, &db->name);
if (status != 0) {
sfree(db);
}
/* Fill the `o_database_t' structure.. */
}
/* Fill the `o_database_t' structure.. */
if (status != 0) {
o_database_free(db);
if (status != 0) {
o_database_free(db);
} /* }}} int o_config_add_database */
static int o_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int o_config_add_database */
static int o_config(oconfig_item_t *ci) /* {{{ */
}
} /* for (ci->children) */
}
} /* for (ci->children) */
} /* }}} int o_config */
/* }}} End of configuration handling functions */
} /* }}} int o_config */
/* }}} End of configuration handling functions */
int status;
if (oci_env != NULL)
int status;
if (oci_env != NULL)
status = OCIEnvCreate(&oci_env,
/* mode = */ OCI_THREADED,
status = OCIEnvCreate(&oci_env,
/* mode = */ OCI_THREADED,
/* user_data_ptr = */ NULL);
if (status != 0) {
ERROR("oracle plugin: OCIEnvCreate failed with status %i.", status);
/* user_data_ptr = */ NULL);
if (status != 0) {
ERROR("oracle plugin: OCIEnvCreate failed with status %i.", status);
}
status = OCIHandleAlloc(oci_env, (void *)&oci_error, OCI_HTYPE_ERROR,
}
status = OCIHandleAlloc(oci_env, (void *)&oci_error, OCI_HTYPE_ERROR,
ERROR("oracle plugin: OCIHandleAlloc (OCI_HTYPE_ERROR) failed "
"with status %i.",
status);
ERROR("oracle plugin: OCIHandleAlloc (OCI_HTYPE_ERROR) failed "
"with status %i.",
status);
} /* }}} int o_init */
static int o_read_database_query(o_database_t *db, /* {{{ */
} /* }}} int o_init */
static int o_read_database_query(o_database_t *db, /* {{{ */
o_report_error("o_read_database_query", db->name, udb_query_get_name(q),
"OCIHandleAlloc", oci_error);
oci_statement = NULL;
o_report_error("o_read_database_query", db->name, udb_query_get_name(q),
"OCIHandleAlloc", oci_error);
oci_statement = NULL;
}
status = OCIStmtPrepare(oci_statement, oci_error, (text *)statement,
}
status = OCIStmtPrepare(oci_statement, oci_error, (text *)statement,
"OCIStmtPrepare", oci_error);
OCIHandleFree(oci_statement, OCI_HTYPE_STMT);
oci_statement = NULL;
"OCIStmtPrepare", oci_error);
OCIHandleFree(oci_statement, OCI_HTYPE_STMT);
oci_statement = NULL;
}
udb_query_set_user_data(q, oci_statement);
}
udb_query_set_user_data(q, oci_statement);
if (status != OCI_SUCCESS) {
o_report_error("o_read_database_query", db->name, udb_query_get_name(q),
"OCIStmtExecute", oci_error);
if (status != OCI_SUCCESS) {
o_report_error("o_read_database_query", db->name, udb_query_get_name(q),
"OCIStmtExecute", oci_error);
} /* }}} */
/* Acquire the number of columns returned. */
} /* }}} */
/* Acquire the number of columns returned. */
if (status != OCI_SUCCESS) {
o_report_error("o_read_database_query", db->name, udb_query_get_name(q),
"OCIAttrGet", oci_error);
if (status != OCI_SUCCESS) {
o_report_error("o_read_database_query", db->name, udb_query_get_name(q),
"OCIAttrGet", oci_error);
} /* }}} */
column_num = (size_t)param_counter;
} /* }}} */
column_num = (size_t)param_counter;
if ((ptr) == NULL) { \
FREE_ALL; \
ERROR("oracle plugin: o_read_database_query: calloc failed."); \
if ((ptr) == NULL) { \
FREE_ALL; \
ERROR("oracle plugin: o_read_database_query: calloc failed."); \
"udb_query_prepare_result failed.",
db->name, udb_query_get_name(q));
FREE_ALL;
"udb_query_prepare_result failed.",
db->name, udb_query_get_name(q));
FREE_ALL;
}
/* Fetch and handle all the rows that matched the query. */
}
/* Fetch and handle all the rows that matched the query. */
* %s", q->statement); */
FREE_ALL;
* %s", q->statement); */
FREE_ALL;
#undef FREE_ALL
#undef ALLOC_OR_FAIL
} /* }}} int o_read_database_query */
#undef FREE_ALL
#undef ALLOC_OR_FAIL
} /* }}} int o_read_database_query */
if (status != OCI_SUCCESS) {
o_report_error("o_read_database", db->name, NULL, "OCIAttrGet",
oci_error);
if (status != OCI_SUCCESS) {
o_report_error("o_read_database", db->name, NULL, "OCIAttrGet",
oci_error);
}
if (server_handle == NULL) {
}
if (server_handle == NULL) {
if (status != OCI_SUCCESS) {
o_report_error("o_read_database", db->name, NULL, "OCIAttrGet",
oci_error);
if (status != OCI_SUCCESS) {
o_report_error("o_read_database", db->name, NULL, "OCIAttrGet",
oci_error);
DEBUG("oracle plugin: OCILogon (%s): db->oci_service_context = %p;",
db->connect_id, db->oci_service_context);
db->oci_service_context = NULL;
DEBUG("oracle plugin: OCILogon (%s): db->oci_service_context = %p;",
db->connect_id, db->oci_service_context);
db->oci_service_context = NULL;
} else if (status == OCI_SUCCESS_WITH_INFO) {
/* TODO: Print NOTIFY message. */
}
} else if (status == OCI_SUCCESS_WITH_INFO) {
/* TODO: Print NOTIFY message. */
}
for (size_t i = 0; i < db->queries_num; i++)
o_read_database_query(db, db->queries[i], db->q_prep_areas[i]);
for (size_t i = 0; i < db->queries_num; i++)
o_read_database_query(db, db->queries[i], db->q_prep_areas[i]);
} /* }}} int o_read_database */
static int o_read(void) /* {{{ */
} /* }}} int o_read_database */
static int o_read(void) /* {{{ */
for (i = 0; i < databases_num; i++)
o_read_database(databases[i]);
for (i = 0; i < databases_num; i++)
o_read_database(databases[i]);
} /* }}} int o_read */
static int o_shutdown(void) /* {{{ */
} /* }}} int o_read */
static int o_shutdown(void) /* {{{ */
queries = NULL;
queries_num = 0;
queries = NULL;
queries_num = 0;
} /* }}} int o_shutdown */
void module_register(void) /* {{{ */
} /* }}} int o_shutdown */
void module_register(void) /* {{{ */
*/
static int ovs_events_ctx_lock() {
pthread_mutex_lock(&ovs_events_ctx.mutex);
*/
static int ovs_events_ctx_lock() {
pthread_mutex_lock(&ovs_events_ctx.mutex);
}
/* This function is used only by "OVS_EVENTS_CTX_LOCK" define (see above).
}
/* This function is used only by "OVS_EVENTS_CTX_LOCK" define (see above).
*/
static int ovs_events_ctx_unlock() {
pthread_mutex_unlock(&ovs_events_ctx.mutex);
*/
static int ovs_events_ctx_unlock() {
pthread_mutex_unlock(&ovs_events_ctx.mutex);
}
/* Check if given interface name exists in configuration file. It
}
/* Check if given interface name exists in configuration file. It
*/
static int ovs_events_config_iface_exists(const char *ifname) {
if (ovs_events_ctx.config.ifaces == NULL)
*/
static int ovs_events_config_iface_exists(const char *ifname) {
if (ovs_events_ctx.config.ifaces == NULL)
/* check if given interface exists */
for (ovs_events_iface_list_t *iface = ovs_events_ctx.config.ifaces; iface;
iface = iface->next)
if (strcmp(ifname, iface->name) == 0)
/* check if given interface exists */
for (ovs_events_iface_list_t *iface = ovs_events_ctx.config.ifaces; iface;
iface = iface->next)
if (strcmp(ifname, iface->name) == 0)
}
/* Get OVS DB select parameter request based on rfc7047,
}
/* Get OVS DB select parameter request based on rfc7047,
if (ci->values[j].type != OCONFIG_TYPE_STRING) {
ERROR(OVS_EVENTS_PLUGIN
": given interface name is not a string [idx=%d]", j);
if (ci->values[j].type != OCONFIG_TYPE_STRING) {
ERROR(OVS_EVENTS_PLUGIN
": given interface name is not a string [idx=%d]", j);
}
/* allocate memory for configured interface */
ovs_events_iface_list_t *new_iface = calloc(1, sizeof(*new_iface));
if (new_iface == NULL) {
ERROR(OVS_EVENTS_PLUGIN ": calloc () copy interface name fail");
}
/* allocate memory for configured interface */
ovs_events_iface_list_t *new_iface = calloc(1, sizeof(*new_iface));
if (new_iface == NULL) {
ERROR(OVS_EVENTS_PLUGIN ": calloc () copy interface name fail");
} else {
/* store interface name */
sstrncpy(new_iface->name, ci->values[j].value.string,
} else {
/* store interface name */
sstrncpy(new_iface->name, ci->values[j].value.string,
}
/* Parse plugin configuration file and store the config
}
/* Parse plugin configuration file and store the config
if (cf_util_get_boolean(child,
&ovs_events_ctx.config.send_notification) != 0) {
ovs_events_config_free();
if (cf_util_get_boolean(child,
&ovs_events_ctx.config.send_notification) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("Address", child->key) == 0) {
if (cf_util_get_string_buffer(
child, ovs_events_ctx.config.ovs_db_node,
sizeof(ovs_events_ctx.config.ovs_db_node)) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("Address", child->key) == 0) {
if (cf_util_get_string_buffer(
child, ovs_events_ctx.config.ovs_db_node,
sizeof(ovs_events_ctx.config.ovs_db_node)) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("Port", child->key) == 0) {
char *service = NULL;
if (cf_util_get_service(child, &service) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("Port", child->key) == 0) {
char *service = NULL;
if (cf_util_get_service(child, &service) != 0) {
ovs_events_config_free();
}
strncpy(ovs_events_ctx.config.ovs_db_serv, service,
sizeof(ovs_events_ctx.config.ovs_db_serv));
}
strncpy(ovs_events_ctx.config.ovs_db_serv, service,
sizeof(ovs_events_ctx.config.ovs_db_serv));
child, ovs_events_ctx.config.ovs_db_unix,
sizeof(ovs_events_ctx.config.ovs_db_unix)) != 0) {
ovs_events_config_free();
child, ovs_events_ctx.config.ovs_db_unix,
sizeof(ovs_events_ctx.config.ovs_db_unix)) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("Interfaces", child->key) == 0) {
if (ovs_events_config_get_interfaces(child) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("Interfaces", child->key) == 0) {
if (ovs_events_config_get_interfaces(child) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("DispatchValues", child->key) == 0) {
if (cf_util_get_boolean(child, &dispatch_values) != 0) {
ovs_events_config_free();
}
} else if (strcasecmp("DispatchValues", child->key) == 0) {
if (cf_util_get_boolean(child, &dispatch_values) != 0) {
ovs_events_config_free();
}
} else {
ERROR(OVS_EVENTS_PLUGIN ": option '%s' is not allowed here", child->key);
ovs_events_config_free();
}
} else {
ERROR(OVS_EVENTS_PLUGIN ": option '%s' is not allowed here", child->key);
ovs_events_config_free();
}
}
/* Check and warn about invalid configuration */
}
}
/* Check and warn about invalid configuration */
return plugin_register_complex_read(NULL, OVS_EVENTS_PLUGIN,
ovs_events_plugin_read, 0, NULL);
return plugin_register_complex_read(NULL, OVS_EVENTS_PLUGIN,
ovs_events_plugin_read, 0, NULL);
}
/* Dispatch OVS interface link status event to collectd */
}
/* Dispatch OVS interface link status event to collectd */
/* check YAJL type */
if (!YAJL_IS_OBJECT(jobject))
/* check YAJL type */
if (!YAJL_IS_OBJECT(jobject))
/* zero the interface info structure */
memset(ifinfo, 0, sizeof(*ifinfo));
/* zero the interface info structure */
memset(ifinfo, 0, sizeof(*ifinfo));
/* try to find external_ids, name and link_state fields */
jexternal_ids = ovs_utils_get_value_by_key(jobject, "external_ids");
if (jexternal_ids == NULL || ifinfo == NULL)
/* try to find external_ids, name and link_state fields */
jexternal_ids = ovs_utils_get_value_by_key(jobject, "external_ids");
if (jexternal_ids == NULL || ifinfo == NULL)
/* get iface-id from external_ids field */
jvalue = ovs_utils_get_map_value(jexternal_ids, "iface-id");
/* get iface-id from external_ids field */
jvalue = ovs_utils_get_map_value(jexternal_ids, "iface-id");
jvalue = ovs_utils_get_value_by_key(jobject, "_uuid");
if (jvalue == NULL || !YAJL_IS_ARRAY(jvalue) ||
YAJL_GET_ARRAY(jvalue)->len != 2)
jvalue = ovs_utils_get_value_by_key(jobject, "_uuid");
if (jvalue == NULL || !YAJL_IS_ARRAY(jvalue) ||
YAJL_GET_ARRAY(jvalue)->len != 2)
juuid = YAJL_GET_ARRAY(jvalue)->values[1];
if (juuid == NULL || !YAJL_IS_STRING(juuid))
juuid = YAJL_GET_ARRAY(jvalue)->values[1];
if (juuid == NULL || !YAJL_IS_STRING(juuid))
sstrncpy(ifinfo->uuid, YAJL_GET_STRING(juuid), sizeof(ifinfo->uuid));
/* get interface name */
jvalue = ovs_utils_get_value_by_key(jobject, "name");
if (jvalue == NULL || !YAJL_IS_STRING(jvalue))
sstrncpy(ifinfo->uuid, YAJL_GET_STRING(juuid), sizeof(ifinfo->uuid));
/* get interface name */
jvalue = ovs_utils_get_value_by_key(jobject, "name");
if (jvalue == NULL || !YAJL_IS_STRING(jvalue))
sstrncpy(ifinfo->name, YAJL_GET_STRING(jvalue), sizeof(ifinfo->name));
/* get OVS DB interface link status */
sstrncpy(ifinfo->name, YAJL_GET_STRING(jvalue), sizeof(ifinfo->name));
/* get OVS DB interface link status */
else if (strcmp(state, "down") == 0)
ifinfo->link_status = DOWN;
}
else if (strcmp(state, "down") == 0)
ifinfo->link_status = DOWN;
}
}
/* Process OVS DB update table event. It handles link status update event(s)
}
/* Process OVS DB update table event. It handles link status update event(s)
ovs_events_ctx.ovs_db_select_params,
ovs_events_poll_result_cb) < 0) {
ERROR(OVS_EVENTS_PLUGIN ": get interface info failed");
ovs_events_ctx.ovs_db_select_params,
ovs_events_poll_result_cb) < 0) {
ERROR(OVS_EVENTS_PLUGIN ": get interface info failed");
}
/* Initialize OVS plugin */
}
/* Initialize OVS plugin */
OVS_EVENTS_CTX_LOCK { ovs_events_ctx.ovs_db = ovs_db; }
DEBUG(OVS_EVENTS_PLUGIN ": plugin has been initialized");
OVS_EVENTS_CTX_LOCK { ovs_events_ctx.ovs_db = ovs_db; }
DEBUG(OVS_EVENTS_PLUGIN ": plugin has been initialized");
ovs_events_failure:
ERROR(OVS_EVENTS_PLUGIN ": plugin initialize failed");
/* release allocated memory */
ovs_events_config_free();
ovs_events_failure:
ERROR(OVS_EVENTS_PLUGIN ": plugin initialize failed");
/* release allocated memory */
ovs_events_config_free();
}
/* Shutdown OVS plugin */
}
/* Shutdown OVS plugin */
ovs_events_config_free();
DEBUG(OVS_EVENTS_PLUGIN ": plugin has been destroyed");
ovs_events_config_free();
DEBUG(OVS_EVENTS_PLUGIN ": plugin has been destroyed");
}
/* Register OVS plugin callbacks */
}
/* Register OVS plugin callbacks */
}
} else
WARNING("%s: Incorrect data for deleting bridge", plugin_name);
}
} else
WARNING("%s: Incorrect data for deleting bridge", plugin_name);
}
/* Update Bridge. Create bridge ports*/
}
/* Update Bridge. Create bridge ports*/
br = (bridge_list_t *)calloc(1, sizeof(bridge_list_t));
if (!br) {
ERROR("%s: Error allocating memory for bridge", plugin_name);
br = (bridge_list_t *)calloc(1, sizeof(bridge_list_t));
if (!br) {
ERROR("%s: Error allocating memory for bridge", plugin_name);
}
char *tmp = YAJL_GET_STRING(br_name);
}
char *tmp = YAJL_GET_STRING(br_name);
if (br->name == NULL) {
sfree(br);
pthread_mutex_unlock(&g_stats_lock);
if (br->name == NULL) {
sfree(br);
pthread_mutex_unlock(&g_stats_lock);
}
br->next = g_bridge_list_head;
g_bridge_list_head = br;
}
br->next = g_bridge_list_head;
g_bridge_list_head = br;
}
} else {
ERROR("Incorrect JSON Bridge data");
}
} else {
ERROR("Incorrect JSON Bridge data");
}
/* Handle JSON with Bridge Table change event */
}
/* Handle JSON with Bridge Table change event */
}
} else {
ERROR("Incorrect JSON Port data");
}
} else {
ERROR("Incorrect JSON Port data");
}
/* Delete port from global port list */
}
/* Delete port from global port list */
}
/* Handle JSON with Port Table change event */
}
/* Handle JSON with Port Table change event */
for (size_t i = 0; i < YAJL_GET_ARRAY(stats)->len; i++) {
stat = YAJL_GET_ARRAY(stats)->values[i];
if (!YAJL_IS_ARRAY(stat))
for (size_t i = 0; i < YAJL_GET_ARRAY(stats)->len; i++) {
stat = YAJL_GET_ARRAY(stats)->values[i];
if (!YAJL_IS_ARRAY(stat))
counter_name = YAJL_GET_STRING(YAJL_GET_ARRAY(stat)->values[0]);
counter_index = ovs_stats_counter_name_to_type(counter_name);
counter_value = YAJL_GET_INTEGER(YAJL_GET_ARRAY(stat)->values[1]);
counter_name = YAJL_GET_STRING(YAJL_GET_ARRAY(stat)->values[0]);
counter_index = ovs_stats_counter_name_to_type(counter_name);
counter_value = YAJL_GET_INTEGER(YAJL_GET_ARRAY(stat)->values[1]);
port->stats[counter_index] = counter_value;
}
port->stats[counter_index] = counter_value;
}
}
/* Update interface external_ids */
}
/* Update interface external_ids */
for (size_t i = 0; i < YAJL_GET_ARRAY(ext_ids)->len; i++) {
ext_id = YAJL_GET_ARRAY(ext_ids)->values[i];
if (!YAJL_IS_ARRAY(ext_id))
for (size_t i = 0; i < YAJL_GET_ARRAY(ext_ids)->len; i++) {
ext_id = YAJL_GET_ARRAY(ext_ids)->values[i];
if (!YAJL_IS_ARRAY(ext_id))
key = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[0]);
value = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[1]);
if (key && value) {
key = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[0]);
value = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[1]);
if (key && value) {
}
/* Get interface statistic and external_ids */
}
/* Get interface statistic and external_ids */
if (iface_name && YAJL_IS_STRING(iface_name)) {
port = ovs_stats_get_port_by_name(YAJL_GET_STRING(iface_name));
if (port == NULL)
if (iface_name && YAJL_IS_STRING(iface_name)) {
port = ovs_stats_get_port_by_name(YAJL_GET_STRING(iface_name));
if (port == NULL)
}
} else {
ERROR("Incorrect JSON Port data");
}
} else {
ERROR("Incorrect JSON Port data");
}
/* Handle JSON with Interface Table change event */
}
/* Handle JSON with Interface Table change event */
static int ovs_stats_is_monitored_bridge(const char *br_name) {
/* if no bridges are configured, return true */
if (g_monitored_bridge_list_head == NULL)
static int ovs_stats_is_monitored_bridge(const char *br_name) {
/* if no bridges are configured, return true */
if (g_monitored_bridge_list_head == NULL)
/* check if given bridge exists */
if (ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name) != NULL)
/* check if given bridge exists */
if (ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name) != NULL)
if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_node,
OVS_DB_ADDR_NODE_SIZE) != 0) {
ERROR("%s: parse '%s' option failed", plugin_name, child->key);
if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_node,
OVS_DB_ADDR_NODE_SIZE) != 0) {
ERROR("%s: parse '%s' option failed", plugin_name, child->key);
}
} else if (strcasecmp("Port", child->key) == 0) {
if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_serv,
OVS_DB_ADDR_SERVICE_SIZE) != 0) {
ERROR("%s: parse '%s' option failed", plugin_name, child->key);
}
} else if (strcasecmp("Port", child->key) == 0) {
if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_serv,
OVS_DB_ADDR_SERVICE_SIZE) != 0) {
ERROR("%s: parse '%s' option failed", plugin_name, child->key);
}
} else if (strcasecmp("Socket", child->key) == 0) {
if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_unix,
OVS_DB_ADDR_UNIX_SIZE) != 0) {
ERROR("%s: parse '%s' option failed", plugin_name, child->key);
}
} else if (strcasecmp("Socket", child->key) == 0) {
if (cf_util_get_string_buffer(child, ovs_stats_cfg.ovs_db_unix,
OVS_DB_ADDR_UNIX_SIZE) != 0) {
ERROR("%s: parse '%s' option failed", plugin_name, child->key);
}
} else if (strcasecmp("Bridges", child->key) == 0) {
for (int j = 0; j < child->values_num; j++) {
}
} else if (strcasecmp("Bridges", child->key) == 0) {
for (int j = 0; j < child->values_num; j++) {
cleanup_fail:
ovs_stats_free_bridge_list(g_monitored_bridge_list_head);
cleanup_fail:
ovs_stats_free_bridge_list(g_monitored_bridge_list_head);
}
/* Initialize OvS Stats plugin*/
}
/* Initialize OvS Stats plugin*/
ovs_stats_cfg.ovs_db_serv,
ovs_stats_cfg.ovs_db_unix, &cb)) == NULL) {
ERROR("%s: plugin: failed to connect to OvS DB server", plugin_name);
ovs_stats_cfg.ovs_db_serv,
ovs_stats_cfg.ovs_db_unix, &cb)) == NULL) {
ERROR("%s: plugin: failed to connect to OvS DB server", plugin_name);
}
int err = pthread_mutex_init(&g_stats_lock, NULL);
if (err < 0) {
ERROR("%s: plugin: failed to initialize cache lock", plugin_name);
ovs_db_destroy(g_ovs_db);
}
int err = pthread_mutex_init(&g_stats_lock, NULL);
if (err < 0) {
ERROR("%s: plugin: failed to initialize cache lock", plugin_name);
ovs_db_destroy(g_ovs_db);
}
/* OvS stats read callback. Read bridge/port information and submit it*/
}
/* OvS stats read callback. Read bridge/port information and submit it*/
continue;
}
pthread_mutex_unlock(&g_stats_lock);
continue;
}
pthread_mutex_unlock(&g_stats_lock);
}
/* Shutdown OvS Stats plugin */
}
/* Shutdown OvS Stats plugin */
ovs_stats_free_port_list(g_port_list_head);
pthread_mutex_unlock(&g_stats_lock);
pthread_mutex_destroy(&g_stats_lock);
ovs_stats_free_port_list(g_port_list_head);
pthread_mutex_unlock(&g_stats_lock);
pthread_mutex_destroy(&g_stats_lock);
}
/* Register OvS Stats plugin callbacks */
}
/* Register OvS Stats plugin callbacks */
else
status = ssnprintf(buf, buf_len, "%s::%s", base_name, module);
if ((status < 0) || ((unsigned int)status >= buf_len))
else
status = ssnprintf(buf, buf_len, "%s::%s", base_name, module);
if ((status < 0) || ((unsigned int)status >= buf_len))
- return (NULL);
- return (buf);
+ return NULL;
+ return buf;
} /* char *get_module_name */
/*
} /* char *get_module_name */
/*
if (NULL == get_module_name(module_name, sizeof(module_name), value)) {
log_err("Invalid module name %s", value);
if (NULL == get_module_name(module_name, sizeof(module_name), value)) {
log_err("Invalid module name %s", value);
}
if (0 != init_pi(perl_argc, perl_argv))
}
if (0 != init_pi(perl_argc, perl_argv))
char errbuf[1024];
ERROR("pf plugin: Unable to open %s: %s", pf_device,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("pf plugin: Unable to open %s: %s", pf_device,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
status = ioctl(fd, DIOCGETSTATUS, &state);
}
status = ioctl(fd, DIOCGETSTATUS, &state);
ERROR("pf plugin: ioctl(DIOCGETSTATUS) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
ERROR("pf plugin: ioctl(DIOCGETSTATUS) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
}
close(fd);
if (!state.running) {
WARNING("pf plugin: PF is not running.");
}
close(fd);
if (!state.running) {
WARNING("pf plugin: PF is not running.");
}
for (int i = 0; i < PFRES_MAX; i++)
}
for (int i = 0; i < PFRES_MAX; i++)
pf_submit("pf_states", "current", (uint32_t)state.states,
/* is gauge = */ 1);
pf_submit("pf_states", "current", (uint32_t)state.states,
/* is gauge = */ 1);
} /* int pf_read */
void module_register(void) { plugin_register_read("pf", pf_read); }
} /* int pf_read */
void module_register(void) { plugin_register_read("pf", pf_read); }
ret = (derive_t)(fc->i * factor);
ret += (derive_t)(fc->n / (1000000000 / factor));
ret = (derive_t)(fc->i * factor);
ret += (derive_t)(fc->n / (1000000000 / factor));
} /* }}} derive_t float_counter_get */
static void strset(char **str, const char *new) /* {{{ */
} /* }}} derive_t float_counter_get */
static void strset(char **str, const char *new) /* {{{ */
/* reset node */
node->mem_peak = NAN;
/* reset node */
node->mem_peak = NAN;
} /* }}} unsigned int service_statnode_collect */
static void service_statnode_process(pinba_statnode_t *node, /* {{{ */
} /* }}} unsigned int service_statnode_collect */
static void service_statnode_process(pinba_statnode_t *node, /* {{{ */
static int pb_del_socket(pinba_socket_t *s, /* {{{ */
nfds_t index) {
if (index >= s->fd_num)
static int pb_del_socket(pinba_socket_t *s, /* {{{ */
nfds_t index) {
if (index >= s->fd_num)
close(s->fd[index].fd);
s->fd[index].fd = -1;
close(s->fd[index].fd);
s->fd[index].fd = -1;
} /* }}} int pb_del_socket */
static int pb_add_socket(pinba_socket_t *s, /* {{{ */
} /* }}} int pb_del_socket */
static int pb_add_socket(pinba_socket_t *s, /* {{{ */
"%i sockets. Please complain to the collectd developers so we can "
"raise the limit.",
PINBA_MAX_SOCKETS);
"%i sockets. Please complain to the collectd developers so we can "
"raise the limit.",
PINBA_MAX_SOCKETS);
}
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
}
fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
char errbuf[1024];
ERROR("pinba plugin: socket(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("pinba plugin: socket(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("pinba plugin: bind(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
ERROR("pinba plugin: bind(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
}
s->fd[s->fd_num].fd = fd;
}
s->fd[s->fd_num].fd = fd;
s->fd[s->fd_num].revents = 0;
s->fd_num++;
s->fd[s->fd_num].revents = 0;
s->fd_num++;
} /* }}} int pb_add_socket */
static pinba_socket_t *pinba_socket_open(const char *node, /* {{{ */
} /* }}} int pb_add_socket */
static pinba_socket_t *pinba_socket_open(const char *node, /* {{{ */
status = getaddrinfo(node, service, &ai_hints, &ai_list);
if (status != 0) {
ERROR("pinba plugin: getaddrinfo(3) failed: %s", gai_strerror(status));
status = getaddrinfo(node, service, &ai_hints, &ai_list);
if (status != 0) {
ERROR("pinba plugin: getaddrinfo(3) failed: %s", gai_strerror(status));
}
assert(ai_list != NULL);
}
assert(ai_list != NULL);
if (s == NULL) {
freeaddrinfo(ai_list);
ERROR("pinba plugin: calloc failed.");
if (s == NULL) {
freeaddrinfo(ai_list);
ERROR("pinba plugin: calloc failed.");
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
} /* }}} pinba_socket_open */
static void pinba_socket_free(pinba_socket_t *socket) /* {{{ */
} /* }}} pinba_socket_open */
static void pinba_socket_free(pinba_socket_t *socket) /* {{{ */
request = pinba__request__unpack(NULL, buffer_size, buffer);
if (!request)
request = pinba__request__unpack(NULL, buffer_size, buffer);
if (!request)
service_process_request(request);
pinba__request__free_unpacked(request, NULL);
service_process_request(request);
pinba__request__free_unpacked(request, NULL);
} /* }}} int pinba_process_stats_packet */
static int pinba_udp_read_callback_fn(int sock) /* {{{ */
} /* }}} int pinba_process_stats_packet */
static int pinba_udp_read_callback_fn(int sock) /* {{{ */
WARNING("pinba plugin: recvfrom(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
WARNING("pinba plugin: recvfrom(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
} else if (status == 0) {
DEBUG("pinba plugin: recvfrom(2) returned unexpected status zero.");
} else if (status == 0) {
DEBUG("pinba plugin: recvfrom(2) returned unexpected status zero.");
} else /* if (status > 0) */
{
assert(((size_t)status) < buffer_size);
} else /* if (status > 0) */
{
assert(((size_t)status) < buffer_size);
status = pinba_process_stats_packet(buffer, buffer_size);
if (status != 0)
DEBUG("pinba plugin: Parsing packet failed.");
status = pinba_process_stats_packet(buffer, buffer_size);
if (status != 0)
DEBUG("pinba plugin: Parsing packet failed.");
}
} /* while (42) */
/* not reached */
assert(23 == 42);
}
} /* while (42) */
/* not reached */
assert(23 == 42);
} /* }}} void pinba_udp_read_callback_fn */
static int receive_loop(void) /* {{{ */
} /* }}} void pinba_udp_read_callback_fn */
static int receive_loop(void) /* {{{ */
s = pinba_socket_open(conf_node, conf_service);
if (s == NULL) {
ERROR("pinba plugin: Collector thread is exiting prematurely.");
s = pinba_socket_open(conf_node, conf_service);
if (s == NULL) {
ERROR("pinba plugin: Collector thread is exiting prematurely.");
}
while (!collector_thread_do_shutdown) {
}
while (!collector_thread_do_shutdown) {
ERROR("pinba plugin: poll(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
pinba_socket_free(s);
ERROR("pinba plugin: poll(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
pinba_socket_free(s);
}
for (nfds_t i = 0; i < s->fd_num; i++) {
}
for (nfds_t i = 0; i < s->fd_num; i++) {
pinba_socket_free(s);
s = NULL;
pinba_socket_free(s);
s = NULL;
} /* }}} int receive_loop */
static void *collector_thread(void *arg) /* {{{ */
} /* }}} int receive_loop */
static void *collector_thread(void *arg) /* {{{ */
memset(&collector_thread_id, 0, sizeof(collector_thread_id));
collector_thread_running = 0;
pthread_exit(NULL);
memset(&collector_thread_id, 0, sizeof(collector_thread_id));
collector_thread_running = 0;
pthread_exit(NULL);
} /* }}} void *collector_thread */
/*
} /* }}} void *collector_thread */
/*
status = cf_util_get_string(ci, &name);
if (status != 0)
status = cf_util_get_string(ci, &name);
if (status != 0)
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *child = ci->children + i;
sfree(server);
sfree(script);
sfree(server);
sfree(script);
} /* }}} int pinba_config_view */
static int plugin_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int pinba_config_view */
static int plugin_config(oconfig_item_t *ci) /* {{{ */
pthread_mutex_unlock(&stat_nodes_lock);
pthread_mutex_unlock(&stat_nodes_lock);
} /* }}} int pinba_config */
static int plugin_init(void) /* {{{ */
} /* }}} int pinba_config */
static int plugin_init(void) /* {{{ */
}
if (collector_thread_running)
}
if (collector_thread_running)
status = plugin_thread_create(&collector_thread_id,
/* attrs = */ NULL, collector_thread,
status = plugin_thread_create(&collector_thread_id,
/* attrs = */ NULL, collector_thread,
char errbuf[1024];
ERROR("pinba plugin: pthread_create(3) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("pinba plugin: pthread_create(3) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
collector_thread_running = 1;
}
collector_thread_running = 1;
} /* }}} */
static int plugin_shutdown(void) /* {{{ */
} /* }}} */
static int plugin_shutdown(void) /* {{{ */
collector_thread_do_shutdown = 0;
} /* if (collector_thread_running) */
collector_thread_do_shutdown = 0;
} /* if (collector_thread_running) */
} /* }}} int plugin_shutdown */
static int plugin_submit(const pinba_statnode_t *res) /* {{{ */
} /* }}} int plugin_shutdown */
static int plugin_submit(const pinba_statnode_t *res) /* {{{ */
sstrncpy(vl.type_instance, "peak", sizeof(vl.type_instance));
plugin_dispatch_values(&vl);
sstrncpy(vl.type_instance, "peak", sizeof(vl.type_instance));
plugin_dispatch_values(&vl);
} /* }}} int plugin_submit */
static int plugin_read(void) /* {{{ */
} /* }}} int plugin_submit */
static int plugin_read(void) /* {{{ */
} /* }}} ping_max_missed */
} /* }}} for (iter) */
} /* }}} ping_max_missed */
} /* }}} for (iter) */
} /* }}} int ping_dispatch_all */
static void *ping_thread(void *arg) /* {{{ */
} /* }}} int ping_dispatch_all */
static void *ping_thread(void *arg) /* {{{ */
ERROR("ping plugin: ping_construct failed.");
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
ERROR("ping plugin: ping_construct failed.");
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
}
if (ping_source != NULL)
}
if (ping_source != NULL)
ERROR("ping plugin: No host could be added to ping object. Giving up.");
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
ERROR("ping plugin: No host could be added to ping object. Giving up.");
ping_thread_error = 1;
pthread_mutex_unlock(&ping_lock);
pthread_mutex_unlock(&ping_lock);
ping_destroy(pingobj);
pthread_mutex_unlock(&ping_lock);
ping_destroy(pingobj);
} /* }}} void *ping_thread */
static int start_thread(void) /* {{{ */
} /* }}} void *ping_thread */
static int start_thread(void) /* {{{ */
if (ping_thread_loop != 0) {
pthread_mutex_unlock(&ping_lock);
if (ping_thread_loop != 0) {
pthread_mutex_unlock(&ping_lock);
ping_thread_loop = 0;
ERROR("ping plugin: Starting thread failed.");
pthread_mutex_unlock(&ping_lock);
ping_thread_loop = 0;
ERROR("ping plugin: Starting thread failed.");
pthread_mutex_unlock(&ping_lock);
}
pthread_mutex_unlock(&ping_lock);
}
pthread_mutex_unlock(&ping_lock);
} /* }}} int start_thread */
static int stop_thread(void) /* {{{ */
} /* }}} int start_thread */
static int stop_thread(void) /* {{{ */
if (ping_thread_loop == 0) {
pthread_mutex_unlock(&ping_lock);
if (ping_thread_loop == 0) {
pthread_mutex_unlock(&ping_lock);
ping_thread_error = 0;
pthread_mutex_unlock(&ping_lock);
ping_thread_error = 0;
pthread_mutex_unlock(&ping_lock);
} /* }}} int stop_thread */
static int ping_init(void) /* {{{ */
{
if (hostlist_head == NULL) {
NOTICE("ping plugin: No hosts have been configured.");
} /* }}} int stop_thread */
static int ping_init(void) /* {{{ */
{
if (hostlist_head == NULL) {
NOTICE("ping plugin: No hosts have been configured.");
}
if (ping_timeout > ping_interval) {
}
if (ping_timeout > ping_interval) {
- return (start_thread());
} /* }}} int ping_init */
static int config_set_string(const char *name, /* {{{ */
} /* }}} int ping_init */
static int config_set_string(const char *name, /* {{{ */
char errbuf[1024];
ERROR("ping plugin: Setting `%s' to `%s' failed: strdup failed: %s", name,
value, sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("ping plugin: Setting `%s' to `%s' failed: strdup failed: %s", name,
value, sstrerror(errno, errbuf, sizeof(errbuf)));
}
if (*var != NULL)
free(*var);
*var = tmp;
}
if (*var != NULL)
free(*var);
*var = tmp;
} /* }}} int config_set_string */
static int ping_config(const char *key, const char *value) /* {{{ */
} /* }}} int config_set_string */
static int ping_config(const char *key, const char *value) /* {{{ */
char errbuf[1024];
ERROR("ping plugin: malloc failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("ping plugin: malloc failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(hl);
ERROR("ping plugin: strdup failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(hl);
ERROR("ping plugin: strdup failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
} else if (strcasecmp(key, "SourceAddress") == 0) {
int status = config_set_string(key, &ping_source, value);
if (status != 0)
} else if (strcasecmp(key, "SourceAddress") == 0) {
int status = config_set_string(key, &ping_source, value);
if (status != 0)
}
#ifdef HAVE_OPING_1_3
else if (strcasecmp(key, "Device") == 0) {
int status = config_set_string(key, &ping_device, value);
if (status != 0)
}
#ifdef HAVE_OPING_1_3
else if (strcasecmp(key, "Device") == 0) {
int status = config_set_string(key, &ping_device, value);
if (status != 0)
}
#endif
else if (strcasecmp(key, "TTL") == 0) {
}
#endif
else if (strcasecmp(key, "TTL") == 0) {
ping_data = malloc(size + 1);
if (ping_data == NULL) {
ERROR("ping plugin: malloc failed.");
ping_data = malloc(size + 1);
if (ping_data == NULL) {
ERROR("ping plugin: malloc failed.");
}
/* Note: By default oping is using constant string
}
/* Note: By default oping is using constant string
if (ping_max_missed < 0)
INFO("ping plugin: MaxMissed < 0, disabled re-resolving of hosts");
} else {
if (ping_max_missed < 0)
INFO("ping plugin: MaxMissed < 0, disabled re-resolving of hosts");
} else {
} /* }}} int ping_config */
static void submit(const char *host, const char *type, /* {{{ */
} /* }}} int ping_config */
static void submit(const char *host, const char *type, /* {{{ */
} /* if (ping_thread_error != 0) */
for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next) /* {{{ */
} /* if (ping_thread_error != 0) */
for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next) /* {{{ */
submit(hl->host, "ping_droprate", droprate);
} /* }}} for (hl = hostlist_head; hl != NULL; hl = hl->next) */
submit(hl->host, "ping_droprate", droprate);
} /* }}} for (hl = hostlist_head; hl != NULL; hl = hl->next) */
} /* }}} int ping_read */
static int ping_shutdown(void) /* {{{ */
} /* }}} int ping_read */
static int ping_shutdown(void) /* {{{ */
INFO("ping plugin: Shutting down thread.");
if (stop_thread() < 0)
INFO("ping plugin: Shutting down thread.");
if (stop_thread() < 0)
hl = hostlist_head;
while (hl != NULL) {
hl = hostlist_head;
while (hl != NULL) {
} /* }}} int ping_shutdown */
void module_register(void) {
} /* }}} int ping_shutdown */
void module_register(void) {
char interval[64];
if ((data == NULL) || (data->params_num == 0))
char interval[64];
if ((data == NULL) || (data->params_num == 0))
- return (c_psql_exec_query_noparams(db, q));
+ return c_psql_exec_query_noparams(db, q);
assert(db->max_params_num >= data->params_num);
assert(db->max_params_num >= data->params_num);
}
return PQexecParams(db->conn, udb_query_get_statement(q), data->params_num,
}
return PQexecParams(db->conn, udb_query_get_statement(q), data->params_num,
- NULL, (const char *const *)params, NULL, NULL,
- /* return text data */ 0);
+ NULL, (const char *const*)params, NULL, NULL, 0);
} /* c_psql_exec_query_params */
/* db->db_lock must be locked when calling this function */
} /* c_psql_exec_query_params */
/* db->db_lock must be locked when calling this function */
} /* config_query_param_add */
static int config_query_callback(udb_query_t *q, oconfig_item_t *ci) {
} /* config_query_param_add */
static int config_query_callback(udb_query_t *q, oconfig_item_t *ci) {
log_err("Option not allowed within a Query block: `%s'", ci->key);
log_err("Option not allowed within a Query block: `%s'", ci->key);
} /* config_query_callback */
static int config_add_writer(oconfig_item_t *ci, c_psql_writer_t *src_writers,
} /* config_query_callback */
static int config_add_writer(oconfig_item_t *ci, c_psql_writer_t *src_writers,
sd = socket(PF_UNIX, item->socktype, 0);
if (sd < 0) {
FUNC_ERROR("socket");
sd = socket(PF_UNIX, item->socktype, 0);
if (sd < 0) {
FUNC_ERROR("socket");
}
sa_unix.sun_family = AF_UNIX;
}
sa_unix.sun_family = AF_UNIX;
if ((status != 0) && (errno != ENOENT)) {
SOCK_ERROR("unlink", sa_unix.sun_path);
close(sd);
if ((status != 0) && (errno != ENOENT)) {
SOCK_ERROR("unlink", sa_unix.sun_path);
close(sd);
unlink(sa_unix.sun_path);
if (status != 0)
unlink(sa_unix.sun_path);
if (status != 0)
assert(buffer_size > 0);
buffer = malloc(buffer_size);
if (buffer == NULL) {
FUNC_ERROR("malloc");
assert(buffer_size > 0);
buffer = malloc(buffer_size);
if (buffer == NULL) {
FUNC_ERROR("malloc");
}
memcpy(buffer, temp, buffer_size - 1);
}
memcpy(buffer, temp, buffer_size - 1);
*ret_buffer = buffer;
*ret_buffer_size = buffer_size;
*ret_buffer = buffer;
*ret_buffer_size = buffer_size;
} /* }}} int powerdns_get_data_dgram */
static int powerdns_get_data_stream(list_item_t *item, /* {{{ */
} /* }}} int powerdns_get_data_dgram */
static int powerdns_get_data_stream(list_item_t *item, /* {{{ */
sd = socket(PF_UNIX, item->socktype, 0);
if (sd < 0) {
FUNC_ERROR("socket");
sd = socket(PF_UNIX, item->socktype, 0);
if (sd < 0) {
FUNC_ERROR("socket");
}
struct timeval timeout;
}
struct timeval timeout;
if (status != 0) {
FUNC_ERROR("setsockopt");
close(sd);
if (status != 0) {
FUNC_ERROR("setsockopt");
close(sd);
if (status != 0) {
SOCK_ERROR("connect", item->sockaddr.sun_path);
close(sd);
if (status != 0) {
SOCK_ERROR("connect", item->sockaddr.sun_path);
close(sd);
}
/* strlen + 1, because we need to send the terminating NULL byte, too. */
}
/* strlen + 1, because we need to send the terminating NULL byte, too. */
if (status < 0) {
SOCK_ERROR("send", item->sockaddr.sun_path);
close(sd);
if (status < 0) {
SOCK_ERROR("send", item->sockaddr.sun_path);
close(sd);
*ret_buffer_size = buffer_size;
}
*ret_buffer_size = buffer_size;
}
} /* }}} int powerdns_get_data_stream */
static int powerdns_get_data(list_item_t *item, char **ret_buffer,
size_t *ret_buffer_size) {
if (item->socktype == SOCK_DGRAM)
} /* }}} int powerdns_get_data_stream */
static int powerdns_get_data(list_item_t *item, char **ret_buffer,
size_t *ret_buffer_size) {
if (item->socktype == SOCK_DGRAM)
- return (powerdns_get_data_dgram(item, ret_buffer, ret_buffer_size));
+ return powerdns_get_data_dgram(item, ret_buffer, ret_buffer_size);
else if (item->socktype == SOCK_STREAM)
else if (item->socktype == SOCK_STREAM)
- return (powerdns_get_data_stream(item, ret_buffer, ret_buffer_size));
+ return powerdns_get_data_stream(item, ret_buffer, ret_buffer_size);
else {
ERROR("powerdns plugin: Unknown socket type: %i", (int)item->socktype);
else {
ERROR("powerdns plugin: Unknown socket type: %i", (int)item->socktype);
}
} /* int powerdns_get_data */
}
} /* int powerdns_get_data */
item->command = strdup(SERVER_COMMAND);
if (item->command == NULL) {
ERROR("powerdns plugin: strdup failed.");
item->command = strdup(SERVER_COMMAND);
if (item->command == NULL) {
ERROR("powerdns plugin: strdup failed.");
}
status = powerdns_get_data(item, &buffer, &buffer_size);
if (status != 0)
}
status = powerdns_get_data(item, &buffer, &buffer_size);
if (status != 0)
if (item->fields_num != 0) {
fields = (const char *const *)item->fields;
if (item->fields_num != 0) {
fields = (const char *const *)item->fields;
} /* }}} int powerdns_read_server */
/*
} /* }}} int powerdns_read_server */
/*
int status;
if (li == NULL)
int status;
if (li == NULL)
if (li->fields_num < 1) {
sstrncpy(buffer, RECURSOR_COMMAND, sizeof(buffer));
if (li->fields_num < 1) {
sstrncpy(buffer, RECURSOR_COMMAND, sizeof(buffer));
/* seperator = */ " ");
if (status < 0) {
ERROR("powerdns plugin: strjoin failed.");
/* seperator = */ " ");
if (status < 0) {
ERROR("powerdns plugin: strjoin failed.");
}
buffer[sizeof(buffer) - 1] = 0;
size_t len = strlen(buffer);
}
buffer[sizeof(buffer) - 1] = 0;
size_t len = strlen(buffer);
li->command = strdup(buffer);
if (li->command == NULL) {
ERROR("powerdns plugin: strdup failed.");
li->command = strdup(buffer);
if (li->command == NULL) {
ERROR("powerdns plugin: strdup failed.");
} /* }}} int powerdns_update_recursor_command */
static int powerdns_read_recursor(list_item_t *item) /* {{{ */
} /* }}} int powerdns_update_recursor_command */
static int powerdns_read_recursor(list_item_t *item) /* {{{ */
status = powerdns_update_recursor_command(item);
if (status != 0) {
ERROR("powerdns plugin: powerdns_update_recursor_command failed.");
status = powerdns_update_recursor_command(item);
if (status != 0) {
ERROR("powerdns plugin: powerdns_update_recursor_command failed.");
}
DEBUG("powerdns plugin: powerdns_read_recursor: item->command = %s;",
}
DEBUG("powerdns plugin: powerdns_read_recursor: item->command = %s;",
status = powerdns_get_data(item, &buffer, &buffer_size);
if (status != 0) {
ERROR("powerdns plugin: powerdns_get_data failed.");
status = powerdns_get_data(item, &buffer, &buffer_size);
if (status != 0) {
ERROR("powerdns plugin: powerdns_get_data failed.");
}
keys_list = strdup(item->command);
if (keys_list == NULL) {
FUNC_ERROR("strdup");
sfree(buffer);
}
keys_list = strdup(item->command);
if (keys_list == NULL) {
FUNC_ERROR("strdup");
sfree(buffer);
sfree(buffer);
sfree(keys_list);
sfree(buffer);
sfree(keys_list);
} /* }}} int powerdns_read_recursor */
static int powerdns_config_add_collect(list_item_t *li, /* {{{ */
} /* }}} int powerdns_read_recursor */
static int powerdns_config_add_collect(list_item_t *li, /* {{{ */
if (ci->values_num < 1) {
WARNING("powerdns plugin: The `Collect' option needs "
"at least one argument.");
if (ci->values_num < 1) {
WARNING("powerdns plugin: The `Collect' option needs "
"at least one argument.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("powerdns plugin: Only string arguments are allowed to "
"the `Collect' option.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("powerdns plugin: Only string arguments are allowed to "
"the `Collect' option.");
}
temp =
realloc(li->fields, sizeof(char *) * (li->fields_num + ci->values_num));
if (temp == NULL) {
WARNING("powerdns plugin: realloc failed.");
}
temp =
realloc(li->fields, sizeof(char *) * (li->fields_num + ci->values_num));
if (temp == NULL) {
WARNING("powerdns plugin: realloc failed.");
/* Invalidate a previously computed command */
sfree(li->command);
/* Invalidate a previously computed command */
sfree(li->command);
} /* }}} int powerdns_config_add_collect */
static int powerdns_config_add_server(oconfig_item_t *ci) /* {{{ */
} /* }}} int powerdns_config_add_collect */
static int powerdns_config_add_server(oconfig_item_t *ci) /* {{{ */
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("powerdns plugin: `%s' needs exactly one string argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("powerdns plugin: `%s' needs exactly one string argument.",
ci->key);
}
item = calloc(1, sizeof(*item));
if (item == NULL) {
ERROR("powerdns plugin: calloc failed.");
}
item = calloc(1, sizeof(*item));
if (item == NULL) {
ERROR("powerdns plugin: calloc failed.");
}
item->instance = strdup(ci->values[0].value.string);
if (item->instance == NULL) {
ERROR("powerdns plugin: strdup failed.");
sfree(item);
}
item->instance = strdup(ci->values[0].value.string);
if (item->instance == NULL) {
ERROR("powerdns plugin: strdup failed.");
sfree(item);
} else {
/* We must never get here.. */
assert(0);
} else {
/* We must never get here.. */
assert(0);
if (status != 0) {
sfree(socket_temp);
sfree(item);
if (status != 0) {
sfree(socket_temp);
sfree(item);
}
DEBUG("powerdns plugin: Add server: instance = %s;", item->instance);
sfree(socket_temp);
}
DEBUG("powerdns plugin: Add server: instance = %s;", item->instance);
sfree(socket_temp);
} /* }}} int powerdns_config_add_server */
static int powerdns_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int powerdns_config_add_server */
static int powerdns_config(oconfig_item_t *ci) /* {{{ */
if (list == NULL) {
ERROR("powerdns plugin: `llist_create' failed.");
if (list == NULL) {
ERROR("powerdns plugin: `llist_create' failed.");
} else {
char *temp = strdup(option->values[0].value.string);
if (temp == NULL)
} else {
char *temp = strdup(option->values[0].value.string);
if (temp == NULL)
sfree(local_sockpath);
local_sockpath = temp;
}
sfree(local_sockpath);
local_sockpath = temp;
}
}
} /* for (i = 0; i < ci->children_num; i++) */
}
} /* for (i = 0; i < ci->children_num; i++) */
} /* }}} int powerdns_config */
static int powerdns_read(void) {
} /* }}} int powerdns_config */
static int powerdns_read(void) {
} /* static int powerdns_read */
static int powerdns_shutdown(void) {
if (list == NULL)
} /* static int powerdns_read */
static int powerdns_shutdown(void) {
if (list == NULL)
for (llentry_t *e = llist_head(list); e != NULL; e = e->next) {
list_item_t *item = (list_item_t *)e->value;
for (llentry_t *e = llist_head(list); e != NULL; e = e->next) {
list_item_t *item = (list_item_t *)e->value;
llist_destroy(list);
list = NULL;
llist_destroy(list);
list = NULL;
} /* static int powerdns_shutdown */
void module_register(void) {
} /* static int powerdns_shutdown */
void module_register(void) {
new = calloc(1, sizeof(*new));
if (new == NULL) {
ERROR("processes plugin: ps_list_register: calloc failed.");
new = calloc(1, sizeof(*new));
if (new == NULL) {
ERROR("processes plugin: ps_list_register: calloc failed.");
}
sstrncpy(new->name, name, sizeof(new->name));
}
sstrncpy(new->name, name, sizeof(new->name));
if (new->re == NULL) {
ERROR("processes plugin: ps_list_register: malloc failed.");
sfree(new);
if (new->re == NULL) {
ERROR("processes plugin: ps_list_register: malloc failed.");
sfree(new);
}
status = regcomp(new->re, regexp, REG_EXTENDED | REG_NOSUB);
}
status = regcomp(new->re, regexp, REG_EXTENDED | REG_NOSUB);
regexp);
sfree(new->re);
sfree(new);
regexp);
sfree(new->re);
sfree(new);
"has been disabled at compile time.",
regexp);
sfree(new);
"has been disabled at compile time.",
regexp);
sfree(new);
sfree(new->re);
#endif
sfree(new);
sfree(new->re);
#endif
sfree(new);
} /* void ps_list_register */
/* try to match name against entry, returns 1 if success */
} /* void ps_list_register */
/* try to match name against entry, returns 1 if success */
/* pmatch = */ NULL,
/* eflags = */ 0);
if (status == 0)
/* pmatch = */ NULL,
/* eflags = */ 0);
if (status == 0)
} else
#endif
if (strcmp(ps->name, name) == 0)
} else
#endif
if (strcmp(ps->name, name) == 0)
} /* int ps_list_match */
static void ps_update_counter(derive_t *group_counter, derive_t *curr_counter,
} /* int ps_list_match */
static void ps_update_counter(derive_t *group_counter, derive_t *curr_counter,
}
static int ps_init(void) {
}
static int ps_init(void) {
ERROR("host_processor_sets failed: %s\n", mach_error_string(status));
pset_list = NULL;
pset_list_len = 0;
ERROR("host_processor_sets failed: %s\n", mach_error_string(status));
pset_list = NULL;
pset_list_len = 0;
}
/* #endif HAVE_THREAD_INFO */
}
/* #endif HAVE_THREAD_INFO */
pagesize = getpagesize();
#endif /* HAVE_PROCINFO_H */
pagesize = getpagesize();
#endif /* HAVE_PROCINFO_H */
} /* int ps_init */
/* submit global state (e.g.: qty of zombies, running, etc..) */
} /* int ps_init */
/* submit global state (e.g.: qty of zombies, running, etc..) */
if ((dh = opendir(dirname)) == NULL) {
DEBUG("Failed to open directory `%s'", dirname);
if ((dh = opendir(dirname)) == NULL) {
DEBUG("Failed to open directory `%s'", dirname);
}
while ((ent = readdir(dh)) != NULL) {
}
while ((ent = readdir(dh)) != NULL) {
ps->cswitch_vol = cswitch_vol;
ps->cswitch_invol = cswitch_invol;
ps->cswitch_vol = cswitch_vol;
ps->cswitch_invol = cswitch_invol;
} /* int *ps_read_tasks_status */
/* Read data from /proc/pid/status */
} /* int *ps_read_tasks_status */
/* Read data from /proc/pid/status */
ssnprintf(filename, sizeof(filename), "/proc/%li/status", pid);
if ((fh = fopen(filename, "r")) == NULL)
ssnprintf(filename, sizeof(filename), "/proc/%li/status", pid);
if ((fh = fopen(filename, "r")) == NULL)
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
unsigned long tmp;
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
unsigned long tmp;
if (threads != 0)
ps->num_lwp = threads;
if (threads != 0)
ps->num_lwp = threads;
} /* int *ps_read_status */
static int ps_read_io(process_entry_t *ps) {
} /* int *ps_read_status */
static int ps_read_io(process_entry_t *ps) {
ssnprintf(filename, sizeof(filename), "/proc/%li/io", ps->id);
if ((fh = fopen(filename, "r")) == NULL) {
DEBUG("ps_read_io: Failed to open file `%s'", filename);
ssnprintf(filename, sizeof(filename), "/proc/%li/io", ps->id);
if ((fh = fopen(filename, "r")) == NULL) {
DEBUG("ps_read_io: Failed to open file `%s'", filename);
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
char errbuf[1024];
WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
char errbuf[1024];
WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
} /* int ps_read_io (...) */
static int ps_count_fd(int pid) {
} /* int ps_read_io (...) */
static int ps_count_fd(int pid) {
if ((dh = opendir(dirname)) == NULL) {
DEBUG("Failed to open directory `%s'", dirname);
if ((dh = opendir(dirname)) == NULL) {
DEBUG("Failed to open directory `%s'", dirname);
}
while ((ent = readdir(dh)) != NULL) {
if (!isdigit((int)ent->d_name[0]))
}
while ((ent = readdir(dh)) != NULL) {
if (!isdigit((int)ent->d_name[0]))
- return ((count >= 1) ? count : 1);
+ return (count >= 1) ? count : 1;
} /* int ps_count_fd (pid) */
static void ps_fill_details(const procstat_t *ps, process_entry_t *entry) {
} /* int ps_count_fd (pid) */
static void ps_fill_details(const procstat_t *ps, process_entry_t *entry) {
status = read_file_contents(filename, buffer, sizeof(buffer) - 1);
if (status <= 0)
status = read_file_contents(filename, buffer, sizeof(buffer) - 1);
if (status <= 0)
buffer_len = (size_t)status;
buffer[buffer_len] = 0;
buffer_len = (size_t)status;
buffer[buffer_len] = 0;
if (name_start_pos >= name_end_pos) {
ERROR("processes plugin: name_start_pos = %zu >= name_end_pos = %zu",
name_start_pos, name_end_pos);
if (name_start_pos >= name_end_pos) {
ERROR("processes plugin: name_start_pos = %zu >= name_end_pos = %zu",
name_start_pos, name_end_pos);
}
name_len = (name_end_pos - name_start_pos) - 1;
}
name_len = (name_end_pos - name_start_pos) - 1;
sstrncpy(ps->name, &buffer[name_start_pos + 1], name_len + 1);
if ((buffer_len - name_end_pos) < 2)
sstrncpy(ps->name, &buffer[name_start_pos + 1], name_len + 1);
if ((buffer_len - name_end_pos) < 2)
buffer_ptr = &buffer[name_end_pos + 2];
fields_len = strsplit(buffer_ptr, fields, STATIC_ARRAY_SIZE(fields));
buffer_ptr = &buffer[name_end_pos + 2];
fields_len = strsplit(buffer_ptr, fields, STATIC_ARRAY_SIZE(fields));
DEBUG("processes plugin: ps_read_process (pid = %li):"
" `%s' has only %i fields..",
pid, filename, fields_len);
DEBUG("processes plugin: ps_read_process (pid = %li):"
" `%s' has only %i fields..",
pid, filename, fields_len);
DEBUG("processes plugin: This is only a zombie: pid = %li; "
"name = %s;",
pid, ps->name);
DEBUG("processes plugin: This is only a zombie: pid = %li; "
"name = %s;",
pid, ps->name);
}
cpu_user_counter = atoll(fields[11]);
}
cpu_user_counter = atoll(fields[11]);
ps->cswitch_invol = -1;
/* success */
ps->cswitch_invol = -1;
/* success */
} /* int ps_read_process (...) */
static char *ps_get_cmdline(long pid, char *name, char *buf, size_t buf_len) {
} /* int ps_read_process (...) */
static char *ps_get_cmdline(long pid, char *name, char *buf, size_t buf_len) {
char errbuf[1024];
ERROR("processes plugin: fopen (/proc/stat) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("processes plugin: fopen (/proc/stat) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, sizeof(buffer), proc_stat) != NULL) {
}
while (fgets(buffer, sizeof(buffer), proc_stat) != NULL) {
fclose(proc_stat);
if (!value_valid)
fclose(proc_stat);
if (!value_valid)
ps_submit_fork_rate(value.derive);
ps_submit_fork_rate(value.derive);
}
#endif /*KERNEL_LINUX */
}
#endif /*KERNEL_LINUX */
"while reading \"%s\": "
"Returned %zd but expected %zu.",
path, status, buffer_size);
"while reading \"%s\": "
"Returned %zd but expected %zu.",
path, status, buffer_size);
}
info.pr_psargs[sizeof(info.pr_psargs) - 1] = 0;
sstrncpy(buffer, info.pr_psargs, buffer_size);
}
info.pr_psargs[sizeof(info.pr_psargs) - 1] = 0;
sstrncpy(buffer, info.pr_psargs, buffer_size);
} /* }}} int ps_get_cmdline */
/*
} /* }}} int ps_get_cmdline */
/*
sfree(myStatus);
sfree(myInfo);
sfree(myUsage);
sfree(myStatus);
sfree(myInfo);
sfree(myUsage);
} else {
ps->num_proc = 1;
ps->num_lwp = myInfo->pr_nlwp;
} else {
ps->num_proc = 1;
ps->num_lwp = myInfo->pr_nlwp;
sfree(myInfo);
sfree(myUsage);
sfree(myInfo);
sfree(myUsage);
derive_t result = 0;
if (kc == NULL)
derive_t result = 0;
if (kc == NULL)
for (kstat_t *ksp_chain = kc->kc_chain; ksp_chain != NULL;
ksp_chain = ksp_chain->ks_next) {
for (kstat_t *ksp_chain = kc->kc_chain; ksp_chain != NULL;
ksp_chain = ksp_chain->ks_next) {
}
ps_submit_fork_rate(result);
}
ps_submit_fork_rate(result);
}
#endif /* KERNEL_SOLARIS */
}
#endif /* KERNEL_SOLARIS */
mib[2] = KERN_PROC_PID;
if (pid_for_task(t, pid) != KERN_SUCCESS)
mib[2] = KERN_PROC_PID;
if (pid_for_task(t, pid) != KERN_SUCCESS)
mib[3] = *pid;
kp_size = sizeof(kp);
if (sysctl(mib, 4, &kp, &kp_size, NULL, 0) != 0)
mib[3] = *pid;
kp_size = sizeof(kp);
if (sysctl(mib, 4, &kp, &kp_size, NULL, 0) != 0)
if (name_max_len > (MAXCOMLEN + 1))
name_max_len = MAXCOMLEN + 1;
if (name_max_len > (MAXCOMLEN + 1))
name_max_len = MAXCOMLEN + 1;
* `top' does it, because it is a lot of work and only used when
* debugging. -octo */
* `top' does it, because it is a lot of work and only used when
* debugging. -octo */
}
#endif /* HAVE_THREAD_INFO */
/* ------- end of additional functions for KERNEL_LINUX/HAVE_THREAD_INFO -------
}
#endif /* HAVE_THREAD_INFO */
/* ------- end of additional functions for KERNEL_LINUX/HAVE_THREAD_INFO -------
if ((proc = opendir("/proc")) == NULL) {
char errbuf[1024];
ERROR("Cannot open `/proc': %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if ((proc = opendir("/proc")) == NULL) {
char errbuf[1024];
ERROR("Cannot open `/proc': %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
while ((ent = readdir(proc)) != NULL) {
}
while ((ent = readdir(proc)) != NULL) {
kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf);
if (kd == NULL) {
ERROR("processes plugin: Cannot open kvm interface: %s", errbuf);
kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf);
if (kd == NULL) {
ERROR("processes plugin: Cannot open kvm interface: %s", errbuf);
}
/* Get the list of processes. */
}
/* Get the list of processes. */
ERROR("processes plugin: Cannot get kvm processes list: %s",
kvm_geterr(kd));
kvm_close(kd);
ERROR("processes plugin: Cannot get kvm processes list: %s",
kvm_geterr(kd));
kvm_close(kd);
}
/* Iterate through the processes in kinfo_proc */
}
/* Iterate through the processes in kinfo_proc */
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
if (kd == NULL) {
ERROR("processes plugin: Cannot open kvm interface: %s", errbuf);
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
if (kd == NULL) {
ERROR("processes plugin: Cannot open kvm interface: %s", errbuf);
}
/* Get the list of processes. */
}
/* Get the list of processes. */
ERROR("processes plugin: Cannot get kvm processes list: %s",
kvm_geterr(kd));
kvm_close(kd);
ERROR("processes plugin: Cannot get kvm processes list: %s",
kvm_geterr(kd));
kvm_close(kd);
}
/* Iterate through the processes in kinfo_proc */
}
/* Iterate through the processes in kinfo_proc */
proc = opendir("/proc");
if (proc == NULL)
proc = opendir("/proc");
if (proc == NULL)
while ((ent = readdir(proc)) != NULL) {
long pid;
while ((ent = readdir(proc)) != NULL) {
long pid;
} /* int ps_read */
void module_register(void) {
} /* int ps_read */
void module_register(void) {
if (fh == NULL) {
ERROR("protocols plugin: fopen (%s) failed: %s.", path,
sstrerror(errno, key_buffer, sizeof(key_buffer)));
if (fh == NULL) {
ERROR("protocols plugin: fopen (%s) failed: %s.", path,
sstrerror(errno, key_buffer, sizeof(key_buffer)));
} /* int read_file */
static int protocols_read(void) {
} /* int read_file */
static int protocols_read(void) {
success++;
if (success == 0)
success++;
if (success == 0)
} /* int protocols_read */
static int protocols_config(const char *key, const char *value) {
} /* int protocols_read */
static int protocols_config(const char *key, const char *value) {
invert = 0;
ignorelist_set_invert(values_list, invert);
} else {
invert = 0;
ignorelist_set_invert(values_list, invert);
} else {
} /* int protocols_config */
void module_register(void) {
} /* int protocols_config */
void module_register(void) {
static PyObject *cpy_register_notification(PyObject *self, PyObject *args,
PyObject *kwds) {
return cpy_register_generic_userdata((void *)plugin_register_notification,
static PyObject *cpy_register_notification(PyObject *self, PyObject *args,
PyObject *kwds) {
return cpy_register_generic_userdata((void *)plugin_register_notification,
- (void *)cpy_notification_callback, args,
- kwds);
+ (void *)cpy_notification_callback,
+ args, kwds);
}
static PyObject *cpy_register_flush(PyObject *self, PyObject *args,
}
static PyObject *cpy_register_flush(PyObject *self, PyObject *args,
}
static PyObject *cpy_unregister_write(PyObject *self, PyObject *arg) {
}
static PyObject *cpy_unregister_write(PyObject *self, PyObject *arg) {
- return cpy_unregister_generic_userdata(plugin_unregister_write, arg, "write");
+ return cpy_unregister_generic_userdata(plugin_unregister_write, arg,
+ "write");
}
static PyObject *cpy_unregister_notification(PyObject *self, PyObject *arg) {
}
static PyObject *cpy_unregister_notification(PyObject *self, PyObject *arg) {
}
static PyObject *cpy_unregister_flush(PyObject *self, PyObject *arg) {
}
static PyObject *cpy_unregister_flush(PyObject *self, PyObject *arg) {
- return cpy_unregister_generic_userdata(plugin_unregister_flush, arg, "flush");
+ return cpy_unregister_generic_userdata(plugin_unregister_flush, arg,
+ "flush");
}
static PyObject *cpy_unregister_shutdown(PyObject *self, PyObject *arg) {
}
static PyObject *cpy_unregister_shutdown(PyObject *self, PyObject *arg) {
}
void module_register(void) {
}
void module_register(void) {
if (rn_ptr != NULL) {
ERROR("redis plugin: A node with the name `%s' already exists.", rn->name);
if (rn_ptr != NULL) {
ERROR("redis plugin: A node with the name `%s' already exists.", rn->name);
}
rn_copy = malloc(sizeof(*rn_copy));
if (rn_copy == NULL) {
ERROR("redis plugin: malloc failed adding redis_node to the tree.");
}
rn_copy = malloc(sizeof(*rn_copy));
if (rn_copy == NULL) {
ERROR("redis plugin: malloc failed adding redis_node to the tree.");
}
memcpy(rn_copy, rn, sizeof(*rn_copy));
}
memcpy(rn_copy, rn, sizeof(*rn_copy));
rn_ptr->next = rn_copy;
}
rn_ptr->next = rn_copy;
}
} /* }}} */
static redis_query_t *redis_config_query(oconfig_item_t *ci) /* {{{ */
} /* }}} */
static redis_query_t *redis_config_query(oconfig_item_t *ci) /* {{{ */
status = cf_util_get_string_buffer(ci, rn.name, sizeof(rn.name));
if (status != 0)
status = cf_util_get_string_buffer(ci, rn.name, sizeof(rn.name));
if (status != 0)
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *option = ci->children + i;
for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *option = ci->children + i;
- return (redis_node_add(&rn));
+ return redis_node_add(&rn);
} /* }}} int redis_config_node */
static int redis_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int redis_config_node */
static int redis_config(oconfig_item_t *ci) /* {{{ */
if (nodes_head == NULL) {
ERROR("redis plugin: No valid node configuration could be found.");
if (nodes_head == NULL) {
ERROR("redis plugin: No valid node configuration could be found.");
} /* }}} */
__attribute__((nonnull(2))) static void
} /* }}} */
__attribute__((nonnull(2))) static void
if (nodes_head == NULL)
redis_node_add(&rn);
if (nodes_head == NULL)
redis_node_add(&rn);
} /* }}} int redis_init */
static int redis_handle_info(char *node, char const *info_line,
} /* }}} int redis_init */
static int redis_handle_info(char *node, char const *info_line,
if (parse_value(buf, &val, ds_type) == -1) {
WARNING("redis plugin: Unable to parse field `%s'.", field_name);
if (parse_value(buf, &val, ds_type) == -1) {
WARNING("redis plugin: Unable to parse field `%s'.", field_name);
}
redis_submit(node, type, type_instance, val);
}
redis_submit(node, type, type_instance, val);
} /* }}} int redis_handle_info */
} /* }}} int redis_handle_info */
ds = plugin_get_ds(rq->type);
if (!ds) {
ERROR("redis plugin: DataSet `%s' not defined.", rq->type);
ds = plugin_get_ds(rq->type);
if (!ds) {
ERROR("redis plugin: DataSet `%s' not defined.", rq->type);
}
if (ds->ds_num != 1) {
ERROR("redis plugin: DS `%s' has too many types.", rq->type);
}
if (ds->ds_num != 1) {
ERROR("redis plugin: DS `%s' has too many types.", rq->type);
}
if ((rr = redisCommand(rh, rq->query)) == NULL) {
WARNING("redis plugin: unable to carry out query `%s'.", rq->query);
}
if ((rr = redisCommand(rh, rq->query)) == NULL) {
WARNING("redis plugin: unable to carry out query `%s'.", rq->query);
if (parse_value(rr->str, &val, ds->ds[0].type) == -1) {
WARNING("redis plugin: Unable to parse field `%s'.", rq->type);
freeReplyObject(rr);
if (parse_value(rr->str, &val, ds->ds[0].type) == -1) {
WARNING("redis plugin: Unable to parse field `%s'.", rq->type);
freeReplyObject(rr);
}
break;
default:
WARNING("redis plugin: Cannot coerce redis type.");
freeReplyObject(rr);
}
break;
default:
WARNING("redis plugin: Cannot coerce redis type.");
freeReplyObject(rr);
}
redis_submit(rn->name, rq->type,
}
redis_submit(rn->name, rq->type,
if (parse_value(buf, &val, DS_TYPE_GAUGE) != 0) {
WARNING("redis plugin: Unable to parse field `%s'.", field_name);
if (parse_value(buf, &val, DS_TYPE_GAUGE) != 0) {
WARNING("redis plugin: Unable to parse field `%s'.", field_name);
}
ssnprintf(db_id, sizeof(db_id), "%d", db);
redis_submit(node, "records", db_id, val);
}
}
ssnprintf(db_id, sizeof(db_id), "%d", db);
redis_submit(node, "records", db_id, val);
}
} /* }}} int redis_db_stats */
} /* }}} int redis_db_stats */
const ros_interface_t *i,
void *user_data) {
if ((i == NULL) || (user_data == NULL))
const ros_interface_t *i,
void *user_data) {
if ((i == NULL) || (user_data == NULL))
submit_interface(user_data, i);
submit_interface(user_data, i);
} /* }}} int handle_interface */
static void cr_submit_gauge(cr_data_t *rd, const char *type, /* {{{ */
} /* }}} int handle_interface */
static void cr_submit_gauge(cr_data_t *rd, const char *type, /* {{{ */
const ros_registration_table_t *r,
void *user_data) {
if ((r == NULL) || (user_data == NULL))
const ros_registration_table_t *r,
void *user_data) {
if ((r == NULL) || (user_data == NULL))
submit_regtable(user_data, r);
submit_regtable(user_data, r);
} /* }}} int handle_regtable */
#if ROS_VERSION >= ROS_VERSION_ENCODE(1, 1, 0)
} /* }}} int handle_regtable */
#if ROS_VERSION >= ROS_VERSION_ENCODE(1, 1, 0)
cr_data_t *rd;
if ((r == NULL) || (user_data == NULL))
cr_data_t *rd;
if ((r == NULL) || (user_data == NULL))
rd = user_data;
if (rd->collect_cpu_load)
rd = user_data;
if (rd->collect_cpu_load)
cr_submit_gauge(rd, "gauge", "bad_blocks", (gauge_t)r->bad_blocks);
}
cr_submit_gauge(rd, "gauge", "bad_blocks", (gauge_t)r->bad_blocks);
}
} /* }}} int handle_system_resource */
#endif
} /* }}} int handle_system_resource */
#endif
cr_data_t *rd;
if (user_data == NULL)
cr_data_t *rd;
if (user_data == NULL)
rd = user_data->data;
if (rd == NULL)
rd = user_data->data;
if (rd == NULL)
if (rd->connection == NULL) {
rd->connection =
if (rd->connection == NULL) {
rd->connection =
char errbuf[128];
ERROR("routeros plugin: ros_connect failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[128];
ERROR("routeros plugin: ros_connect failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
}
assert(rd->connection != NULL);
}
}
assert(rd->connection != NULL);
sstrerror(status, errbuf, sizeof(errbuf)));
ros_disconnect(rd->connection);
rd->connection = NULL;
sstrerror(status, errbuf, sizeof(errbuf)));
ros_disconnect(rd->connection);
rd->connection = NULL;
sstrerror(status, errbuf, sizeof(errbuf)));
ros_disconnect(rd->connection);
rd->connection = NULL;
sstrerror(status, errbuf, sizeof(errbuf)));
ros_disconnect(rd->connection);
rd->connection = NULL;
sstrerror(status, errbuf, sizeof(errbuf)));
ros_disconnect(rd->connection);
rd->connection = NULL;
sstrerror(status, errbuf, sizeof(errbuf)));
ros_disconnect(rd->connection);
rd->connection = NULL;
} /* }}} int cr_read */
static void cr_free_data(cr_data_t *ptr) /* {{{ */
} /* }}} int cr_read */
static void cr_free_data(cr_data_t *ptr) /* {{{ */
router_data = calloc(1, sizeof(*router_data));
if (router_data == NULL)
router_data = calloc(1, sizeof(*router_data));
if (router_data == NULL)
router_data->connection = NULL;
router_data->node = NULL;
router_data->service = NULL;
router_data->connection = NULL;
router_data->node = NULL;
router_data->service = NULL;
if (status != 0)
cr_free_data(router_data);
if (status != 0)
cr_free_data(router_data);
} /* }}} int cr_config_router */
static int cr_config(oconfig_item_t *ci) {
} /* }}} int cr_config_router */
static int cr_config(oconfig_item_t *ci) {
} /* }}} int cr_config */
void module_register(void) {
} /* }}} int cr_config */
void module_register(void) {
t = CDTIME_T_TO_TIME_T(vl->time);
status = ssnprintf(buffer, buffer_len, "%lu", (unsigned long)t);
if ((status < 1) || (status >= buffer_len))
t = CDTIME_T_TO_TIME_T(vl->time);
status = ssnprintf(buffer, buffer_len, "%lu", (unsigned long)t);
if ((status < 1) || (status >= buffer_len))
offset = status;
for (size_t i = 0; i < ds->ds_num; i++) {
offset = status;
for (size_t i = 0; i < ds->ds_num; i++) {
(ds->ds[i].type != DS_TYPE_GAUGE) &&
(ds->ds[i].type != DS_TYPE_DERIVE) &&
(ds->ds[i].type != DS_TYPE_ABSOLUTE))
(ds->ds[i].type != DS_TYPE_GAUGE) &&
(ds->ds[i].type != DS_TYPE_DERIVE) &&
(ds->ds[i].type != DS_TYPE_ABSOLUTE))
if (ds->ds[i].type == DS_TYPE_COUNTER) {
status = ssnprintf(buffer + offset, buffer_len - offset, ":%llu",
if (ds->ds[i].type == DS_TYPE_COUNTER) {
status = ssnprintf(buffer + offset, buffer_len - offset, ":%llu",
}
if ((status < 1) || (status >= (buffer_len - offset)))
}
if ((status < 1) || (status >= (buffer_len - offset)))
offset += status;
} /* for ds->ds_num */
offset += status;
} /* for ds->ds_num */
} /* int value_list_to_string */
static int value_list_to_filename(char *buffer, size_t buffer_size,
} /* int value_list_to_string */
static int value_list_to_filename(char *buffer, size_t buffer_size,
size_t datadir_len = strlen(datadir) + 1;
if (datadir_len >= buffer_size)
size_t datadir_len = strlen(datadir) + 1;
if (datadir_len >= buffer_size)
sstrncpy(buffer, datadir, buffer_size);
buffer[datadir_len - 1] = '/';
sstrncpy(buffer, datadir, buffer_size);
buffer[datadir_len - 1] = '/';
status = FORMAT_VL(buffer, buffer_size, vl);
if (status != 0)
status = FORMAT_VL(buffer, buffer_size, vl);
if (status != 0)
len = strlen(buffer);
assert(len < buffer_size);
len = strlen(buffer);
assert(len < buffer_size);
buffer_size -= len;
if (buffer_size <= sizeof(suffix))
buffer_size -= len;
if (buffer_size <= sizeof(suffix))
memcpy(buffer, suffix, sizeof(suffix));
memcpy(buffer, suffix, sizeof(suffix));
} /* int value_list_to_filename */
static int rc_config_get_int_positive(oconfig_item_t const *ci, int *ret) {
} /* int value_list_to_filename */
static int rc_config_get_int_positive(oconfig_item_t const *ci, int *ret) {
status = cf_util_get_int(ci, &tmp);
if (status != 0)
status = cf_util_get_int(ci, &tmp);
if (status != 0)
} /* int rc_config_get_int_positive */
static int rc_config_get_xff(oconfig_item_t const *ci, double *ret) {
} /* int rc_config_get_int_positive */
static int rc_config_get_xff(oconfig_item_t const *ci, double *ret) {
ERROR("rrdcached plugin: The \"%s\" needs exactly one numeric argument "
"in the range [0.0, 1.0)",
ci->key);
ERROR("rrdcached plugin: The \"%s\" needs exactly one numeric argument "
"in the range [0.0, 1.0)",
ci->key);
}
value = ci->values[0].value.number;
if ((value >= 0.0) && (value < 1.0)) {
*ret = value;
}
value = ci->values[0].value.number;
if ((value >= 0.0) && (value < 1.0)) {
*ret = value;
}
ERROR("rrdcached plugin: The \"%s\" needs exactly one numeric argument "
"in the range [0.0, 1.0)",
ci->key);
}
ERROR("rrdcached plugin: The \"%s\" needs exactly one numeric argument "
"in the range [0.0, 1.0)",
ci->key);
} /* int rc_config_get_xff */
static int rc_config_add_timespan(int timespan) {
int *tmp;
if (timespan <= 0)
} /* int rc_config_get_xff */
static int rc_config_add_timespan(int timespan) {
int *tmp;
if (timespan <= 0)
tmp = realloc(rrdcreate_config.timespans,
sizeof(*rrdcreate_config.timespans) *
(rrdcreate_config.timespans_num + 1));
if (tmp == NULL)
tmp = realloc(rrdcreate_config.timespans,
sizeof(*rrdcreate_config.timespans) *
(rrdcreate_config.timespans_num + 1));
if (tmp == NULL)
rrdcreate_config.timespans = tmp;
rrdcreate_config.timespans[rrdcreate_config.timespans_num] = timespan;
rrdcreate_config.timespans_num++;
rrdcreate_config.timespans = tmp;
rrdcreate_config.timespans[rrdcreate_config.timespans_num] = timespan;
rrdcreate_config.timespans_num++;
} /* int rc_config_add_timespan */
static int rc_config(oconfig_item_t *ci) {
} /* int rc_config_add_timespan */
static int rc_config(oconfig_item_t *ci) {
plugin_register_write("rrdcached", rc_write, /* user_data = */ NULL);
plugin_register_flush("rrdcached", rc_flush, /* user_data = */ NULL);
}
plugin_register_write("rrdcached", rc_write, /* user_data = */ NULL);
plugin_register_flush("rrdcached", rc_flush, /* user_data = */ NULL);
}
} /* int rc_config */
static int try_reconnect(void) {
} /* int rc_config */
static int try_reconnect(void) {
ERROR("rrdcached plugin: Failed to reconnect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
ERROR("rrdcached plugin: Failed to reconnect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
}
INFO("rrdcached plugin: Successfully reconnected to RRDCacheD "
"at %s",
daemon_address);
}
INFO("rrdcached plugin: Successfully reconnected to RRDCacheD "
"at %s",
daemon_address);
} /* int try_reconnect */
static int rc_read(void) {
} /* int try_reconnect */
static int rc_read(void) {
vl.values_len = 1;
if (daemon_address == NULL)
vl.values_len = 1;
if (daemon_address == NULL)
if (!config_collect_stats)
if (!config_collect_stats)
if ((strncmp("unix:", daemon_address, strlen("unix:")) != 0) &&
(daemon_address[0] != '/'))
if ((strncmp("unix:", daemon_address, strlen("unix:")) != 0) &&
(daemon_address[0] != '/'))
ERROR("rrdcached plugin: Failed to connect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
ERROR("rrdcached plugin: Failed to connect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
ERROR("rrdcached plugin: rrdc_stats_get failed: %s (status=%i).",
rrd_get_error(), status);
ERROR("rrdcached plugin: rrdc_stats_get failed: %s (status=%i).",
rrd_get_error(), status);
}
for (rrdc_stats_t *ptr = head; ptr != NULL; ptr = ptr->next) {
}
for (rrdc_stats_t *ptr = head; ptr != NULL; ptr = ptr->next) {
} /* int rc_read */
static int rc_init(void) {
if (config_collect_stats)
plugin_register_read("rrdcached", rc_read);
} /* int rc_read */
static int rc_init(void) {
if (config_collect_stats)
plugin_register_read("rrdcached", rc_read);
} /* int rc_init */
static int rc_write(const data_set_t *ds, const value_list_t *vl,
} /* int rc_init */
static int rc_write(const data_set_t *ds, const value_list_t *vl,
if (daemon_address == NULL) {
ERROR("rrdcached plugin: daemon_address == NULL.");
plugin_unregister_write("rrdcached");
if (daemon_address == NULL) {
ERROR("rrdcached plugin: daemon_address == NULL.");
plugin_unregister_write("rrdcached");
}
if (strcmp(ds->type, vl->type) != 0) {
ERROR("rrdcached plugin: DS type does not match value list type");
}
if (strcmp(ds->type, vl->type) != 0) {
ERROR("rrdcached plugin: DS type does not match value list type");
}
if (value_list_to_filename(filename, sizeof(filename), vl) != 0) {
ERROR("rrdcached plugin: value_list_to_filename failed.");
}
if (value_list_to_filename(filename, sizeof(filename), vl) != 0) {
ERROR("rrdcached plugin: value_list_to_filename failed.");
}
if (value_list_to_string(values, sizeof(values), ds, vl) != 0) {
ERROR("rrdcached plugin: value_list_to_string failed.");
}
if (value_list_to_string(values, sizeof(values), ds, vl) != 0) {
ERROR("rrdcached plugin: value_list_to_string failed.");
}
values_array[0] = values;
}
values_array[0] = values;
char errbuf[1024];
ERROR("rrdcached plugin: stat (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("rrdcached plugin: stat (%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
status = cu_rrd_create_file(filename, ds, vl, &rrdcreate_config);
if (status != 0) {
ERROR("rrdcached plugin: cu_rrd_create_file (%s) failed.", filename);
}
status = cu_rrd_create_file(filename, ds, vl, &rrdcreate_config);
if (status != 0) {
ERROR("rrdcached plugin: cu_rrd_create_file (%s) failed.", filename);
} else if (rrdcreate_config.async)
} else if (rrdcreate_config.async)
ERROR("rrdcached plugin: Failed to connect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
ERROR("rrdcached plugin: Failed to connect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
ERROR("rrdcached plugin: rrdc_update (%s, [%s], 1) failed: %s (status=%i)",
filename, values_array[0], rrd_get_error(), status);
ERROR("rrdcached plugin: rrdc_update (%s, [%s], 1) failed: %s (status=%i)",
filename, values_array[0], rrd_get_error(), status);
} /* int rc_write */
static int rc_flush(__attribute__((unused)) cdtime_t timeout, /* {{{ */
} /* int rc_write */
static int rc_flush(__attribute__((unused)) cdtime_t timeout, /* {{{ */
_Bool retried = 0;
if (identifier == NULL)
_Bool retried = 0;
if (identifier == NULL)
if (datadir != NULL)
ssnprintf(filename, sizeof(filename), "%s/%s.rrd", datadir, identifier);
if (datadir != NULL)
ssnprintf(filename, sizeof(filename), "%s/%s.rrd", datadir, identifier);
ERROR("rrdcached plugin: Failed to connect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
ERROR("rrdcached plugin: Failed to connect to RRDCacheD "
"at %s: %s (status=%d)",
daemon_address, rrd_get_error(), status);
ERROR("rrdcached plugin: rrdc_flush (%s) failed: %s (status=%i).", filename,
rrd_get_error(), status);
ERROR("rrdcached plugin: rrdc_flush (%s) failed: %s (status=%i).", filename,
rrd_get_error(), status);
}
DEBUG("rrdcached plugin: rrdc_flush (%s): Success.", filename);
}
DEBUG("rrdcached plugin: rrdc_flush (%s): Success.", filename);
} /* }}} int rc_flush */
static int rc_shutdown(void) {
rrdc_disconnect();
} /* }}} int rc_flush */
static int rc_shutdown(void) {
rrdc_disconnect();
} /* int rc_shutdown */
void module_register(void) {
} /* int rc_shutdown */
void module_register(void) {
} /* int srrd_update */
/* #endif HAVE_THREADSAFE_LIBRRD */
} /* int srrd_update */
/* #endif HAVE_THREADSAFE_LIBRRD */
new_argv = malloc((new_argc + 1) * sizeof(*new_argv));
if (new_argv == NULL) {
ERROR("rrdtool plugin: malloc failed.");
new_argv = malloc((new_argc + 1) * sizeof(*new_argv));
if (new_argv == NULL) {
ERROR("rrdtool plugin: malloc failed.");
}
new_argv[0] = "update";
}
new_argv[0] = "update";
} /* int srrd_update */
#endif /* !HAVE_THREADSAFE_LIBRRD */
} /* int srrd_update */
#endif /* !HAVE_THREADSAFE_LIBRRD */
tt = CDTIME_T_TO_TIME_T(vl->time);
status = ssnprintf(buffer, buffer_len, "%u", (unsigned int)tt);
if ((status < 1) || (status >= buffer_len))
tt = CDTIME_T_TO_TIME_T(vl->time);
status = ssnprintf(buffer, buffer_len, "%u", (unsigned int)tt);
if ((status < 1) || (status >= buffer_len))
offset = status;
for (size_t i = 0; i < ds->ds_num; i++) {
offset = status;
for (size_t i = 0; i < ds->ds_num; i++) {
(ds->ds[i].type != DS_TYPE_GAUGE) &&
(ds->ds[i].type != DS_TYPE_DERIVE) &&
(ds->ds[i].type != DS_TYPE_ABSOLUTE))
(ds->ds[i].type != DS_TYPE_GAUGE) &&
(ds->ds[i].type != DS_TYPE_DERIVE) &&
(ds->ds[i].type != DS_TYPE_ABSOLUTE))
if (ds->ds[i].type == DS_TYPE_COUNTER)
status = ssnprintf(buffer + offset, buffer_len - offset, ":%llu",
if (ds->ds[i].type == DS_TYPE_COUNTER)
status = ssnprintf(buffer + offset, buffer_len - offset, ":%llu",
vl->values[i].absolute);
if ((status < 1) || (status >= (buffer_len - offset)))
vl->values[i].absolute);
if ((status < 1) || (status >= (buffer_len - offset)))
offset += status;
} /* for ds->ds_num */
offset += status;
} /* for ds->ds_num */
} /* int value_list_to_string_multiple */
static int value_list_to_string(char *buffer, int buffer_len,
} /* int value_list_to_string_multiple */
static int value_list_to_string(char *buffer, int buffer_len,
time_t tt;
if (ds->ds_num != 1)
time_t tt;
if (ds->ds_num != 1)
- return (value_list_to_string_multiple(buffer, buffer_len, ds, vl));
+ return value_list_to_string_multiple(buffer, buffer_len, ds, vl);
tt = CDTIME_T_TO_TIME_T(vl->time);
switch (ds->ds[0].type) {
tt = CDTIME_T_TO_TIME_T(vl->time);
switch (ds->ds[0].type) {
vl->values[0].absolute);
break;
default:
vl->values[0].absolute);
break;
default:
}
if ((status < 1) || (status >= buffer_len))
}
if ((status < 1) || (status >= buffer_len))
} /* int value_list_to_string */
static int value_list_to_filename(char *buffer, size_t buffer_size,
} /* int value_list_to_string */
static int value_list_to_filename(char *buffer, size_t buffer_size,
size_t datadir_len = strlen(datadir) + 1;
if (datadir_len >= buffer_size)
size_t datadir_len = strlen(datadir) + 1;
if (datadir_len >= buffer_size)
sstrncpy(buffer, datadir, buffer_size);
buffer[datadir_len - 1] = '/';
sstrncpy(buffer, datadir, buffer_size);
buffer[datadir_len - 1] = '/';
status = FORMAT_VL(buffer, buffer_size, vl);
if (status != 0)
status = FORMAT_VL(buffer, buffer_size, vl);
if (status != 0)
len = strlen(buffer);
assert(len < buffer_size);
len = strlen(buffer);
assert(len < buffer_size);
buffer_size -= len;
if (buffer_size <= sizeof(suffix))
buffer_size -= len;
if (buffer_size <= sizeof(suffix))
memcpy(buffer, suffix, sizeof(suffix));
memcpy(buffer, suffix, sizeof(suffix));
} /* int value_list_to_filename */
static void *rrd_queue_thread(void __attribute__((unused)) * data) {
} /* int value_list_to_filename */
static void *rrd_queue_thread(void __attribute__((unused)) * data) {
} /* while (42) */
pthread_exit((void *)0);
} /* while (42) */
pthread_exit((void *)0);
} /* void *rrd_queue_thread */
static int rrd_queue_enqueue(const char *filename, rrd_queue_t **head,
} /* void *rrd_queue_thread */
static int rrd_queue_enqueue(const char *filename, rrd_queue_t **head,
queue_entry = malloc(sizeof(*queue_entry));
if (queue_entry == NULL)
queue_entry = malloc(sizeof(*queue_entry));
if (queue_entry == NULL)
queue_entry->filename = strdup(filename);
if (queue_entry->filename == NULL) {
free(queue_entry);
queue_entry->filename = strdup(filename);
if (queue_entry->filename == NULL) {
free(queue_entry);
}
queue_entry->next = NULL;
}
queue_entry->next = NULL;
pthread_cond_signal(&queue_cond);
pthread_mutex_unlock(&queue_lock);
pthread_cond_signal(&queue_cond);
pthread_mutex_unlock(&queue_lock);
} /* int rrd_queue_enqueue */
static int rrd_queue_dequeue(const char *filename, rrd_queue_t **head,
} /* int rrd_queue_enqueue */
static int rrd_queue_dequeue(const char *filename, rrd_queue_t **head,
if (this == NULL) {
pthread_mutex_unlock(&queue_lock);
if (this == NULL) {
pthread_mutex_unlock(&queue_lock);
sfree(this->filename);
sfree(this);
sfree(this->filename);
sfree(this);
} /* int rrd_queue_dequeue */
/* XXX: You must hold "cache_lock" when calling this function! */
} /* int rrd_queue_dequeue */
/* XXX: You must hold "cache_lock" when calling this function! */
if (identifier == NULL) {
rrd_cache_flush(timeout);
if (identifier == NULL) {
rrd_cache_flush(timeout);
INFO("rrdtool plugin: rrd_cache_flush_identifier: "
"c_avl_get (%s) failed. Does that file really exist?",
key);
INFO("rrdtool plugin: rrd_cache_flush_identifier: "
"c_avl_get (%s) failed. Does that file really exist?",
key);
}
if (rc->flags == FLAG_FLUSHQ) {
}
if (rc->flags == FLAG_FLUSHQ) {
rc->flags = FLAG_FLUSHQ;
}
rc->flags = FLAG_FLUSHQ;
}
} /* int rrd_cache_flush_identifier */
static int64_t rrd_get_random_variation(void) {
} /* int rrd_cache_flush_identifier */
static int64_t rrd_get_random_variation(void) {
long max;
if (random_timeout == 0)
long max;
if (random_timeout == 0)
/* Assure that "cache_timeout + random_variation" is never negative. */
if (random_timeout > cache_timeout) {
/* Assure that "cache_timeout + random_variation" is never negative. */
if (random_timeout > cache_timeout) {
max = (long)(random_timeout / 2);
min = max - ((long)random_timeout);
max = (long)(random_timeout / 2);
min = max - ((long)random_timeout);
- return ((int64_t)cdrand_range(min, max));
+ return (int64_t)cdrand_range(min, max);
} /* int64_t rrd_get_random_variation */
static int rrd_cache_insert(const char *filename, const char *value,
} /* int64_t rrd_get_random_variation */
static int rrd_cache_insert(const char *filename, const char *value,
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
WARNING("rrdtool plugin: cache == NULL.");
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
WARNING("rrdtool plugin: cache == NULL.");
}
c_avl_get(cache, filename, (void *)&rc);
}
c_avl_get(cache, filename, (void *)&rc);
rc = malloc(sizeof(*rc));
if (rc == NULL) {
pthread_mutex_unlock(&cache_lock);
rc = malloc(sizeof(*rc));
if (rc == NULL) {
pthread_mutex_unlock(&cache_lock);
}
rc->values_num = 0;
rc->values = NULL;
}
rc->values_num = 0;
rc->values = NULL;
DEBUG("rrdtool plugin: (rc->last_value = %" PRIu64 ") "
">= (value_time = %" PRIu64 ")",
rc->last_value, value_time);
DEBUG("rrdtool plugin: (rc->last_value = %" PRIu64 ") "
">= (value_time = %" PRIu64 ")",
rc->last_value, value_time);
sfree(cache_key);
sfree(rc->values);
sfree(rc);
sfree(cache_key);
sfree(rc->values);
sfree(rc);
}
rc->values = values_new;
}
rc->values = values_new;
sfree(rc->values[0]);
sfree(rc->values);
sfree(rc);
sfree(rc->values[0]);
sfree(rc->values);
sfree(rc);
}
c_avl_insert(cache, cache_key, rc);
}
c_avl_insert(cache, cache_key, rc);
pthread_mutex_unlock(&cache_lock);
pthread_mutex_unlock(&cache_lock);
} /* int rrd_cache_insert */
static int rrd_cache_destroy(void) /* {{{ */
} /* int rrd_cache_insert */
static int rrd_cache_destroy(void) /* {{{ */
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
}
while (c_avl_pick(cache, &key, &value) == 0) {
}
while (c_avl_pick(cache, &key, &value) == 0) {
}
pthread_mutex_unlock(&cache_lock);
}
pthread_mutex_unlock(&cache_lock);
} /* }}} int rrd_cache_destroy */
static int rrd_compare_numeric(const void *a_ptr, const void *b_ptr) {
} /* }}} int rrd_cache_destroy */
static int rrd_compare_numeric(const void *a_ptr, const void *b_ptr) {
int b = *((int *)b_ptr);
if (a < b)
int b = *((int *)b_ptr);
if (a < b)
} /* int rrd_compare_numeric */
static int rrd_write(const data_set_t *ds, const value_list_t *vl,
} /* int rrd_compare_numeric */
static int rrd_write(const data_set_t *ds, const value_list_t *vl,
int status;
if (do_shutdown)
int status;
if (do_shutdown)
if (0 != strcmp(ds->type, vl->type)) {
ERROR("rrdtool plugin: DS type does not match value list type");
if (0 != strcmp(ds->type, vl->type)) {
ERROR("rrdtool plugin: DS type does not match value list type");
}
if (value_list_to_filename(filename, sizeof(filename), vl) != 0)
}
if (value_list_to_filename(filename, sizeof(filename), vl) != 0)
if (value_list_to_string(values, sizeof(values), ds, vl) != 0)
if (value_list_to_string(values, sizeof(values), ds, vl) != 0)
if (stat(filename, &statbuf) == -1) {
if (errno == ENOENT) {
status = cu_rrd_create_file(filename, ds, vl, &rrdcreate_config);
if (status != 0)
if (stat(filename, &statbuf) == -1) {
if (errno == ENOENT) {
status = cu_rrd_create_file(filename, ds, vl, &rrdcreate_config);
if (status != 0)
else if (rrdcreate_config.async)
else if (rrdcreate_config.async)
} else {
char errbuf[1024];
ERROR("stat(%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
} else {
char errbuf[1024];
ERROR("stat(%s) failed: %s", filename,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
} else if (!S_ISREG(statbuf.st_mode)) {
ERROR("stat(%s): Not a regular file!", filename);
}
} else if (!S_ISREG(statbuf.st_mode)) {
ERROR("stat(%s): Not a regular file!", filename);
}
status = rrd_cache_insert(filename, values, vl->time);
}
status = rrd_cache_insert(filename, values, vl->time);
} /* int rrd_write */
static int rrd_flush(cdtime_t timeout, const char *identifier,
} /* int rrd_write */
static int rrd_flush(cdtime_t timeout, const char *identifier,
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
}
rrd_cache_flush_identifier(timeout, identifier);
pthread_mutex_unlock(&cache_lock);
}
rrd_cache_flush_identifier(timeout, identifier);
pthread_mutex_unlock(&cache_lock);
} /* int rrd_flush */
static int rrd_config(const char *key, const char *value) {
} /* int rrd_flush */
static int rrd_config(const char *key, const char *value) {
"be greater than 0.\n");
ERROR("rrdtool: `CacheTimeout' must "
"be greater than 0.\n");
"be greater than 0.\n");
ERROR("rrdtool: `CacheTimeout' must "
"be greater than 0.\n");
}
cache_timeout = DOUBLE_TO_CDTIME_T(tmp);
} else if (strcasecmp("CacheFlush", key) == 0) {
}
cache_timeout = DOUBLE_TO_CDTIME_T(tmp);
} else if (strcasecmp("CacheFlush", key) == 0) {
"be greater than 0.\n");
ERROR("rrdtool: `CacheFlush' must "
"be greater than 0.\n");
"be greater than 0.\n");
ERROR("rrdtool: `CacheFlush' must "
"be greater than 0.\n");
}
cache_flush_timeout = tmp;
} else if (strcasecmp("DataDir", key) == 0) {
}
cache_flush_timeout = tmp;
} else if (strcasecmp("DataDir", key) == 0) {
tmp = strdup(value);
if (tmp == NULL) {
ERROR("rrdtool plugin: strdup failed.");
tmp = strdup(value);
if (tmp == NULL) {
ERROR("rrdtool plugin: strdup failed.");
if (len == 0) {
ERROR("rrdtool plugin: Invalid \"DataDir\" option.");
sfree(tmp);
if (len == 0) {
ERROR("rrdtool plugin: Invalid \"DataDir\" option.");
sfree(tmp);
"be greater than 0.\n");
ERROR("rrdtool: `RRARows' must "
"be greater than 0.\n");
"be greater than 0.\n");
ERROR("rrdtool: `RRARows' must "
"be greater than 0.\n");
}
rrdcreate_config.rrarows = tmp;
} else if (strcasecmp("RRATimespan", key) == 0) {
}
rrdcreate_config.rrarows = tmp;
} else if (strcasecmp("RRATimespan", key) == 0) {
value_copy = strdup(value);
if (value_copy == NULL)
value_copy = strdup(value);
if (value_copy == NULL)
dummy = value_copy;
while ((ptr = strtok_r(dummy, ", \t", &saveptr)) != NULL) {
dummy = value_copy;
while ((ptr = strtok_r(dummy, ", \t", &saveptr)) != NULL) {
fprintf(stderr, "rrdtool: realloc failed.\n");
ERROR("rrdtool: realloc failed.\n");
free(value_copy);
fprintf(stderr, "rrdtool: realloc failed.\n");
ERROR("rrdtool: realloc failed.\n");
free(value_copy);
}
rrdcreate_config.timespans = tmp_alloc;
rrdcreate_config.timespans[rrdcreate_config.timespans_num] = atoi(ptr);
}
rrdcreate_config.timespans = tmp_alloc;
rrdcreate_config.timespans[rrdcreate_config.timespans_num] = atoi(ptr);
"be in the range 0 to 1 (exclusive).");
ERROR("rrdtool: `XFF' must "
"be in the range 0 to 1 (exclusive).");
"be in the range 0 to 1 (exclusive).");
ERROR("rrdtool: `XFF' must "
"be in the range 0 to 1 (exclusive).");
}
rrdcreate_config.xff = tmp;
} else if (strcasecmp("WritesPerSecond", key) == 0) {
}
rrdcreate_config.xff = tmp;
} else if (strcasecmp("WritesPerSecond", key) == 0) {
if (wps < 0.0) {
fprintf(stderr, "rrdtool: `WritesPerSecond' must be "
"greater than or equal to zero.");
if (wps < 0.0) {
fprintf(stderr, "rrdtool: `WritesPerSecond' must be "
"greater than or equal to zero.");
} else if (wps == 0.0) {
write_rate = 0.0;
} else {
} else if (wps == 0.0) {
write_rate = 0.0;
} else {
random_timeout = DOUBLE_TO_CDTIME_T(tmp);
}
} else {
random_timeout = DOUBLE_TO_CDTIME_T(tmp);
}
} else {
} /* int rrd_config */
static int rrd_shutdown(void) {
} /* int rrd_config */
static int rrd_shutdown(void) {
} /* int rrd_shutdown */
static int rrd_init(void) {
} /* int rrd_shutdown */
static int rrd_init(void) {
int status;
if (init_once != 0)
int status;
if (init_once != 0)
init_once = 1;
if (rrdcreate_config.heartbeat <= 0)
init_once = 1;
if (rrdcreate_config.heartbeat <= 0)
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
ERROR("rrdtool plugin: c_avl_create failed.");
if (cache == NULL) {
pthread_mutex_unlock(&cache_lock);
ERROR("rrdtool plugin: c_avl_create failed.");
}
cache_flush_last = cdtime();
}
cache_flush_last = cdtime();
/* args = */ NULL, "rrdtool queue");
if (status != 0) {
ERROR("rrdtool plugin: Cannot create queue-thread.");
/* args = */ NULL, "rrdtool queue");
if (status != 0) {
ERROR("rrdtool plugin: Cannot create queue-thread.");
}
queue_thread_running = 1;
}
queue_thread_running = 1;
rrdcreate_config.heartbeat, rrdcreate_config.rrarows,
rrdcreate_config.xff);
rrdcreate_config.heartbeat, rrdcreate_config.rrarows,
rrdcreate_config.xff);
} /* int rrd_init */
void module_register(void) {
} /* int rrd_init */
void module_register(void) {
} /* int sensors_snprintf_chip_name */
static int sensors_feature_name_to_type(const char *name) {
} /* int sensors_snprintf_chip_name */
static int sensors_feature_name_to_type(const char *name) {
* it's a one time cost.. */
for (int i = 0; i < known_features_num; i++)
if (strcasecmp(known_features[i].label, name) == 0)
* it's a one time cost.. */
for (int i = 0; i < known_features_num; i++)
if (strcasecmp(known_features[i].label, name) == 0)
- return (known_features[i].type);
+ return known_features[i].type;
- return (SENSOR_TYPE_UNKNOWN);
+ return SENSOR_TYPE_UNKNOWN;
} /* int sensors_feature_name_to_type */
#endif
} /* int sensors_feature_name_to_type */
#endif
if (ignorelist_add(sensor_list, value)) {
ERROR("sensors plugin: "
"Cannot add value to ignorelist.");
if (ignorelist_add(sensor_list, value)) {
ERROR("sensors plugin: "
"Cannot add value to ignorelist.");
}
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
ignorelist_set_invert(sensor_list, 1);
}
} else if (strcasecmp(key, "IgnoreSelected") == 0) {
ignorelist_set_invert(sensor_list, 1);
}
static void sensors_free_features(void) {
}
static void sensors_free_features(void) {
char errbuf[1024];
ERROR("sensors plugin: fopen(%s) failed: %s", conffile,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("sensors plugin: fopen(%s) failed: %s", conffile,
sstrerror(errno, errbuf, sizeof(errbuf)));
if (status != 0) {
ERROR("sensors plugin: Cannot initialize sensors. "
"Data will not be collected.");
if (status != 0) {
ERROR("sensors plugin: Cannot initialize sensors. "
"Data will not be collected.");
}
#if SENSORS_API_VERSION < 0x400
}
#if SENSORS_API_VERSION < 0x400
sensors_cleanup();
INFO("sensors plugin: lm_sensors reports no "
"features. Data will not be collected.");
sensors_cleanup();
INFO("sensors plugin: lm_sensors reports no "
"features. Data will not be collected.");
} /* int sensors_load_conf */
static int sensors_shutdown(void) {
sensors_free_features();
ignorelist_free(sensor_list);
} /* int sensors_load_conf */
static int sensors_shutdown(void) {
sensors_free_features();
ignorelist_free(sensor_list);
} /* int sensors_shutdown */
static void sensors_submit(const char *plugin_instance, const char *type,
} /* int sensors_shutdown */
static void sensors_submit(const char *plugin_instance, const char *type,
static int sensors_read(void) {
if (sensors_load_conf() != 0)
static int sensors_read(void) {
if (sensors_load_conf() != 0)
#if SENSORS_API_VERSION < 0x400
for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next) {
#if SENSORS_API_VERSION < 0x400
for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next) {
} /* for fl = first_feature .. NULL */
#endif /* (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
} /* for fl = first_feature .. NULL */
#endif /* (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
} /* int sensors_read */
void module_register(void) {
} /* int sensors_read */
void module_register(void) {
(fh = fopen("/proc/tty/driver/ttyS", "r")) == NULL) {
char errbuf[1024];
WARNING("serial: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
(fh = fopen("/proc/tty/driver/ttyS", "r")) == NULL) {
char errbuf[1024];
WARNING("serial: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
} /* int serial_read */
void module_register(void) {
} /* int serial_read */
void module_register(void) {
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
if (ignorelist == NULL)
ignorelist = ignorelist_create(/* invert = */ 1);
if (ignorelist == NULL)
if (strcasecmp("Disk", key) == 0) {
ignorelist_add(ignorelist, value);
if (strcasecmp("Disk", key) == 0) {
ignorelist_add(ignorelist, value);
if (IS_TRUE(value))
use_serial = 1;
} else {
if (IS_TRUE(value))
use_serial = 1;
} else {
} /* int smart_config */
static void smart_submit(const char *dev, const char *type,
} /* int smart_config */
static void smart_submit(const char *dev, const char *type,
handle_udev = udev_new();
if (!handle_udev) {
ERROR("smart plugin: unable to initialize udev.");
handle_udev = udev_new();
if (!handle_udev) {
ERROR("smart plugin: unable to initialize udev.");
}
enumerate = udev_enumerate_new(handle_udev);
udev_enumerate_add_match_subsystem(enumerate, "block");
}
enumerate = udev_enumerate_new(handle_udev);
udev_enumerate_add_match_subsystem(enumerate, "block");
udev_enumerate_unref(enumerate);
udev_unref(handle_udev);
udev_enumerate_unref(enumerate);
udev_unref(handle_udev);
} /* int smart_read */
static int smart_init(void) {
} /* int smart_read */
static int smart_init(void) {
"running \"setcap cap_sys_rawio=ep\" on the collectd binary.");
}
#endif
"running \"setcap cap_sys_rawio=ep\" on the collectd binary.");
}
#endif
} /* int smart_init */
void module_register(void) {
} /* int smart_init */
void module_register(void) {
}
static int csnmp_oid_compare(oid_t const *left, oid_t const *right) {
}
static int csnmp_oid_compare(oid_t const *left, oid_t const *right) {
- return (
- snmp_oid_compare(left->oid, left->oid_len, right->oid, right->oid_len));
+ return snmp_oid_compare(left->oid, left->oid_len, right->oid,
+ right->oid_len);
}
static int csnmp_oid_suffix(oid_t *dst, oid_t const *src, oid_t const *root) {
/* Make sure "src" is in "root"s subtree. */
if (src->oid_len <= root->oid_len)
}
static int csnmp_oid_suffix(oid_t *dst, oid_t const *src, oid_t const *root) {
/* Make sure "src" is in "root"s subtree. */
if (src->oid_len <= root->oid_len)
if (snmp_oid_ncompare(root->oid, root->oid_len, src->oid, src->oid_len,
/* n = */ root->oid_len) != 0)
if (snmp_oid_ncompare(root->oid, root->oid_len, src->oid, src->oid_len,
/* n = */ root->oid_len) != 0)
memset(dst, 0, sizeof(*dst));
dst->oid_len = src->oid_len - root->oid_len;
memcpy(dst->oid, &src->oid[root->oid_len],
dst->oid_len * sizeof(dst->oid[0]));
memset(dst, 0, sizeof(*dst));
dst->oid_len = src->oid_len - root->oid_len;
memcpy(dst->oid, &src->oid[root->oid_len],
dst->oid_len * sizeof(dst->oid[0]));
}
static int csnmp_oid_to_string(char *buffer, size_t buffer_size,
}
static int csnmp_oid_to_string(char *buffer, size_t buffer_size,
oid_str_ptr[i] = oid_str[i];
}
oid_str_ptr[i] = oid_str[i];
}
- return (strjoin(buffer, buffer_size, oid_str_ptr, o->oid_len,
- /* separator = */ "."));
+ return strjoin(buffer, buffer_size, oid_str_ptr, o->oid_len, ".");
}
static void csnmp_host_close_session(host_definition_t *host) /* {{{ */
}
static void csnmp_host_close_session(host_definition_t *host) /* {{{ */
if (!read_objid(buffer, dd->instance.oid.oid, &dd->instance.oid.oid_len)) {
ERROR("snmp plugin: read_objid (%s) failed.", buffer);
if (!read_objid(buffer, dd->instance.oid.oid, &dd->instance.oid.oid_len)) {
ERROR("snmp plugin: read_objid (%s) failed.", buffer);
}
} else {
/* Instance is a simple string */
sstrncpy(dd->instance.string, buffer, sizeof(dd->instance.string));
}
}
} else {
/* Instance is a simple string */
sstrncpy(dd->instance.string, buffer, sizeof(dd->instance.string));
}
} /* int csnmp_config_add_data_instance */
static int csnmp_config_add_data_instance_prefix(data_definition_t *dd,
} /* int csnmp_config_add_data_instance */
static int csnmp_config_add_data_instance_prefix(data_definition_t *dd,
WARNING("snmp plugin: data %s: InstancePrefix is ignored when `Table' "
"is set to `false'.",
dd->name);
WARNING("snmp plugin: data %s: InstancePrefix is ignored when `Table' "
"is set to `false'.",
dd->name);
}
status = cf_util_get_string(ci, &dd->instance_prefix);
}
status = cf_util_get_string(ci, &dd->instance_prefix);
oconfig_item_t *ci) {
if (ci->values_num < 1) {
WARNING("snmp plugin: `Values' needs at least one argument.");
oconfig_item_t *ci) {
if (ci->values_num < 1) {
WARNING("snmp plugin: `Values' needs at least one argument.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("snmp plugin: `Values' needs only string argument.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("snmp plugin: `Values' needs only string argument.");
}
sfree(dd->values);
dd->values_len = 0;
dd->values = malloc(sizeof(*dd->values) * ci->values_num);
if (dd->values == NULL)
}
sfree(dd->values);
dd->values_len = 0;
dd->values = malloc(sizeof(*dd->values) * ci->values_num);
if (dd->values == NULL)
dd->values_len = (size_t)ci->values_num;
for (int i = 0; i < ci->values_num; i++) {
dd->values_len = (size_t)ci->values_num;
for (int i = 0; i < ci->values_num; i++) {
free(dd->values);
dd->values = NULL;
dd->values_len = 0;
free(dd->values);
dd->values = NULL;
dd->values_len = 0;
} /* int csnmp_config_add_data_instance */
static int csnmp_config_add_data_blacklist(data_definition_t *dd,
oconfig_item_t *ci) {
if (ci->values_num < 1)
} /* int csnmp_config_add_data_instance */
static int csnmp_config_add_data_blacklist(data_definition_t *dd,
oconfig_item_t *ci) {
if (ci->values_num < 1)
for (int i = 0; i < ci->values_num; i++) {
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("snmp plugin: `Ignore' needs only string argument.");
for (int i = 0; i < ci->values_num; i++) {
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("snmp plugin: `Ignore' needs only string argument.");
ci->values[i].value.string) != 0) {
ERROR("snmp plugin: Can't allocate memory");
strarray_free(dd->ignores, dd->ignores_len);
ci->values[i].value.string) != 0) {
ERROR("snmp plugin: Can't allocate memory");
strarray_free(dd->ignores, dd->ignores_len);
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
WARNING("snmp plugin: `InvertMatch' needs exactly one boolean argument.");
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) {
WARNING("snmp plugin: `InvertMatch' needs exactly one boolean argument.");
}
dd->invert_match = ci->values[0].value.boolean ? 1 : 0;
}
dd->invert_match = ci->values[0].value.boolean ? 1 : 0;
} /* int csnmp_config_add_data_blacklist_match_inverted */
static int csnmp_config_add_data(oconfig_item_t *ci) {
} /* int csnmp_config_add_data_blacklist_match_inverted */
static int csnmp_config_add_data(oconfig_item_t *ci) {
dd = calloc(1, sizeof(*dd));
if (dd == NULL)
dd = calloc(1, sizeof(*dd));
if (dd == NULL)
status = cf_util_get_string(ci, &dd->name);
if (status != 0) {
free(dd);
status = cf_util_get_string(ci, &dd->name);
if (status != 0) {
free(dd);
sfree(dd->values);
sfree(dd->ignores);
sfree(dd);
sfree(dd->values);
sfree(dd->ignores);
sfree(dd);
}
DEBUG("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = "
}
DEBUG("snmp plugin: dd = { name = %s, type = %s, is_table = %s, values_len = "
} /* int csnmp_config_add_data */
static int csnmp_config_add_host_version(host_definition_t *hd,
} /* int csnmp_config_add_data */
static int csnmp_config_add_host_version(host_definition_t *hd,
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
WARNING("snmp plugin: The `Version' config option needs exactly one number "
"argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_NUMBER)) {
WARNING("snmp plugin: The `Version' config option needs exactly one number "
"argument.");
}
version = (int)ci->values[0].value.number;
if ((version < 1) || (version > 3)) {
WARNING("snmp plugin: `Version' must either be `1', `2', or `3'.");
}
version = (int)ci->values[0].value.number;
if ((version < 1) || (version > 3)) {
WARNING("snmp plugin: `Version' must either be `1', `2', or `3'.");
} /* int csnmp_config_add_host_address */
static int csnmp_config_add_host_collect(host_definition_t *host,
} /* int csnmp_config_add_host_address */
static int csnmp_config_add_host_collect(host_definition_t *host,
if (ci->values_num < 1) {
WARNING("snmp plugin: `Collect' needs at least one argument.");
if (ci->values_num < 1) {
WARNING("snmp plugin: `Collect' needs at least one argument.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("snmp plugin: All arguments to `Collect' must be strings.");
}
for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
WARNING("snmp plugin: All arguments to `Collect' must be strings.");
}
data_list_len = host->data_list_len + ci->values_num;
data_list =
realloc(host->data_list, sizeof(data_definition_t *) * data_list_len);
if (data_list == NULL)
}
data_list_len = host->data_list_len + ci->values_num;
data_list =
realloc(host->data_list, sizeof(data_definition_t *) * data_list_len);
if (data_list == NULL)
host->data_list = data_list;
for (int i = 0; i < ci->values_num; i++) {
host->data_list = data_list;
for (int i = 0; i < ci->values_num; i++) {
host->data_list_len++;
} /* for (values_num) */
host->data_list_len++;
} /* for (values_num) */
} /* int csnmp_config_add_host_collect */
static int csnmp_config_add_host_auth_protocol(host_definition_t *hd,
} /* int csnmp_config_add_host_collect */
static int csnmp_config_add_host_auth_protocol(host_definition_t *hd,
} else {
WARNING("snmp plugin: The `AuthProtocol' config option must be `MD5' or "
"`SHA'.");
} else {
WARNING("snmp plugin: The `AuthProtocol' config option must be `MD5' or "
"`SHA'.");
}
DEBUG("snmp plugin: host = %s; host->auth_protocol = %s;", hd->name,
hd->auth_protocol == usmHMACMD5AuthProtocol ? "MD5" : "SHA");
}
DEBUG("snmp plugin: host = %s; host->auth_protocol = %s;", hd->name,
hd->auth_protocol == usmHMACMD5AuthProtocol ? "MD5" : "SHA");
} /* int csnmp_config_add_host_auth_protocol */
static int csnmp_config_add_host_priv_protocol(host_definition_t *hd,
} /* int csnmp_config_add_host_auth_protocol */
static int csnmp_config_add_host_priv_protocol(host_definition_t *hd,
} else {
WARNING("snmp plugin: The `PrivProtocol' config option must be `AES' or "
"`DES'.");
} else {
WARNING("snmp plugin: The `PrivProtocol' config option must be `AES' or "
"`DES'.");
}
DEBUG("snmp plugin: host = %s; host->priv_protocol = %s;", hd->name,
hd->priv_protocol == usmAESPrivProtocol ? "AES" : "DES");
}
DEBUG("snmp plugin: host = %s; host->priv_protocol = %s;", hd->name,
hd->priv_protocol == usmAESPrivProtocol ? "AES" : "DES");
} /* int csnmp_config_add_host_priv_protocol */
static int csnmp_config_add_host_security_level(host_definition_t *hd,
} /* int csnmp_config_add_host_priv_protocol */
static int csnmp_config_add_host_security_level(host_definition_t *hd,
else {
WARNING("snmp plugin: The `SecurityLevel' config option must be "
"`noAuthNoPriv', `authNoPriv', or `authPriv'.");
else {
WARNING("snmp plugin: The `SecurityLevel' config option must be "
"`noAuthNoPriv', `authNoPriv', or `authPriv'.");
}
DEBUG("snmp plugin: host = %s; host->security_level = %d;", hd->name,
hd->security_level);
}
DEBUG("snmp plugin: host = %s; host->security_level = %d;", hd->name,
hd->security_level);
} /* int csnmp_config_add_host_security_level */
static int csnmp_config_add_host(oconfig_item_t *ci) {
} /* int csnmp_config_add_host_security_level */
static int csnmp_config_add_host(oconfig_item_t *ci) {
hd = calloc(1, sizeof(*hd));
if (hd == NULL)
hd = calloc(1, sizeof(*hd));
if (hd == NULL)
hd->version = 2;
C_COMPLAIN_INIT(&hd->complaint);
hd->version = 2;
C_COMPLAIN_INIT(&hd->complaint);
if (status != 0) {
csnmp_host_definition_destroy(hd);
if (status != 0) {
csnmp_host_definition_destroy(hd);
}
DEBUG("snmp plugin: hd = { name = %s, address = %s, community = %s, version "
}
DEBUG("snmp plugin: hd = { name = %s, address = %s, community = %s, version "
if (status != 0) {
ERROR("snmp plugin: Registering complex read function failed.");
csnmp_host_definition_destroy(hd);
if (status != 0) {
ERROR("snmp plugin: Registering complex read function failed.");
csnmp_host_definition_destroy(hd);
} /* int csnmp_config_add_host */
static int csnmp_config(oconfig_item_t *ci) {
} /* int csnmp_config_add_host */
static int csnmp_config(oconfig_item_t *ci) {
}
} /* for (ci->children) */
}
} /* for (ci->children) */
} /* int csnmp_config */
/* }}} End of the config stuff. Now the interesting part begins */
} /* int csnmp_config */
/* }}} End of the config stuff. Now the interesting part begins */
} /* value_t csnmp_value_list_to_value */
/* csnmp_strvbcopy_hexstring converts the bit string contained in "vb" to a hex
} /* value_t csnmp_value_list_to_value */
/* csnmp_strvbcopy_hexstring converts the bit string contained in "vb" to a hex
(uint8_t)vb->val.string[2], (uint8_t)vb->val.string[3]);
} else {
dst[0] = 0;
(uint8_t)vb->val.string[2], (uint8_t)vb->val.string[3]);
} else {
dst[0] = 0;
}
num_chars = dst_size - 1;
}
num_chars = dst_size - 1;
for (size_t i = 0; i < num_chars; i++) {
/* Check for control characters. */
if ((unsigned char)src[i] < 32)
for (size_t i = 0; i < num_chars; i++) {
/* Check for control characters. */
if ((unsigned char)src[i] < 32)
- return (csnmp_strvbcopy_hexstring(dst, vb, dst_size));
+ return csnmp_strvbcopy_hexstring(dst, vb, dst_size);
dst[i] = src[i];
}
dst[num_chars] = 0;
dst[i] = src[i];
}
dst[num_chars] = 0;
vb = vb->next_variable)
/* do nothing */;
if (vb == NULL)
vb = vb->next_variable)
/* do nothing */;
if (vb == NULL)
csnmp_oid_init(&vb_name, vb->name, vb->name_length);
il = calloc(1, sizeof(*il));
if (il == NULL) {
ERROR("snmp plugin: calloc failed.");
csnmp_oid_init(&vb_name, vb->name, vb->name_length);
il = calloc(1, sizeof(*il));
if (il == NULL) {
ERROR("snmp plugin: calloc failed.");
}
il->next = NULL;
status = csnmp_oid_suffix(&il->suffix, &vb_name, &dd->instance.oid);
if (status != 0) {
sfree(il);
}
il->next = NULL;
status = csnmp_oid_suffix(&il->suffix, &vb_name, &dd->instance.oid);
if (status != 0) {
sfree(il);
}
/* Get instance name */
}
/* Get instance name */
(*tail)->next = il;
*tail = il;
(*tail)->next = il;
*tail = il;
} /* int csnmp_instance_list_add */
static int csnmp_dispatch_table(host_definition_t *host,
} /* int csnmp_instance_list_add */
static int csnmp_dispatch_table(host_definition_t *host,
ds = plugin_get_ds(data->type);
if (!ds) {
ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
ds = plugin_get_ds(data->type);
if (!ds) {
ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
}
assert(ds->ds_num == data->values_len);
assert(data->values_len > 0);
}
assert(ds->ds_num == data->values_len);
assert(data->values_len > 0);
value_table_ptr = calloc(data->values_len, sizeof(*value_table_ptr));
if (value_table_ptr == NULL)
value_table_ptr = calloc(data->values_len, sizeof(*value_table_ptr));
if (value_table_ptr == NULL)
for (i = 0; i < data->values_len; i++)
value_table_ptr[i] = value_table[i];
for (i = 0; i < data->values_len; i++)
value_table_ptr[i] = value_table[i];
if (vl.values == NULL) {
ERROR("snmp plugin: malloc failed.");
sfree(value_table_ptr);
if (vl.values == NULL) {
ERROR("snmp plugin: malloc failed.");
sfree(value_table_ptr);
}
sstrncpy(vl.host, host->name, sizeof(vl.host));
}
sstrncpy(vl.host, host->name, sizeof(vl.host));
sfree(vl.values);
sfree(value_table_ptr);
sfree(vl.values);
sfree(value_table_ptr);
} /* int csnmp_dispatch_table */
static int csnmp_read_table(host_definition_t *host, data_definition_t *data) {
} /* int csnmp_dispatch_table */
static int csnmp_read_table(host_definition_t *host, data_definition_t *data) {
if (host->sess_handle == NULL) {
DEBUG("snmp plugin: csnmp_read_table: host->sess_handle == NULL");
if (host->sess_handle == NULL) {
DEBUG("snmp plugin: csnmp_read_table: host->sess_handle == NULL");
}
ds = plugin_get_ds(data->type);
if (!ds) {
ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
}
ds = plugin_get_ds(data->type);
if (!ds) {
ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
}
if (ds->ds_num != data->values_len) {
ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
"about %zu",
data->type, ds->ds_num, data->values_len);
}
if (ds->ds_num != data->values_len) {
ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
"about %zu",
data->type, ds->ds_num, data->values_len);
}
assert(data->values_len > 0);
}
assert(data->values_len > 0);
ERROR("snmp plugin: csnmp_read_table: calloc failed.");
sfree(value_list_head);
sfree(value_list_tail);
ERROR("snmp plugin: csnmp_read_table: calloc failed.");
sfree(value_list_head);
sfree(value_list_tail);
}
instance_list_head = NULL;
}
instance_list_head = NULL;
sfree(value_list_head);
sfree(value_list_tail);
sfree(value_list_head);
sfree(value_list_tail);
} /* int csnmp_read_table */
static int csnmp_read_value(host_definition_t *host, data_definition_t *data) {
} /* int csnmp_read_table */
static int csnmp_read_value(host_definition_t *host, data_definition_t *data) {
if (host->sess_handle == NULL) {
DEBUG("snmp plugin: csnmp_read_value: host->sess_handle == NULL");
if (host->sess_handle == NULL) {
DEBUG("snmp plugin: csnmp_read_value: host->sess_handle == NULL");
}
ds = plugin_get_ds(data->type);
if (!ds) {
ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
}
ds = plugin_get_ds(data->type);
if (!ds) {
ERROR("snmp plugin: DataSet `%s' not defined.", data->type);
}
if (ds->ds_num != data->values_len) {
ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
"about %zu",
data->type, ds->ds_num, data->values_len);
}
if (ds->ds_num != data->values_len) {
ERROR("snmp plugin: DataSet `%s' requires %zu values, but config talks "
"about %zu",
data->type, ds->ds_num, data->values_len);
}
vl.values_len = ds->ds_num;
vl.values = malloc(sizeof(*vl.values) * vl.values_len);
if (vl.values == NULL)
}
vl.values_len = ds->ds_num;
vl.values = malloc(sizeof(*vl.values) * vl.values_len);
if (vl.values == NULL)
for (i = 0; i < vl.values_len; i++) {
if (ds->ds[i].type == DS_TYPE_COUNTER)
vl.values[i].counter = 0;
for (i = 0; i < vl.values_len; i++) {
if (ds->ds[i].type == DS_TYPE_COUNTER)
vl.values[i].counter = 0;
if (req == NULL) {
ERROR("snmp plugin: snmp_pdu_create failed.");
sfree(vl.values);
if (req == NULL) {
ERROR("snmp plugin: snmp_pdu_create failed.");
sfree(vl.values);
}
for (i = 0; i < data->values_len; i++)
}
for (i = 0; i < data->values_len; i++)
sfree(vl.values);
csnmp_host_close_session(host);
sfree(vl.values);
csnmp_host_close_session(host);
}
for (vb = res->variables; vb != NULL; vb = vb->next_variable) {
}
for (vb = res->variables; vb != NULL; vb = vb->next_variable) {
plugin_dispatch_values(&vl);
sfree(vl.values);
plugin_dispatch_values(&vl);
sfree(vl.values);
} /* int csnmp_read_value */
static int csnmp_read_host(user_data_t *ud) {
} /* int csnmp_read_value */
static int csnmp_read_host(user_data_t *ud) {
csnmp_host_open_session(host);
if (host->sess_handle == NULL)
csnmp_host_open_session(host);
if (host->sess_handle == NULL)
success = 0;
for (i = 0; i < host->data_list_len; i++) {
success = 0;
for (i = 0; i < host->data_list_len; i++) {
} /* int csnmp_read_host */
static int csnmp_init(void) {
call_snmp_init_once();
} /* int csnmp_read_host */
static int csnmp_init(void) {
call_snmp_init_once();
} /* int csnmp_init */
static int csnmp_shutdown(void) {
} /* int csnmp_init */
static int csnmp_shutdown(void) {
} /* int csnmp_shutdown */
void module_register(void) {
} /* int csnmp_shutdown */
void module_register(void) {
key[0] = 's';
break;
default:
key[0] = 's';
break;
default:
status = c_avl_get(metrics_tree, key, (void *)&metric);
if (status == 0)
status = c_avl_get(metrics_tree, key, (void *)&metric);
if (status == 0)
key_copy = strdup(key);
if (key_copy == NULL) {
ERROR("statsd plugin: strdup failed.");
key_copy = strdup(key);
if (key_copy == NULL) {
ERROR("statsd plugin: strdup failed.");
}
metric = calloc(1, sizeof(*metric));
if (metric == NULL) {
ERROR("statsd plugin: calloc failed.");
sfree(key_copy);
}
metric = calloc(1, sizeof(*metric));
if (metric == NULL) {
ERROR("statsd plugin: calloc failed.");
sfree(key_copy);
ERROR("statsd plugin: c_avl_insert failed.");
sfree(key_copy);
sfree(metric);
ERROR("statsd plugin: c_avl_insert failed.");
sfree(key_copy);
sfree(metric);
} /* }}} statsd_metric_lookup_unsafe */
static int statsd_metric_set(char const *name, double value, /* {{{ */
} /* }}} statsd_metric_lookup_unsafe */
static int statsd_metric_set(char const *name, double value, /* {{{ */
metric = statsd_metric_lookup_unsafe(name, type);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
metric = statsd_metric_lookup_unsafe(name, type);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
pthread_mutex_unlock(&metrics_lock);
pthread_mutex_unlock(&metrics_lock);
} /* }}} int statsd_metric_set */
static int statsd_metric_add(char const *name, double delta, /* {{{ */
} /* }}} int statsd_metric_set */
static int statsd_metric_add(char const *name, double delta, /* {{{ */
metric = statsd_metric_lookup_unsafe(name, type);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
metric = statsd_metric_lookup_unsafe(name, type);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
}
metric->value += delta;
}
metric->value += delta;
pthread_mutex_unlock(&metrics_lock);
pthread_mutex_unlock(&metrics_lock);
} /* }}} int statsd_metric_add */
static void statsd_metric_free(statsd_metric_t *metric) /* {{{ */
} /* }}} int statsd_metric_add */
static void statsd_metric_free(statsd_metric_t *metric) /* {{{ */
ret_value->gauge = (gauge_t)strtod(str, &endptr);
if ((str == endptr) || ((endptr != NULL) && (*endptr != 0)))
ret_value->gauge = (gauge_t)strtod(str, &endptr);
if ((str == endptr) || ((endptr != NULL) && (*endptr != 0)))
} /* }}} int statsd_parse_value */
static int statsd_handle_counter(char const *name, /* {{{ */
} /* }}} int statsd_parse_value */
static int statsd_handle_counter(char const *name, /* {{{ */
int status;
if ((extra != NULL) && (extra[0] != '@'))
int status;
if ((extra != NULL) && (extra[0] != '@'))
scale.gauge = 1.0;
if (extra != NULL) {
status = statsd_parse_value(extra + 1, &scale);
if (status != 0)
scale.gauge = 1.0;
if (extra != NULL) {
status = statsd_parse_value(extra + 1, &scale);
if (status != 0)
if (!isfinite(scale.gauge) || (scale.gauge <= 0.0) || (scale.gauge > 1.0))
if (!isfinite(scale.gauge) || (scale.gauge <= 0.0) || (scale.gauge > 1.0))
}
value.gauge = 1.0;
status = statsd_parse_value(value_str, &value);
if (status != 0)
}
value.gauge = 1.0;
status = statsd_parse_value(value_str, &value);
if (status != 0)
/* Changes to the counter are added to (statsd_metric_t*)->value. ->counter is
* only updated in statsd_metric_submit_unsafe(). */
/* Changes to the counter are added to (statsd_metric_t*)->value. ->counter is
* only updated in statsd_metric_submit_unsafe(). */
- return (statsd_metric_add(name, (double)(value.gauge / scale.gauge),
- STATSD_COUNTER));
+ return statsd_metric_add(name, (double)(value.gauge / scale.gauge),
+ STATSD_COUNTER);
} /* }}} int statsd_handle_counter */
static int statsd_handle_gauge(char const *name, /* {{{ */
} /* }}} int statsd_handle_counter */
static int statsd_handle_gauge(char const *name, /* {{{ */
value.gauge = 0;
status = statsd_parse_value(value_str, &value);
if (status != 0)
value.gauge = 0;
status = statsd_parse_value(value_str, &value);
if (status != 0)
if ((value_str[0] == '+') || (value_str[0] == '-'))
if ((value_str[0] == '+') || (value_str[0] == '-'))
- return (statsd_metric_add(name, (double)value.gauge, STATSD_GAUGE));
+ return statsd_metric_add(name, (double)value.gauge, STATSD_GAUGE);
- return (statsd_metric_set(name, (double)value.gauge, STATSD_GAUGE));
+ return statsd_metric_set(name, (double)value.gauge, STATSD_GAUGE);
} /* }}} int statsd_handle_gauge */
static int statsd_handle_timer(char const *name, /* {{{ */
} /* }}} int statsd_handle_gauge */
static int statsd_handle_timer(char const *name, /* {{{ */
int status;
if ((extra != NULL) && (extra[0] != '@'))
int status;
if ((extra != NULL) && (extra[0] != '@'))
scale.gauge = 1.0;
if (extra != NULL) {
status = statsd_parse_value(extra + 1, &scale);
if (status != 0)
scale.gauge = 1.0;
if (extra != NULL) {
status = statsd_parse_value(extra + 1, &scale);
if (status != 0)
if (!isfinite(scale.gauge) || (scale.gauge <= 0.0) || (scale.gauge > 1.0))
if (!isfinite(scale.gauge) || (scale.gauge <= 0.0) || (scale.gauge > 1.0))
}
value_ms.derive = 0;
status = statsd_parse_value(value_str, &value_ms);
if (status != 0)
}
value_ms.derive = 0;
status = statsd_parse_value(value_str, &value_ms);
if (status != 0)
value = MS_TO_CDTIME_T(value_ms.gauge / scale.gauge);
value = MS_TO_CDTIME_T(value_ms.gauge / scale.gauge);
metric = statsd_metric_lookup_unsafe(name, STATSD_TIMER);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
metric = statsd_metric_lookup_unsafe(name, STATSD_TIMER);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
}
if (metric->latency == NULL)
metric->latency = latency_counter_create();
if (metric->latency == NULL) {
pthread_mutex_unlock(&metrics_lock);
}
if (metric->latency == NULL)
metric->latency = latency_counter_create();
if (metric->latency == NULL) {
pthread_mutex_unlock(&metrics_lock);
}
latency_counter_add(metric->latency, value);
metric->updates_num++;
pthread_mutex_unlock(&metrics_lock);
}
latency_counter_add(metric->latency, value);
metric->updates_num++;
pthread_mutex_unlock(&metrics_lock);
} /* }}} int statsd_handle_timer */
static int statsd_handle_set(char const *name, /* {{{ */
} /* }}} int statsd_handle_timer */
static int statsd_handle_set(char const *name, /* {{{ */
metric = statsd_metric_lookup_unsafe(name, STATSD_SET);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
metric = statsd_metric_lookup_unsafe(name, STATSD_SET);
if (metric == NULL) {
pthread_mutex_unlock(&metrics_lock);
}
/* Make sure metric->set exists. */
}
/* Make sure metric->set exists. */
if (metric->set == NULL) {
pthread_mutex_unlock(&metrics_lock);
ERROR("statsd plugin: c_avl_create failed.");
if (metric->set == NULL) {
pthread_mutex_unlock(&metrics_lock);
ERROR("statsd plugin: c_avl_create failed.");
}
set_key = strdup(set_key_orig);
if (set_key == NULL) {
pthread_mutex_unlock(&metrics_lock);
ERROR("statsd plugin: strdup failed.");
}
set_key = strdup(set_key_orig);
if (set_key == NULL) {
pthread_mutex_unlock(&metrics_lock);
ERROR("statsd plugin: strdup failed.");
}
status = c_avl_insert(metric->set, set_key, /* value = */ NULL);
}
status = c_avl_insert(metric->set, set_key, /* value = */ NULL);
ERROR("statsd plugin: c_avl_insert (\"%s\") failed with status %i.",
set_key, status);
sfree(set_key);
ERROR("statsd plugin: c_avl_insert (\"%s\") failed with status %i.",
set_key, status);
sfree(set_key);
} else if (status > 0) /* key already exists */
{
sfree(set_key);
} else if (status > 0) /* key already exists */
{
sfree(set_key);
metric->updates_num++;
pthread_mutex_unlock(&metrics_lock);
metric->updates_num++;
pthread_mutex_unlock(&metrics_lock);
} /* }}} int statsd_handle_set */
static int statsd_parse_line(char *buffer) /* {{{ */
} /* }}} int statsd_handle_set */
static int statsd_parse_line(char *buffer) /* {{{ */
type = strchr(name, '|');
if (type == NULL)
type = strchr(name, '|');
if (type == NULL)
*type = 0;
type++;
value = strrchr(name, ':');
if (value == NULL)
*type = 0;
type++;
value = strrchr(name, ':');
if (value == NULL)
}
if (strcmp("c", type) == 0)
}
if (strcmp("c", type) == 0)
- return (statsd_handle_counter(name, value, extra));
+ return statsd_handle_counter(name, value, extra);
else if (strcmp("ms", type) == 0)
else if (strcmp("ms", type) == 0)
- return (statsd_handle_timer(name, value, extra));
+ return statsd_handle_timer(name, value, extra);
/* extra is only valid for counters and timers */
if (extra != NULL)
/* extra is only valid for counters and timers */
if (extra != NULL)
if (strcmp("g", type) == 0)
if (strcmp("g", type) == 0)
- return (statsd_handle_gauge(name, value));
+ return statsd_handle_gauge(name, value);
else if (strcmp("s", type) == 0)
else if (strcmp("s", type) == 0)
- return (statsd_handle_set(name, value));
+ return statsd_handle_set(name, value);
} /* }}} void statsd_parse_line */
static void statsd_parse_buffer(char *buffer) /* {{{ */
} /* }}} void statsd_parse_line */
static void statsd_parse_buffer(char *buffer) /* {{{ */
if (status != 0) {
ERROR("statsd plugin: getaddrinfo (\"%s\", \"%s\") failed: %s", node,
service, gai_strerror(status));
if (status != 0) {
ERROR("statsd plugin: getaddrinfo (\"%s\", \"%s\") failed: %s", node,
service, gai_strerror(status));
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
}
for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL;
if (fds_num == 0) {
ERROR("statsd plugin: Unable to create listening socket for [%s]:%s.",
(node != NULL) ? node : "::", service);
if (fds_num == 0) {
ERROR("statsd plugin: Unable to create listening socket for [%s]:%s.",
(node != NULL) ? node : "::", service);
}
*ret_fds = fds;
*ret_fds_num = fds_num;
}
*ret_fds = fds;
*ret_fds_num = fds_num;
} /* }}} int statsd_network_init */
static void *statsd_network_thread(void *args) /* {{{ */
} /* }}} int statsd_network_init */
static void *statsd_network_thread(void *args) /* {{{ */
close(fds[i].fd);
sfree(fds);
close(fds[i].fd);
sfree(fds);
} /* }}} void *statsd_network_thread */
static int statsd_config_timer_percentile(oconfig_item_t *ci) /* {{{ */
} /* }}} void *statsd_network_thread */
static int statsd_config_timer_percentile(oconfig_item_t *ci) /* {{{ */
status = cf_util_get_double(ci, &percent);
if (status != 0)
status = cf_util_get_double(ci, &percent);
if (status != 0)
if ((percent <= 0.0) || (percent >= 100)) {
ERROR("statsd plugin: The value for \"%s\" must be between 0 and 100, "
"exclusively.",
ci->key);
if ((percent <= 0.0) || (percent >= 100)) {
ERROR("statsd plugin: The value for \"%s\" must be between 0 and 100, "
"exclusively.",
ci->key);
}
tmp = realloc(conf_timer_percentile, sizeof(*conf_timer_percentile) *
(conf_timer_percentile_num + 1));
if (tmp == NULL) {
ERROR("statsd plugin: realloc failed.");
}
tmp = realloc(conf_timer_percentile, sizeof(*conf_timer_percentile) *
(conf_timer_percentile_num + 1));
if (tmp == NULL) {
ERROR("statsd plugin: realloc failed.");
}
conf_timer_percentile = tmp;
conf_timer_percentile[conf_timer_percentile_num] = percent;
conf_timer_percentile_num++;
}
conf_timer_percentile = tmp;
conf_timer_percentile[conf_timer_percentile_num] = percent;
conf_timer_percentile_num++;
} /* }}} int statsd_config_timer_percentile */
static int statsd_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int statsd_config_timer_percentile */
static int statsd_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int statsd_config */
static int statsd_init(void) /* {{{ */
} /* }}} int statsd_config */
static int statsd_init(void) /* {{{ */
pthread_mutex_unlock(&metrics_lock);
ERROR("statsd plugin: pthread_create failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
pthread_mutex_unlock(&metrics_lock);
ERROR("statsd plugin: pthread_create failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
}
network_thread_running = 1;
pthread_mutex_unlock(&metrics_lock);
}
}
network_thread_running = 1;
pthread_mutex_unlock(&metrics_lock);
} /* }}} int statsd_init */
/* Must hold metrics_lock when calling this function. */
} /* }}} int statsd_init */
/* Must hold metrics_lock when calling this function. */
void *value;
if ((metric == NULL) || (metric->type != STATSD_SET))
void *value;
if ((metric == NULL) || (metric->type != STATSD_SET))
while (c_avl_pick(metric->set, &key, &value) == 0) {
sfree(key);
sfree(value);
}
while (c_avl_pick(metric->set, &key, &value) == 0) {
sfree(key);
sfree(value);
}
} /* }}} int statsd_metric_clear_set_unsafe */
/* Must hold metrics_lock when calling this function. */
} /* }}} int statsd_metric_clear_set_unsafe */
/* Must hold metrics_lock when calling this function. */
}
latency_counter_reset(metric->latency);
}
latency_counter_reset(metric->latency);
} else if (metric->type == STATSD_SET) {
if (metric->set == NULL)
vl.values[0].gauge = 0.0;
} else if (metric->type == STATSD_SET) {
if (metric->set == NULL)
vl.values[0].gauge = 0.0;
vl.values[0].derive = metric->counter;
}
vl.values[0].derive = metric->counter;
}
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
} /* }}} int statsd_metric_submit_unsafe */
static int statsd_read(void) /* {{{ */
} /* }}} int statsd_metric_submit_unsafe */
static int statsd_read(void) /* {{{ */
if (metrics_tree == NULL) {
pthread_mutex_unlock(&metrics_lock);
if (metrics_tree == NULL) {
pthread_mutex_unlock(&metrics_lock);
}
iter = c_avl_get_iterator(metrics_tree);
}
iter = c_avl_get_iterator(metrics_tree);
strarray_free(to_be_deleted, to_be_deleted_num);
strarray_free(to_be_deleted, to_be_deleted_num);
} /* }}} int statsd_read */
static int statsd_shutdown(void) /* {{{ */
} /* }}} int statsd_read */
static int statsd_shutdown(void) /* {{{ */
pthread_mutex_unlock(&metrics_lock);
pthread_mutex_unlock(&metrics_lock);
} /* }}} int statsd_shutdown */
void module_register(void) {
} /* }}} int statsd_shutdown */
void module_register(void) {
WARNING("swap plugin: Unknown config option: \"%s\"", child->key);
}
WARNING("swap plugin: Unknown config option: \"%s\"", child->key);
}
} /* }}} int swap_config */
static int swap_init(void) /* {{{ */
} /* }}} int swap_config */
static int swap_init(void) /* {{{ */
if (kvm_obj == NULL) {
ERROR("swap plugin: kvm_openfiles failed, %s", errbuf);
if (kvm_obj == NULL) {
ERROR("swap plugin: kvm_openfiles failed, %s", errbuf);
}
/* #endif HAVE_LIBKVM_GETSWAPINFO */
}
/* #endif HAVE_LIBKVM_GETSWAPINFO */
pagesize = getpagesize();
#endif /* HAVE_PERFSTAT */
pagesize = getpagesize();
#endif /* HAVE_PERFSTAT */
} /* }}} int swap_init */
static void swap_submit_usage(char const *plugin_instance, /* {{{ */
} /* }}} int swap_init */
static void swap_submit_usage(char const *plugin_instance, /* {{{ */
char errbuf[1024];
WARNING("swap plugin: fopen (/proc/swaps) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("swap plugin: fopen (/proc/swaps) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
} /* }}} int swap_read_separate */
static int swap_read_combined(void) /* {{{ */
} /* }}} int swap_read_separate */
static int swap_read_combined(void) /* {{{ */
char errbuf[1024];
WARNING("swap plugin: fopen (/proc/meminfo) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("swap plugin: fopen (/proc/meminfo) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
fclose(fh);
if (isnan(swap_total) || isnan(swap_free))
fclose(fh);
if (isnan(swap_total) || isnan(swap_free))
/* Some systems, OpenVZ for example, don't provide SwapCached. */
if (isnan(swap_cached))
/* Some systems, OpenVZ for example, don't provide SwapCached. */
if (isnan(swap_cached))
assert(!isnan(swap_used));
if (swap_used < 0.0)
assert(!isnan(swap_used));
if (swap_used < 0.0)
swap_submit_usage(NULL, swap_used * 1024.0, swap_free * 1024.0,
isnan(swap_cached) ? NULL : "cached",
isnan(swap_cached) ? NAN : swap_cached * 1024.0);
swap_submit_usage(NULL, swap_used * 1024.0, swap_free * 1024.0,
isnan(swap_cached) ? NULL : "cached",
isnan(swap_cached) ? NAN : swap_cached * 1024.0);
} /* }}} int swap_read_combined */
static int swap_read_io(void) /* {{{ */
} /* }}} int swap_read_combined */
static int swap_read_io(void) /* {{{ */
if (fh == NULL) {
char errbuf[1024];
WARNING("swap: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if (fh == NULL) {
char errbuf[1024];
WARNING("swap: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(fh);
if (have_data != 0x03)
fclose(fh);
if (have_data != 0x03)
if (report_bytes) {
swap_in = swap_in * pagesize;
if (report_bytes) {
swap_in = swap_in * pagesize;
swap_submit_derive("in", swap_in);
swap_submit_derive("out", swap_out);
swap_submit_derive("in", swap_in);
swap_submit_derive("out", swap_out);
} /* }}} int swap_read_io */
static int swap_read(void) /* {{{ */
} /* }}} int swap_read_io */
static int swap_read(void) /* {{{ */
} /* }}} int swap_read */
/* #endif KERNEL_LINUX */
} /* }}} int swap_read */
/* #endif KERNEL_LINUX */
char errbuf[1024];
ERROR("swap plugin: swapctl failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("swap plugin: swapctl failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
swap_avail = (gauge_t)((ai.ani_max - ai.ani_resv) * pagesize);
swap_submit_usage(NULL, swap_alloc, swap_avail, "reserved", swap_resv);
swap_avail = (gauge_t)((ai.ani_max - ai.ani_resv) * pagesize);
swap_submit_usage(NULL, swap_alloc, swap_avail, "reserved", swap_resv);
} /* }}} int swap_read_kstat */
/* #endif 0 && HAVE_LIBKSTAT */
} /* }}} int swap_read_kstat */
/* #endif 0 && HAVE_LIBKSTAT */
swap_num = swapctl(SC_GETNSWP, NULL);
if (swap_num < 0) {
ERROR("swap plugin: swapctl (SC_GETNSWP) failed with status %i.", swap_num);
swap_num = swapctl(SC_GETNSWP, NULL);
if (swap_num < 0) {
ERROR("swap plugin: swapctl (SC_GETNSWP) failed with status %i.", swap_num);
} else if (swap_num == 0)
} else if (swap_num == 0)
/* Allocate and initialize the swaptbl_t structure */
s = malloc(swap_num * sizeof(swapent_t) + sizeof(struct swaptable));
if (s == NULL) {
ERROR("swap plugin: malloc failed.");
/* Allocate and initialize the swaptbl_t structure */
s = malloc(swap_num * sizeof(swapent_t) + sizeof(struct swaptable));
if (s == NULL) {
ERROR("swap plugin: malloc failed.");
}
/* Memory to store the path names. We only use these paths when the
}
/* Memory to store the path names. We only use these paths when the
if (s_paths == NULL) {
ERROR("swap plugin: calloc failed.");
sfree(s);
if (s_paths == NULL) {
ERROR("swap plugin: calloc failed.");
sfree(s);
}
for (int i = 0; i < swap_num; i++)
s->swt_ent[i].ste_path = s_paths + (i * PATH_MAX);
}
for (int i = 0; i < swap_num; i++)
s->swt_ent[i].ste_path = s_paths + (i * PATH_MAX);
sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(s_paths);
sfree(s);
sstrerror(errno, errbuf, sizeof(errbuf)));
sfree(s_paths);
sfree(s);
} else if (swap_num < status) {
/* more elements returned than requested */
ERROR("swap plugin: I allocated memory for %i structure%s, "
} else if (swap_num < status) {
/* more elements returned than requested */
ERROR("swap plugin: I allocated memory for %i structure%s, "
swap_num, (swap_num == 1) ? "" : "s", status);
sfree(s_paths);
sfree(s);
swap_num, (swap_num == 1) ? "" : "s", status);
sfree(s_paths);
sfree(s);
} else if (swap_num > status)
/* less elements returned than requested */
swap_num = status;
} else if (swap_num > status)
/* less elements returned than requested */
swap_num = status;
total, avail);
sfree(s_paths);
sfree(s);
total, avail);
sfree(s_paths);
sfree(s);
}
/* If the "separate" option was specified (report_by_device == 1), all
}
/* If the "separate" option was specified (report_by_device == 1), all
sfree(s_paths);
sfree(s);
sfree(s_paths);
sfree(s);
} /* }}} int swap_read */
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
} /* }}} int swap_read */
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
swap_num = swapctl(SWAP_NSWAP, NULL, 0);
if (swap_num < 0) {
ERROR("swap plugin: swapctl (SWAP_NSWAP) failed with status %i.", swap_num);
swap_num = swapctl(SWAP_NSWAP, NULL, 0);
if (swap_num < 0) {
ERROR("swap plugin: swapctl (SWAP_NSWAP) failed with status %i.", swap_num);
} else if (swap_num == 0)
} else if (swap_num == 0)
swap_entries = calloc(swap_num, sizeof(*swap_entries));
if (swap_entries == NULL) {
ERROR("swap plugin: calloc failed.");
swap_entries = calloc(swap_num, sizeof(*swap_entries));
if (swap_entries == NULL) {
ERROR("swap plugin: calloc failed.");
}
status = swapctl(SWAP_STATS, swap_entries, swap_num);
if (status != swap_num) {
ERROR("swap plugin: swapctl (SWAP_STATS) failed with status %i.", status);
sfree(swap_entries);
}
status = swapctl(SWAP_STATS, swap_entries, swap_num);
if (status != swap_num) {
ERROR("swap plugin: swapctl (SWAP_STATS) failed with status %i.", status);
sfree(swap_entries);
}
#if defined(DEV_BSIZE) && (DEV_BSIZE > 0)
}
#if defined(DEV_BSIZE) && (DEV_BSIZE > 0)
"swap plugin: Total swap space (%g) is less than used swap space (%g).",
total, used);
sfree(swap_entries);
"swap plugin: Total swap space (%g) is less than used swap space (%g).",
total, used);
sfree(swap_entries);
}
swap_submit_usage(NULL, used, total - used, NULL, NAN);
sfree(swap_entries);
}
swap_submit_usage(NULL, used, total - used, NULL, NAN);
sfree(swap_entries);
} /* }}} int swap_read */
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS */
} /* }}} int swap_read */
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS */
sw_usage_len = sizeof(struct xsw_usage);
if (sysctl(mib, mib_len, &sw_usage, &sw_usage_len, NULL, 0) != 0)
sw_usage_len = sizeof(struct xsw_usage);
if (sysctl(mib, mib_len, &sw_usage, &sw_usage_len, NULL, 0) != 0)
/* The returned values are bytes. */
swap_submit_usage(NULL, (gauge_t)sw_usage.xsu_used,
(gauge_t)sw_usage.xsu_avail, NULL, NAN);
/* The returned values are bytes. */
swap_submit_usage(NULL, (gauge_t)sw_usage.xsu_used,
(gauge_t)sw_usage.xsu_avail, NULL, NAN);
} /* }}} int swap_read */
/* #endif VM_SWAPUSAGE */
} /* }}} int swap_read */
/* #endif VM_SWAPUSAGE */
gauge_t total;
if (kvm_obj == NULL)
gauge_t total;
if (kvm_obj == NULL)
/* only one structure => only get the grand total, no details */
status = kvm_getswapinfo(kvm_obj, &data_s, 1, 0);
if (status == -1)
/* only one structure => only get the grand total, no details */
status = kvm_getswapinfo(kvm_obj, &data_s, 1, 0);
if (status == -1)
total = (gauge_t)data_s.ksw_total;
used = (gauge_t)data_s.ksw_used;
total = (gauge_t)data_s.ksw_total;
used = (gauge_t)data_s.ksw_used;
swap_submit_usage(NULL, used, total - used, NULL, NAN);
swap_submit_usage(NULL, used, total - used, NULL, NAN);
} /* }}} int swap_read */
/* #endif HAVE_LIBKVM_GETSWAPINFO */
} /* }}} int swap_read */
/* #endif HAVE_LIBKVM_GETSWAPINFO */
swap = sg_get_swap_stats();
if (swap == NULL)
swap = sg_get_swap_stats();
if (swap == NULL)
swap_submit_usage(NULL, (gauge_t)swap->used, (gauge_t)swap->free, NULL, NAN);
swap_submit_usage(NULL, (gauge_t)swap->used, (gauge_t)swap->free, NULL, NAN);
} /* }}} int swap_read */
/* #endif HAVE_LIBSTATGRAB */
} /* }}} int swap_read */
/* #endif HAVE_LIBSTATGRAB */
char errbuf[1024];
WARNING("swap plugin: perfstat_memory_total failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
WARNING("swap plugin: perfstat_memory_total failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
total = (gauge_t)(pmemory.pgsp_total * pagesize);
}
total = (gauge_t)(pmemory.pgsp_total * pagesize);
swap_submit_derive("in", (derive_t)pmemory.pgspins * pagesize);
swap_submit_derive("out", (derive_t)pmemory.pgspouts * pagesize);
swap_submit_derive("in", (derive_t)pmemory.pgspins * pagesize);
swap_submit_derive("out", (derive_t)pmemory.pgspouts * pagesize);
} /* }}} int swap_read */
#endif /* HAVE_PERFSTAT */
} /* }}} int swap_read */
#endif /* HAVE_PERFSTAT */
if (log_level < 0) {
log_level = LOG_INFO;
ERROR("syslog: invalid loglevel [%s] defaulting to 'info'", value);
if (log_level < 0) {
log_level = LOG_INFO;
ERROR("syslog: invalid loglevel [%s] defaulting to 'info'", value);
}
} else if (strcasecmp(key, "NotifyLevel") == 0) {
notif_severity = parse_notif_severity(value);
if (notif_severity < 0)
}
} else if (strcasecmp(key, "NotifyLevel") == 0) {
notif_severity = parse_notif_severity(value);
if (notif_severity < 0)
} /* int sl_config */
static void sl_log(int severity, const char *msg,
} /* int sl_config */
static void sl_log(int severity, const char *msg,
static int sl_shutdown(void) {
closelog();
static int sl_shutdown(void) {
closelog();
}
static int sl_notification(const notification_t *n,
}
static int sl_notification(const notification_t *n,
int status;
if (n->severity > notif_severity)
int status;
if (n->severity > notif_severity)
switch (n->severity) {
case NOTIF_FAILURE:
switch (n->severity) {
case NOTIF_FAILURE:
do { \
status = ssnprintf(&buf[offset], sizeof(buf) - offset, __VA_ARGS__); \
if (status < 1) \
do { \
status = ssnprintf(&buf[offset], sizeof(buf) - offset, __VA_ARGS__); \
if (status < 1) \
else if (((size_t)status) >= (sizeof(buf) - offset)) \
else if (((size_t)status) >= (sizeof(buf) - offset)) \
else \
offset += ((size_t)status); \
} while (0)
else \
offset += ((size_t)status); \
} while (0)
sl_log(log_severity, buf, NULL);
sl_log(log_severity, buf, NULL);
} /* int sl_notification */
void module_register(void) {
} /* int sl_notification */
void module_register(void) {
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("tail plugin: `DSType' needs exactly one string argument.");
oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("tail plugin: `DSType' needs exactly one string argument.");
}
char const *ds_type = ci->values[0].value.string;
}
char const *ds_type = ci->values[0].value.string;
int status = latency_config(&cm->latency, ci, "tail");
if (status != 0)
int status = latency_config(&cm->latency, ci, "tail");
if (status != 0)
} else if (strncasecmp("Counter", ds_type, strlen("Counter")) == 0) {
cm->flags = UTILS_MATCH_DS_TYPE_COUNTER;
if (strcasecmp("CounterSet", ds_type) == 0)
} else if (strncasecmp("Counter", ds_type, strlen("Counter")) == 0) {
cm->flags = UTILS_MATCH_DS_TYPE_COUNTER;
if (strcasecmp("CounterSet", ds_type) == 0)
if (cm->flags == 0) {
WARNING("tail plugin: `%s' is not a valid argument to `DSType'.",
ci->values[0].value.string);
if (cm->flags == 0) {
WARNING("tail plugin: `%s' is not a valid argument to `DSType'.",
ci->values[0].value.string);
} /* int ctail_config_add_match_dstype */
static int ctail_config_add_match(cu_tail_match_t *tm,
} /* int ctail_config_add_match_dstype */
static int ctail_config_add_match(cu_tail_match_t *tm,
sfree(cm.type_instance);
latency_config_free(cm.latency);
sfree(cm.type_instance);
latency_config_free(cm.latency);
} /* int ctail_config_add_match */
static int ctail_config_add_file(oconfig_item_t *ci) {
} /* int ctail_config_add_match */
static int ctail_config_add_file(oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("tail plugin: `File' needs exactly one string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("tail plugin: `File' needs exactly one string argument.");
}
tm = tail_match_create(ci->values[0].value.string);
if (tm == NULL) {
ERROR("tail plugin: tail_match_create (%s) failed.",
ci->values[0].value.string);
}
tm = tail_match_create(ci->values[0].value.string);
if (tm == NULL) {
ERROR("tail plugin: tail_match_create (%s) failed.",
ci->values[0].value.string);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
ERROR("tail plugin: No (valid) matches found for file `%s'.",
ci->values[0].value.string);
tail_match_destroy(tm);
ERROR("tail plugin: No (valid) matches found for file `%s'.",
ci->values[0].value.string);
tail_match_destroy(tm);
} else {
cu_tail_match_t **temp;
} else {
cu_tail_match_t **temp;
if (temp == NULL) {
ERROR("tail plugin: realloc failed.");
tail_match_destroy(tm);
if (temp == NULL) {
ERROR("tail plugin: realloc failed.");
tail_match_destroy(tm);
}
tail_match_list = temp;
}
tail_match_list = temp;
} /* int ctail_config_add_file */
static int ctail_config(oconfig_item_t *ci) {
} /* int ctail_config_add_file */
static int ctail_config(oconfig_item_t *ci) {
}
} /* for (i = 0; i < ci->children_num; i++) */
}
} /* for (i = 0; i < ci->children_num; i++) */
} /* int ctail_config */
static int ctail_read(user_data_t *ud) {
} /* int ctail_config */
static int ctail_read(user_data_t *ud) {
status = tail_match_read((cu_tail_match_t *)ud->data);
if (status != 0) {
ERROR("tail plugin: tail_match_read failed.");
status = tail_match_read((cu_tail_match_t *)ud->data);
if (status != 0) {
ERROR("tail plugin: tail_match_read failed.");
} /* int ctail_read */
static int ctail_init(void) {
} /* int ctail_read */
static int ctail_init(void) {
if (tail_match_list_num == 0) {
WARNING("tail plugin: File list is empty. Returning an error.");
if (tail_match_list_num == 0) {
WARNING("tail plugin: File list is empty. Returning an error.");
}
for (size_t i = 0; i < tail_match_list_num; i++) {
}
for (size_t i = 0; i < tail_match_list_num; i++) {
} /* int ctail_init */
static int ctail_shutdown(void) {
} /* int ctail_init */
static int ctail_shutdown(void) {
sfree(tail_match_list);
tail_match_list_num = 0;
sfree(tail_match_list);
tail_match_list_num = 0;
} /* int ctail_shutdown */
void module_register(void) {
} /* int ctail_shutdown */
void module_register(void) {
vl.time = t;
vl.interval = id->interval;
vl.time = t;
vl.interval = id->interval;
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
}
static cdtime_t parse_time(char const *tbuf) {
}
static cdtime_t parse_time(char const *tbuf) {
errno = 0;
t = strtod(tbuf, &endptr);
if ((errno != 0) || (endptr == NULL) || (endptr[0] != 0))
errno = 0;
t = strtod(tbuf, &endptr);
if ((errno != 0) || (endptr == NULL) || (endptr[0] != 0))
- return (DOUBLE_TO_CDTIME_T(t));
+ return DOUBLE_TO_CDTIME_T(t);
}
static int tcsv_read_metric(instance_definition_t *id, metric_definition_t *md,
}
static int tcsv_read_metric(instance_definition_t *id, metric_definition_t *md,
int status;
if (md->data_source_type == -1)
int status;
if (md->data_source_type == -1)
assert(md->value_from >= 0);
if (((size_t)md->value_from) >= fields_num)
assert(md->value_from >= 0);
if (((size_t)md->value_from) >= fields_num)
status = parse_value(fields[md->value_from], &v, md->data_source_type);
if (status != 0)
status = parse_value(fields[md->value_from], &v, md->data_source_type);
if (status != 0)
if (id->time_from >= 0) {
if (((size_t)id->time_from) >= fields_num)
if (id->time_from >= 0) {
if (((size_t)id->time_from) >= fields_num)
t = parse_time(fields[id->time_from]);
}
t = parse_time(fields[id->time_from]);
}
- return (tcsv_submit(id, md, v, t));
+ return tcsv_submit(id, md, v, t);
}
static _Bool tcsv_check_index(ssize_t index, size_t fields_num,
}
static _Bool tcsv_check_index(ssize_t index, size_t fields_num,
ERROR("tail_csv plugin: Metric \"%s\": Request for index %zd when "
"only %zu fields are available.",
name, index, fields_num);
ERROR("tail_csv plugin: Metric \"%s\": Request for index %zd when "
"only %zu fields are available.",
name, index, fields_num);
}
static int tcsv_read_buffer(instance_definition_t *id, char *buffer,
}
static int tcsv_read_buffer(instance_definition_t *id, char *buffer,
/* Ignore empty lines. */
if ((buffer_size == 0) || (buffer[0] == '#'))
/* Ignore empty lines. */
if ((buffer_size == 0) || (buffer[0] == '#'))
/* Count the number of fields. */
metrics_num = 1;
/* Count the number of fields. */
metrics_num = 1;
ERROR("tail_csv plugin: last line of `%s' does not contain "
"enough values.",
id->path);
ERROR("tail_csv plugin: last line of `%s' does not contain "
"enough values.",
id->path);
}
/* Create a list of all values */
metrics = calloc(metrics_num, sizeof(*metrics));
if (metrics == NULL) {
ERROR("tail_csv plugin: calloc failed.");
}
/* Create a list of all values */
metrics = calloc(metrics_num, sizeof(*metrics));
if (metrics == NULL) {
ERROR("tail_csv plugin: calloc failed.");
/* Free up resources */
sfree(metrics);
/* Free up resources */
sfree(metrics);
}
static int tcsv_read(user_data_t *ud) {
}
static int tcsv_read(user_data_t *ud) {
id->tail = cu_tail_create(id->path);
if (id->tail == NULL) {
ERROR("tail_csv plugin: cu_tail_create (\"%s\") failed.", id->path);
id->tail = cu_tail_create(id->path);
if (id->tail == NULL) {
ERROR("tail_csv plugin: cu_tail_create (\"%s\") failed.", id->path);
ERROR("tail_csv plugin: File \"%s\": cu_tail_readline failed "
"with status %i.",
id->path, status);
ERROR("tail_csv plugin: File \"%s\": cu_tail_readline failed "
"with status %i.",
id->path, status);
}
buffer_len = strlen(buffer);
}
buffer_len = strlen(buffer);
tcsv_read_buffer(id, buffer, buffer_len);
}
tcsv_read_buffer(id, buffer, buffer_len);
}
}
static void tcsv_metric_definition_destroy(void *arg) {
}
static void tcsv_metric_definition_destroy(void *arg) {
WARNING("tail_csv plugin: The \"%s\" config option needs exactly one "
"integer argument.",
ci->key);
WARNING("tail_csv plugin: The \"%s\" config option needs exactly one "
"integer argument.",
ci->key);
}
if (ci->values[0].value.number < 0) {
WARNING("tail_csv plugin: The \"%s\" config option must be positive "
"(or zero).",
ci->key);
}
if (ci->values[0].value.number < 0) {
WARNING("tail_csv plugin: The \"%s\" config option must be positive "
"(or zero).",
ci->key);
}
*ret_index = (ssize_t)ci->values[0].value.number;
}
*ret_index = (ssize_t)ci->values[0].value.number;
md = calloc(1, sizeof(*md));
if (md == NULL)
md = calloc(1, sizeof(*md));
if (md == NULL)
md->name = NULL;
md->type = NULL;
md->instance = NULL;
md->name = NULL;
md->type = NULL;
md->instance = NULL;
status = cf_util_get_string(ci, &md->name);
if (status != 0) {
sfree(md);
status = cf_util_get_string(ci, &md->name);
if (status != 0) {
sfree(md);
}
for (int i = 0; i < ci->children_num; ++i) {
}
for (int i = 0; i < ci->children_num; ++i) {
if (status != 0) {
tcsv_metric_definition_destroy(md);
if (status != 0) {
tcsv_metric_definition_destroy(md);
}
/* Verify all necessary options have been set. */
}
/* Verify all necessary options have been set. */
}
if (status != 0) {
tcsv_metric_definition_destroy(md);
}
if (status != 0) {
tcsv_metric_definition_destroy(md);
}
if (metric_head == NULL)
}
if (metric_head == NULL)
}
static void tcsv_instance_definition_destroy(void *arg) {
}
static void tcsv_instance_definition_destroy(void *arg) {
if (ci->values_num < 1) {
WARNING("tail_csv plugin: The `Collect' config option needs at least one "
"argument.");
if (ci->values_num < 1) {
WARNING("tail_csv plugin: The `Collect' config option needs at least one "
"argument.");
}
metric_list_size = id->metric_list_len + (size_t)ci->values_num;
metric_list =
realloc(id->metric_list, sizeof(*id->metric_list) * metric_list_size);
if (metric_list == NULL)
}
metric_list_size = id->metric_list_len + (size_t)ci->values_num;
metric_list =
realloc(id->metric_list, sizeof(*id->metric_list) * metric_list_size);
if (metric_list == NULL)
id->metric_list = metric_list;
for (int i = 0; i < ci->values_num; i++) {
id->metric_list = metric_list;
for (int i = 0; i < ci->values_num; i++) {
id = calloc(1, sizeof(*id));
if (id == NULL)
id = calloc(1, sizeof(*id));
if (id == NULL)
id->instance = NULL;
id->path = NULL;
id->metric_list = NULL;
id->instance = NULL;
id->path = NULL;
id->metric_list = NULL;
status = cf_util_get_string(ci, &id->path);
if (status != 0) {
sfree(id);
status = cf_util_get_string(ci, &id->path);
if (status != 0) {
sfree(id);
}
/* Use default interval. */
}
/* Use default interval. */
if (status != 0) {
tcsv_instance_definition_destroy(id);
if (status != 0) {
tcsv_instance_definition_destroy(id);
}
/* Verify all necessary options have been set. */
}
/* Verify all necessary options have been set. */
if (status != 0) {
tcsv_instance_definition_destroy(id);
if (status != 0) {
tcsv_instance_definition_destroy(id);
}
ssnprintf(cb_name, sizeof(cb_name), "tail_csv/%s", id->path);
}
ssnprintf(cb_name, sizeof(cb_name), "tail_csv/%s", id->path);
if (status != 0) {
ERROR("tail_csv plugin: Registering complex read function failed.");
tcsv_instance_definition_destroy(id);
if (status != 0) {
ERROR("tail_csv plugin: Registering complex read function failed.");
tcsv_instance_definition_destroy(id);
} /* int tcsv_config */
static int tcsv_init(void) { /* {{{ */
} /* int tcsv_config */
static int tcsv_init(void) { /* {{{ */
metric_definition_t *md;
if (have_init)
metric_definition_t *md;
if (have_init)
for (md = metric_head; md != NULL; md = md->next) {
data_set_t const *ds;
for (md = metric_head; md != NULL; md = md->next) {
data_set_t const *ds;
md->data_source_type = ds->ds->type;
}
md->data_source_type = ds->ds->type;
}
} /* }}} int tcsv_init */
static int tcsv_shutdown(void) {
tcsv_metric_definition_destroy(metric_head);
metric_head = NULL;
} /* }}} int tcsv_init */
static int tcsv_shutdown(void) {
tcsv_metric_definition_destroy(metric_head);
metric_head = NULL;
}
void module_register(void) {
}
void module_register(void) {
numtape = 0;
if (kc == NULL)
numtape = 0;
if (kc == NULL)
for (numtape = 0, ksp_chain = kc->kc_chain;
(numtape < MAX_NUMTAPE) && (ksp_chain != NULL);
for (numtape = 0, ksp_chain = kc->kc_chain;
(numtape < MAX_NUMTAPE) && (ksp_chain != NULL);
ksp[numtape++] = ksp_chain;
}
ksp[numtape++] = ksp_chain;
}
} /* int tape_init */
static void tape_submit(const char *plugin_instance, const char *type,
} /* int tape_init */
static void tape_submit(const char *plugin_instance, const char *type,
static kstat_io_t kio;
if (kc == NULL)
static kstat_io_t kio;
if (kc == NULL)
for (int i = 0; i < numtape; i++) {
if (kstat_read(kc, ksp[i], &kio) == -1)
for (int i = 0; i < numtape; i++) {
if (kstat_read(kc, ksp[i], &kio) == -1)
}
void module_register(void) {
}
void module_register(void) {
ERROR("Target `notification': The `%s' option requires exactly one string "
"argument.",
ci->key);
ERROR("Target `notification': The `%s' option requires exactly one string "
"argument.",
ci->key);
}
if ((strcasecmp("FAILURE", ci->values[0].value.string) == 0) ||
}
if ((strcasecmp("FAILURE", ci->values[0].value.string) == 0) ||
data->severity = NOTIF_FAILURE;
}
data->severity = NOTIF_FAILURE;
}
} /* }}} int tn_config_add_severity */
static int tn_config_add_string(char **dest, /* {{{ */
} /* }}} int tn_config_add_severity */
static int tn_config_add_string(char **dest, /* {{{ */
char *temp;
if (dest == NULL)
char *temp;
if (dest == NULL)
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("Target `notification': The `%s' option requires exactly one string "
"argument.",
ci->key);
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("Target `notification': The `%s' option requires exactly one string "
"argument.",
ci->key);
}
if (ci->values[0].value.string[0] == 0) {
ERROR(
"Target `notification': The `%s' option does not accept empty strings.",
ci->key);
}
if (ci->values[0].value.string[0] == 0) {
ERROR(
"Target `notification': The `%s' option does not accept empty strings.",
ci->key);
}
temp = sstrdup(ci->values[0].value.string);
if (temp == NULL) {
ERROR("tn_config_add_string: sstrdup failed.");
}
temp = sstrdup(ci->values[0].value.string);
if (temp == NULL) {
ERROR("tn_config_add_string: sstrdup failed.");
}
free(*dest);
*dest = temp;
}
free(*dest);
*dest = temp;
} /* }}} int tn_config_add_string */
static int tn_destroy(void **user_data) /* {{{ */
} /* }}} int tn_config_add_string */
static int tn_destroy(void **user_data) /* {{{ */
tn_data_t *data;
if (user_data == NULL)
tn_data_t *data;
if (user_data == NULL)
data = *user_data;
if (data == NULL)
data = *user_data;
if (data == NULL)
sfree(data->message);
sfree(data);
sfree(data->message);
sfree(data);
} /* }}} int tn_destroy */
static int tn_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
} /* }}} int tn_destroy */
static int tn_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("tn_create: calloc failed.");
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("tn_create: calloc failed.");
if (status != 0) {
tn_destroy((void *)&data);
if (status != 0) {
tn_destroy((void *)&data);
} /* }}} int tn_create */
static int tn_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int tn_create */
static int tn_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
int rates_failed;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
int rates_failed;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
data = *user_data;
if (data == NULL) {
ERROR("Target `notification': Invoke: `data' is NULL.");
data = *user_data;
if (data == NULL) {
ERROR("Target `notification': Invoke: `data' is NULL.");
}
/* Initialize the structure. */
}
/* Initialize the structure. */
plugin_dispatch_notification(&n);
plugin_dispatch_notification(&n);
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int tn_invoke */
void module_register(void) {
} /* }}} int tn_invoke */
void module_register(void) {
char *dest;
if (orig == NULL)
char *dest;
if (orig == NULL)
sz = strlen(orig) + 1;
dest = malloc(sz);
if (dest == NULL)
sz = strlen(orig) + 1;
dest = malloc(sz);
if (dest == NULL)
} /* }}} char *tr_strdup */
static void tr_action_destroy(tr_action_t *act) /* {{{ */
} /* }}} char *tr_strdup */
static void tr_action_destroy(tr_action_t *act) /* {{{ */
int status;
if (dest == NULL)
int status;
if (dest == NULL)
if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
ERROR("Target `replace': The `%s' option requires exactly two string "
"arguments.",
ci->key);
if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
(ci->values[1].type != OCONFIG_TYPE_STRING)) {
ERROR("Target `replace': The `%s' option requires exactly two string "
"arguments.",
ci->key);
}
act = calloc(1, sizeof(*act));
if (act == NULL) {
ERROR("tr_config_add_action: calloc failed.");
}
act = calloc(1, sizeof(*act));
if (act == NULL) {
ERROR("tr_config_add_action: calloc failed.");
}
act->replacement = NULL;
}
act->replacement = NULL;
"failed: %s.",
ci->values[0].value.string, errbuf);
sfree(act);
"failed: %s.",
ci->values[0].value.string, errbuf);
sfree(act);
}
act->replacement = tr_strdup(ci->values[1].value.string);
if (act->replacement == NULL) {
ERROR("tr_config_add_action: tr_strdup failed.");
tr_action_destroy(act);
}
act->replacement = tr_strdup(ci->values[1].value.string);
if (act->replacement == NULL) {
ERROR("tr_config_add_action: tr_strdup failed.");
tr_action_destroy(act);
}
/* Insert action at end of list. */
}
/* Insert action at end of list. */
} /* }}} int tr_config_add_action */
static int tr_config_add_meta_action(tr_meta_data_action_t **dest, /* {{{ */
} /* }}} int tr_config_add_action */
static int tr_config_add_meta_action(tr_meta_data_action_t **dest, /* {{{ */
int status;
if (dest == NULL)
int status;
if (dest == NULL)
if (should_delete) {
if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
if (should_delete) {
if ((ci->values_num != 2) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
ERROR("Target `replace': The `%s' option requires exactly two string "
"arguments.",
ci->key);
ERROR("Target `replace': The `%s' option requires exactly two string "
"arguments.",
ci->key);
}
} else {
if ((ci->values_num != 3) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
}
} else {
if ((ci->values_num != 3) || (ci->values[0].type != OCONFIG_TYPE_STRING) ||
ERROR("Target `replace': The `%s' option requires exactly three string "
"arguments.",
ci->key);
ERROR("Target `replace': The `%s' option requires exactly three string "
"arguments.",
ci->key);
ERROR("Target `replace': The `%s' option does not accept empty string as "
"first argument.",
ci->key);
ERROR("Target `replace': The `%s' option does not accept empty string as "
"first argument.",
ci->key);
}
act = calloc(1, sizeof(*act));
if (act == NULL) {
ERROR("tr_config_add_meta_action: calloc failed.");
}
act = calloc(1, sizeof(*act));
if (act == NULL) {
ERROR("tr_config_add_meta_action: calloc failed.");
ci->values[1].value.string, errbuf);
sfree(act->key);
sfree(act);
ci->values[1].value.string, errbuf);
sfree(act->key);
sfree(act);
}
act->key = tr_strdup(ci->values[0].value.string);
if (act->key == NULL) {
ERROR("tr_config_add_meta_action: tr_strdup failed.");
tr_meta_data_action_destroy(act);
}
act->key = tr_strdup(ci->values[0].value.string);
if (act->key == NULL) {
ERROR("tr_config_add_meta_action: tr_strdup failed.");
tr_meta_data_action_destroy(act);
if (act->replacement == NULL) {
ERROR("tr_config_add_meta_action: tr_strdup failed.");
tr_meta_data_action_destroy(act);
if (act->replacement == NULL) {
ERROR("tr_config_add_meta_action: tr_strdup failed.");
tr_meta_data_action_destroy(act);
} /* }}} int tr_config_add_meta_action */
static int tr_action_invoke(tr_action_t *act_head, /* {{{ */
} /* }}} int tr_config_add_meta_action */
static int tr_action_invoke(tr_action_t *act_head, /* {{{ */
regmatch_t matches[8] = {[0] = {0}};
if (act_head == NULL)
regmatch_t matches[8] = {[0] = {0}};
if (act_head == NULL)
sstrncpy(buffer, buffer_in, sizeof(buffer));
sstrncpy(buffer, buffer_in, sizeof(buffer));
if ((may_be_empty == 0) && (buffer[0] == 0)) {
WARNING("Target `replace': Replacement resulted in an empty string, "
"which is not allowed for this buffer (`host' or `plugin').");
if ((may_be_empty == 0) && (buffer[0] == 0)) {
WARNING("Target `replace': Replacement resulted in an empty string, "
"which is not allowed for this buffer (`host' or `plugin').");
}
DEBUG("target_replace plugin: tr_action_invoke: -> buffer = %s;", buffer);
sstrncpy(buffer_in, buffer, buffer_in_size);
}
DEBUG("target_replace plugin: tr_action_invoke: -> buffer = %s;", buffer);
sstrncpy(buffer_in, buffer, buffer_in_size);
} /* }}} int tr_action_invoke */
static int tr_meta_data_action_invoke(/* {{{ */
} /* }}} int tr_action_invoke */
static int tr_meta_data_action_invoke(/* {{{ */
regmatch_t matches[8] = {[0] = {0}};
if (act_head == NULL)
regmatch_t matches[8] = {[0] = {0}};
if (act_head == NULL)
if ((*dest) == NULL) /* nothing to do */
if ((*dest) == NULL) /* nothing to do */
for (tr_meta_data_action_t *act = act_head; act != NULL; act = act->next) {
char temp[DATA_MAX_NAME_LEN];
for (tr_meta_data_action_t *act = act_head; act != NULL; act = act->next) {
char temp[DATA_MAX_NAME_LEN];
if (meta_data_status != 0) {
ERROR("Target `replace': Unable to retrieve metadata value for `%s'.",
act->key);
if (meta_data_status != 0) {
ERROR("Target `replace': Unable to retrieve metadata value for `%s'.",
act->key);
- return (meta_data_status);
+ return meta_data_status;
}
DEBUG("target_replace plugin: tr_meta_data_action_invoke: `%s' "
}
DEBUG("target_replace plugin: tr_meta_data_action_invoke: `%s' "
if ((result = meta_data_create()) == NULL) {
ERROR("Target `replace': failed to create metadata for `%s'.", act->key);
sfree(value);
if ((result = meta_data_create()) == NULL) {
ERROR("Target `replace': failed to create metadata for `%s'.", act->key);
sfree(value);
}
meta_data_status = meta_data_add_string(result, act->key, temp);
}
meta_data_status = meta_data_add_string(result, act->key, temp);
act->key);
meta_data_destroy(result);
sfree(value);
act->key);
meta_data_destroy(result);
sfree(value);
- return (meta_data_status);
+ return meta_data_status;
}
meta_data_clone_merge(dest, result);
}
meta_data_clone_merge(dest, result);
sfree(value);
} /* for (act = act_head; act != NULL; act = act->next) */
sfree(value);
} /* for (act = act_head; act != NULL; act = act->next) */
} /* }}} int tr_meta_data_action_invoke */
static int tr_destroy(void **user_data) /* {{{ */
} /* }}} int tr_meta_data_action_invoke */
static int tr_destroy(void **user_data) /* {{{ */
tr_data_t *data;
if (user_data == NULL)
tr_data_t *data;
if (user_data == NULL)
data = *user_data;
if (data == NULL)
data = *user_data;
if (data == NULL)
tr_action_destroy(data->host);
tr_action_destroy(data->plugin);
tr_action_destroy(data->host);
tr_action_destroy(data->plugin);
tr_meta_data_action_destroy(data->meta);
sfree(data);
tr_meta_data_action_destroy(data->meta);
sfree(data);
} /* }}} int tr_destroy */
static int tr_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
} /* }}} int tr_destroy */
static int tr_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("tr_create: calloc failed.");
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("tr_create: calloc failed.");
if (status != 0) {
tr_destroy((void *)&data);
if (status != 0) {
tr_destroy((void *)&data);
} /* }}} int tr_create */
static int tr_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int tr_create */
static int tr_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
tr_data_t *data;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
tr_data_t *data;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
data = *user_data;
if (data == NULL) {
ERROR("Target `replace': Invoke: `data' is NULL.");
data = *user_data;
if (data == NULL) {
ERROR("Target `replace': Invoke: `data' is NULL.");
}
if (data->meta != NULL) {
}
if (data->meta != NULL) {
/* HANDLE_FIELD (type, 0); */
HANDLE_FIELD(type_instance, 1);
/* HANDLE_FIELD (type, 0); */
HANDLE_FIELD(type_instance, 1);
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int tr_invoke */
void module_register(void) {
} /* }}} int tr_invoke */
void module_register(void) {
uc_meta_data_add_unsigned_int(vl, key_int_counter, int_counter);
uc_meta_data_add_double(vl, key_int_fraction, int_fraction);
uc_meta_data_add_unsigned_int(vl, key_int_counter, int_counter);
uc_meta_data_add_double(vl, key_int_fraction, int_fraction);
} /* }}} int ts_invoke_counter */
static int ts_invoke_gauge(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int ts_invoke_counter */
static int ts_invoke_gauge(const data_set_t *ds, value_list_t *vl, /* {{{ */
if (!isnan(data->offset))
vl->values[dsrc_index].gauge += data->offset;
if (!isnan(data->offset))
vl->values[dsrc_index].gauge += data->offset;
} /* }}} int ts_invoke_gauge */
static int ts_invoke_derive(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int ts_invoke_gauge */
static int ts_invoke_derive(const data_set_t *ds, value_list_t *vl, /* {{{ */
uc_meta_data_add_signed_int(vl, key_int_derive, int_derive);
uc_meta_data_add_double(vl, key_int_fraction, int_fraction);
uc_meta_data_add_signed_int(vl, key_int_derive, int_derive);
uc_meta_data_add_double(vl, key_int_fraction, int_fraction);
} /* }}} int ts_invoke_derive */
static int ts_invoke_absolute(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int ts_invoke_derive */
static int ts_invoke_absolute(const data_set_t *ds, value_list_t *vl, /* {{{ */
/* Update to the new absolute value */
uc_meta_data_add_double(vl, key_int_fraction, int_fraction);
/* Update to the new absolute value */
uc_meta_data_add_double(vl, key_int_fraction, int_fraction);
} /* }}} int ts_invoke_absolute */
static int ts_config_set_double(double *ret, oconfig_item_t *ci) /* {{{ */
} /* }}} int ts_invoke_absolute */
static int ts_config_set_double(double *ret, oconfig_item_t *ci) /* {{{ */
WARNING("scale target: The `%s' config option needs "
"exactly one numeric argument.",
ci->key);
WARNING("scale target: The `%s' config option needs "
"exactly one numeric argument.",
ci->key);
}
*ret = ci->values[0].value.number;
DEBUG("ts_config_set_double: *ret = %g", *ret);
}
*ret = ci->values[0].value.number;
DEBUG("ts_config_set_double: *ret = %g", *ret);
} /* }}} int ts_config_set_double */
static int ts_config_add_data_source(ts_data_t *data, /* {{{ */
} /* }}} int ts_config_set_double */
static int ts_config_add_data_source(ts_data_t *data, /* {{{ */
/* Check number of arbuments. */
if (ci->values_num < 1) {
ERROR("`value' match: `%s' needs at least one argument.", ci->key);
/* Check number of arbuments. */
if (ci->values_num < 1) {
ERROR("`value' match: `%s' needs at least one argument.", ci->key);
}
/* Check type of arguments */
}
/* Check type of arguments */
ci->key, i + 1,
(ci->values[i].type == OCONFIG_TYPE_BOOLEAN) ? "truth value"
: "number");
ci->key, i + 1,
(ci->values[i].type == OCONFIG_TYPE_BOOLEAN) ? "truth value"
: "number");
}
/* Allocate space for the char pointers */
}
/* Allocate space for the char pointers */
temp = realloc(data->data_sources, new_data_sources_num * sizeof(char *));
if (temp == NULL) {
ERROR("`value' match: realloc failed.");
temp = realloc(data->data_sources, new_data_sources_num * sizeof(char *));
if (temp == NULL) {
ERROR("`value' match: realloc failed.");
}
data->data_sources = temp;
}
data->data_sources = temp;
data->data_sources_num++;
}
data->data_sources_num++;
}
} /* }}} int ts_config_add_data_source */
static int ts_destroy(void **user_data) /* {{{ */
} /* }}} int ts_config_add_data_source */
static int ts_destroy(void **user_data) /* {{{ */
ts_data_t *data;
if (user_data == NULL)
ts_data_t *data;
if (user_data == NULL)
data = (ts_data_t *)*user_data;
data = (ts_data_t *)*user_data;
sfree(data);
*user_data = NULL;
sfree(data);
*user_data = NULL;
} /* }}} int ts_destroy */
static int ts_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
} /* }}} int ts_destroy */
static int ts_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("ts_create: calloc failed.");
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("ts_create: calloc failed.");
if (status != 0) {
ts_destroy((void *)&data);
if (status != 0) {
ts_destroy((void *)&data);
} /* }}} int ts_create */
static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int ts_create */
static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
ts_data_t *data;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
ts_data_t *data;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
data = *user_data;
if (data == NULL) {
ERROR("Target `scale': Invoke: `data' is NULL.");
data = *user_data;
if (data == NULL) {
ERROR("Target `scale': Invoke: `data' is NULL.");
}
for (size_t i = 0; i < ds->ds_num; i++) {
}
for (size_t i = 0; i < ds->ds_num; i++) {
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int ts_invoke */
void module_register(void) {
} /* }}} int ts_invoke */
void module_register(void) {
ERROR("ts_util_get_key_and_string_wo_strdup: The %s option requires "
"exactly two string arguments.",
ci->key);
ERROR("ts_util_get_key_and_string_wo_strdup: The %s option requires "
"exactly two string arguments.",
ci->key);
}
*ret_key = ci->values[0].value.string;
*ret_string = ci->values[1].value.string;
}
*ret_key = ci->values[0].value.string;
*ret_string = ci->values[1].value.string;
} /* }}} int ts_util_get_key_and_string_wo_strdup */
static int ts_config_add_string(char **dest, /* {{{ */
} /* }}} int ts_util_get_key_and_string_wo_strdup */
static int ts_config_add_string(char **dest, /* {{{ */
status = cf_util_get_string(ci, &tmp);
if (status != 0)
status = cf_util_get_string(ci, &tmp);
if (status != 0)
if (!may_be_empty && (strlen(tmp) == 0)) {
ERROR("Target `set': The `%s' option does not accept empty strings.",
ci->key);
sfree(tmp);
if (!may_be_empty && (strlen(tmp) == 0)) {
ERROR("Target `set': The `%s' option does not accept empty strings.",
ci->key);
sfree(tmp);
} /* }}} int ts_config_add_string */
static int ts_config_add_meta(meta_data_t **dest, /* {{{ */
} /* }}} int ts_config_add_string */
static int ts_config_add_meta(meta_data_t **dest, /* {{{ */
status = ts_util_get_key_and_string_wo_strdup(ci, &key, &string);
if (status != 0)
status = ts_util_get_key_and_string_wo_strdup(ci, &key, &string);
if (status != 0)
if (strlen(key) == 0) {
ERROR("Target `set': The `%s' option does not accept empty string as "
"first argument.",
ci->key);
if (strlen(key) == 0) {
ERROR("Target `set': The `%s' option does not accept empty string as "
"first argument.",
ci->key);
}
if (!may_be_empty && (strlen(string) == 0)) {
ERROR("Target `set': The `%s' option does not accept empty string as "
"second argument.",
ci->key);
}
if (!may_be_empty && (strlen(string) == 0)) {
ERROR("Target `set': The `%s' option does not accept empty string as "
"second argument.",
ci->key);
}
if ((*dest) == NULL) {
/* Create a new meta_data_t */
if ((*dest = meta_data_create()) == NULL) {
ERROR("Target `set': failed to create a meta data for `%s'.", ci->key);
}
if ((*dest) == NULL) {
/* Create a new meta_data_t */
if ((*dest = meta_data_create()) == NULL) {
ERROR("Target `set': failed to create a meta data for `%s'.", ci->key);
- return (meta_data_add_string(*dest, key, string));
+ return meta_data_add_string(*dest, key, string);
} /* }}} int ts_config_add_meta */
static int ts_config_add_meta_delete(ts_key_list_t **dest, /* {{{ */
} /* }}} int ts_config_add_meta */
static int ts_config_add_meta_delete(ts_key_list_t **dest, /* {{{ */
entry = calloc(1, sizeof(*entry));
if (entry == NULL) {
ERROR("ts_config_add_meta_delete: calloc failed.");
entry = calloc(1, sizeof(*entry));
if (entry == NULL) {
ERROR("ts_config_add_meta_delete: calloc failed.");
}
if (cf_util_get_string(ci, &entry->key) != 0) {
ts_key_list_free(entry);
}
if (cf_util_get_string(ci, &entry->key) != 0) {
ts_key_list_free(entry);
- return (-1); /* An error has already been reported. */
+ return -1; /* An error has already been reported. */
}
if (strlen(entry->key) == 0) {
}
if (strlen(entry->key) == 0) {
"first argument.",
ci->key);
ts_key_list_free(entry);
"first argument.",
ci->key);
ts_key_list_free(entry);
}
entry->next = *dest;
*dest = entry;
}
entry->next = *dest;
*dest = entry;
} /* }}} int ts_config_add_meta_delete */
static void ts_subst(char *dest, size_t size, const char *string, /* {{{ */
} /* }}} int ts_config_add_meta_delete */
static void ts_subst(char *dest, size_t size, const char *string, /* {{{ */
ts_data_t *data;
if (user_data == NULL)
ts_data_t *data;
if (user_data == NULL)
data = *user_data;
if (data == NULL)
data = *user_data;
if (data == NULL)
free(data->host);
free(data->plugin);
free(data->host);
free(data->plugin);
ts_key_list_free(data->meta_delete);
free(data);
ts_key_list_free(data->meta_delete);
free(data);
} /* }}} int ts_destroy */
static int ts_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
} /* }}} int ts_destroy */
static int ts_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("ts_create: calloc failed.");
data = calloc(1, sizeof(*data));
if (data == NULL) {
ERROR("ts_create: calloc failed.");
if (status != 0) {
ts_destroy((void *)&data);
if (status != 0) {
ts_destroy((void *)&data);
} /* }}} int ts_create */
static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
} /* }}} int ts_create */
static int ts_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
meta_data_t *new_meta = NULL;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
meta_data_t *new_meta = NULL;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
data = *user_data;
if (data == NULL) {
ERROR("Target `set': Invoke: `data' is NULL.");
data = *user_data;
if (data == NULL) {
ERROR("Target `set': Invoke: `data' is NULL.");
if ((new_meta = meta_data_create()) == NULL) {
ERROR("Target `set': failed to create replacement metadata.");
if ((new_meta = meta_data_create()) == NULL) {
ERROR("Target `set': failed to create replacement metadata.");
}
meta_entries = meta_data_toc(data->meta, &meta_toc);
}
meta_entries = meta_data_toc(data->meta, &meta_toc);
key);
strarray_free(meta_toc, (size_t)meta_entries);
meta_data_destroy(new_meta);
key);
strarray_free(meta_toc, (size_t)meta_entries);
meta_data_destroy(new_meta);
}
ts_subst(temp, sizeof(temp), string, &orig);
}
ts_subst(temp, sizeof(temp), string, &orig);
ERROR("Target `set': Unable to set metadata value `%s'.", key);
strarray_free(meta_toc, (size_t)meta_entries);
meta_data_destroy(new_meta);
ERROR("Target `set': Unable to set metadata value `%s'.", key);
strarray_free(meta_toc, (size_t)meta_entries);
meta_data_destroy(new_meta);
meta_data_delete(vl->meta, l->key);
}
meta_data_delete(vl->meta, l->key);
}
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int ts_invoke */
void module_register(void) {
} /* }}} int ts_invoke */
void module_register(void) {
/* Can't upgrade if both instances have been set. */
if ((vl->plugin_instance[0] != 0) && (vl->type_instance[0] != 0))
/* Can't upgrade if both instances have been set. */
if ((vl->plugin_instance[0] != 0) && (vl->type_instance[0] != 0))
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
static int v5_interface(const data_set_t *ds, value_list_t *vl) /* {{{ */
{
if ((vl->plugin_instance[0] != 0) || (vl->type_instance[0] == 0))
static int v5_interface(const data_set_t *ds, value_list_t *vl) /* {{{ */
{
if ((vl->plugin_instance[0] != 0) || (vl->type_instance[0] == 0))
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int v5_interface */
/*
} /* }}} int v5_interface */
/*
value_list_t new_vl;
if (vl->values_len != 5)
value_list_t new_vl;
if (vl->values_len != 5)
- return (FC_TARGET_STOP);
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
} /* }}} int v5_mysql_qcache */
/*
} /* }}} int v5_mysql_qcache */
/*
value_list_t new_vl;
if (vl->values_len != 4)
value_list_t new_vl;
if (vl->values_len != 4)
- return (FC_TARGET_STOP);
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
} /* }}} int v5_mysql_threads */
/*
} /* }}} int v5_mysql_threads */
/*
_Bool is_hits;
if (vl->values_len != 4)
_Bool is_hits;
if (vl->values_len != 4)
- return (FC_TARGET_STOP);
if (strcmp("hits", vl->type_instance) == 0)
is_hits = 1;
else if (strcmp("misses", vl->type_instance) == 0)
is_hits = 0;
else
if (strcmp("hits", vl->type_instance) == 0)
is_hits = 1;
else if (strcmp("misses", vl->type_instance) == 0)
is_hits = 0;
else
- return (FC_TARGET_STOP);
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
} /* }}} int v5_zfs_arc_counts */
/*
} /* }}} int v5_zfs_arc_counts */
/*
value_list_t new_vl;
if (vl->values_len != 2)
value_list_t new_vl;
if (vl->values_len != 2)
- return (FC_TARGET_STOP);
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
} /* }}} int v5_zfs_arc_l2_bytes */
/*
} /* }}} int v5_zfs_arc_l2_bytes */
/*
value_list_t new_vl;
if (vl->values_len != 1)
value_list_t new_vl;
if (vl->values_len != 1)
- return (FC_TARGET_STOP);
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
} /* }}} int v5_zfs_arc_l2_size */
/*
} /* }}} int v5_zfs_arc_l2_size */
/*
value_list_t new_vl;
if (vl->values_len != 1)
value_list_t new_vl;
if (vl->values_len != 1)
- return (FC_TARGET_STOP);
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
} /* }}} int v5_zfs_arc_ratio */
/*
} /* }}} int v5_zfs_arc_ratio */
/*
value_list_t new_vl;
if (vl->values_len != 4)
value_list_t new_vl;
if (vl->values_len != 4)
- return (FC_TARGET_STOP);
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
/* Copy everything: Time, interval, host, ... */
memcpy(&new_vl, vl, sizeof(new_vl));
plugin_dispatch_values(&new_vl);
/* Abort processing */
plugin_dispatch_values(&new_vl);
/* Abort processing */
- return (FC_TARGET_STOP);
} /* }}} int v5_zfs_arc_size */
static int v5_destroy(void **user_data) /* {{{ */
{
} /* }}} int v5_zfs_arc_size */
static int v5_destroy(void **user_data) /* {{{ */
{
} /* }}} int v5_destroy */
static int v5_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
{
*user_data = NULL;
} /* }}} int v5_destroy */
static int v5_create(const oconfig_item_t *ci, void **user_data) /* {{{ */
{
*user_data = NULL;
} /* }}} int v5_create */
static int v5_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
} /* }}} int v5_create */
static int v5_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
notification_meta_t __attribute__((unused)) * *meta,
void __attribute__((unused)) * *user_data) {
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
if (strcmp("df", vl->type) == 0)
if (strcmp("df", vl->type) == 0)
- return (v5_df(ds, vl));
else if (strcmp("interface", vl->plugin) == 0)
else if (strcmp("interface", vl->plugin) == 0)
- return (v5_interface(ds, vl));
+ return v5_interface(ds, vl);
else if (strcmp("mysql_qcache", vl->type) == 0)
else if (strcmp("mysql_qcache", vl->type) == 0)
- return (v5_mysql_qcache(ds, vl));
+ return v5_mysql_qcache(ds, vl);
else if (strcmp("mysql_threads", vl->type) == 0)
else if (strcmp("mysql_threads", vl->type) == 0)
- return (v5_mysql_threads(ds, vl));
+ return v5_mysql_threads(ds, vl);
else if (strcmp("arc_counts", vl->type) == 0)
else if (strcmp("arc_counts", vl->type) == 0)
- return (v5_zfs_arc_counts(ds, vl));
+ return v5_zfs_arc_counts(ds, vl);
else if (strcmp("arc_l2_bytes", vl->type) == 0)
else if (strcmp("arc_l2_bytes", vl->type) == 0)
- return (v5_zfs_arc_l2_bytes(ds, vl));
+ return v5_zfs_arc_l2_bytes(ds, vl);
else if (strcmp("arc_l2_size", vl->type) == 0)
else if (strcmp("arc_l2_size", vl->type) == 0)
- return (v5_zfs_arc_l2_size(ds, vl));
+ return v5_zfs_arc_l2_size(ds, vl);
else if (strcmp("arc_ratio", vl->type) == 0)
else if (strcmp("arc_ratio", vl->type) == 0)
- return (v5_zfs_arc_ratio(ds, vl));
+ return v5_zfs_arc_ratio(ds, vl);
else if (strcmp("arc_size", vl->type) == 0)
else if (strcmp("arc_size", vl->type) == 0)
- return (v5_zfs_arc_size(ds, vl));
+ return v5_zfs_arc_size(ds, vl);
- return (FC_TARGET_CONTINUE);
+ return FC_TARGET_CONTINUE;
} /* }}} int v5_invoke */
void module_register(void) {
} /* }}} int v5_invoke */
void module_register(void) {
if ((ret == NULL) && (create != 0)) {
ret = calloc(1, sizeof(*ret));
if (ret == NULL)
if ((ret == NULL) && (create != 0)) {
ret = calloc(1, sizeof(*ret));
if (ret == NULL)
ret->port = port;
ret->next = port_list_head;
port_list_head = ret;
}
ret->port = port;
ret->next = port_list_head;
port_list_head = ret;
}
} /* port_entry_t *conn_get_port_entry */
/* Removes ports that were added automatically due to the `ListeningPorts'
} /* port_entry_t *conn_get_port_entry */
/* Removes ports that were added automatically due to the `ListeningPorts'
NOTICE("tcpconns plugin: Ignoring connection with "
"unknown state 0x%02" PRIx8 ".",
state);
NOTICE("tcpconns plugin: Ignoring connection with "
"unknown state 0x%02" PRIx8 ".",
state);
if (pe != NULL)
pe->count_remote[state]++;
if (pe != NULL)
pe->count_remote[state]++;
} /* int conn_handle_ports */
#if KERNEL_LINUX
} /* int conn_handle_ports */
#if KERNEL_LINUX
ERROR("tcpconns plugin: conn_read_netlink: socket(AF_NETLINK, SOCK_RAW, "
"NETLINK_INET_DIAG) failed: %s",
sstrerror(errno, buf, sizeof(buf)));
ERROR("tcpconns plugin: conn_read_netlink: socket(AF_NETLINK, SOCK_RAW, "
"NETLINK_INET_DIAG) failed: %s",
sstrerror(errno, buf, sizeof(buf)));
}
struct sockaddr_nl nladdr = {.nl_family = AF_NETLINK};
}
struct sockaddr_nl nladdr = {.nl_family = AF_NETLINK};
ERROR("tcpconns plugin: conn_read_netlink: sendmsg(2) failed: %s",
sstrerror(errno, buf, sizeof(buf)));
close(fd);
ERROR("tcpconns plugin: conn_read_netlink: sendmsg(2) failed: %s",
sstrerror(errno, buf, sizeof(buf)));
close(fd);
ERROR("tcpconns plugin: conn_read_netlink: recvmsg(2) failed: %s",
sstrerror(errno, buf, sizeof(buf)));
close(fd);
ERROR("tcpconns plugin: conn_read_netlink: recvmsg(2) failed: %s",
sstrerror(errno, buf, sizeof(buf)));
close(fd);
} else if (status == 0) {
close(fd);
DEBUG("tcpconns plugin: conn_read_netlink: Unexpected zero-sized "
"reply from netlink socket.");
} else if (status == 0) {
close(fd);
DEBUG("tcpconns plugin: conn_read_netlink: Unexpected zero-sized "
"reply from netlink socket.");
}
h = (struct nlmsghdr *)buf;
}
h = (struct nlmsghdr *)buf;
if (h->nlmsg_type == NLMSG_DONE) {
close(fd);
if (h->nlmsg_type == NLMSG_DONE) {
close(fd);
} else if (h->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *msg_error;
} else if (h->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *msg_error;
msg_error->error);
close(fd);
msg_error->error);
close(fd);
} /* while (1) */
/* Not reached because the while() loop above handles the exit condition. */
} /* while (1) */
/* Not reached because the while() loop above handles the exit condition. */
#endif /* HAVE_STRUCT_LINUX_INET_DIAG_REQ */
} /* int conn_read_netlink */
#endif /* HAVE_STRUCT_LINUX_INET_DIAG_REQ */
} /* int conn_read_netlink */
while ((buffer_len > 0) && (buffer[buffer_len - 1] < 32))
buffer[--buffer_len] = '\0';
if (buffer_len <= 0)
while ((buffer_len > 0) && (buffer[buffer_len - 1] < 32))
buffer[--buffer_len] = '\0';
if (buffer_len <= 0)
fields_len = strsplit(buffer, fields, STATIC_ARRAY_SIZE(fields));
if (fields_len < 12) {
DEBUG("tcpconns plugin: Got %i fields, expected at least 12.", fields_len);
fields_len = strsplit(buffer, fields, STATIC_ARRAY_SIZE(fields));
if (fields_len < 12) {
DEBUG("tcpconns plugin: Got %i fields, expected at least 12.", fields_len);
}
port_local_str = strchr(fields[1], ':');
port_remote_str = strchr(fields[2], ':');
if ((port_local_str == NULL) || (port_remote_str == NULL))
}
port_local_str = strchr(fields[1], ':');
port_remote_str = strchr(fields[2], ':');
if ((port_local_str == NULL) || (port_remote_str == NULL))
port_local_str++;
port_remote_str++;
if ((*port_local_str == '\0') || (*port_remote_str == '\0'))
port_local_str++;
port_remote_str++;
if ((*port_local_str == '\0') || (*port_remote_str == '\0'))
endptr = NULL;
port_local = (uint16_t)strtol(port_local_str, &endptr, 16);
if ((endptr == NULL) || (*endptr != '\0'))
endptr = NULL;
port_local = (uint16_t)strtol(port_local_str, &endptr, 16);
if ((endptr == NULL) || (*endptr != '\0'))
endptr = NULL;
port_remote = (uint16_t)strtol(port_remote_str, &endptr, 16);
if ((endptr == NULL) || (*endptr != '\0'))
endptr = NULL;
port_remote = (uint16_t)strtol(port_remote_str, &endptr, 16);
if ((endptr == NULL) || (*endptr != '\0'))
endptr = NULL;
state = (uint8_t)strtol(fields[3], &endptr, 16);
if ((endptr == NULL) || (*endptr != '\0'))
endptr = NULL;
state = (uint8_t)strtol(fields[3], &endptr, 16);
if ((endptr == NULL) || (*endptr != '\0'))
- return (conn_handle_ports(port_local, port_remote, state));
+ return conn_handle_ports(port_local, port_remote, state);
} /* int conn_handle_line */
static int conn_read_file(const char *file) {
} /* int conn_handle_line */
static int conn_read_file(const char *file) {
fh = fopen(file, "r");
if (fh == NULL)
fh = fopen(file, "r");
if (fh == NULL)
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
conn_handle_line(buffer);
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
conn_handle_line(buffer);
} /* int conn_read_file */
/* #endif KERNEL_LINUX */
} /* int conn_read_file */
/* #endif KERNEL_LINUX */
if ((port < 1) || (port > 65535)) {
ERROR("tcpconns plugin: Invalid port: %i", port);
if ((port < 1) || (port > 65535)) {
ERROR("tcpconns plugin: Invalid port: %i", port);
}
pe = conn_get_port_entry((uint16_t)port, 1 /* create */);
if (pe == NULL) {
ERROR("tcpconns plugin: conn_get_port_entry failed.");
}
pe = conn_get_port_entry((uint16_t)port, 1 /* create */);
if (pe == NULL) {
ERROR("tcpconns plugin: conn_get_port_entry failed.");
}
if (strcasecmp(key, "LocalPort") == 0)
}
if (strcasecmp(key, "LocalPort") == 0)
else
port_collect_total = 0;
} else {
else
port_collect_total = 0;
} else {
} /* int conn_config */
#if KERNEL_LINUX
} /* int conn_config */
#if KERNEL_LINUX
if (port_collect_total == 0 && port_list_head == NULL)
port_collect_listening = 1;
if (port_collect_total == 0 && port_list_head == NULL)
port_collect_listening = 1;
} /* int conn_init */
static int conn_read(void) {
} /* int conn_init */
static int conn_read(void) {
linux_source = SRC_PROC;
/* return success here to avoid the "plugin failed" message. */
linux_source = SRC_PROC;
/* return success here to avoid the "plugin failed" message. */
}
}
if (status == 0)
conn_submit_all();
else
}
}
if (status == 0)
conn_submit_all();
else
} /* int conn_read */
/* #endif KERNEL_LINUX */
} /* int conn_read */
/* #endif KERNEL_LINUX */
status = sysctlbyname("net.inet.tcp.pcblist", NULL, &buffer_len, 0, 0);
if (status < 0) {
ERROR("tcpconns plugin: sysctlbyname failed.");
status = sysctlbyname("net.inet.tcp.pcblist", NULL, &buffer_len, 0, 0);
if (status < 0) {
ERROR("tcpconns plugin: sysctlbyname failed.");
}
buffer = malloc(buffer_len);
if (buffer == NULL) {
ERROR("tcpconns plugin: malloc failed.");
}
buffer = malloc(buffer_len);
if (buffer == NULL) {
ERROR("tcpconns plugin: malloc failed.");
}
status = sysctlbyname("net.inet.tcp.pcblist", buffer, &buffer_len, 0, 0);
if (status < 0) {
ERROR("tcpconns plugin: sysctlbyname failed.");
sfree(buffer);
}
status = sysctlbyname("net.inet.tcp.pcblist", buffer, &buffer_len, 0, 0);
if (status < 0) {
ERROR("tcpconns plugin: sysctlbyname failed.");
sfree(buffer);
}
if (buffer_len <= sizeof(struct xinpgen)) {
ERROR("tcpconns plugin: (buffer_len <= sizeof (struct xinpgen))");
sfree(buffer);
}
if (buffer_len <= sizeof(struct xinpgen)) {
ERROR("tcpconns plugin: (buffer_len <= sizeof (struct xinpgen))");
sfree(buffer);
}
in_orig = (struct xinpgen *)buffer;
}
in_orig = (struct xinpgen *)buffer;
} /* int conn_read */
/* #endif HAVE_SYSCTLBYNAME */
} /* int conn_read */
/* #endif HAVE_SYSCTLBYNAME */
kvmd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, buf);
if (kvmd == NULL) {
ERROR("tcpconns plugin: kvm_openfiles failed: %s", buf);
kvmd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, buf);
if (kvmd == NULL) {
ERROR("tcpconns plugin: kvm_openfiles failed: %s", buf);
} /* int conn_init */
static int conn_read(void) {
} /* int conn_init */
static int conn_read(void) {
sizeof(*kf), &fcnt);
if (kf == NULL) {
ERROR("tcpconns plugin: kvm_getfiles failed.");
sizeof(*kf), &fcnt);
if (kf == NULL) {
ERROR("tcpconns plugin: kvm_getfiles failed.");
}
for (i = 0; i < fcnt; i++) {
}
for (i = 0; i < fcnt; i++) {
}
/* int conn_read */
/* #endif HAVE_KVM_GETFILES */
}
/* int conn_read */
/* #endif HAVE_KVM_GETFILES */
if (status != size) {
ERROR("tcpconns plugin: kvm_read failed (got %i, expected %i): %s\n",
status, size, kvm_geterr(kvmd));
if (status != size) {
ERROR("tcpconns plugin: kvm_read failed (got %i, expected %i): %s\n",
status, size, kvm_geterr(kvmd));
} /* int kread */
static int conn_init(void) {
} /* int kread */
static int conn_init(void) {
kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buf);
if (kvmd == NULL) {
ERROR("tcpconns plugin: kvm_openfiles failed: %s", buf);
kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, buf);
if (kvmd == NULL) {
ERROR("tcpconns plugin: kvm_openfiles failed: %s", buf);
}
status = kvm_nlist(kvmd, nl);
if (status < 0) {
ERROR("tcpconns plugin: kvm_nlist failed with status %i.", status);
}
status = kvm_nlist(kvmd, nl);
if (status < 0) {
ERROR("tcpconns plugin: kvm_nlist failed with status %i.", status);
}
if (nl[N_TCBTABLE].n_type == 0) {
ERROR("tcpconns plugin: Error looking up kernel's namelist: "
"N_TCBTABLE is invalid.");
}
if (nl[N_TCBTABLE].n_type == 0) {
ERROR("tcpconns plugin: Error looking up kernel's namelist: "
"N_TCBTABLE is invalid.");
}
inpcbtable_off = (u_long)nl[N_TCBTABLE].n_value;
inpcbtable_ptr = (struct inpcbtable *)nl[N_TCBTABLE].n_value;
}
inpcbtable_off = (u_long)nl[N_TCBTABLE].n_value;
inpcbtable_ptr = (struct inpcbtable *)nl[N_TCBTABLE].n_value;
} /* int conn_init */
static int conn_read(void) {
} /* int conn_init */
static int conn_read(void) {
/* Read the pcbtable from the kernel */
status = kread(inpcbtable_off, &table, sizeof(table));
if (status != 0)
/* Read the pcbtable from the kernel */
status = kread(inpcbtable_off, &table, sizeof(table));
if (status != 0)
#if defined(__OpenBSD__) || \
(defined(__NetBSD_Version__) && __NetBSD_Version__ > 699002700)
#if defined(__OpenBSD__) || \
(defined(__NetBSD_Version__) && __NetBSD_Version__ > 699002700)
/* Read the pcb pointed to by `next' into `inpcb' */
status = kread((u_long)next, &inpcb, sizeof(inpcb));
if (status != 0)
/* Read the pcb pointed to by `next' into `inpcb' */
status = kread((u_long)next, &inpcb, sizeof(inpcb));
if (status != 0)
/* Advance `next' */
#if defined(__OpenBSD__) || \
/* Advance `next' */
#if defined(__OpenBSD__) || \
status = kread((u_long)inpcb.inp_ppcb, &tcpcb, sizeof(tcpcb));
if (status != 0)
status = kread((u_long)inpcb.inp_ppcb, &tcpcb, sizeof(tcpcb));
if (status != 0)
conn_handle_ports(ntohs(inpcb.inp_lport), ntohs(inpcb.inp_fport),
tcpcb.t_state);
} /* while (next != head) */
conn_submit_all();
conn_handle_ports(ntohs(inpcb.inp_lport), ntohs(inpcb.inp_fport),
tcpcb.t_state);
} /* while (next != head) */
conn_submit_all();
}
/* #endif HAVE_LIBKVM_NLIST */
}
/* #endif HAVE_LIBKVM_NLIST */
size = netinfo(NETINFO_TCP, 0, 0, 0);
if (size < 0) {
ERROR("tcpconns plugin: netinfo failed return: %i", size);
size = netinfo(NETINFO_TCP, 0, 0, 0);
if (size < 0) {
ERROR("tcpconns plugin: netinfo failed return: %i", size);
if ((size - sizeof(struct netinfo_header)) % sizeof(struct netinfo_conn)) {
ERROR("tcpconns plugin: invalid buffer size");
if ((size - sizeof(struct netinfo_header)) % sizeof(struct netinfo_conn)) {
ERROR("tcpconns plugin: invalid buffer size");
}
data = malloc(size);
if (data == NULL) {
ERROR("tcpconns plugin: malloc failed");
}
data = malloc(size);
if (data == NULL) {
ERROR("tcpconns plugin: malloc failed");
}
if (netinfo(NETINFO_TCP, data, &size, 0) < 0) {
ERROR("tcpconns plugin: netinfo failed");
free(data);
}
if (netinfo(NETINFO_TCP, data, &size, 0) < 0) {
ERROR("tcpconns plugin: netinfo failed");
free(data);
}
header = (struct netinfo_header *)data;
}
header = (struct netinfo_header *)data;
}
#endif /* KERNEL_AIX */
}
#endif /* KERNEL_AIX */
/* Check port range */
if ((vserver_port <= 0) || (vserver_port > 65535)) {
ERROR("teamspeak2 plugin: VServer port is invalid: %i", vserver_port);
/* Check port range */
if ((vserver_port <= 0) || (vserver_port > 65535)) {
ERROR("teamspeak2 plugin: VServer port is invalid: %i", vserver_port);
}
/* Allocate memory */
entry = calloc(1, sizeof(*entry));
if (entry == NULL) {
ERROR("teamspeak2 plugin: calloc failed.");
}
/* Allocate memory */
entry = calloc(1, sizeof(*entry));
if (entry == NULL) {
ERROR("teamspeak2 plugin: calloc failed.");
INFO("teamspeak2 plugin: Registered new vserver: %i", vserver_port);
INFO("teamspeak2 plugin: Registered new vserver: %i", vserver_port);
} /* int tss2_add_vserver */
static void tss2_submit_gauge(const char *plugin_instance, const char *type,
} /* int tss2_add_vserver */
static void tss2_submit_gauge(const char *plugin_instance, const char *type,
*ret_read_fh = global_read_fh;
if (ret_write_fh != NULL)
*ret_write_fh = global_write_fh;
*ret_read_fh = global_read_fh;
if (ret_write_fh != NULL)
*ret_write_fh = global_write_fh;
}
/* Get all addrs for this hostname */
}
/* Get all addrs for this hostname */
&ai_hints, &ai_head);
if (status != 0) {
ERROR("teamspeak2 plugin: getaddrinfo failed: %s", gai_strerror(status));
&ai_hints, &ai_head);
if (status != 0) {
ERROR("teamspeak2 plugin: getaddrinfo failed: %s", gai_strerror(status));
}
/* Try all given hosts until we can connect to one */
}
/* Try all given hosts until we can connect to one */
/* Check if we really got connected */
if (sd < 0)
/* Check if we really got connected */
if (sd < 0)
/* Create file objects from sockets */
global_read_fh = fdopen(sd, "r");
/* Create file objects from sockets */
global_read_fh = fdopen(sd, "r");
ERROR("teamspeak2 plugin: fdopen failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sd);
ERROR("teamspeak2 plugin: fdopen failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sd);
}
global_write_fh = fdopen(sd, "w");
}
global_write_fh = fdopen(sd, "w");
ERROR("teamspeak2 plugin: fdopen failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
tss2_close_socket();
ERROR("teamspeak2 plugin: fdopen failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
tss2_close_socket();
}
{ /* Check that the server correctly identifies itself. */
}
{ /* Check that the server correctly identifies itself. */
"to server. Expected ``[TS]'', got ``%s''.",
buffer);
tss2_close_socket();
"to server. Expected ``[TS]'', got ``%s''.",
buffer);
tss2_close_socket();
}
DEBUG("teamspeak2 plugin: Server send correct banner, connected!");
}
}
DEBUG("teamspeak2 plugin: Server send correct banner, connected!");
}
*ret_read_fh = global_read_fh;
if (ret_write_fh != NULL)
*ret_write_fh = global_write_fh;
*ret_read_fh = global_read_fh;
if (ret_write_fh != NULL)
*ret_write_fh = global_write_fh;
} /* int tss2_get_socket */
static int tss2_send_request(FILE *fh, const char *request) {
} /* int tss2_get_socket */
static int tss2_send_request(FILE *fh, const char *request) {
if (status < 0) {
ERROR("teamspeak2 plugin: fputs failed.");
tss2_close_socket();
if (status < 0) {
ERROR("teamspeak2 plugin: fputs failed.");
tss2_close_socket();
} /* int tss2_send_request */
static int tss2_receive_line(FILE *fh, char *buffer, int buffer_size) {
} /* int tss2_send_request */
static int tss2_receive_line(FILE *fh, char *buffer, int buffer_size) {
ERROR("teamspeak2 plugin: fgets failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
tss2_close_socket();
ERROR("teamspeak2 plugin: fgets failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
tss2_close_socket();
}
buffer[buffer_size - 1] = 0;
}
buffer[buffer_size - 1] = 0;
} /* int tss2_receive_line */
static int tss2_select_vserver(FILE *read_fh, FILE *write_fh,
} /* int tss2_receive_line */
static int tss2_select_vserver(FILE *read_fh, FILE *write_fh,
status = tss2_send_request(write_fh, command);
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_send_request (%s) failed.", command);
status = tss2_send_request(write_fh, command);
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_send_request (%s) failed.", command);
}
/* Get answer */
status = tss2_receive_line(read_fh, response, sizeof(response));
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_receive_line failed.");
}
/* Get answer */
status = tss2_receive_line(read_fh, response, sizeof(response));
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_receive_line failed.");
}
response[sizeof(response) - 1] = 0;
/* Check answer */
if ((strncasecmp("OK", response, 2) == 0) &&
((response[2] == 0) || (response[2] == '\n') || (response[2] == '\r')))
}
response[sizeof(response) - 1] = 0;
/* Check answer */
if ((strncasecmp("OK", response, 2) == 0) &&
((response[2] == 0) || (response[2] == '\n') || (response[2] == '\r')))
ERROR("teamspeak2 plugin: Command ``%s'' failed. "
"Response received from server was: ``%s''.",
command, response);
ERROR("teamspeak2 plugin: Command ``%s'' failed. "
"Response received from server was: ``%s''.",
command, response);
} /* int tss2_select_vserver */
static int tss2_vserver_gapl(FILE *read_fh, FILE *write_fh,
} /* int tss2_select_vserver */
static int tss2_vserver_gapl(FILE *read_fh, FILE *write_fh,
status = tss2_send_request(write_fh, "gapl\r\n");
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_send_request (gapl) failed.");
status = tss2_send_request(write_fh, "gapl\r\n");
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_send_request (gapl) failed.");
read_fh = NULL;
write_fh = NULL;
ERROR("teamspeak2 plugin: tss2_receive_line failed.");
read_fh = NULL;
write_fh = NULL;
ERROR("teamspeak2 plugin: tss2_receive_line failed.");
}
buffer[sizeof(buffer) - 1] = 0;
}
buffer[sizeof(buffer) - 1] = 0;
break;
} else if (strncasecmp("ERROR", buffer, 5) == 0) {
ERROR("teamspeak2 plugin: Server returned an error: %s", buffer);
break;
} else if (strncasecmp("ERROR", buffer, 5) == 0) {
ERROR("teamspeak2 plugin: Server returned an error: %s", buffer);
} else {
WARNING("teamspeak2 plugin: Server returned unexpected string: %s",
buffer);
} else {
WARNING("teamspeak2 plugin: Server returned unexpected string: %s",
buffer);
}
*ret_value = packet_loss;
}
*ret_value = packet_loss;
} /* int tss2_vserver_gapl */
static int tss2_read_vserver(vserver_list_t *vserver) {
} /* int tss2_vserver_gapl */
static int tss2_read_vserver(vserver_list_t *vserver) {
status = tss2_get_socket(&read_fh, &write_fh);
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_get_socket failed.");
status = tss2_get_socket(&read_fh, &write_fh);
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_get_socket failed.");
/* Select the server */
status = tss2_select_vserver(read_fh, write_fh, vserver);
if (status != 0)
/* Select the server */
status = tss2_select_vserver(read_fh, write_fh, vserver);
if (status != 0)
status = tss2_send_request(write_fh, "si\r\n");
}
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_send_request failed.");
status = tss2_send_request(write_fh, "si\r\n");
}
if (status != 0) {
ERROR("teamspeak2 plugin: tss2_send_request failed.");
tss2_submit_gauge(plugin_instance, "gauge", "servers", servers);
if (valid == 0)
tss2_submit_gauge(plugin_instance, "gauge", "servers", servers);
if (valid == 0)
- return (-1);
- return (0);
} /* int tss2_read_vserver */
static int tss2_config(const char *key, const char *value) {
} /* int tss2_read_vserver */
static int tss2_config(const char *key, const char *value) {
temp = strdup(value);
if (temp == NULL) {
ERROR("teamspeak2 plugin: strdup failed.");
temp = strdup(value);
if (temp == NULL) {
ERROR("teamspeak2 plugin: strdup failed.");
}
sfree(config_host);
config_host = temp;
}
sfree(config_host);
config_host = temp;
temp = strdup(value);
if (temp == NULL) {
ERROR("teamspeak2 plugin: strdup failed.");
temp = strdup(value);
if (temp == NULL) {
ERROR("teamspeak2 plugin: strdup failed.");
}
sfree(config_port);
config_port = temp;
}
sfree(config_port);
config_port = temp;
status = tss2_add_vserver(atoi(value));
if (status != 0)
status = tss2_add_vserver(atoi(value));
if (status != 0)
} else {
/* Unknown variable found */
} else {
/* Unknown variable found */
- return (-1);
- return (0);
} /* int tss2_read */
static int tss2_shutdown(void) {
} /* int tss2_read */
static int tss2_shutdown(void) {
sfree(config_host);
sfree(config_port);
sfree(config_host);
sfree(config_port);
} /* int tss2_shutdown */
void module_register(void) {
} /* int tss2_shutdown */
void module_register(void) {
status = write(fd, pkt_request, sizeof(pkt_request));
if (status <= 0) {
ERROR("ted plugin: swrite failed.");
status = write(fd, pkt_request, sizeof(pkt_request));
if (status <= 0) {
ERROR("ted plugin: swrite failed.");
}
/* Loop until we find the end of the package */
}
/* Loop until we find the end of the package */
{
WARNING("ted plugin: Timeout while waiting for file descriptor "
"to become ready.");
{
WARNING("ted plugin: Timeout while waiting for file descriptor "
"to become ready.");
} else if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
/* Some signal or something. Start over.. */
continue;
} else if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR))) {
/* Some signal or something. Start over.. */
continue;
char errbuf[1024];
ERROR("ted plugin: select failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("ted plugin: select failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
receive_buffer_length = read(fd, receive_buffer, sizeof(receive_buffer));
}
receive_buffer_length = read(fd, receive_buffer, sizeof(receive_buffer));
continue;
ERROR("ted plugin: read(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
continue;
ERROR("ted plugin: read(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
} else if (receive_buffer_length == 0) {
/* Should we close the FD in this case? */
WARNING("ted plugin: Received EOF from file descriptor.");
} else if (receive_buffer_length == 0) {
/* Should we close the FD in this case? */
WARNING("ted plugin: Received EOF from file descriptor.");
} else if (((size_t)receive_buffer_length) > sizeof(receive_buffer)) {
ERROR("ted plugin: read(2) returned invalid value %zi.",
receive_buffer_length);
} else if (((size_t)receive_buffer_length) > sizeof(receive_buffer)) {
ERROR("ted plugin: read(2) returned invalid value %zi.",
receive_buffer_length);
/* Check for errors inside the loop. */
if ((end_flag == 0) || (package_buffer_pos != EXPECTED_PACKAGE_LENGTH))
/* Check for errors inside the loop. */
if ((end_flag == 0) || (package_buffer_pos != EXPECTED_PACKAGE_LENGTH))
/*
* Power is at positions 247 and 248 (LSB first) in [10kW].
/*
* Power is at positions 247 and 248 (LSB first) in [10kW].
((int)package_buffer[251]));
/* success */
((int)package_buffer[251]));
/* success */
} /* int ted_read_value */
static int ted_open_device(void) {
} /* int ted_read_value */
static int ted_open_device(void) {
struct termios options;
if (fd >= 0)
struct termios options;
if (fd >= 0)
dev = DEFAULT_DEVICE;
if (conf_device != NULL)
dev = DEFAULT_DEVICE;
if (conf_device != NULL)
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (fd < 0) {
ERROR("ted plugin: Unable to open device %s.", dev);
fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (fd < 0) {
ERROR("ted plugin: Unable to open device %s.", dev);
}
/* Get the current options for the port... */
}
/* Get the current options for the port... */
tcsetattr(fd, TCSANOW, &options);
INFO("ted plugin: Successfully opened %s.", dev);
tcsetattr(fd, TCSANOW, &options);
INFO("ted plugin: Successfully opened %s.", dev);
} /* int ted_open_device */
static void ted_submit(const char *type, double value) {
} /* int ted_open_device */
static void ted_submit(const char *type, double value) {
tmp = atoi(value);
if (tmp < 0) {
WARNING("ted plugin: Invalid retry count: %i", tmp);
tmp = atoi(value);
if (tmp < 0) {
WARNING("ted plugin: Invalid retry count: %i", tmp);
}
conf_retries = tmp;
} else {
ERROR("ted plugin: Unknown config option: %s", key);
}
conf_retries = tmp;
} else {
ERROR("ted plugin: Unknown config option: %s", key);
} /* int ted_config */
static int ted_read(void) {
} /* int ted_config */
static int ted_read(void) {
status = ted_open_device();
if (status != 0)
status = ted_open_device();
if (status != 0)
power = NAN;
voltage = NAN;
power = NAN;
voltage = NAN;
ted_submit("power", power);
ted_submit("voltage", voltage);
ted_submit("power", power);
ted_submit("voltage", voltage);
} /* int ted_read */
static int ted_shutdown(void) {
} /* int ted_read */
static int ted_shutdown(void) {
} /* int ted_shutdown */
void module_register(void) {
} /* int ted_shutdown */
void module_register(void) {
if (strcmp(expect, got__) != 0) { \
printf("not ok %i - %s = \"%s\", want \"%s\"\n", ++check_count__, \
#actual, got__, expect); \
if (strcmp(expect, got__) != 0) { \
printf("not ok %i - %s = \"%s\", want \"%s\"\n", ++check_count__, \
#actual, got__, expect); \
} \
printf("ok %i - %s = \"%s\"\n", ++check_count__, #actual, got__); \
} while (0)
} \
printf("ok %i - %s = \"%s\"\n", ++check_count__, #actual, got__); \
} while (0)
if (got__ != want__) { \
printf("not ok %i - %s = %d, want %d\n", ++check_count__, #actual, \
got__, want__); \
if (got__ != want__) { \
printf("not ok %i - %s = %d, want %d\n", ++check_count__, #actual, \
got__, want__); \
} \
printf("ok %i - %s = %d\n", ++check_count__, #actual, got__); \
} while (0)
} \
printf("ok %i - %s = %d\n", ++check_count__, #actual, got__); \
} while (0)
if (got__ != want__) { \
printf("not ok %i - %s = %" PRIu64 ", want %" PRIu64 "\n", \
++check_count__, #actual, got__, want__); \
if (got__ != want__) { \
printf("not ok %i - %s = %" PRIu64 ", want %" PRIu64 "\n", \
++check_count__, #actual, got__, want__); \
} \
printf("ok %i - %s = %" PRIu64 "\n", ++check_count__, #actual, got__); \
} while (0)
} \
printf("ok %i - %s = %" PRIu64 "\n", ++check_count__, #actual, got__); \
} while (0)
if (isnan(want__) && !isnan(got__)) { \
printf("not ok %i - %s = %.15g, want %.15g\n", ++check_count__, #actual, \
got__, want__); \
if (isnan(want__) && !isnan(got__)) { \
printf("not ok %i - %s = %.15g, want %.15g\n", ++check_count__, #actual, \
got__, want__); \
} else if (!isnan(want__) && (((want__ - got__) < -DBL_PRECISION) || \
((want__ - got__) > DBL_PRECISION))) { \
printf("not ok %i - %s = %.15g, want %.15g\n", ++check_count__, #actual, \
got__, want__); \
} else if (!isnan(want__) && (((want__ - got__) < -DBL_PRECISION) || \
((want__ - got__) > DBL_PRECISION))) { \
printf("not ok %i - %s = %.15g, want %.15g\n", ++check_count__, #actual, \
got__, want__); \
} \
printf("ok %i - %s = %.15g\n", ++check_count__, #actual, got__); \
} while (0)
} \
printf("ok %i - %s = %.15g\n", ++check_count__, #actual, got__); \
} while (0)
- return (success ? 0 : -1);
+ return success ? 0 : -1;
}
static int thermal_procfs_device_read(const char __attribute__((unused)) * dir,
}
static int thermal_procfs_device_read(const char __attribute__((unused)) * dir,
}
static int thermal_sysfs_read(void) {
}
static int thermal_sysfs_read(void) {
- return walk_directory(dirname_sysfs, thermal_sysfs_device_read,
- /* user_data = */ NULL, /* include hidden */ 0);
+ return walk_directory(dirname_sysfs, thermal_sysfs_device_read, NULL, 0);
}
static int thermal_procfs_read(void) {
}
static int thermal_procfs_read(void) {
- return walk_directory(dirname_procfs, thermal_procfs_device_read,
- /* user_data = */ NULL, /* include hidden */ 0);
+ return walk_directory(dirname_procfs, thermal_procfs_device_read, NULL, 0);
}
static int thermal_init(void) {
}
static int thermal_init(void) {
if (format_name(name, sizeof(name), th->host, th->plugin, th->plugin_instance,
th->type, th->type_instance) != 0) {
ERROR("ut_threshold_add: format_name failed.");
if (format_name(name, sizeof(name), th->host, th->plugin, th->plugin_instance,
th->type, th->type_instance) != 0) {
ERROR("ut_threshold_add: format_name failed.");
}
name_copy = strdup(name);
if (name_copy == NULL) {
ERROR("ut_threshold_add: strdup failed.");
}
name_copy = strdup(name);
if (name_copy == NULL) {
ERROR("ut_threshold_add: strdup failed.");
}
th_copy = malloc(sizeof(*th_copy));
if (th_copy == NULL) {
sfree(name_copy);
ERROR("ut_threshold_add: malloc failed.");
}
th_copy = malloc(sizeof(*th_copy));
if (th_copy == NULL) {
sfree(name_copy);
ERROR("ut_threshold_add: malloc failed.");
}
memcpy(th_copy, th, sizeof(threshold_t));
}
memcpy(th_copy, th, sizeof(threshold_t));
} /* }}} int ut_threshold_add */
/*
} /* }}} int ut_threshold_add */
/*
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `DataSource' option needs exactly one "
"string argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `DataSource' option needs exactly one "
"string argument.");
}
sstrncpy(th->data_source, ci->values[0].value.string,
sizeof(th->data_source));
}
sstrncpy(th->data_source, ci->values[0].value.string,
sizeof(th->data_source));
} /* int ut_config_type_datasource */
static int ut_config_type_instance(threshold_t *th, oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Instance' option needs exactly one "
"string argument.");
} /* int ut_config_type_datasource */
static int ut_config_type_instance(threshold_t *th, oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Instance' option needs exactly one "
"string argument.");
}
sstrncpy(th->type_instance, ci->values[0].value.string,
sizeof(th->type_instance));
}
sstrncpy(th->type_instance, ci->values[0].value.string,
sizeof(th->type_instance));
} /* int ut_config_type_instance */
static int ut_config_type_max(threshold_t *th, oconfig_item_t *ci) {
} /* int ut_config_type_instance */
static int ut_config_type_max(threshold_t *th, oconfig_item_t *ci) {
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
}
if (strcasecmp(ci->key, "WarningMax") == 0)
}
if (strcasecmp(ci->key, "WarningMax") == 0)
else
th->failure_max = ci->values[0].value.number;
else
th->failure_max = ci->values[0].value.number;
} /* int ut_config_type_max */
static int ut_config_type_min(threshold_t *th, oconfig_item_t *ci) {
} /* int ut_config_type_max */
static int ut_config_type_min(threshold_t *th, oconfig_item_t *ci) {
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
}
if (strcasecmp(ci->key, "WarningMin") == 0)
}
if (strcasecmp(ci->key, "WarningMin") == 0)
else
th->failure_min = ci->values[0].value.number;
else
th->failure_min = ci->values[0].value.number;
} /* int ut_config_type_min */
static int ut_config_type_hits(threshold_t *th, oconfig_item_t *ci) {
} /* int ut_config_type_min */
static int ut_config_type_hits(threshold_t *th, oconfig_item_t *ci) {
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
}
th->hits = ci->values[0].value.number;
}
th->hits = ci->values[0].value.number;
} /* int ut_config_type_hits */
static int ut_config_type_hysteresis(threshold_t *th, oconfig_item_t *ci) {
} /* int ut_config_type_hits */
static int ut_config_type_hysteresis(threshold_t *th, oconfig_item_t *ci) {
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
WARNING("threshold values: The `%s' option needs exactly one "
"number argument.",
ci->key);
}
th->hysteresis = ci->values[0].value.number;
}
th->hysteresis = ci->values[0].value.number;
} /* int ut_config_type_hysteresis */
static int ut_config_type(const threshold_t *th_orig, oconfig_item_t *ci) {
} /* int ut_config_type_hysteresis */
static int ut_config_type(const threshold_t *th_orig, oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Type' block needs exactly one string "
"argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Type' block needs exactly one string "
"argument.");
}
if (ci->children_num < 1) {
WARNING("threshold values: The `Type' block needs at least one option.");
}
if (ci->children_num < 1) {
WARNING("threshold values: The `Type' block needs at least one option.");
}
memcpy(&th, th_orig, sizeof(th));
}
memcpy(&th, th_orig, sizeof(th));
status = ut_threshold_add(&th);
}
status = ut_threshold_add(&th);
}
} /* int ut_config_type */
static int ut_config_plugin_instance(threshold_t *th, oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Instance' option needs exactly one "
"string argument.");
} /* int ut_config_type */
static int ut_config_plugin_instance(threshold_t *th, oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Instance' option needs exactly one "
"string argument.");
}
sstrncpy(th->plugin_instance, ci->values[0].value.string,
sizeof(th->plugin_instance));
}
sstrncpy(th->plugin_instance, ci->values[0].value.string,
sizeof(th->plugin_instance));
} /* int ut_config_plugin_instance */
static int ut_config_plugin(const threshold_t *th_orig, oconfig_item_t *ci) {
} /* int ut_config_plugin_instance */
static int ut_config_plugin(const threshold_t *th_orig, oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Plugin' block needs exactly one string "
"argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Plugin' block needs exactly one string "
"argument.");
}
if (ci->children_num < 1) {
WARNING("threshold values: The `Plugin' block needs at least one nested "
"block.");
}
if (ci->children_num < 1) {
WARNING("threshold values: The `Plugin' block needs at least one nested "
"block.");
}
memcpy(&th, th_orig, sizeof(th));
}
memcpy(&th, th_orig, sizeof(th));
} /* int ut_config_plugin */
static int ut_config_host(const threshold_t *th_orig, oconfig_item_t *ci) {
} /* int ut_config_plugin */
static int ut_config_host(const threshold_t *th_orig, oconfig_item_t *ci) {
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Host' block needs exactly one string "
"argument.");
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("threshold values: The `Host' block needs exactly one string "
"argument.");
}
if (ci->children_num < 1) {
WARNING("threshold values: The `Host' block needs at least one nested "
"block.");
}
if (ci->children_num < 1) {
WARNING("threshold values: The `Host' block needs at least one nested "
"block.");
}
memcpy(&th, th_orig, sizeof(th));
}
memcpy(&th, th_orig, sizeof(th));
} /* int ut_config_host */
/*
* End of the functions used to configure threshold values.
} /* int ut_config_host */
/*
* End of the functions used to configure threshold values.
DEBUG("ut_report_state: th->hits = %d, uc_get_hits = %d", th->hits,
uc_get_hits(ds, vl));
(void)uc_inc_hits(ds, vl, 1); /* increase hit counter */
DEBUG("ut_report_state: th->hits = %d, uc_get_hits = %d", th->hits,
uc_get_hits(ds, vl));
(void)uc_inc_hits(ds, vl, 1); /* increase hit counter */
* state is `okay', then only report if `persist_ok` flag is set. */
if (state == state_old) {
if ((th->flags & UT_FLAG_PERSIST) == 0)
* state is `okay', then only report if `persist_ok` flag is set. */
if (state == state_old) {
if ((th->flags & UT_FLAG_PERSIST) == 0)
else if ((state == STATE_OKAY) && ((th->flags & UT_FLAG_PERSIST_OK) == 0))
else if ((state == STATE_OKAY) && ((th->flags & UT_FLAG_PERSIST_OK) == 0))
}
if (state != state_old)
}
if (state != state_old)
plugin_dispatch_notification(&n);
plugin_notification_meta_free(n.meta);
plugin_dispatch_notification(&n);
plugin_notification_meta_free(n.meta);
} /* }}} int ut_report_state */
/*
} /* }}} int ut_report_state */
/*
if (ds != NULL) {
ds_name = ds->ds[ds_index].name;
if ((th->data_source[0] != 0) && (strcmp(ds_name, th->data_source) != 0))
if (ds != NULL) {
ds_name = ds->ds[ds_index].name;
if ((th->data_source[0] != 0) && (strcmp(ds_name, th->data_source) != 0))
}
if ((th->flags & UT_FLAG_INVERT) != 0) {
}
if ((th->flags & UT_FLAG_INVERT) != 0) {
- return (STATE_WARNING);
} /* }}} int ut_check_one_data_source */
/*
} /* }}} int ut_check_one_data_source */
/*
if (ret_ds_index != NULL)
*ret_ds_index = ds_index;
if (ret_ds_index != NULL)
*ret_ds_index = ds_index;
} /* }}} int ut_check_one_threshold */
/*
} /* }}} int ut_check_one_threshold */
/*
int worst_ds_index = -1;
if (threshold_tree == NULL)
int worst_ds_index = -1;
if (threshold_tree == NULL)
/* Is this lock really necessary? So far, thresholds are only inserted at
* startup. -octo */
/* Is this lock really necessary? So far, thresholds are only inserted at
* startup. -octo */
th = threshold_search(vl);
pthread_mutex_unlock(&threshold_lock);
if (th == NULL)
th = threshold_search(vl);
pthread_mutex_unlock(&threshold_lock);
if (th == NULL)
DEBUG("ut_check_threshold: Found matching threshold(s)");
values = uc_get_rate(ds, vl);
if (values == NULL)
DEBUG("ut_check_threshold: Found matching threshold(s)");
values = uc_get_rate(ds, vl);
if (values == NULL)
while (th != NULL) {
int ds_index = -1;
while (th != NULL) {
int ds_index = -1;
if (status < 0) {
ERROR("ut_check_threshold: ut_check_one_threshold failed.");
sfree(values);
if (status < 0) {
ERROR("ut_check_threshold: ut_check_one_threshold failed.");
sfree(values);
}
if (worst_state < status) {
}
if (worst_state < status) {
if (status != 0) {
ERROR("ut_check_threshold: ut_report_state failed.");
sfree(values);
if (status != 0) {
ERROR("ut_check_threshold: ut_report_state failed.");
sfree(values);
} /* }}} int ut_check_threshold */
/*
} /* }}} int ut_check_threshold */
/*
cdtime_t now;
if (threshold_tree == NULL)
cdtime_t now;
if (threshold_tree == NULL)
th = threshold_search(vl);
/* dispatch notifications for "interesting" values only */
if ((th == NULL) || ((th->flags & UT_FLAG_INTERESTING) == 0))
th = threshold_search(vl);
/* dispatch notifications for "interesting" values only */
if ((th == NULL) || ((th->flags & UT_FLAG_INTERESTING) == 0))
now = cdtime();
missing_time = now - vl->time;
now = cdtime();
missing_time = now - vl->time;
plugin_dispatch_notification(&n);
plugin_dispatch_notification(&n);
} /* }}} int ut_missing */
static int ut_config(oconfig_item_t *ci) { /* {{{ */
} /* }}} int ut_missing */
static int ut_config(oconfig_item_t *ci) { /* {{{ */
threshold_tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (threshold_tree == NULL) {
ERROR("ut_config: c_avl_create failed.");
threshold_tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (threshold_tree == NULL) {
ERROR("ut_config: c_avl_create failed.");
/* user data = */ NULL);
}
/* user data = */ NULL);
}
} /* }}} int um_config */
void module_register(void) {
} /* }}} int um_config */
void module_register(void) {
temp = strdup(value);
if (temp == NULL) {
ERROR("tokyotyrant plugin: Host strdup failed.");
temp = strdup(value);
if (temp == NULL) {
ERROR("tokyotyrant plugin: Host strdup failed.");
}
sfree(config_host);
config_host = temp;
}
sfree(config_host);
config_host = temp;
temp = strdup(value);
if (temp == NULL) {
ERROR("tokyotyrant plugin: Port strdup failed.");
temp = strdup(value);
if (temp == NULL) {
ERROR("tokyotyrant plugin: Port strdup failed.");
}
sfree(config_port);
config_port = temp;
} else {
ERROR("tokyotyrant plugin: error: unrecognized configuration key %s", key);
}
sfree(config_port);
config_port = temp;
} else {
ERROR("tokyotyrant plugin: error: unrecognized configuration key %s", key);
}
static void printerr(void) {
}
static void printerr(void) {
tt_open_db();
if (rdb == NULL)
tt_open_db();
if (rdb == NULL)
rnum = tcrdbrnum(rdb);
tt_submit(rnum, "records");
rnum = tcrdbrnum(rdb);
tt_submit(rnum, "records");
size = tcrdbsize(rdb);
tt_submit(size, "file_size");
size = tcrdbsize(rdb);
tt_submit(size, "file_size");
}
static int tt_shutdown(void) {
}
static int tt_shutdown(void) {
if (!tcrdbclose(rdb)) {
printerr();
tcrdbdel(rdb);
if (!tcrdbclose(rdb)) {
printerr();
tcrdbdel(rdb);
}
tcrdbdel(rdb);
rdb = NULL;
}
}
tcrdbdel(rdb);
rdb = NULL;
}
}
void module_register(void) {
}
void module_register(void) {
retval = func(cpu_num);
if (retval) {
fclose(fp);
retval = func(cpu_num);
if (retval) {
fclose(fp);
char errbuf[1024];
ERROR("unixsock plugin: socket failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("unixsock plugin: socket failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
sa.sun_family = AF_UNIX;
}
sa.sun_family = AF_UNIX;
ERROR("unixsock plugin: bind failed: %s", errbuf);
close(sock_fd);
sock_fd = -1;
ERROR("unixsock plugin: bind failed: %s", errbuf);
close(sock_fd);
sock_fd = -1;
}
status = chmod(sa.sun_path, sock_perms);
}
status = chmod(sa.sun_path, sock_perms);
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sock_fd);
sock_fd = -1;
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sock_fd);
sock_fd = -1;
}
status = listen(sock_fd, 8);
}
status = listen(sock_fd, 8);
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sock_fd);
sock_fd = -1;
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sock_fd);
sock_fd = -1;
} /* int us_open_socket */
static void *us_handle_client(void *arg) {
} /* int us_open_socket */
static void *us_handle_client(void *arg) {
close(fdin);
close(fdout);
pthread_exit((void *)1);
close(fdin);
close(fdout);
pthread_exit((void *)1);
}
fhout = fdopen(fdout, "w");
}
fhout = fdopen(fdout, "w");
fclose(fhin); /* this closes fdin as well */
close(fdout);
pthread_exit((void *)1);
fclose(fhin); /* this closes fdin as well */
close(fdout);
pthread_exit((void *)1);
}
/* change output buffer to line buffered mode */
}
/* change output buffer to line buffered mode */
fclose(fhin);
fclose(fhout);
pthread_exit((void *)1);
fclose(fhin);
fclose(fhout);
pthread_exit((void *)1);
fclose(fhin);
fclose(fhout);
pthread_exit((void *)1);
fclose(fhin);
fclose(fhout);
pthread_exit((void *)1);
}
if (strcasecmp(fields[0], "getval") == 0) {
}
if (strcasecmp(fields[0], "getval") == 0) {
fclose(fhout);
pthread_exit((void *)0);
fclose(fhout);
pthread_exit((void *)0);
} /* void *us_handle_client */
static void *us_server_thread(void __attribute__((unused)) * arg) {
} /* void *us_handle_client */
static void *us_server_thread(void __attribute__((unused)) * arg) {
sstrerror(errno, errbuf, sizeof(errbuf)));
}
sstrerror(errno, errbuf, sizeof(errbuf)));
}
} /* void *us_server_thread */
static int us_config(const char *key, const char *val) {
if (strcasecmp(key, "SocketFile") == 0) {
char *new_sock_file = strdup(val);
if (new_sock_file == NULL)
} /* void *us_server_thread */
static int us_config(const char *key, const char *val) {
if (strcasecmp(key, "SocketFile") == 0) {
char *new_sock_file = strdup(val);
if (new_sock_file == NULL)
sfree(sock_file);
sock_file = new_sock_file;
} else if (strcasecmp(key, "SocketGroup") == 0) {
char *new_sock_group = strdup(val);
if (new_sock_group == NULL)
sfree(sock_file);
sock_file = new_sock_file;
} else if (strcasecmp(key, "SocketGroup") == 0) {
char *new_sock_group = strdup(val);
if (new_sock_group == NULL)
sfree(sock_group);
sock_group = new_sock_group;
sfree(sock_group);
sock_group = new_sock_group;
else
delete_socket = 0;
} else {
else
delete_socket = 0;
} else {
} /* int us_config */
static int us_init(void) {
} /* int us_config */
static int us_init(void) {
/* Initialize only once. */
if (have_init != 0)
/* Initialize only once. */
if (have_init != 0)
char errbuf[1024];
ERROR("unixsock plugin: pthread_create failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("unixsock plugin: pthread_create failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
} /* int us_init */
static int us_shutdown(void) {
} /* int us_init */
static int us_shutdown(void) {
plugin_unregister_init("unixsock");
plugin_unregister_shutdown("unixsock");
plugin_unregister_init("unixsock");
plugin_unregister_shutdown("unixsock");
} /* int us_shutdown */
void module_register(void) {
} /* int us_shutdown */
void module_register(void) {
char errbuf[1024];
ERROR("uptime plugin: Cannot open " STAT_FILE ": %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("uptime plugin: Cannot open " STAT_FILE ": %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, 1024, fh) != NULL) {
}
while (fgets(buffer, 1024, fh) != NULL) {
/* loop done, check if no value has been found/read */
if (ret != 1) {
ERROR("uptime plugin: No value read from " STAT_FILE "");
/* loop done, check if no value has been found/read */
if (ret != 1) {
ERROR("uptime plugin: No value read from " STAT_FILE "");
}
boottime = (time_t)starttime;
}
boottime = (time_t)starttime;
if (boottime == 0) {
ERROR("uptime plugin: btime read from " STAT_FILE ", "
"but `boottime' is zero!");
if (boottime == 0) {
ERROR("uptime plugin: btime read from " STAT_FILE ", "
"but `boottime' is zero!");
}
/* #endif KERNEL_LINUX */
}
/* #endif KERNEL_LINUX */
* went fine. */
if (kc == NULL) {
ERROR("uptime plugin: kstat chain control structure not available.");
* went fine. */
if (kc == NULL) {
ERROR("uptime plugin: kstat chain control structure not available.");
}
ksp = kstat_lookup(kc, "unix", 0, "system_misc");
if (ksp == NULL) {
ERROR("uptime plugin: Cannot find unix:0:system_misc kstat.");
}
ksp = kstat_lookup(kc, "unix", 0, "system_misc");
if (ksp == NULL) {
ERROR("uptime plugin: Cannot find unix:0:system_misc kstat.");
}
if (kstat_read(kc, ksp, NULL) < 0) {
ERROR("uptime plugin: kstat_read failed.");
}
if (kstat_read(kc, ksp, NULL) < 0) {
ERROR("uptime plugin: kstat_read failed.");
}
knp = (kstat_named_t *)kstat_data_lookup(ksp, "boot_time");
if (knp == NULL) {
ERROR("uptime plugin: kstat_data_lookup (boot_time) failed.");
}
knp = (kstat_named_t *)kstat_data_lookup(ksp, "boot_time");
if (knp == NULL) {
ERROR("uptime plugin: kstat_data_lookup (boot_time) failed.");
}
boottime = (time_t)knp->value.ui32;
}
boottime = (time_t)knp->value.ui32;
if (boottime == 0) {
ERROR("uptime plugin: kstat_data_lookup returned success, "
"but `boottime' is zero!");
if (boottime == 0) {
ERROR("uptime plugin: kstat_data_lookup returned success, "
"but `boottime' is zero!");
}
/* #endif HAVE_LIBKSTAT */
}
/* #endif HAVE_LIBKSTAT */
char errbuf[1024];
ERROR("uptime plugin: No value read from sysctl interface: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("uptime plugin: No value read from sysctl interface: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
boottime = boottv.tv_sec;
}
boottime = boottv.tv_sec;
if (boottime == 0) {
ERROR("uptime plugin: sysctl(3) returned success, "
"but `boottime' is zero!");
if (boottime == 0) {
ERROR("uptime plugin: sysctl(3) returned success, "
"but `boottime' is zero!");
}
/* #endif HAVE_SYS_SYSCTL_H */
}
/* #endif HAVE_SYS_SYSCTL_H */
char errbuf[1024];
ERROR("uptime plugin: perfstat_cpu_total: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("uptime plugin: perfstat_cpu_total: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
hertz = sysconf(_SC_CLK_TCK);
}
hertz = sysconf(_SC_CLK_TCK);
boottime = time(NULL) - cputotal.lbolt / hertz;
#endif /* HAVE_PERFSTAT */
boottime = time(NULL) - cputotal.lbolt / hertz;
#endif /* HAVE_PERFSTAT */
} /* }}} int uptime_init */
static int uptime_read(void) {
} /* }}} int uptime_init */
static int uptime_read(void) {
}
void module_register(void) {
}
void module_register(void) {
us = sg_get_user_stats();
#endif
if (us == NULL)
us = sg_get_user_stats();
#endif
if (us == NULL)
users_submit((gauge_t)
#if HAVE_LIBSTATGRAB_0_90
users_submit((gauge_t)
#if HAVE_LIBSTATGRAB_0_90
#error "No applicable input method."
#endif
#error "No applicable input method."
#endif
} /* int users_read */
void module_register(void) {
} /* int users_read */
void module_register(void) {
if ((ret_flush == NULL) || (opts == NULL)) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid arguments to cmd_parse_flush.");
if ((ret_flush == NULL) || (opts == NULL)) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid arguments to cmd_parse_flush.");
}
for (size_t i = 0; i < argc; i++) {
}
for (size_t i = 0; i < argc; i++) {
if (status == CMD_NO_OPTION)
cmd_error(CMD_PARSE_ERROR, err, "Invalid option string `%s'.", argv[i]);
cmd_destroy_flush(ret_flush);
if (status == CMD_NO_OPTION)
cmd_error(CMD_PARSE_ERROR, err, "Invalid option string `%s'.", argv[i]);
cmd_destroy_flush(ret_flush);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
}
if (strcasecmp("plugin", opt_key) == 0) {
}
if (strcasecmp("plugin", opt_key) == 0) {
if (id == NULL) {
cmd_error(CMD_ERROR, err, "realloc failed.");
cmd_destroy_flush(ret_flush);
if (id == NULL) {
cmd_error(CMD_ERROR, err, "realloc failed.");
cmd_destroy_flush(ret_flush);
}
ret_flush->identifiers = id;
}
ret_flush->identifiers = id;
opts->identifier_default_host) != 0) {
cmd_error(CMD_PARSE_ERROR, err, "Invalid identifier `%s'.", opt_value);
cmd_destroy_flush(ret_flush);
opts->identifier_default_host) != 0) {
cmd_error(CMD_PARSE_ERROR, err, "Invalid identifier `%s'.", opt_value);
cmd_destroy_flush(ret_flush);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
}
} else if (strcasecmp("timeout", opt_key) == 0) {
char *endptr;
}
} else if (strcasecmp("timeout", opt_key) == 0) {
char *endptr;
cmd_error(CMD_PARSE_ERROR, err,
"Invalid value for option `timeout': %s", opt_value);
cmd_destroy_flush(ret_flush);
cmd_error(CMD_PARSE_ERROR, err,
"Invalid value for option `timeout': %s", opt_value);
cmd_destroy_flush(ret_flush);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
} else if (ret_flush->timeout < 0.0) {
ret_flush->timeout = 0.0;
}
} else {
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse option `%s'.", opt_key);
cmd_destroy_flush(ret_flush);
} else if (ret_flush->timeout < 0.0) {
ret_flush->timeout = 0.0;
}
} else {
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse option `%s'.", opt_key);
cmd_destroy_flush(ret_flush);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
} /* cmd_status_t cmd_parse_flush */
cmd_status_t cmd_handle_flush(FILE *fh, char *buffer) {
} /* cmd_status_t cmd_parse_flush */
cmd_status_t cmd_handle_flush(FILE *fh, char *buffer) {
int status;
if ((fh == NULL) || (buffer == NULL))
int status;
if ((fh == NULL) || (buffer == NULL))
DEBUG("utils_cmd_flush: cmd_handle_flush (fh = %p, buffer = %s);", (void *)fh,
buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
DEBUG("utils_cmd_flush: cmd_handle_flush (fh = %p, buffer = %s);", (void *)fh,
buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
if (cmd.type != CMD_FLUSH) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
cmd_destroy(&cmd);
if (cmd.type != CMD_FLUSH) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
cmd_destroy(&cmd);
- return (CMD_UNKNOWN_COMMAND);
+ return CMD_UNKNOWN_COMMAND;
}
for (size_t i = 0; (i == 0) || (i < cmd.cmd.flush.plugins_num); i++) {
}
for (size_t i = 0; (i == 0) || (i < cmd.cmd.flush.plugins_num); i++) {
cmd_error(CMD_OK, &err, "Done: %i successful, %i errors", success, error);
cmd_destroy(&cmd);
cmd_error(CMD_OK, &err, "Done: %i successful, %i errors", success, error);
cmd_destroy(&cmd);
#undef PRINT_TO_SOCK
} /* cmd_status_t cmd_handle_flush */
#undef PRINT_TO_SOCK
} /* cmd_status_t cmd_handle_flush */
size_t i;
if ((fh == NULL) || (buffer == NULL))
size_t i;
if ((fh == NULL) || (buffer == NULL))
DEBUG("utils_cmd_getthreshold: handle_getthreshold (fh = %p, buffer = %s);",
(void *)fh, buffer);
DEBUG("utils_cmd_getthreshold: handle_getthreshold (fh = %p, buffer = %s);",
(void *)fh, buffer);
status = parse_string(&buffer, &command);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse command.\n");
status = parse_string(&buffer, &command);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse command.\n");
}
assert(command != NULL);
if (strcasecmp("GETTHRESHOLD", command) != 0) {
print_to_socket(fh, "-1 Unexpected command: `%s'.\n", command);
}
assert(command != NULL);
if (strcasecmp("GETTHRESHOLD", command) != 0) {
print_to_socket(fh, "-1 Unexpected command: `%s'.\n", command);
}
identifier = NULL;
status = parse_string(&buffer, &identifier);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse identifier.\n");
}
identifier = NULL;
status = parse_string(&buffer, &identifier);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse identifier.\n");
}
assert(identifier != NULL);
if (*buffer != 0) {
print_to_socket(fh, "-1 Garbage after end of command: %s\n", buffer);
}
assert(identifier != NULL);
if (*buffer != 0) {
print_to_socket(fh, "-1 Garbage after end of command: %s\n", buffer);
}
/* parse_identifier() modifies its first argument,
}
/* parse_identifier() modifies its first argument,
DEBUG("handle_getthreshold: Cannot parse identifier `%s'.", identifier);
print_to_socket(fh, "-1 Cannot parse identifier `%s'.\n", identifier);
sfree(identifier_copy);
DEBUG("handle_getthreshold: Cannot parse identifier `%s'.", identifier);
print_to_socket(fh, "-1 Cannot parse identifier `%s'.\n", identifier);
sfree(identifier_copy);
}
value_list_t vl = {.values = NULL};
}
value_list_t vl = {.values = NULL};
if (status == ENOENT) {
print_to_socket(fh, "-1 No threshold found for identifier %s\n",
identifier);
if (status == ENOENT) {
print_to_socket(fh, "-1 No threshold found for identifier %s\n",
identifier);
} else if (status != 0) {
print_to_socket(fh, "-1 Error while looking up threshold: %i\n", status);
} else if (status != 0) {
print_to_socket(fh, "-1 Error while looking up threshold: %i\n", status);
}
/* Lets count the number of lines we'll return. */
}
/* Lets count the number of lines we'll return. */
if (threshold.hits > 1)
print_to_socket(fh, "Hits: %i\n", threshold.hits);
if (threshold.hits > 1)
print_to_socket(fh, "Hits: %i\n", threshold.hits);
} /* int handle_getthreshold */
} /* int handle_getthreshold */
if ((ret_getval == NULL) || (opts == NULL)) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid arguments to cmd_parse_getval.");
if ((ret_getval == NULL) || (opts == NULL)) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid arguments to cmd_parse_getval.");
else
cmd_error(CMD_PARSE_ERROR, err, "Garbage after identifier: `%s'.",
argv[1]);
else
cmd_error(CMD_PARSE_ERROR, err, "Garbage after identifier: `%s'.",
argv[1]);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
}
/* parse_identifier() modifies its first argument,
}
/* parse_identifier() modifies its first argument,
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse identifier `%s'.",
identifier_copy);
sfree(identifier_copy);
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse identifier `%s'.",
identifier_copy);
sfree(identifier_copy);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
}
ret_getval->raw_identifier = identifier_copy;
}
ret_getval->raw_identifier = identifier_copy;
} /* cmd_status_t cmd_parse_getval */
#define print_to_socket(fh, ...) \
} /* cmd_status_t cmd_parse_getval */
#define print_to_socket(fh, ...) \
const data_set_t *ds;
if ((fh == NULL) || (buffer == NULL))
const data_set_t *ds;
if ((fh == NULL) || (buffer == NULL))
DEBUG("utils_cmd_getval: cmd_handle_getval (fh = %p, buffer = %s);",
(void *)fh, buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
DEBUG("utils_cmd_getval: cmd_handle_getval (fh = %p, buffer = %s);",
(void *)fh, buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
if (cmd.type != CMD_GETVAL) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
cmd_destroy(&cmd);
if (cmd.type != CMD_GETVAL) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
cmd_destroy(&cmd);
- return (CMD_UNKNOWN_COMMAND);
+ return CMD_UNKNOWN_COMMAND;
}
ds = plugin_get_ds(cmd.cmd.getval.identifier.type);
}
ds = plugin_get_ds(cmd.cmd.getval.identifier.type);
cmd_error(CMD_ERROR, &err, "Type `%s' is unknown.\n",
cmd.cmd.getval.identifier.type);
cmd_destroy(&cmd);
cmd_error(CMD_ERROR, &err, "Type `%s' is unknown.\n",
cmd.cmd.getval.identifier.type);
cmd_destroy(&cmd);
if (status != 0) {
cmd_error(CMD_ERROR, &err, "No such value.");
cmd_destroy(&cmd);
if (status != 0) {
cmd_error(CMD_ERROR, &err, "No such value.");
cmd_destroy(&cmd);
}
if (ds->ds_num != values_num) {
}
if (ds->ds_num != values_num) {
cmd_error(CMD_ERROR, &err, "Error reading value from cache.");
sfree(values);
cmd_destroy(&cmd);
cmd_error(CMD_ERROR, &err, "Error reading value from cache.");
sfree(values);
cmd_destroy(&cmd);
}
print_to_socket(fh, "%zu Value%s found\n", values_num,
}
print_to_socket(fh, "%zu Value%s found\n", values_num,
sfree(values);
cmd_destroy(&cmd);
sfree(values);
cmd_destroy(&cmd);
} /* cmd_status_t cmd_handle_getval */
void cmd_destroy_getval(cmd_getval_t *getval) {
} /* cmd_status_t cmd_handle_getval */
void cmd_destroy_getval(cmd_getval_t *getval) {
if (argc != 0) {
cmd_error(CMD_PARSE_ERROR, err, "Garbage after end of command: `%s'.",
argv[0]);
if (argc != 0) {
cmd_error(CMD_PARSE_ERROR, err, "Garbage after end of command: `%s'.",
argv[0]);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
} /* cmd_status_t cmd_parse_listval */
#define free_everything_and_return(status) \
} /* cmd_status_t cmd_parse_listval */
#define free_everything_and_return(status) \
} \
sfree(names); \
sfree(times); \
} \
sfree(names); \
sfree(times); \
} while (0)
#define print_to_socket(fh, ...) \
} while (0)
#define print_to_socket(fh, ...) \
buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
if (cmd.type != CMD_LISTVAL) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
if (cmd.type != CMD_LISTVAL) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
else if (strcasecmp(value, "Okay") == 0)
n->severity = NOTIF_OKAY;
else
else if (strcasecmp(value, "Okay") == 0)
n->severity = NOTIF_OKAY;
else
} /* int set_option_severity */
static int set_option_time(notification_t *n, const char *value) {
} /* int set_option_severity */
static int set_option_time(notification_t *n, const char *value) {
|| (endptr == value) /* Invalid string */
|| (endptr == NULL) /* This should not happen */
|| (*endptr != 0)) /* Trailing chars */
|| (endptr == value) /* Invalid string */
|| (endptr == NULL) /* This should not happen */
|| (*endptr != 0)) /* Trailing chars */
n->time = DOUBLE_TO_CDTIME_T(tmp);
n->time = DOUBLE_TO_CDTIME_T(tmp);
} /* int set_option_time */
static int set_option(notification_t *n, const char *option,
const char *value) {
if ((n == NULL) || (option == NULL) || (value == NULL))
} /* int set_option_time */
static int set_option(notification_t *n, const char *option,
const char *value) {
if ((n == NULL) || (option == NULL) || (value == NULL))
DEBUG("utils_cmd_putnotif: set_option (option = %s, value = %s);", option,
value);
DEBUG("utils_cmd_putnotif: set_option (option = %s, value = %s);", option,
value);
if (option[0] != '\0' && option[1] == ':') {
/* Refuse empty key */
if (option[2] == '\0')
if (option[0] != '\0' && option[1] == ':') {
/* Refuse empty key */
if (option[2] == '\0')
if (option[0] == 's')
return plugin_notification_meta_add_string(n, option + 2, value);
else
if (option[0] == 's')
return plugin_notification_meta_add_string(n, option + 2, value);
else
}
if (strcasecmp("severity", option) == 0)
}
if (strcasecmp("severity", option) == 0)
- return (set_option_severity(n, value));
+ return set_option_severity(n, value);
else if (strcasecmp("time", option) == 0)
else if (strcasecmp("time", option) == 0)
- return (set_option_time(n, value));
+ return set_option_time(n, value);
else if (strcasecmp("message", option) == 0)
sstrncpy(n->message, value, sizeof(n->message));
else if (strcasecmp("host", option) == 0)
else if (strcasecmp("message", option) == 0)
sstrncpy(n->message, value, sizeof(n->message));
else if (strcasecmp("host", option) == 0)
else if (strcasecmp("type_instance", option) == 0)
sstrncpy(n->type_instance, value, sizeof(n->type_instance));
else
else if (strcasecmp("type_instance", option) == 0)
sstrncpy(n->type_instance, value, sizeof(n->type_instance));
else
} /* int set_option */
int handle_putnotif(FILE *fh, char *buffer) {
} /* int set_option */
int handle_putnotif(FILE *fh, char *buffer) {
int status;
if ((fh == NULL) || (buffer == NULL))
int status;
if ((fh == NULL) || (buffer == NULL))
DEBUG("utils_cmd_putnotif: handle_putnotif (fh = %p, buffer = %s);",
(void *)fh, buffer);
DEBUG("utils_cmd_putnotif: handle_putnotif (fh = %p, buffer = %s);",
(void *)fh, buffer);
status = parse_string(&buffer, &command);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse command.\n");
status = parse_string(&buffer, &command);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse command.\n");
}
assert(command != NULL);
if (strcasecmp("PUTNOTIF", command) != 0) {
print_to_socket(fh, "-1 Unexpected command: `%s'.\n", command);
}
assert(command != NULL);
if (strcasecmp("PUTNOTIF", command) != 0) {
print_to_socket(fh, "-1 Unexpected command: `%s'.\n", command);
print_to_socket(fh, "0 Success\n");
}
print_to_socket(fh, "0 Success\n");
}
} /* int handle_putnotif */
} /* int handle_putnotif */
static int set_option(value_list_t *vl, const char *key, const char *value) {
if ((vl == NULL) || (key == NULL) || (value == NULL))
static int set_option(value_list_t *vl, const char *key, const char *value) {
if ((vl == NULL) || (key == NULL) || (value == NULL))
if (strcasecmp("interval", key) == 0) {
double tmp;
if (strcasecmp("interval", key) == 0) {
double tmp;
if ((errno == 0) && (endptr != NULL) && (endptr != value) && (tmp > 0.0))
vl->interval = DOUBLE_TO_CDTIME_T(tmp);
} else
if ((errno == 0) && (endptr != NULL) && (endptr != value) && (tmp > 0.0))
vl->interval = DOUBLE_TO_CDTIME_T(tmp);
} else
} /* int set_option */
/*
} /* int set_option */
/*
if ((ret_putval == NULL) || (opts == NULL)) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid arguments to cmd_parse_putval.");
if ((ret_putval == NULL) || (opts == NULL)) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid arguments to cmd_parse_putval.");
}
if (argc < 2) {
cmd_error(CMD_PARSE_ERROR, err, "Missing identifier and/or value-list.");
}
if (argc < 2) {
cmd_error(CMD_PARSE_ERROR, err, "Missing identifier and/or value-list.");
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse identifier `%s'.",
identifier_copy);
sfree(identifier_copy);
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse identifier `%s'.",
identifier_copy);
sfree(identifier_copy);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
}
if ((strlen(hostname) >= sizeof(vl.host)) ||
}
if ((strlen(hostname) >= sizeof(vl.host)) ||
(strlen(type_instance) >= sizeof(vl.type_instance)))) {
cmd_error(CMD_PARSE_ERROR, err, "Identifier too long.");
sfree(identifier_copy);
(strlen(type_instance) >= sizeof(vl.type_instance)))) {
cmd_error(CMD_PARSE_ERROR, err, "Identifier too long.");
sfree(identifier_copy);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
}
sstrncpy(vl.host, hostname, sizeof(vl.host));
}
sstrncpy(vl.host, hostname, sizeof(vl.host));
if (ds == NULL) {
cmd_error(CMD_PARSE_ERROR, err, "1 Type `%s' isn't defined.", type);
sfree(identifier_copy);
if (ds == NULL) {
cmd_error(CMD_PARSE_ERROR, err, "1 Type `%s' isn't defined.", type);
sfree(identifier_copy);
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
cmd_error(CMD_ERROR, err, "malloc failed.");
cmd_destroy_putval(ret_putval);
sfree(vl.values);
cmd_error(CMD_ERROR, err, "malloc failed.");
cmd_destroy_putval(ret_putval);
sfree(vl.values);
}
/* All the remaining fields are part of the option list. */
}
/* All the remaining fields are part of the option list. */
if (result != CMD_OK)
cmd_destroy_putval(ret_putval);
if (result != CMD_OK)
cmd_destroy_putval(ret_putval);
} /* cmd_status_t cmd_parse_putval */
void cmd_destroy_putval(cmd_putval_t *putval) {
} /* cmd_status_t cmd_parse_putval */
void cmd_destroy_putval(cmd_putval_t *putval) {
(void *)fh, buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
(void *)fh, buffer);
if ((status = cmd_parse(buffer, &cmd, NULL, &err)) != CMD_OK)
if (cmd.type != CMD_PUTVAL) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
cmd_destroy(&cmd);
if (cmd.type != CMD_PUTVAL) {
cmd_error(CMD_UNKNOWN_COMMAND, &err, "Unexpected command: `%s'.",
CMD_TO_STRING(cmd.type));
cmd_destroy(&cmd);
- return (CMD_UNKNOWN_COMMAND);
+ return CMD_UNKNOWN_COMMAND;
}
for (size_t i = 0; i < cmd.cmd.putval.vl_num; ++i)
}
for (size_t i = 0; i < cmd.cmd.putval.vl_num; ++i)
(cmd.cmd.putval.vl_num == 1) ? "value has" : "values have");
cmd_destroy(&cmd);
(cmd.cmd.putval.vl_num == 1) ? "value has" : "values have");
cmd_destroy(&cmd);
} /* int cmd_handle_putval */
int cmd_create_putval(char *ret, size_t ret_len, /* {{{ */
} /* int cmd_handle_putval */
int cmd_create_putval(char *ret, size_t ret_len, /* {{{ */
status = FORMAT_VL(buffer_ident, sizeof(buffer_ident), vl);
if (status != 0)
status = FORMAT_VL(buffer_ident, sizeof(buffer_ident), vl);
if (status != 0)
escape_string(buffer_ident, sizeof(buffer_ident));
status = format_values(buffer_values, sizeof(buffer_values), ds, vl,
/* store rates = */ 0);
if (status != 0)
escape_string(buffer_ident, sizeof(buffer_ident));
status = format_values(buffer_values, sizeof(buffer_values), ds, vl,
/* store rates = */ 0);
if (status != 0)
escape_string(buffer_values, sizeof(buffer_values));
ssnprintf(ret, ret_len, "PUTVAL %s interval=%.3f %s", buffer_ident,
escape_string(buffer_values, sizeof(buffer_values));
ssnprintf(ret, ret_len, "PUTVAL %s interval=%.3f %s", buffer_ident,
: CDTIME_T_TO_DOUBLE(plugin_get_interval()),
buffer_values);
: CDTIME_T_TO_DOUBLE(plugin_get_interval()),
buffer_values);
} /* }}} int cmd_create_putval */
} /* }}} int cmd_create_putval */
fields = malloc((estimate + 1) * sizeof(*fields));
if (fields == NULL) {
cmd_error(CMD_ERROR, err, "malloc failed.");
fields = malloc((estimate + 1) * sizeof(*fields));
if (fields == NULL) {
cmd_error(CMD_ERROR, err, "malloc failed.");
if (string[1] == '\0') {
free(fields);
cmd_error(CMD_PARSE_ERROR, err, "Backslash at end of string.");
if (string[1] == '\0') {
free(fields);
cmd_error(CMD_PARSE_ERROR, err, "Backslash at end of string.");
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
}
/* un-escape the next character; skip backslash */
}
/* un-escape the next character; skip backslash */
if (in_quotes) {
free(fields);
cmd_error(CMD_PARSE_ERROR, err, "Unterminated quoted string.");
if (in_quotes) {
free(fields);
cmd_error(CMD_PARSE_ERROR, err, "Unterminated quoted string.");
- return (CMD_PARSE_ERROR);
+ return CMD_PARSE_ERROR;
*ret_fields = fields;
else
free(fields);
*ret_fields = fields;
else
free(fields);
} else {
ret_cmd->type = CMD_UNKNOWN;
cmd_error(CMD_UNKNOWN_COMMAND, err, "Unknown command `%s'.", command);
} else {
ret_cmd->type = CMD_UNKNOWN;
cmd_error(CMD_UNKNOWN_COMMAND, err, "Unknown command `%s'.", command);
- return (CMD_UNKNOWN_COMMAND);
+ return CMD_UNKNOWN_COMMAND;
}
if (status != CMD_OK)
ret_cmd->type = CMD_UNKNOWN;
}
if (status != CMD_OK)
ret_cmd->type = CMD_UNKNOWN;
} /* cmd_status_t cmd_parsev */
cmd_status_t cmd_parse(char *buffer, cmd_t *ret_cmd, const cmd_options_t *opts,
} /* cmd_status_t cmd_parsev */
cmd_status_t cmd_parse(char *buffer, cmd_t *ret_cmd, const cmd_options_t *opts,
status = cmd_parsev(fields_num, fields, ret_cmd, opts, err);
free(fields);
status = cmd_parsev(fields_num, fields, ret_cmd, opts, err);
free(fields);
} /* cmd_status_t cmd_parse */
void cmd_destroy(cmd_t *cmd) {
} /* cmd_status_t cmd_parse */
void cmd_destroy(cmd_t *cmd) {
if (field == NULL) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid argument to cmd_parse_option.");
if (field == NULL) {
errno = EINVAL;
cmd_error(CMD_ERROR, err, "Invalid argument to cmd_parse_option.");
value++;
if ((value[0] != '=') || (value == key)) {
/* Whether this is a fatal error is up to the caller. */
value++;
if ((value[0] != '=') || (value == key)) {
/* Whether this is a fatal error is up to the caller. */
- return (CMD_NO_OPTION);
}
*value = '\0';
value++;
}
*value = '\0';
value++;
if (ret_value != NULL)
*ret_value = value;
if (ret_value != NULL)
*ret_value = value;
} /* cmd_status_t cmd_parse_option */
void cmd_error_fh(void *ud, cmd_status_t status, const char *format,
} /* cmd_status_t cmd_parse_option */
void cmd_error_fh(void *ud, cmd_status_t status, const char *format,
}
int main(int argc, char **argv) {
}
int main(int argc, char **argv) {
WARNING("db query utils: The `%s' config option "
"needs exactly one string argument.",
ci->key);
WARNING("db query utils: The `%s' config option "
"needs exactly one string argument.",
ci->key);
}
string = strdup(ci->values[0].value.string);
if (string == NULL) {
ERROR("db query utils: strdup failed.");
}
string = strdup(ci->values[0].value.string);
if (string == NULL) {
ERROR("db query utils: strdup failed.");
}
if (*ret_string != NULL)
free(*ret_string);
*ret_string = string;
}
if (*ret_string != NULL)
free(*ret_string);
*ret_string = string;
} /* }}} int udb_config_set_string */
static int udb_config_add_string(char ***ret_array, /* {{{ */
} /* }}} int udb_config_set_string */
static int udb_config_add_string(char ***ret_array, /* {{{ */
WARNING("db query utils: The `%s' config option "
"needs at least one argument.",
ci->key);
WARNING("db query utils: The `%s' config option "
"needs at least one argument.",
ci->key);
}
for (int i = 0; i < ci->values_num; i++) {
}
for (int i = 0; i < ci->values_num; i++) {
WARNING("db query utils: Argument %i to the `%s' option "
"is not a string.",
i + 1, ci->key);
WARNING("db query utils: Argument %i to the `%s' option "
"is not a string.",
i + 1, ci->key);
array = realloc(*ret_array, sizeof(char *) * (array_len + ci->values_num));
if (array == NULL) {
ERROR("db query utils: realloc failed.");
array = realloc(*ret_array, sizeof(char *) * (array_len + ci->values_num));
if (array == NULL) {
ERROR("db query utils: realloc failed.");
if (array[array_len] == NULL) {
ERROR("db query utils: strdup failed.");
*ret_array_len = array_len;
if (array[array_len] == NULL) {
ERROR("db query utils: strdup failed.");
*ret_array_len = array_len;
}
array_len++;
}
*ret_array_len = array_len;
}
array_len++;
}
*ret_array_len = array_len;
} /* }}} int udb_config_add_string */
static int udb_config_set_uint(unsigned int *ret_value, /* {{{ */
} /* }}} int udb_config_add_string */
static int udb_config_set_uint(unsigned int *ret_value, /* {{{ */
WARNING("db query utils: The `%s' config option "
"needs exactly one numeric argument.",
ci->key);
WARNING("db query utils: The `%s' config option "
"needs exactly one numeric argument.",
ci->key);
}
tmp = ci->values[0].value.number;
if ((tmp < 0.0) || (tmp > ((double)UINT_MAX)))
}
tmp = ci->values[0].value.number;
if ((tmp < 0.0) || (tmp > ((double)UINT_MAX)))
*ret_value = (unsigned int)(tmp + .5);
*ret_value = (unsigned int)(tmp + .5);
} /* }}} int udb_config_set_uint */
/*
} /* }}} int udb_config_set_uint */
/*
vl.values = calloc(r->values_num, sizeof(*vl.values));
if (vl.values == NULL) {
ERROR("db query utils: calloc failed.");
vl.values = calloc(r->values_num, sizeof(*vl.values));
if (vl.values == NULL) {
ERROR("db query utils: calloc failed.");
}
vl.values_len = r_area->ds->ds_num;
}
vl.values_len = r_area->ds->ds_num;
value_str, DS_TYPE_TO_STRING(r_area->ds->ds[i].type));
errno = EINVAL;
free(vl.values);
value_str, DS_TYPE_TO_STRING(r_area->ds->ds[i].type));
errno = EINVAL;
free(vl.values);
ERROR(
"udb_result_submit: creating type_instance failed with status %d.",
status);
ERROR(
"udb_result_submit: creating type_instance failed with status %d.",
status);
}
} else {
char tmp[DATA_MAX_NAME_LEN];
}
} else {
char tmp[DATA_MAX_NAME_LEN];
ERROR(
"udb_result_submit: creating type_instance failed with status %d.",
status);
ERROR(
"udb_result_submit: creating type_instance failed with status %d.",
status);
}
tmp[sizeof(tmp) - 1] = 0;
}
tmp[sizeof(tmp) - 1] = 0;
vl.meta = meta_data_create();
if (vl.meta == NULL) {
ERROR("db query utils:: meta_data_create failed.");
vl.meta = meta_data_create();
if (vl.meta == NULL) {
ERROR("db query utils:: meta_data_create failed.");
}
for (size_t i = 0; i < r->metadata_num; i++) {
}
for (size_t i = 0; i < r->metadata_num; i++) {
ERROR("db query utils:: meta_data_add_string failed.");
meta_data_destroy(vl.meta);
vl.meta = NULL;
ERROR("db query utils:: meta_data_add_string failed.");
meta_data_destroy(vl.meta);
vl.meta = NULL;
vl.meta = NULL;
}
sfree(vl.values);
vl.meta = NULL;
}
sfree(vl.values);
} /* }}} void udb_result_submit */
static void udb_result_finish_result(udb_result_t const *r, /* {{{ */
} /* }}} void udb_result_submit */
static void udb_result_finish_result(udb_result_t const *r, /* {{{ */
udb_result_preparation_area_t *prep_area,
char **column_names, size_t column_num) {
if ((r == NULL) || (prep_area == NULL))
udb_result_preparation_area_t *prep_area,
char **column_names, size_t column_num) {
if ((r == NULL) || (prep_area == NULL))
#define BAIL_OUT(status) \
prep_area->ds = NULL; \
#define BAIL_OUT(status) \
prep_area->ds = NULL; \
} /* }}} for (i = 0; i < r->metadata_num; i++) */
#undef BAIL_OUT
} /* }}} for (i = 0; i < r->metadata_num; i++) */
#undef BAIL_OUT
} /* }}} int udb_result_prepare_result */
static void udb_result_free(udb_result_t *r) /* {{{ */
} /* }}} int udb_result_prepare_result */
static void udb_result_free(udb_result_t *r) /* {{{ */
r = calloc(1, sizeof(*r));
if (r == NULL) {
ERROR("db query utils: calloc failed.");
r = calloc(1, sizeof(*r));
if (r == NULL) {
ERROR("db query utils: calloc failed.");
}
r->type = NULL;
r->instance_prefix = NULL;
}
r->type = NULL;
r->instance_prefix = NULL;
if (status != 0) {
udb_result_free(r);
if (status != 0) {
udb_result_free(r);
}
/* If all went well, add this result to the list of results. */
}
/* If all went well, add this result to the list of results. */
} /* }}} int udb_result_create */
/*
} /* }}} int udb_result_create */
/*
int status;
if ((ret_query_list == NULL) || (ret_query_list_len == NULL))
int status;
if ((ret_query_list == NULL) || (ret_query_list_len == NULL))
query_list = *ret_query_list;
query_list_len = *ret_query_list_len;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("db query utils: The `Query' block "
"needs exactly one string argument.");
query_list = *ret_query_list;
query_list_len = *ret_query_list_len;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("db query utils: The `Query' block "
"needs exactly one string argument.");
}
q = calloc(1, sizeof(*q));
if (q == NULL) {
ERROR("db query utils: calloc failed.");
}
q = calloc(1, sizeof(*q));
if (q == NULL) {
ERROR("db query utils: calloc failed.");
}
q->min_version = 0;
q->max_version = UINT_MAX;
}
q->min_version = 0;
q->max_version = UINT_MAX;
status = udb_config_set_string(&q->name, ci);
if (status != 0) {
sfree(q);
status = udb_config_set_string(&q->name, ci);
if (status != 0) {
sfree(q);
}
/* Fill the `udb_query_t' structure.. */
}
/* Fill the `udb_query_t' structure.. */
if (status != 0) {
udb_query_free_one(q);
if (status != 0) {
udb_query_free_one(q);
}
*ret_query_list = query_list;
*ret_query_list_len = query_list_len;
}
*ret_query_list = query_list;
*ret_query_list_len = query_list_len;
} /* }}} int udb_query_create */
void udb_query_free(udb_query_t **query_list, size_t query_list_len) /* {{{ */
} /* }}} int udb_query_create */
void udb_query_free(udb_query_t **query_list, size_t query_list_len) /* {{{ */
(dst_list_len == NULL)) {
ERROR("db query utils: udb_query_pick_from_list_by_name: "
"Invalid argument.");
(dst_list_len == NULL)) {
ERROR("db query utils: udb_query_pick_from_list_by_name: "
"Invalid argument.");
tmp_list = realloc(*dst_list, (tmp_list_len + 1) * sizeof(udb_query_t *));
if (tmp_list == NULL) {
ERROR("db query utils: realloc failed.");
tmp_list = realloc(*dst_list, (tmp_list_len + 1) * sizeof(udb_query_t *));
if (tmp_list == NULL) {
ERROR("db query utils: realloc failed.");
}
tmp_list[tmp_list_len] = src_list[i];
}
tmp_list[tmp_list_len] = src_list[i];
ERROR("db query utils: Cannot find query `%s'. Make sure the <Query> "
"block is above the database definition!",
name);
ERROR("db query utils: Cannot find query `%s'. Make sure the <Query> "
"block is above the database definition!",
name);
} else {
DEBUG("db query utils: Added %i versions of query `%s'.", num_added, name);
}
} else {
DEBUG("db query utils: Added %i versions of query `%s'.", num_added, name);
}
} /* }}} int udb_query_pick_from_list_by_name */
int udb_query_pick_from_list(oconfig_item_t *ci, /* {{{ */
} /* }}} int udb_query_pick_from_list_by_name */
int udb_query_pick_from_list(oconfig_item_t *ci, /* {{{ */
(dst_list_len == NULL)) {
ERROR("db query utils: udb_query_pick_from_list: "
"Invalid argument.");
(dst_list_len == NULL)) {
ERROR("db query utils: udb_query_pick_from_list: "
"Invalid argument.");
}
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("db query utils: The `%s' config option "
"needs exactly one string argument.",
ci->key);
}
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
ERROR("db query utils: The `%s' config option "
"needs exactly one string argument.",
ci->key);
}
name = ci->values[0].value.string;
}
name = ci->values[0].value.string;
- return (udb_query_pick_from_list_by_name(name, src_list, src_list_len,
- dst_list, dst_list_len));
+ return udb_query_pick_from_list_by_name(name, src_list, src_list_len,
+ dst_list, dst_list_len);
} /* }}} int udb_query_pick_from_list */
const char *udb_query_get_name(udb_query_t *q) /* {{{ */
{
if (q == NULL)
} /* }}} int udb_query_pick_from_list */
const char *udb_query_get_name(udb_query_t *q) /* {{{ */
{
if (q == NULL)
} /* }}} const char *udb_query_get_name */
const char *udb_query_get_statement(udb_query_t *q) /* {{{ */
{
if (q == NULL)
} /* }}} const char *udb_query_get_name */
const char *udb_query_get_statement(udb_query_t *q) /* {{{ */
{
if (q == NULL)
} /* }}} const char *udb_query_get_statement */
void udb_query_set_user_data(udb_query_t *q, void *user_data) /* {{{ */
} /* }}} const char *udb_query_get_statement */
void udb_query_set_user_data(udb_query_t *q, void *user_data) /* {{{ */
void *udb_query_get_user_data(udb_query_t *q) /* {{{ */
{
if (q == NULL)
void *udb_query_get_user_data(udb_query_t *q) /* {{{ */
{
if (q == NULL)
} /* }}} void *udb_query_get_user_data */
int udb_query_check_version(udb_query_t *q, unsigned int version) /* {{{ */
{
if (q == NULL)
} /* }}} void *udb_query_get_user_data */
int udb_query_check_version(udb_query_t *q, unsigned int version) /* {{{ */
{
if (q == NULL)
if ((version < q->min_version) || (version > q->max_version))
if ((version < q->min_version) || (version > q->max_version))
} /* }}} int udb_query_check_version */
void udb_query_finish_result(udb_query_t const *q, /* {{{ */
} /* }}} int udb_query_check_version */
void udb_query_finish_result(udb_query_t const *q, /* {{{ */
int status;
if ((q == NULL) || (prep_area == NULL))
int status;
if ((q == NULL) || (prep_area == NULL))
if ((prep_area->column_num < 1) || (prep_area->host == NULL) ||
(prep_area->plugin == NULL) || (prep_area->db_name == NULL)) {
ERROR("db query utils: Query `%s': Query is not prepared; "
"can't handle result.",
q->name);
if ((prep_area->column_num < 1) || (prep_area->host == NULL) ||
(prep_area->plugin == NULL) || (prep_area->db_name == NULL)) {
ERROR("db query utils: Query `%s': Query is not prepared; "
"can't handle result.",
q->name);
}
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG /* {{{ */
}
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG /* {{{ */
ERROR("db query utils: udb_query_handle_result (%s, %s): "
"All results failed.",
prep_area->db_name, q->name);
ERROR("db query utils: udb_query_handle_result (%s, %s): "
"All results failed.",
prep_area->db_name, q->name);
} /* }}} int udb_query_handle_result */
int udb_query_prepare_result(udb_query_t const *q, /* {{{ */
} /* }}} int udb_query_handle_result */
int udb_query_prepare_result(udb_query_t const *q, /* {{{ */
int status;
if ((q == NULL) || (prep_area == NULL))
int status;
if ((q == NULL) || (prep_area == NULL))
udb_query_finish_result(q, prep_area);
udb_query_finish_result(q, prep_area);
ERROR("db query utils: Query `%s': Prepare failed: Out of memory.",
q->name);
udb_query_finish_result(q, prep_area);
ERROR("db query utils: Query `%s': Prepare failed: Out of memory.",
q->name);
udb_query_finish_result(q, prep_area);
}
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG
}
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG
"Column `%s' from `PluginInstanceFrom' could not be found.",
q->plugin_instance_from);
udb_query_finish_result(q, prep_area);
"Column `%s' from `PluginInstanceFrom' could not be found.",
q->plugin_instance_from);
udb_query_finish_result(q, prep_area);
"preparation areas.",
q->name);
udb_query_finish_result(q, prep_area);
"preparation areas.",
q->name);
udb_query_finish_result(q, prep_area);
}
status = udb_result_prepare_result(r, r_area, column_names, column_num);
if (status != 0) {
udb_query_finish_result(q, prep_area);
}
status = udb_result_prepare_result(r, r_area, column_names, column_num);
if (status != 0) {
udb_query_finish_result(q, prep_area);
} /* }}} int udb_query_prepare_result */
udb_query_preparation_area_t *
} /* }}} int udb_query_prepare_result */
udb_query_preparation_area_t *
next_r_area = &r_area->next;
}
next_r_area = &r_area->next;
}
} /* }}} udb_query_preparation_area_t *udb_query_allocate_preparation_area */
void udb_query_delete_preparation_area(
} /* }}} udb_query_preparation_area_t *udb_query_allocate_preparation_area */
void udb_query_delete_preparation_area(
- return (a->s6_addr[i] > b->s6_addr[i] ? 1 : -1);
+ return a->s6_addr[i] > b->s6_addr[i] ? 1 : -1;
} /* int cmp_addrinfo */
static inline int ignore_list_match(const struct in6_addr *addr) {
for (ip_list_t *ptr = IgnoreList; ptr != NULL; ptr = ptr->next)
if (cmp_in6_addr(addr, &ptr->addr) == 0)
} /* int cmp_addrinfo */
static inline int ignore_list_match(const struct in6_addr *addr) {
for (ip_list_t *ptr = IgnoreList; ptr != NULL; ptr = ptr->next)
if (cmp_in6_addr(addr, &ptr->addr) == 0)
- return (1);
- return (0);
} /* int ignore_list_match */
static void ignore_list_add(const struct in6_addr *addr) {
} /* int ignore_list_match */
static void ignore_list_add(const struct in6_addr *addr) {
uint16_t payload_len;
if (0 > len)
uint16_t payload_len;
if (0 > len)
offset = sizeof(struct ip6_hdr);
nexthdr = ipv6->ip6_nxt;
offset = sizeof(struct ip6_hdr);
nexthdr = ipv6->ip6_nxt;
payload_len = ntohs(ipv6->ip6_plen);
if (ignore_list_match(&c_src_addr))
payload_len = ntohs(ipv6->ip6_plen);
if (ignore_list_match(&c_src_addr))
/* Parse extension headers. This only handles the standard headers, as
* defined in RFC 2460, correctly. Fragments are discarded. */
/* Parse extension headers. This only handles the standard headers, as
* defined in RFC 2460, correctly. Fragments are discarded. */
/* Catch broken packets */
if ((offset + sizeof(struct ip6_ext)) > (unsigned int)len)
/* Catch broken packets */
if ((offset + sizeof(struct ip6_ext)) > (unsigned int)len)
/* Cannot handle fragments. */
if (IPPROTO_FRAGMENT == nexthdr)
/* Cannot handle fragments. */
if (IPPROTO_FRAGMENT == nexthdr)
memcpy(&ext_hdr, (char *)ipv6 + offset, sizeof(struct ip6_ext));
nexthdr = ext_hdr.ip6e_nxt;
memcpy(&ext_hdr, (char *)ipv6 + offset, sizeof(struct ip6_ext));
nexthdr = ext_hdr.ip6e_nxt;
/* This header is longer than the packets payload.. WTF? */
if (ext_hdr_len > payload_len)
/* This header is longer than the packets payload.. WTF? */
if (ext_hdr_len > payload_len)
offset += ext_hdr_len;
payload_len -= ext_hdr_len;
offset += ext_hdr_len;
payload_len -= ext_hdr_len;
/* Catch broken and empty packets */
if (((offset + payload_len) > (unsigned int)len) || (payload_len == 0) ||
(payload_len > PCAP_SNAPLEN))
/* Catch broken and empty packets */
if (((offset + payload_len) > (unsigned int)len) || (payload_len == 0) ||
(payload_len > PCAP_SNAPLEN))
if (IPPROTO_UDP != nexthdr)
if (IPPROTO_UDP != nexthdr)
memcpy(buf, (char *)ipv6 + offset, payload_len);
if (handle_udp((struct udphdr *)buf, payload_len) == 0)
memcpy(buf, (char *)ipv6 + offset, payload_len);
if (handle_udp((struct udphdr *)buf, payload_len) == 0)
- return (1); /* Success */
+ return 1; /* Success */
} /* int handle_ipv6 */
/* #endif HAVE_IPV6 */
#else /* if !HAVE_IPV6 */
static int handle_ipv6(__attribute__((unused)) void *pkg,
__attribute__((unused)) int len) {
} /* int handle_ipv6 */
/* #endif HAVE_IPV6 */
#else /* if !HAVE_IPV6 */
static int handle_ipv6(__attribute__((unused)) void *pkg,
__attribute__((unused)) int len) {
}
#endif /* !HAVE_IPV6 */
}
#endif /* !HAVE_IPV6 */
struct in6_addr c_dst_addr;
if (ip->ip_v == 6)
struct in6_addr c_dst_addr;
if (ip->ip_v == 6)
- return (handle_ipv6((void *)ip, len));
+ return handle_ipv6((void *)ip, len);
in6_addr_from_buffer(&c_src_addr, &ip->ip_src.s_addr,
sizeof(ip->ip_src.s_addr), AF_INET);
in6_addr_from_buffer(&c_dst_addr, &ip->ip_dst.s_addr,
sizeof(ip->ip_dst.s_addr), AF_INET);
if (ignore_list_match(&c_src_addr))
in6_addr_from_buffer(&c_src_addr, &ip->ip_src.s_addr,
sizeof(ip->ip_src.s_addr), AF_INET);
in6_addr_from_buffer(&c_dst_addr, &ip->ip_dst.s_addr,
sizeof(ip->ip_dst.s_addr), AF_INET);
if (ignore_list_match(&c_src_addr))
if (IPPROTO_UDP != ip->ip_p)
return 0;
memcpy(buf, ((char *)ip) + offset, len - offset);
if (IPPROTO_UDP != ip->ip_p)
return 0;
memcpy(buf, ((char *)ip) + offset, len - offset);
return 0;
memcpy(buf, pkt, len);
if (ETHERTYPE_IPV6 == etype)
return 0;
memcpy(buf, pkt, len);
if (ETHERTYPE_IPV6 == etype)
- return (handle_ipv6((void *)buf, len));
+ return handle_ipv6((void *)buf, len);
else
return handle_ip((struct ip *)buf, len);
}
else
return handle_ip((struct ip *)buf, len);
}
uint16_t etype;
if ((0 > len) || ((unsigned int)len < sizeof(struct sll_header)))
uint16_t etype;
if ((0 > len) || ((unsigned int)len < sizeof(struct sll_header)))
hdr = (struct sll_header *)pkt;
pkt = (u_char *)(hdr + 1);
hdr = (struct sll_header *)pkt;
pkt = (u_char *)(hdr + 1);
return 0;
if (ETHERTYPE_IPV6 == etype)
return 0;
if (ETHERTYPE_IPV6 == etype)
- return (handle_ipv6((void *)pkt, len));
+ return handle_ipv6((void *)pkt, len);
else
return handle_ip((struct ip *)pkt, len);
}
else
return handle_ip((struct ip *)pkt, len);
}
switch (t) {
#if (defined(__NAMESER)) && (__NAMESER >= 19991001)
case ns_t_a:
switch (t) {
#if (defined(__NAMESER)) && (__NAMESER >= 19991001)
case ns_t_a:
#if __NAMESER >= 19991006
case ns_t_kx:
#if __NAMESER >= 19991006
case ns_t_kx:
#endif
#if __NAMESER >= 20090302
case ns_t_apl:
#endif
#if __NAMESER >= 20090302
case ns_t_apl:
#if __NAMESER >= 19991006
case ns_t_zxfr:
#if __NAMESER >= 19991006
case ns_t_zxfr:
#endif
#if __NAMESER >= 20090302
case ns_t_dlv:
#endif
#if __NAMESER >= 20090302
case ns_t_dlv:
#endif
/* #endif __NAMESER >= 19991001 */
#elif (defined(__BIND)) && (__BIND >= 19950621)
case T_A:
#endif
/* #endif __NAMESER >= 19991001 */
#elif (defined(__BIND)) && (__BIND >= 19950621)
case T_A:
- return ("A"); /* 1 ... */
+ return "A"; /* 1 ... */
- return ("NAPTR"); /* ... 35 */
+ return "NAPTR"; /* ... 35 */
#if (__BIND >= 19960801)
case T_KX:
#if (__BIND >= 19960801)
case T_KX:
- return ("KX"); /* 36 ... */
+ return "KX"; /* 36 ... */
- return ("DNSKEY"); /* ... 48 */
+ return "DNSKEY"; /* ... 48 */
- return ("TKEY"); /* 249 */
+ return "TKEY"; /* 249 */
#endif /* __BIND >= 19960801 */
case T_TSIG:
#endif /* __BIND >= 19960801 */
case T_TSIG:
- return ("TSIG"); /* 250 ... */
+ return "TSIG"; /* 250 ... */
- return ("ANY"); /* ... 255 */
+ return "ANY"; /* ... 255 */
#endif /* __BIND >= 19950621 */
default:
ssnprintf(buf, sizeof(buf), "#%i", t);
#endif /* __BIND >= 19950621 */
default:
ssnprintf(buf, sizeof(buf), "#%i", t);
switch (rcode) {
#if (defined(__NAMESER)) && (__NAMESER >= 19991006)
case ns_r_noerror:
switch (rcode) {
#if (defined(__NAMESER)) && (__NAMESER >= 19991006)
case ns_r_noerror:
/* #endif __NAMESER >= 19991006 */
#elif (defined(__BIND)) && (__BIND >= 19950621)
case NOERROR:
/* #endif __NAMESER >= 19991006 */
#elif (defined(__BIND)) && (__BIND >= 19950621)
case NOERROR:
#if defined(YXDOMAIN) && defined(NXRRSET)
case YXDOMAIN:
#if defined(YXDOMAIN) && defined(NXRRSET)
case YXDOMAIN:
#endif /* RFC2136 rcodes */
#endif /* __BIND >= 19950621 */
default:
ssnprintf(buf, sizeof(buf), "RCode%i", rcode);
#endif /* RFC2136 rcodes */
#endif /* __BIND >= 19950621 */
default:
ssnprintf(buf, sizeof(buf), "RCode%i", rcode);
}
} /* const char *rcode_str (int rcode) */
}
} /* const char *rcode_str (int rcode) */
- return (phc->shm_size - sizeof(dpdk_helper_ctx_t));
+ return phc->shm_size - sizeof(dpdk_helper_ctx_t);
}
int dpdk_helper_init(const char *name, size_t data_size,
}
int dpdk_helper_init(const char *name, size_t data_size,
fh = fopen(h->filename, "r");
if (fh == NULL)
fh = fopen(h->filename, "r");
if (fh == NULL)
fl.l_type = F_RDLCK;
fl.l_whence = SEEK_SET;
fl.l_type = F_RDLCK;
fl.l_whence = SEEK_SET;
status = fcntl(fileno(fh), F_SETLK, &fl);
if (status != 0) {
fclose(fh);
status = fcntl(fileno(fh), F_SETLK, &fl);
if (status != 0) {
fclose(fh);
}
tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (tree == NULL) {
fclose(fh);
}
tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (tree == NULL) {
fclose(fh);
}
/* Read `fh' into `tree' */
}
/* Read `fh' into `tree' */
fbh_free_tree(h->tree);
h->tree = tree;
fbh_free_tree(h->tree);
h->tree = tree;
} /* }}} int fbh_read_file */
static int fbh_check_file(fbhash_t *h) /* {{{ */
} /* }}} int fbh_read_file */
static int fbh_check_file(fbhash_t *h) /* {{{ */
status = stat(h->filename, &statbuf);
if (status != 0)
status = stat(h->filename, &statbuf);
if (status != 0)
if (h->mtime >= statbuf.st_mtime)
if (h->mtime >= statbuf.st_mtime)
status = fbh_read_file(h);
if (status == 0)
h->mtime = statbuf.st_mtime;
status = fbh_read_file(h);
if (status == 0)
h->mtime = statbuf.st_mtime;
} /* }}} int fbh_check_file */
/*
} /* }}} int fbh_check_file */
/*
int status;
if (file == NULL)
int status;
if (file == NULL)
h = calloc(1, sizeof(*h));
if (h == NULL)
h = calloc(1, sizeof(*h));
if (h == NULL)
h->filename = strdup(file);
if (h->filename == NULL) {
free(h);
h->filename = strdup(file);
if (h->filename == NULL) {
free(h);
if (status != 0) {
fbh_destroy(h);
free(h);
if (status != 0) {
fbh_destroy(h);
free(h);
} /* }}} fbhash_t *fbh_create */
void fbh_destroy(fbhash_t *h) /* {{{ */
} /* }}} fbhash_t *fbh_create */
void fbh_destroy(fbhash_t *h) /* {{{ */
int status;
if ((h == NULL) || (key == NULL))
int status;
if ((h == NULL) || (key == NULL))
value = NULL;
value_copy = NULL;
value = NULL;
value_copy = NULL;
pthread_mutex_unlock(&h->lock);
pthread_mutex_unlock(&h->lock);
} /* }}} char *fbh_get */
} /* }}} char *fbh_get */
do { \
status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__); \
if (status < 1) { \
do { \
status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__); \
if (status < 1) { \
} else if (((size_t)status) >= (ret_len - offset)) { \
} else if (((size_t)status) >= (ret_len - offset)) { \
} else \
offset += ((size_t)status); \
} while (0)
} else \
offset += ((size_t)status); \
} while (0)
else {
ERROR("gr_format_values plugin: Unknown data source type: %i",
ds->ds[ds_num].type);
else {
ERROR("gr_format_values plugin: Unknown data source type: %i",
ds->ds[ds_num].type);
}
static void gr_copy_escape_part(char *dst, const char *src, size_t dst_len,
}
static void gr_copy_escape_part(char *dst, const char *src, size_t dst_len,
ssnprintf(ret, ret_len, "%s%s%s.%s.%s", prefix, n_host, postfix, tmp_plugin,
tmp_type);
ssnprintf(ret, ret_len, "%s%s%s.%s.%s", prefix, n_host, postfix, tmp_plugin,
tmp_type);
}
static void escape_graphite_string(char *buffer, char escape_char) {
}
static void escape_graphite_string(char *buffer, char escape_char) {
if (status != 0) {
ERROR("format_graphite: error with gr_format_name");
sfree(rates);
if (status != 0) {
ERROR("format_graphite: error with gr_format_name");
sfree(rates);
}
escape_graphite_string(key, escape_char);
}
escape_graphite_string(key, escape_char);
if (status != 0) {
ERROR("format_graphite: error with gr_format_values");
sfree(rates);
if (status != 0) {
ERROR("format_graphite: error with gr_format_values");
sfree(rates);
}
/* Compute the graphite command */
}
/* Compute the graphite command */
"Need %zu bytes.",
message_len + 1);
sfree(rates);
"Need %zu bytes.",
message_len + 1);
sfree(rates);
}
/* Append it in case we got multiple data set */
if ((buffer_pos + message_len) >= buffer_size) {
ERROR("format_graphite: target buffer too small");
sfree(rates);
}
/* Append it in case we got multiple data set */
if ((buffer_pos + message_len) >= buffer_size) {
ERROR("format_graphite: target buffer too small");
sfree(rates);
}
memcpy((void *)(buffer + buffer_pos), message, message_len);
buffer_pos += message_len;
buffer[buffer_pos] = '\0';
}
sfree(rates);
}
memcpy((void *)(buffer + buffer_pos), message, message_len);
buffer_pos += message_len;
buffer[buffer_pos] = '\0';
}
sfree(rates);
} /* int format_graphite */
} /* int format_graphite */
size_t dst_pos;
if ((buffer == NULL) || (string == NULL))
size_t dst_pos;
if ((buffer == NULL) || (string == NULL))
do { \
if (dst_pos >= (buffer_size - 1)) { \
buffer[buffer_size - 1] = 0; \
do { \
if (dst_pos >= (buffer_size - 1)) { \
buffer[buffer_size - 1] = 0; \
} \
buffer[dst_pos] = (c); \
dst_pos++; \
} \
buffer[dst_pos] = (c); \
dst_pos++; \
} /* }}} int json_escape_string */
static int values_to_json(char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int json_escape_string */
static int values_to_json(char *buffer, size_t buffer_size, /* {{{ */
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) { \
sfree(rates); \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) { \
sfree(rates); \
} else if (((size_t)status) >= (buffer_size - offset)) { \
sfree(rates); \
} else if (((size_t)status) >= (buffer_size - offset)) { \
sfree(rates); \
} else \
offset += ((size_t)status); \
} while (0)
} else \
offset += ((size_t)status); \
} while (0)
if (rates == NULL) {
WARNING("utils_format_json: uc_get_rate failed.");
sfree(rates);
if (rates == NULL) {
WARNING("utils_format_json: uc_get_rate failed.");
sfree(rates);
}
if (isfinite(rates[i]))
}
if (isfinite(rates[i]))
else {
ERROR("format_json: Unknown data source type: %i", ds->ds[i].type);
sfree(rates);
else {
ERROR("format_json: Unknown data source type: %i", ds->ds[i].type);
sfree(rates);
}
} /* for ds->ds_num */
BUFFER_ADD("]");
}
} /* for ds->ds_num */
BUFFER_ADD("]");
DEBUG("format_json: values_to_json: buffer = %s;", buffer);
sfree(rates);
DEBUG("format_json: values_to_json: buffer = %s;", buffer);
sfree(rates);
} /* }}} int values_to_json */
static int dstypes_to_json(char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int values_to_json */
static int dstypes_to_json(char *buffer, size_t buffer_size, /* {{{ */
int status; \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
int status; \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
else if (((size_t)status) >= (buffer_size - offset)) \
else if (((size_t)status) >= (buffer_size - offset)) \
else \
offset += ((size_t)status); \
} while (0)
else \
offset += ((size_t)status); \
} while (0)
DEBUG("format_json: dstypes_to_json: buffer = %s;", buffer);
DEBUG("format_json: dstypes_to_json: buffer = %s;", buffer);
} /* }}} int dstypes_to_json */
static int dsnames_to_json(char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int dstypes_to_json */
static int dsnames_to_json(char *buffer, size_t buffer_size, /* {{{ */
int status; \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
int status; \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
else if (((size_t)status) >= (buffer_size - offset)) \
else if (((size_t)status) >= (buffer_size - offset)) \
else \
offset += ((size_t)status); \
} while (0)
else \
offset += ((size_t)status); \
} while (0)
DEBUG("format_json: dsnames_to_json: buffer = %s;", buffer);
DEBUG("format_json: dsnames_to_json: buffer = %s;", buffer);
} /* }}} int dsnames_to_json */
static int meta_data_keys_to_json(char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int dsnames_to_json */
static int meta_data_keys_to_json(char *buffer, size_t buffer_size, /* {{{ */
do { \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
do { \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
else if (((size_t)status) >= (buffer_size - offset)) \
else if (((size_t)status) >= (buffer_size - offset)) \
else \
offset += ((size_t)status); \
} while (0)
else \
offset += ((size_t)status); \
} while (0)
} /* for (keys) */
if (offset == 0)
} /* for (keys) */
if (offset == 0)
buffer[0] = '{'; /* replace leading ',' */
BUFFER_ADD("}");
#undef BUFFER_ADD
buffer[0] = '{'; /* replace leading ',' */
BUFFER_ADD("}");
#undef BUFFER_ADD
} /* }}} int meta_data_keys_to_json */
static int meta_data_to_json(char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int meta_data_keys_to_json */
static int meta_data_to_json(char *buffer, size_t buffer_size, /* {{{ */
int status;
if ((buffer == NULL) || (buffer_size == 0) || (meta == NULL))
int status;
if ((buffer == NULL) || (buffer_size == 0) || (meta == NULL))
status = meta_data_toc(meta, &keys);
if (status <= 0)
status = meta_data_toc(meta, &keys);
if (status <= 0)
keys_num = (size_t)status;
status = meta_data_keys_to_json(buffer, buffer_size, meta, keys, keys_num);
keys_num = (size_t)status;
status = meta_data_keys_to_json(buffer, buffer_size, meta, keys, keys_num);
do { \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
do { \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
else if (((size_t)status) >= (buffer_size - offset)) \
else if (((size_t)status) >= (buffer_size - offset)) \
else \
offset += ((size_t)status); \
} while (0)
else \
offset += ((size_t)status); \
} while (0)
status = values_to_json(temp, sizeof(temp), ds, vl, store_rates);
if (status != 0)
status = values_to_json(temp, sizeof(temp), ds, vl, store_rates);
if (status != 0)
BUFFER_ADD("\"values\":%s", temp);
status = dstypes_to_json(temp, sizeof(temp), ds);
if (status != 0)
BUFFER_ADD("\"values\":%s", temp);
status = dstypes_to_json(temp, sizeof(temp), ds);
if (status != 0)
BUFFER_ADD(",\"dstypes\":%s", temp);
status = dsnames_to_json(temp, sizeof(temp), ds);
if (status != 0)
BUFFER_ADD(",\"dstypes\":%s", temp);
status = dsnames_to_json(temp, sizeof(temp), ds);
if (status != 0)
BUFFER_ADD(",\"dsnames\":%s", temp);
BUFFER_ADD(",\"time\":%.3f", CDTIME_T_TO_DOUBLE(vl->time));
BUFFER_ADD(",\"dsnames\":%s", temp);
BUFFER_ADD(",\"time\":%.3f", CDTIME_T_TO_DOUBLE(vl->time));
do { \
status = json_escape_string(temp, sizeof(temp), (value)); \
if (status != 0) \
do { \
status = json_escape_string(temp, sizeof(temp), (value)); \
if (status != 0) \
BUFFER_ADD(",\"%s\":%s", (key), temp); \
} while (0)
BUFFER_ADD(",\"%s\":%s", (key), temp); \
} while (0)
memset(meta_buffer, 0, sizeof(meta_buffer));
status = meta_data_to_json(meta_buffer, sizeof(meta_buffer), vl->meta);
if (status != 0)
memset(meta_buffer, 0, sizeof(meta_buffer));
status = meta_data_to_json(meta_buffer, sizeof(meta_buffer), vl->meta);
if (status != 0)
BUFFER_ADD(",\"meta\":%s", meta_buffer);
} /* if (vl->meta != NULL) */
BUFFER_ADD(",\"meta\":%s", meta_buffer);
} /* if (vl->meta != NULL) */
DEBUG("format_json: value_list_to_json: buffer = %s;", buffer);
DEBUG("format_json: value_list_to_json: buffer = %s;", buffer);
} /* }}} int value_list_to_json */
static int format_json_value_list_nocheck(char *buffer, /* {{{ */
} /* }}} int value_list_to_json */
static int format_json_value_list_nocheck(char *buffer, /* {{{ */
status = value_list_to_json(temp, sizeof(temp), ds, vl, store_rates);
if (status != 0)
status = value_list_to_json(temp, sizeof(temp), ds, vl, store_rates);
if (status != 0)
temp_size = strlen(temp);
memcpy(buffer + (*ret_buffer_fill), temp, temp_size + 1);
(*ret_buffer_fill) += temp_size;
(*ret_buffer_free) -= temp_size;
temp_size = strlen(temp);
memcpy(buffer + (*ret_buffer_fill), temp, temp_size + 1);
(*ret_buffer_fill) += temp_size;
(*ret_buffer_free) -= temp_size;
} /* }}} int format_json_value_list_nocheck */
int format_json_initialize(char *buffer, /* {{{ */
} /* }}} int format_json_value_list_nocheck */
int format_json_initialize(char *buffer, /* {{{ */
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
buffer_fill = *ret_buffer_fill;
buffer_free = *ret_buffer_free;
buffer_fill = *ret_buffer_fill;
buffer_free = *ret_buffer_free;
buffer_fill = 0;
if (buffer_free < 3)
buffer_fill = 0;
if (buffer_free < 3)
memset(buffer, 0, buffer_free);
*ret_buffer_fill = buffer_fill;
*ret_buffer_free = buffer_free;
memset(buffer, 0, buffer_free);
*ret_buffer_fill = buffer_fill;
*ret_buffer_free = buffer_free;
} /* }}} int format_json_initialize */
int format_json_finalize(char *buffer, /* {{{ */
} /* }}} int format_json_initialize */
int format_json_finalize(char *buffer, /* {{{ */
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
if (*ret_buffer_free < 2)
if (*ret_buffer_free < 2)
/* Replace the leading comma added in `value_list_to_json' with a square
* bracket. */
if (buffer[0] != ',')
/* Replace the leading comma added in `value_list_to_json' with a square
* bracket. */
if (buffer[0] != ',')
buffer[0] = '[';
pos = *ret_buffer_fill;
buffer[0] = '[';
pos = *ret_buffer_fill;
(*ret_buffer_fill)++;
(*ret_buffer_free)--;
(*ret_buffer_fill)++;
(*ret_buffer_free)--;
} /* }}} int format_json_finalize */
int format_json_value_list(char *buffer, /* {{{ */
} /* }}} int format_json_finalize */
int format_json_value_list(char *buffer, /* {{{ */
int store_rates) {
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL) || (ds == NULL) || (vl == NULL))
int store_rates) {
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL) || (ds == NULL) || (vl == NULL))
if (*ret_buffer_free < 3)
if (*ret_buffer_free < 3)
- return (format_json_value_list_nocheck(buffer, ret_buffer_fill,
- ret_buffer_free, ds, vl, store_rates,
- (*ret_buffer_free) - 2));
+ return format_json_value_list_nocheck(buffer, ret_buffer_fill,
+ ret_buffer_free, ds, vl, store_rates,
+ (*ret_buffer_free) - 2);
} /* }}} int format_json_value_list */
#if HAVE_LIBYAJL
} /* }}} int format_json_value_list */
#if HAVE_LIBYAJL
if (str == NULL)
return (int)yajl_gen_null(g);
if (str == NULL)
return (int)yajl_gen_null(g);
- return (int)yajl_gen_string(g, (unsigned char const *)str,
+ return (int)yajl_gen_string(g, (const unsigned char *)str,
(unsigned int)strlen(str));
} /* }}} int json_add_string */
(unsigned int)strlen(str));
} /* }}} int json_add_string */
size_t dst_pos;
if ((buffer == NULL) || (string == NULL))
size_t dst_pos;
if ((buffer == NULL) || (string == NULL))
do { \
if (dst_pos >= (buffer_size - 1)) { \
buffer[buffer_size - 1] = 0; \
do { \
if (dst_pos >= (buffer_size - 1)) { \
buffer[buffer_size - 1] = 0; \
} \
buffer[dst_pos] = (c); \
dst_pos++; \
} \
buffer[dst_pos] = (c); \
dst_pos++; \
} /* }}} int kairosdb_escape_string */
static int values_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int kairosdb_escape_string */
static int values_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) { \
sfree(rates); \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) { \
sfree(rates); \
} else if (((size_t)status) >= (buffer_size - offset)) { \
sfree(rates); \
} else if (((size_t)status) >= (buffer_size - offset)) { \
sfree(rates); \
} else \
offset += ((size_t)status); \
} while (0)
} else \
offset += ((size_t)status); \
} while (0)
"%s|%s|%s|%s|%s",
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
"%s|%s|%s|%s|%s",
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
}
} else if (store_rates) {
if (rates == NULL)
}
} else if (store_rates) {
if (rates == NULL)
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
}
if (isfinite(rates[ds_idx])) {
}
if (isfinite(rates[ds_idx])) {
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
sfree(rates);
vl->plugin, vl->plugin_instance, vl->type, vl->type_instance,
ds->ds[ds_idx].name);
sfree(rates);
}
} else if (ds->ds[ds_idx].type == DS_TYPE_COUNTER) {
BUFFER_ADD("[[");
}
} else if (ds->ds[ds_idx].type == DS_TYPE_COUNTER) {
BUFFER_ADD("[[");
} else {
ERROR("format_kairosdb: Unknown data source type: %i", ds->ds[ds_idx].type);
sfree(rates);
} else {
ERROR("format_kairosdb: Unknown data source type: %i", ds->ds[ds_idx].type);
sfree(rates);
DEBUG("format_kairosdb: values_to_kairosdb: buffer = %s;", buffer);
sfree(rates);
DEBUG("format_kairosdb: values_to_kairosdb: buffer = %s;", buffer);
sfree(rates);
} /* }}} int values_to_kairosdb */
static int value_list_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
} /* }}} int values_to_kairosdb */
static int value_list_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
do { \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
do { \
status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__); \
if (status < 1) \
else if (((size_t)status) >= (buffer_size - offset)) \
else if (((size_t)status) >= (buffer_size - offset)) \
else \
offset += ((size_t)status); \
} while (0)
else \
offset += ((size_t)status); \
} while (0)
do { \
status = kairosdb_escape_string(temp, sizeof(temp), (value)); \
if (status != 0) \
do { \
status = kairosdb_escape_string(temp, sizeof(temp), (value)); \
if (status != 0) \
BUFFER_ADD(",\"%s\": %s", (key), temp); \
} while (0)
BUFFER_ADD(",\"%s\": %s", (key), temp); \
} while (0)
status = values_to_kairosdb(temp, sizeof(temp), ds, vl, store_rates, i);
if (status != 0)
status = values_to_kairosdb(temp, sizeof(temp), ds, vl, store_rates, i);
if (status != 0)
BUFFER_ADD("\", \"datapoints\": %s", temp);
BUFFER_ADD("\", \"datapoints\": %s", temp);
DEBUG("format_kairosdb: value_list_to_kairosdb: buffer = %s;", buffer);
DEBUG("format_kairosdb: value_list_to_kairosdb: buffer = %s;", buffer);
} /* }}} int value_list_to_kairosdb */
static int format_kairosdb_value_list_nocheck(
} /* }}} int value_list_to_kairosdb */
static int format_kairosdb_value_list_nocheck(
status = value_list_to_kairosdb(temp, sizeof(temp), ds, vl, store_rates,
http_attrs, http_attrs_num, data_ttl);
if (status != 0)
status = value_list_to_kairosdb(temp, sizeof(temp), ds, vl, store_rates,
http_attrs, http_attrs_num, data_ttl);
if (status != 0)
temp_size = strlen(temp);
memcpy(buffer + (*ret_buffer_fill), temp, temp_size + 1);
(*ret_buffer_fill) += temp_size;
(*ret_buffer_free) -= temp_size;
temp_size = strlen(temp);
memcpy(buffer + (*ret_buffer_fill), temp, temp_size + 1);
(*ret_buffer_fill) += temp_size;
(*ret_buffer_free) -= temp_size;
} /* }}} int format_kairosdb_value_list_nocheck */
int format_kairosdb_initialize(char *buffer, /* {{{ */
} /* }}} int format_kairosdb_value_list_nocheck */
int format_kairosdb_initialize(char *buffer, /* {{{ */
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
buffer_fill = *ret_buffer_fill;
buffer_free = *ret_buffer_free;
buffer_fill = *ret_buffer_fill;
buffer_free = *ret_buffer_free;
buffer_fill = 0;
if (buffer_free < 3)
buffer_fill = 0;
if (buffer_free < 3)
memset(buffer, 0, buffer_free);
*ret_buffer_fill = buffer_fill;
*ret_buffer_free = buffer_free;
memset(buffer, 0, buffer_free);
*ret_buffer_fill = buffer_fill;
*ret_buffer_free = buffer_free;
} /* }}} int format_kairosdb_initialize */
int format_kairosdb_finalize(char *buffer, /* {{{ */
} /* }}} int format_kairosdb_initialize */
int format_kairosdb_finalize(char *buffer, /* {{{ */
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL))
if (*ret_buffer_free < 2)
if (*ret_buffer_free < 2)
/* Replace the leading comma added in `value_list_to_kairosdb' with a square
* bracket. */
if (buffer[0] != ',')
/* Replace the leading comma added in `value_list_to_kairosdb' with a square
* bracket. */
if (buffer[0] != ',')
buffer[0] = '[';
pos = *ret_buffer_fill;
buffer[0] = '[';
pos = *ret_buffer_fill;
(*ret_buffer_fill)++;
(*ret_buffer_free)--;
(*ret_buffer_fill)++;
(*ret_buffer_free)--;
} /* }}} int format_kairosdb_finalize */
int format_kairosdb_value_list(char *buffer, /* {{{ */
} /* }}} int format_kairosdb_finalize */
int format_kairosdb_value_list(char *buffer, /* {{{ */
size_t http_attrs_num, int data_ttl) {
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL) || (ds == NULL) || (vl == NULL))
size_t http_attrs_num, int data_ttl) {
if ((buffer == NULL) || (ret_buffer_fill == NULL) ||
(ret_buffer_free == NULL) || (ds == NULL) || (vl == NULL))
if (*ret_buffer_free < 3)
if (*ret_buffer_free < 3)
- return (-ENOMEM);
-
- return (format_kairosdb_value_list_nocheck(
- buffer, ret_buffer_fill, ret_buffer_free, ds, vl, store_rates,
- (*ret_buffer_free) - 2, http_attrs, http_attrs_num, data_ttl));
+ return -ENOMEM;
+
+ return format_kairosdb_value_list_nocheck(buffer, ret_buffer_fill,
+ ret_buffer_free, ds, vl,
+ store_rates,
+ (*ret_buffer_free) - 2,
+ http_attrs, http_attrs_num,
+ data_ttl);
} /* }}} int format_kairosdb_value_list */
/* vim: set sw=2 sts=2 et fdm=marker : */
} /* }}} int format_kairosdb_value_list */
/* vim: set sw=2 sts=2 et fdm=marker : */
re = calloc(1, sizeof(*re));
if (re == NULL) {
ERROR("ignorelist_append_regex: calloc failed.");
re = calloc(1, sizeof(*re));
if (re == NULL) {
ERROR("ignorelist_append_regex: calloc failed.");
}
status = regcomp(re, re_str, REG_EXTENDED);
}
status = regcomp(re, re_str, REG_EXTENDED);
"failed: %s",
re_str, errbuf);
sfree(re);
"failed: %s",
re_str, errbuf);
sfree(re);
}
entry = calloc(1, sizeof(*entry));
}
entry = calloc(1, sizeof(*entry));
ERROR("ignorelist_append_regex: calloc failed.");
regfree(re);
sfree(re);
ERROR("ignorelist_append_regex: calloc failed.");
regfree(re);
sfree(re);
}
entry->rmatch = re;
ignorelist_append(il, entry);
}
entry->rmatch = re;
ignorelist_append(il, entry);
} /* int ignorelist_append_regex */
#endif
} /* int ignorelist_append_regex */
#endif
/* create new entry */
if ((new = calloc(1, sizeof(*new))) == NULL) {
ERROR("cannot allocate new entry");
/* create new entry */
if ((new = calloc(1, sizeof(*new))) == NULL) {
ERROR("cannot allocate new entry");
}
new->smatch = sstrdup(entry);
/* append new entry */
ignorelist_append(il, new);
}
new->smatch = sstrdup(entry);
/* append new entry */
ignorelist_append(il, new);
} /* int ignorelist_append_string(ignorelist_t *il, const char *entry) */
#if HAVE_REGEX_H
} /* int ignorelist_append_string(ignorelist_t *il, const char *entry) */
#if HAVE_REGEX_H
/* match regex */
if (regexec(item->rmatch, entry, 0, NULL, 0) == 0)
/* match regex */
if (regexec(item->rmatch, entry, 0, NULL, 0) == 0)
} /* int ignorelist_match_regex (ignorelist_item_t *item, const char *entry) */
#endif
} /* int ignorelist_match_regex (ignorelist_item_t *item, const char *entry) */
#endif
(strlen(entry) > 0));
if (strcmp(entry, item->smatch) == 0)
(strlen(entry) > 0));
if (strcmp(entry, item->smatch) == 0)
} /* int ignorelist_match_string (ignorelist_item_t *item, const char *entry) */
/* *** *** *** ******************************************** *** *** *** */
} /* int ignorelist_match_string (ignorelist_item_t *item, const char *entry) */
/* *** *** *** ******************************************** *** *** *** */
*/
il->ignore = invert ? 0 : 1;
*/
il->ignore = invert ? 0 : 1;
} /* ignorelist_t *ignorelist_create (int ignore) */
/*
} /* ignorelist_t *ignorelist_create (int ignore) */
/*
if (il == NULL) {
DEBUG("add called with ignorelist_t == NULL");
if (il == NULL) {
DEBUG("add called with ignorelist_t == NULL");
/* append nothing */
if (len == 0) {
DEBUG("not appending: empty entry");
/* append nothing */
if (len == 0) {
DEBUG("not appending: empty entry");
int ignorelist_match(ignorelist_t *il, const char *entry) {
/* if no entries, collect all */
if ((il == NULL) || (il->head == NULL))
int ignorelist_match(ignorelist_t *il, const char *entry) {
/* if no entries, collect all */
if ((il == NULL) || (il->head == NULL))
if ((entry == NULL) || (strlen(entry) == 0))
if ((entry == NULL) || (strlen(entry) == 0))
/* traverse list and check entries */
for (ignorelist_item_t *traverse = il->head; traverse != NULL;
/* traverse list and check entries */
for (ignorelist_item_t *traverse = il->head; traverse != NULL;
#if HAVE_REGEX_H
if (traverse->rmatch != NULL) {
if (ignorelist_match_regex(traverse, entry))
#if HAVE_REGEX_H
if (traverse->rmatch != NULL) {
if (ignorelist_match_regex(traverse, entry))
} else
#endif
{
if (ignorelist_match_string(traverse, entry))
} else
#endif
{
if (ignorelist_match_string(traverse, entry))
- return (1 - il->ignore);
} /* int ignorelist_match (ignorelist_t *il, const char *entry) */
} /* int ignorelist_match (ignorelist_t *il, const char *entry) */
lc = calloc(1, sizeof(*lc));
if (lc == NULL)
lc = calloc(1, sizeof(*lc));
if (lc == NULL)
lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
latency_counter_reset(lc);
lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
latency_counter_reset(lc);
} /* }}} latency_counter_t *latency_counter_create */
void latency_counter_destroy(latency_counter_t *lc) /* {{{ */
} /* }}} latency_counter_t *latency_counter_create */
void latency_counter_destroy(latency_counter_t *lc) /* {{{ */
cdtime_t latency_counter_get_min(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
cdtime_t latency_counter_get_min(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
- return (0);
- return (lc->min);
+ return 0;
+ return lc->min;
} /* }}} cdtime_t latency_counter_get_min */
cdtime_t latency_counter_get_max(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
} /* }}} cdtime_t latency_counter_get_min */
cdtime_t latency_counter_get_max(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
- return (0);
- return (lc->max);
+ return 0;
+ return lc->max;
} /* }}} cdtime_t latency_counter_get_max */
cdtime_t latency_counter_get_sum(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
} /* }}} cdtime_t latency_counter_get_max */
cdtime_t latency_counter_get_sum(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
- return (0);
- return (lc->sum);
+ return 0;
+ return lc->sum;
} /* }}} cdtime_t latency_counter_get_sum */
size_t latency_counter_get_num(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
} /* }}} cdtime_t latency_counter_get_sum */
size_t latency_counter_get_num(latency_counter_t *lc) /* {{{ */
{
if (lc == NULL)
- return (0);
- return (lc->num);
+ return 0;
+ return lc->num;
} /* }}} size_t latency_counter_get_num */
cdtime_t latency_counter_get_average(latency_counter_t *lc) /* {{{ */
} /* }}} size_t latency_counter_get_num */
cdtime_t latency_counter_get_average(latency_counter_t *lc) /* {{{ */
double average;
if ((lc == NULL) || (lc->num == 0))
double average;
if ((lc == NULL) || (lc->num == 0))
average = CDTIME_T_TO_DOUBLE(lc->sum) / ((double)lc->num);
average = CDTIME_T_TO_DOUBLE(lc->sum) / ((double)lc->num);
- return (DOUBLE_TO_CDTIME_T(average));
+ return DOUBLE_TO_CDTIME_T(average);
} /* }}} cdtime_t latency_counter_get_average */
cdtime_t latency_counter_get_percentile(latency_counter_t *lc, /* {{{ */
} /* }}} cdtime_t latency_counter_get_average */
cdtime_t latency_counter_get_percentile(latency_counter_t *lc, /* {{{ */
size_t i;
if ((lc == NULL) || (lc->num == 0) || !((percent > 0.0) && (percent < 100.0)))
size_t i;
if ((lc == NULL) || (lc->num == 0) || !((percent > 0.0) && (percent < 100.0)))
/* Find index i so that at least "percent" events are within i+1 ms. */
percent_upper = 0.0;
/* Find index i so that at least "percent" events are within i+1 ms. */
percent_upper = 0.0;
}
if (i >= HISTOGRAM_NUM_BINS)
}
if (i >= HISTOGRAM_NUM_BINS)
assert(percent_upper >= percent);
assert(percent_lower < percent);
if (i == 0)
assert(percent_upper >= percent);
assert(percent_lower < percent);
if (i == 0)
- return (lc->bin_width);
latency_lower = ((cdtime_t)i) * lc->bin_width;
p = (percent - percent_lower) / (percent_upper - percent_lower);
latency_lower = ((cdtime_t)i) * lc->bin_width;
p = (percent - percent_lower) / (percent_upper - percent_lower);
DEBUG("latency_counter_get_percentile: latency_interpolated = %.3f",
CDTIME_T_TO_DOUBLE(latency_interpolated));
DEBUG("latency_counter_get_percentile: latency_interpolated = %.3f",
CDTIME_T_TO_DOUBLE(latency_interpolated));
- return (latency_interpolated);
+ return latency_interpolated;
} /* }}} cdtime_t latency_counter_get_percentile */
double latency_counter_get_rate(const latency_counter_t *lc, /* {{{ */
cdtime_t lower, cdtime_t upper,
const cdtime_t now) {
if ((lc == NULL) || (lc->num == 0))
} /* }}} cdtime_t latency_counter_get_percentile */
double latency_counter_get_rate(const latency_counter_t *lc, /* {{{ */
cdtime_t lower, cdtime_t upper,
const cdtime_t now) {
if ((lc == NULL) || (lc->num == 0))
if (upper && (upper < lower))
if (upper && (upper < lower))
/* Buckets have an exclusive lower bound and an inclusive upper bound. That
* means that the first bucket, index 0, represents (0-bin_width]. That means
/* Buckets have an exclusive lower bound and an inclusive upper bound. That
* means that the first bucket, index 0, represents (0-bin_width]. That means
/* lower is greater than the longest latency observed => rate is zero. */
if (lower_bin >= HISTOGRAM_NUM_BINS)
/* lower is greater than the longest latency observed => rate is zero. */
if (lower_bin >= HISTOGRAM_NUM_BINS)
cdtime_t upper_bin = HISTOGRAM_NUM_BINS - 1;
if (upper)
cdtime_t upper_bin = HISTOGRAM_NUM_BINS - 1;
if (upper)
DOUBLE_TO_CDTIME_T(ci->values[1].value.number);
conf->buckets_num++;
DOUBLE_TO_CDTIME_T(ci->values[1].value.number);
conf->buckets_num++;
} /* int latency_config_add_bucket */
int latency_config(latency_config_t *conf, oconfig_item_t *ci,
} /* int latency_config_add_bucket */
int latency_config(latency_config_t *conf, oconfig_item_t *ci,
const data_set_t *ds, value_t *ret_values) {
if (!lua_istable(L, -1)) {
WARNING("ltoc_values: not a table");
const data_set_t *ds, value_t *ret_values) {
if (!lua_istable(L, -1)) {
WARNING("ltoc_values: not a table");
WARNING("ltoc_values: invalid size for datasource \"%s\": expected %zu, "
"got %zu",
ds->type, ds->ds_num, i);
WARNING("ltoc_values: invalid size for datasource \"%s\": expected %zu, "
"got %zu",
ds->type, ds->ds_num, i);
} /* }}} int ltoc_values */
static int ltoc_table_values(lua_State *L, int idx, /* {{{ */
} /* }}} int ltoc_values */
static int ltoc_table_values(lua_State *L, int idx, /* {{{ */
"value, not a table.",
lua_typename(L, lua_type(L, -1)));
lua_pop(L, 1);
"value, not a table.",
lua_typename(L, lua_type(L, -1)));
lua_pop(L, 1);
}
vl->values_len = ds->ds_num;
}
vl->values_len = ds->ds_num;
ERROR("utils_lua: calloc failed.");
vl->values_len = 0;
lua_pop(L, 1);
ERROR("utils_lua: calloc failed.");
vl->values_len = 0;
lua_pop(L, 1);
}
int status = ltoc_values(L, ds, vl->values);
}
int status = ltoc_values(L, ds, vl->values);
} /* }}} int ltoc_table_values */
static int luaC_pushvalues(lua_State *L, const data_set_t *ds,
} /* }}} int ltoc_table_values */
static int luaC_pushvalues(lua_State *L, const data_set_t *ds,
} /* }}} int luaC_pushvalues */
static int luaC_pushdstypes(lua_State *L, const data_set_t *ds) /* {{{ */
} /* }}} int luaC_pushvalues */
static int luaC_pushdstypes(lua_State *L, const data_set_t *ds) /* {{{ */
} /* }}} int luaC_pushdstypes */
static int luaC_pushdsnames(lua_State *L, const data_set_t *ds) /* {{{ */
} /* }}} int luaC_pushdstypes */
static int luaC_pushdsnames(lua_State *L, const data_set_t *ds) /* {{{ */
} /* }}} int luaC_pushdsnames */
/*
} /* }}} int luaC_pushdsnames */
/*
cdtime_t luaC_tocdtime(lua_State *L, int idx) /* {{{ */
{
if (!lua_isnumber(L, /* stack pos = */ idx))
cdtime_t luaC_tocdtime(lua_State *L, int idx) /* {{{ */
{
if (!lua_isnumber(L, /* stack pos = */ idx))
double d = lua_tonumber(L, idx);
double d = lua_tonumber(L, idx);
- return (DOUBLE_TO_CDTIME_T(d));
+ return DOUBLE_TO_CDTIME_T(d);
} /* }}} int ltoc_table_cdtime */
int luaC_tostringbuffer(lua_State *L, int idx, /* {{{ */
char *buffer, size_t buffer_size) {
const char *str = lua_tostring(L, idx);
if (str == NULL)
} /* }}} int ltoc_table_cdtime */
int luaC_tostringbuffer(lua_State *L, int idx, /* {{{ */
char *buffer, size_t buffer_size) {
const char *str = lua_tostring(L, idx);
if (str == NULL)
sstrncpy(buffer, str, buffer_size);
sstrncpy(buffer, str, buffer_size);
} /* }}} int luaC_tostringbuffer */
value_t luaC_tovalue(lua_State *L, int idx, int ds_type) /* {{{ */
} /* }}} int luaC_tostringbuffer */
value_t luaC_tovalue(lua_State *L, int idx, int ds_type) /* {{{ */
value_t v = {0};
if (!lua_isnumber(L, idx))
value_t v = {0};
if (!lua_isnumber(L, idx))
if (ds_type == DS_TYPE_GAUGE)
v.gauge = (gauge_t)lua_tonumber(L, /* stack pos = */ -1);
if (ds_type == DS_TYPE_GAUGE)
v.gauge = (gauge_t)lua_tonumber(L, /* stack pos = */ -1);
else if (ds_type == DS_TYPE_ABSOLUTE)
v.absolute = (absolute_t)lua_tointeger(L, /* stack pos = */ -1);
else if (ds_type == DS_TYPE_ABSOLUTE)
v.absolute = (absolute_t)lua_tointeger(L, /* stack pos = */ -1);
} /* }}} value_t luaC_tovalue */
value_list_t *luaC_tovaluelist(lua_State *L, int idx) /* {{{ */
} /* }}} value_t luaC_tovalue */
value_list_t *luaC_tovaluelist(lua_State *L, int idx) /* {{{ */
/* Check that idx is in the valid range */
if ((idx < 1) || (idx > lua_gettop(L))) {
DEBUG("luaC_tovaluelist: idx(%d), top(%d)", idx, stack_top_before);
/* Check that idx is in the valid range */
if ((idx < 1) || (idx > lua_gettop(L))) {
DEBUG("luaC_tovaluelist: idx(%d), top(%d)", idx, stack_top_before);
}
value_list_t *vl = calloc(1, sizeof(*vl));
if (vl == NULL) {
DEBUG("luaC_tovaluelist: calloc failed");
}
value_list_t *vl = calloc(1, sizeof(*vl));
if (vl == NULL) {
DEBUG("luaC_tovaluelist: calloc failed");
if (ds == NULL) {
INFO("utils_lua: Unable to lookup type \"%s\".", vl->type);
sfree(vl);
if (ds == NULL) {
INFO("utils_lua: Unable to lookup type \"%s\".", vl->type);
sfree(vl);
}
int status = ltoc_table_values(L, idx, ds, vl);
if (status != 0) {
WARNING("utils_lua: ltoc_table_values failed.");
sfree(vl);
}
int status = ltoc_table_values(L, idx, ds, vl);
if (status != 0) {
WARNING("utils_lua: ltoc_table_values failed.");
sfree(vl);
}
#if COLLECT_DEBUG
assert(stack_top_before == lua_gettop(L));
#endif
}
#if COLLECT_DEBUG
assert(stack_top_before == lua_gettop(L));
#endif
} /* }}} value_list_t *luaC_tovaluelist */
int luaC_pushcdtime(lua_State *L, cdtime_t t) /* {{{ */
} /* }}} value_list_t *luaC_tovaluelist */
int luaC_pushcdtime(lua_State *L, cdtime_t t) /* {{{ */
double d = CDTIME_T_TO_DOUBLE(t);
lua_pushnumber(L, (lua_Number)d);
double d = CDTIME_T_TO_DOUBLE(t);
lua_pushnumber(L, (lua_Number)d);
} /* }}} int luaC_pushcdtime */
int luaC_pushvalue(lua_State *L, value_t v, int ds_type) /* {{{ */
} /* }}} int luaC_pushcdtime */
int luaC_pushvalue(lua_State *L, value_t v, int ds_type) /* {{{ */
else if (ds_type == DS_TYPE_ABSOLUTE)
lua_pushinteger(L, (lua_Integer)v.absolute);
else
else if (ds_type == DS_TYPE_ABSOLUTE)
lua_pushinteger(L, (lua_Integer)v.absolute);
else
- return (-1);
- return (0);
} /* }}} int luaC_pushvalue */
int luaC_pushvaluelist(lua_State *L, const data_set_t *ds,
} /* }}} int luaC_pushvalue */
int luaC_pushvaluelist(lua_State *L, const data_set_t *ds,
luaC_pushcdtime(L, vl->interval);
lua_setfield(L, -2, "interval");
luaC_pushcdtime(L, vl->interval);
lua_setfield(L, -2, "interval");
} /* }}} int luaC_pushvaluelist */
} /* }}} int luaC_pushvaluelist */
size_t ret_len;
if ((begin < 0) || (end < 0) || (begin >= end))
size_t ret_len;
if ((begin < 0) || (end < 0) || (begin >= end))
if ((size_t)end > (strlen(str) + 1)) {
ERROR("utils_match: match_substr: `end' points after end of string.");
if ((size_t)end > (strlen(str) + 1)) {
ERROR("utils_match: match_substr: `end' points after end of string.");
}
ret_len = end - begin;
ret = malloc(ret_len + 1);
if (ret == NULL) {
ERROR("utils_match: match_substr: malloc failed.");
}
ret_len = end - begin;
ret = malloc(ret_len + 1);
if (ret == NULL) {
ERROR("utils_match: match_substr: malloc failed.");
}
sstrncpy(ret, str + begin, ret_len + 1);
}
sstrncpy(ret, str + begin, ret_len + 1);
} /* char *match_substr */
static int default_callback(const char __attribute__((unused)) * str,
} /* char *match_substr */
static int default_callback(const char __attribute__((unused)) * str,
if (data->ds_type & UTILS_MATCH_CF_GAUGE_INC) {
data->value.gauge = isnan(data->value.gauge) ? 1 : data->value.gauge + 1;
data->values_num++;
if (data->ds_type & UTILS_MATCH_CF_GAUGE_INC) {
data->value.gauge = isnan(data->value.gauge) ? 1 : data->value.gauge + 1;
data->values_num++;
value = (gauge_t)strtod(matches[1], &endptr);
if (matches[1] == endptr)
value = (gauge_t)strtod(matches[1], &endptr);
if (matches[1] == endptr)
if (data->ds_type & UTILS_MATCH_CF_GAUGE_DIST) {
latency_counter_add(data->latency, DOUBLE_TO_CDTIME_T(value));
data->values_num++;
if (data->ds_type & UTILS_MATCH_CF_GAUGE_DIST) {
latency_counter_add(data->latency, DOUBLE_TO_CDTIME_T(value));
data->values_num++;
}
if ((data->values_num == 0) ||
}
if ((data->values_num == 0) ||
data->value.gauge += value;
} else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
data->value.gauge += value;
} else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
if (data->ds_type & UTILS_MATCH_CF_COUNTER_INC) {
data->value.counter++;
data->values_num++;
if (data->ds_type & UTILS_MATCH_CF_COUNTER_INC) {
data->value.counter++;
data->values_num++;
value = (counter_t)strtoull(matches[1], &endptr, 0);
if (matches[1] == endptr)
value = (counter_t)strtoull(matches[1], &endptr, 0);
if (matches[1] == endptr)
if (data->ds_type & UTILS_MATCH_CF_COUNTER_SET)
data->value.counter = value;
if (data->ds_type & UTILS_MATCH_CF_COUNTER_SET)
data->value.counter = value;
data->value.counter += value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
data->value.counter += value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC) {
data->value.derive++;
data->values_num++;
if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC) {
data->value.derive++;
data->values_num++;
value = (derive_t)strtoll(matches[1], &endptr, 0);
if (matches[1] == endptr)
value = (derive_t)strtoll(matches[1], &endptr, 0);
if (matches[1] == endptr)
if (data->ds_type & UTILS_MATCH_CF_DERIVE_SET)
data->value.derive = value;
if (data->ds_type & UTILS_MATCH_CF_DERIVE_SET)
data->value.derive = value;
data->value.derive += value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
data->value.derive += value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
char *endptr = NULL;
if (matches_num < 2)
char *endptr = NULL;
if (matches_num < 2)
value = (absolute_t)strtoull(matches[1], &endptr, 0);
if (matches[1] == endptr)
value = (absolute_t)strtoull(matches[1], &endptr, 0);
if (matches[1] == endptr)
if (data->ds_type & UTILS_MATCH_CF_ABSOLUTE_SET)
data->value.absolute = value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
if (data->ds_type & UTILS_MATCH_CF_ABSOLUTE_SET)
data->value.absolute = value;
else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
}
data->values_num++;
} else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
}
data->values_num++;
} else {
ERROR("utils_match: default_callback: obj->ds_type is invalid!");
} /* int default_callback */
static void match_simple_free(void *data) {
} /* int default_callback */
static void match_simple_free(void *data) {
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
status = regcomp(&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
if (status != 0) {
ERROR("Compiling the regular expression \"%s\" failed.", regex);
sfree(obj);
status = regcomp(&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
if (status != 0) {
ERROR("Compiling the regular expression \"%s\" failed.", regex);
sfree(obj);
}
obj->flags |= UTILS_MATCH_FLAGS_REGEX;
}
obj->flags |= UTILS_MATCH_FLAGS_REGEX;
ERROR("Compiling the excluding regular expression \"%s\" failed.",
excluderegex);
sfree(obj);
ERROR("Compiling the excluding regular expression \"%s\" failed.",
excluderegex);
sfree(obj);
}
obj->flags |= UTILS_MATCH_FLAGS_EXCLUDE_REGEX;
}
}
obj->flags |= UTILS_MATCH_FLAGS_EXCLUDE_REGEX;
}
obj->user_data = user_data;
obj->free = free_user_data;
obj->user_data = user_data;
obj->free = free_user_data;
} /* cu_match_t *match_create_callback */
cu_match_t *match_create_simple(const char *regex, const char *excluderegex,
} /* cu_match_t *match_create_callback */
cu_match_t *match_create_simple(const char *regex, const char *excluderegex,
user_data = calloc(1, sizeof(*user_data));
if (user_data == NULL)
user_data = calloc(1, sizeof(*user_data));
if (user_data == NULL)
user_data->ds_type = match_ds_type;
if ((match_ds_type & UTILS_MATCH_DS_TYPE_GAUGE) &&
user_data->ds_type = match_ds_type;
if ((match_ds_type & UTILS_MATCH_DS_TYPE_GAUGE) &&
if (user_data->latency == NULL) {
ERROR("match_create_simple(): latency_counter_create() failed.");
free(user_data);
if (user_data->latency == NULL) {
ERROR("match_create_simple(): latency_counter_create() failed.");
free(user_data);
latency_counter_destroy(user_data->latency);
sfree(user_data);
latency_counter_destroy(user_data->latency);
sfree(user_data);
} /* cu_match_t *match_create_simple */
void match_value_reset(cu_match_value_t *mv) {
} /* cu_match_t *match_create_simple */
void match_value_reset(cu_match_value_t *mv) {
size_t matches_num;
if ((obj == NULL) || (str == NULL))
size_t matches_num;
if ((obj == NULL) || (str == NULL))
if (obj->flags & UTILS_MATCH_FLAGS_EXCLUDE_REGEX) {
status =
if (obj->flags & UTILS_MATCH_FLAGS_EXCLUDE_REGEX) {
status =
/* Regex did match, so exclude this line */
if (status == 0) {
DEBUG("ExludeRegex matched, don't count that line\n");
/* Regex did match, so exclude this line */
if (status == 0) {
DEBUG("ExludeRegex matched, don't count that line\n");
/* Regex did not match */
if (status != 0)
/* Regex did not match */
if (status != 0)
for (matches_num = 0; matches_num < STATIC_ARRAY_SIZE(matches);
matches_num++) {
for (matches_num = 0; matches_num < STATIC_ARRAY_SIZE(matches);
matches_num++) {
} /* int match_apply */
void *match_get_user_data(cu_match_t *obj) {
if (obj == NULL)
} /* int match_apply */
void *match_get_user_data(cu_match_t *obj) {
if (obj == NULL)
- return (NULL);
- return (obj->user_data);
+ return NULL;
+ return obj->user_data;
} /* void *match_get_user_data */
} /* void *match_get_user_data */
static unsigned char fromhex(char c) {
if (isdigit((int)c)) {
static unsigned char fromhex(char c) {
if (isdigit((int)c)) {
} else if (islower((int)c)) {
} else if (islower((int)c)) {
char *rc;
if (optstr == NULL) {
char *rc;
if (optstr == NULL) {
} else if (strncmp(optstr, "UUID=", 5) == 0) {
DEBUG("utils_mount: TODO: check UUID= code!");
rc = get_spec_by_uuid(optstr + 5);
} else if (strncmp(optstr, "UUID=", 5) == 0) {
DEBUG("utils_mount: TODO: check UUID= code!");
rc = get_spec_by_uuid(optstr + 5);
last->next = NULL;
} /* for(p = mntlist; p; p = p->next) */
last->next = NULL;
} /* for(p = mntlist; p; p = p->next) */
} /* cu_mount_t *cu_mount_listmntent(void) */
/* #endif HAVE_LISTMNTENT */
} /* cu_mount_t *cu_mount_listmntent(void) */
/* #endif HAVE_LISTMNTENT */
DEBUG("utils_mount: getv?fsstat failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
#endif /* COLLECT_DEBUG */
DEBUG("utils_mount: getv?fsstat failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
#endif /* COLLECT_DEBUG */
}
if ((buf = calloc(bufsize, sizeof(*buf))) == NULL)
}
if ((buf = calloc(bufsize, sizeof(*buf))) == NULL)
/* The bufsize needs to be passed in bytes. Really. This is not in the
* manpage.. -octo */
/* The bufsize needs to be passed in bytes. Really. This is not in the
* manpage.. -octo */
sstrerror(errno, errbuf, sizeof(errbuf)));
#endif /* COLLECT_DEBUG */
free(buf);
sstrerror(errno, errbuf, sizeof(errbuf)));
#endif /* COLLECT_DEBUG */
free(buf);
}
for (int i = 0; i < num; i++) {
}
for (int i = 0; i < num; i++) {
}
/* #endif HAVE_GETVFSSTAT || HAVE_GETFSSTAT */
}
/* #endif HAVE_GETVFSSTAT || HAVE_GETFSSTAT */
char errbuf[1024];
ERROR("fopen (%s): %s", COLLECTD_MNTTAB,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("fopen (%s): %s", COLLECTD_MNTTAB,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (getmntent(fp, &mt) == 0) {
}
while (getmntent(fp, &mt) == 0) {
} /* static cu_mount_t *cu_mount_gen_getmntent (void) */
/* #endif HAVE_TWO_GETMNTENT || HAVE_GEN_GETMNTENT || HAVE_SUN_GETMNTENT */
} /* static cu_mount_t *cu_mount_gen_getmntent (void) */
/* #endif HAVE_TWO_GETMNTENT || HAVE_GEN_GETMNTENT || HAVE_SUN_GETMNTENT */
char errbuf[1024];
ERROR("setmntent (%s): %s", COLLECTD_MNTTAB,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("setmntent (%s): %s", COLLECTD_MNTTAB,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (getmntent_r(fp, &me, mntbuf, sizeof(mntbuf))) {
}
while (getmntent_r(fp, &me, mntbuf, sizeof(mntbuf))) {
- DEBUG("utils_mount: return (0x%p)", (void *)first);
+ DEBUG("utils_mount: return 0x%p", (void *)first);
} /* HAVE_GETMNTENT_R */
#elif HAVE_ONE_GETMNTENT
} /* HAVE_GETMNTENT_R */
#elif HAVE_ONE_GETMNTENT
char errbuf[1024];
ERROR("setmntent (%s): %s", COLLECTD_MNTTAB,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("setmntent (%s): %s", COLLECTD_MNTTAB,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while ((me = getmntent(fp)) != NULL) {
}
while ((me = getmntent(fp)) != NULL) {
- DEBUG("utils_mount: return (0x%p)", (void *)first);
+ DEBUG("utils_mount: return 0x%p", (void *)first);
}
#endif /* HAVE_ONE_GETMNTENT */
}
#endif /* HAVE_ONE_GETMNTENT */
cu_mount_t *last = NULL;
if (list == NULL)
cu_mount_t *last = NULL;
if (list == NULL)
if (*list != NULL) {
first = *list;
if (*list != NULL) {
first = *list;
while ((last != NULL) && (last->next != NULL))
last = last->next;
while ((last != NULL) && (last->next != NULL))
last = last->next;
} /* cu_mount_t *cu_mount_getlist(cu_mount_t **list) */
void cu_mount_freelist(cu_mount_t *list) {
} /* cu_mount_t *cu_mount_getlist(cu_mount_t **list) */
void cu_mount_freelist(cu_mount_t *list) {
OK(NULL == cu_mount_checkoption(line_bool, "tw", 1));
OK(NULL == cu_mount_checkoption(line_bool, "thr", 1));
OK(NULL == cu_mount_checkoption(line_bool, "tw", 1));
OK(NULL == cu_mount_checkoption(line_bool, "thr", 1));
}
DEF_TEST(cu_mount_getoptionvalue) {
char line_opts[] = "foo=one,bar=two,qux=three";
}
DEF_TEST(cu_mount_getoptionvalue) {
char line_opts[] = "foo=one,bar=two,qux=three";
OK(NULL == (v = cu_mount_getoptionvalue(line_bool, "four")));
sfree(v);
OK(NULL == (v = cu_mount_getoptionvalue(line_bool, "four")));
sfree(v);
pthread_mutex_lock(&pdb->poll_thread.mutex);
state = pdb->poll_thread.state;
pthread_mutex_unlock(&pdb->poll_thread.mutex);
pthread_mutex_lock(&pdb->poll_thread.mutex);
state = pdb->poll_thread.state;
pthread_mutex_unlock(&pdb->poll_thread.mutex);
- return (state == OVS_DB_POLL_STATE_RUNNING);
+ return state == OVS_DB_POLL_STATE_RUNNING;
}
/* Generate unique identifier (UID). It is used by OVS DB API
}
/* Generate unique identifier (UID). It is used by OVS DB API
while (rem > 0) {
if ((nbytes = send(pdb->sock, data + off, rem, 0)) <= 0)
while (rem > 0) {
if ((nbytes = send(pdb->sock, data + off, rem, 0)) <= 0)
rem -= (size_t)nbytes;
off += (size_t)nbytes;
}
rem -= (size_t)nbytes;
off += (size_t)nbytes;
}
*/
static yajl_gen_status ovs_yajl_gen_tstring(yajl_gen hander,
const char *string) {
*/
static yajl_gen_status ovs_yajl_gen_tstring(yajl_gen hander,
const char *string) {
- return yajl_gen_string(hander, (const unsigned char *)string, strlen(string));
+ return yajl_gen_string(hander, (const unsigned char *)string,
+ strlen(string));
}
/* Add YAJL value into YAJL generator handle (JSON object)
}
/* Add YAJL value into YAJL generator handle (JSON object)
yajl_gen_status yajl_gen_ret;
if ((jgen = yajl_gen_alloc(NULL)) == NULL)
yajl_gen_status yajl_gen_ret;
if ((jgen = yajl_gen_alloc(NULL)) == NULL)
/* check & get request attributes */
if ((jparams = yajl_tree_get(jnode, params_path, yajl_t_array)) == NULL ||
/* check & get request attributes */
if ((jparams = yajl_tree_get(jnode, params_path, yajl_t_array)) == NULL ||
}
/* clean up and return success */
yajl_gen_clear(jgen);
}
/* clean up and return success */
yajl_gen_clear(jgen);
yajl_gen_failure:
/* release memory */
yajl_gen_clear(jgen);
yajl_gen_failure:
/* release memory */
yajl_gen_clear(jgen);
}
/* Get OVS DB registered callback by YAJL val. The YAJL
}
/* Get OVS DB registered callback by YAJL val. The YAJL
if ((jparams = yajl_tree_get(jnode, params_path, yajl_t_array)) == NULL ||
(yajl_tree_get(jnode, id_path, yajl_t_null) == NULL)) {
OVS_ERROR("invalid OVS DB request received");
if ((jparams = yajl_tree_get(jnode, params_path, yajl_t_array)) == NULL ||
(yajl_tree_get(jnode, id_path, yajl_t_null) == NULL)) {
OVS_ERROR("invalid OVS DB request received");
}
/* check array length: [<json-value>, <table-updates>] */
if ((YAJL_GET_ARRAY(jparams) == NULL) ||
(YAJL_GET_ARRAY(jparams)->len != 2)) {
OVS_ERROR("invalid OVS DB request received");
}
/* check array length: [<json-value>, <table-updates>] */
if ((YAJL_GET_ARRAY(jparams) == NULL) ||
(YAJL_GET_ARRAY(jparams)->len != 2)) {
OVS_ERROR("invalid OVS DB request received");
}
jvalue = YAJL_GET_ARRAY(jparams)->values[0];
jtable_updates = YAJL_GET_ARRAY(jparams)->values[1];
if ((!YAJL_IS_OBJECT(jtable_updates)) || (!YAJL_IS_STRING(jvalue))) {
OVS_ERROR("invalid OVS DB request id or table update received");
}
jvalue = YAJL_GET_ARRAY(jparams)->values[0];
jtable_updates = YAJL_GET_ARRAY(jparams)->values[1];
if ((!YAJL_IS_OBJECT(jtable_updates)) || (!YAJL_IS_STRING(jvalue))) {
OVS_ERROR("invalid OVS DB request id or table update received");
}
/* find registered callback based on <json-value> */
}
/* find registered callback based on <json-value> */
if (cb == NULL || cb->table.call == NULL) {
OVS_ERROR("No OVS DB table update callback found");
pthread_mutex_unlock(&pdb->mutex);
if (cb == NULL || cb->table.call == NULL) {
OVS_ERROR("No OVS DB table update callback found");
pthread_mutex_unlock(&pdb->mutex);
}
/* call registered callback */
}
/* call registered callback */
/* check & get result attributes */
if (!jresult || !jerror || !jid)
/* check & get result attributes */
if (!jresult || !jerror || !jid)
/* try to find registered callback */
pthread_mutex_lock(&pdb->mutex);
/* try to find registered callback */
pthread_mutex_lock(&pdb->mutex);
}
pthread_mutex_unlock(&pdb->mutex);
}
pthread_mutex_unlock(&pdb->mutex);
}
/* Handle JSON data (one request) and call
}
/* Handle JSON data (one request) and call
/* duplicate the data to make null-terminated string
* required for yajl_tree_parse() */
if ((sjson = calloc(1, len + 1)) == NULL)
/* duplicate the data to make null-terminated string
* required for yajl_tree_parse() */
if ((sjson = calloc(1, len + 1)) == NULL)
sstrncpy(sjson, data, len + 1);
OVS_DEBUG("[len=%zu] %s", len, sjson);
sstrncpy(sjson, data, len + 1);
OVS_DEBUG("[len=%zu] %s", len, sjson);
if (jnode == NULL) {
OVS_ERROR("yajl_tree_parse() %s", yajl_errbuf);
sfree(sjson);
if (jnode == NULL) {
OVS_ERROR("yajl_tree_parse() %s", yajl_errbuf);
sfree(sjson);
if ((method = YAJL_GET_STRING(jval)) == NULL) {
yajl_tree_free(jnode);
sfree(sjson);
if ((method = YAJL_GET_STRING(jval)) == NULL) {
yajl_tree_free(jnode);
sfree(sjson);
}
if (strcmp("echo", method) == 0) {
/* echo request from the server */
}
if (strcmp("echo", method) == 0) {
/* echo request from the server */
/* release memory */
yajl_tree_free(jnode);
sfree(sjson);
/* release memory */
yajl_tree_free(jnode);
sfree(sjson);
/* allocate new chunk of memory */
new_buff = realloc(jreader->buff_ptr, (jreader->buff_size + data_len));
if (new_buff == NULL)
/* allocate new chunk of memory */
new_buff = realloc(jreader->buff_ptr, (jreader->buff_size + data_len));
if (new_buff == NULL)
/* point to new allocated memory */
jreader->buff_ptr = new_buff;
/* point to new allocated memory */
jreader->buff_ptr = new_buff;
/* store input data */
memcpy(jreader->buff_ptr + jreader->buff_offset, data, data_len);
jreader->buff_offset += data_len;
/* store input data */
memcpy(jreader->buff_ptr + jreader->buff_offset, data, data_len);
jreader->buff_offset += data_len;
}
/* Pop one fully-fledged JSON if already exists. Returns 0 if
}
/* Pop one fully-fledged JSON if already exists. Returns 0 if
*json_ptr = jreader->buff_ptr + jreader->json_offset;
*json_len_ptr = json_len + 1;
jreader->json_offset = i + 1;
*json_ptr = jreader->buff_ptr + jreader->json_offset;
*json_len_ptr = json_len + 1;
jreader->json_offset = i + 1;
}
/* increase JSON data length */
}
/* increase JSON data length */
jreader->json_offset = 0;
}
jreader->json_offset = 0;
}
}
/* Reset JSON reader. It is useful when start processing
}
/* Reset JSON reader. It is useful when start processing
/* create JSON reader instance */
if ((jreader = ovs_json_reader_alloc()) == NULL) {
OVS_ERROR("initialize json reader failed");
/* create JSON reader instance */
if ((jreader = ovs_json_reader_alloc()) == NULL) {
OVS_ERROR("initialize json reader failed");
OVS_DEBUG("poll thread has been completed");
ovs_json_reader_free(jreader);
OVS_DEBUG("poll thread has been completed");
ovs_json_reader_free(jreader);
}
/* EVENT worker thread.
}
/* EVENT worker thread.
}
OVS_DEBUG("event thread has been completed");
}
OVS_DEBUG("event thread has been completed");
}
/* Initialize EVENT thread */
}
/* Initialize EVENT thread */
pdb->event_thread.tid = (pthread_t)-1;
/* init event thread condition variable */
if (pthread_cond_init(&pdb->event_thread.cond, NULL)) {
pdb->event_thread.tid = (pthread_t)-1;
/* init event thread condition variable */
if (pthread_cond_init(&pdb->event_thread.cond, NULL)) {
}
/* init event thread mutex */
if (pthread_mutex_init(&pdb->event_thread.mutex, NULL)) {
pthread_cond_destroy(&pdb->event_thread.cond);
}
/* init event thread mutex */
if (pthread_mutex_init(&pdb->event_thread.mutex, NULL)) {
pthread_cond_destroy(&pdb->event_thread.cond);
}
/* Hold the event thread mutex. It ensures that no events
* will be lost while thread is still starting. Once event
}
/* Hold the event thread mutex. It ensures that no events
* will be lost while thread is still starting. Once event
if (pthread_mutex_lock(&pdb->event_thread.mutex)) {
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
if (pthread_mutex_lock(&pdb->event_thread.mutex)) {
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
}
/* start event thread */
pthread_t tid;
}
/* start event thread */
pthread_t tid;
pthread_mutex_unlock(&pdb->event_thread.mutex);
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
pthread_mutex_unlock(&pdb->event_thread.mutex);
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
}
pdb->event_thread.tid = tid;
}
pdb->event_thread.tid = tid;
}
/* Destroy EVENT thread */
static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
if (pdb->event_thread.tid == (pthread_t)-1)
/* already destroyed */
}
/* Destroy EVENT thread */
static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
if (pdb->event_thread.tid == (pthread_t)-1)
/* already destroyed */
ovs_db_event_post(pdb, OVS_DB_EVENT_TERMINATE);
if (pthread_join(pdb->event_thread.tid, NULL) != 0)
ovs_db_event_post(pdb, OVS_DB_EVENT_TERMINATE);
if (pthread_join(pdb->event_thread.tid, NULL) != 0)
/* Event thread always holds the thread mutex when
* performs some task (handles event) and releases it when
* while sleeping. Thus, if event thread exits, the mutex
/* Event thread always holds the thread mutex when
* performs some task (handles event) and releases it when
* while sleeping. Thus, if event thread exits, the mutex
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
pdb->event_thread.tid = (pthread_t)-1;
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
pdb->event_thread.tid = (pthread_t)-1;
}
/* Initialize POLL thread */
}
/* Initialize POLL thread */
pdb->poll_thread.tid = (pthread_t)-1;
/* init event thread mutex */
if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) {
pdb->poll_thread.tid = (pthread_t)-1;
/* init event thread mutex */
if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) {
}
/* start poll thread */
pthread_t tid;
}
/* start poll thread */
pthread_t tid;
if (plugin_thread_create(&tid, NULL, ovs_poll_worker, pdb,
"utils_ovs:poll") != 0) {
pthread_mutex_destroy(&pdb->poll_thread.mutex);
if (plugin_thread_create(&tid, NULL, ovs_poll_worker, pdb,
"utils_ovs:poll") != 0) {
pthread_mutex_destroy(&pdb->poll_thread.mutex);
}
pdb->poll_thread.tid = tid;
}
pdb->poll_thread.tid = tid;
}
/* Destroy POLL thread */
static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
if (pdb->poll_thread.tid == (pthread_t)-1)
/* already destroyed */
}
/* Destroy POLL thread */
static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
if (pdb->poll_thread.tid == (pthread_t)-1)
/* already destroyed */
/* change thread state */
pthread_mutex_lock(&pdb->poll_thread.mutex);
pdb->poll_thread.state = OVS_DB_POLL_STATE_EXITING;
pthread_mutex_unlock(&pdb->poll_thread.mutex);
/* join the thread */
if (pthread_join(pdb->poll_thread.tid, NULL) != 0)
/* change thread state */
pthread_mutex_lock(&pdb->poll_thread.mutex);
pdb->poll_thread.state = OVS_DB_POLL_STATE_EXITING;
pthread_mutex_unlock(&pdb->poll_thread.mutex);
/* join the thread */
if (pthread_join(pdb->poll_thread.tid, NULL) != 0)
pthread_mutex_destroy(&pdb->poll_thread.mutex);
pdb->poll_thread.tid = (pthread_t)-1;
pthread_mutex_destroy(&pdb->poll_thread.mutex);
pdb->poll_thread.tid = (pthread_t)-1;
const char *unix_path, ovs_db_callback_t *cb) {
/* sanity check */
if (node == NULL || service == NULL || unix_path == NULL)
const char *unix_path, ovs_db_callback_t *cb) {
/* sanity check */
if (node == NULL || service == NULL || unix_path == NULL)
/* allocate db data & fill it */
ovs_db_t *pdb = pdb = calloc(1, sizeof(*pdb));
if (pdb == NULL)
/* allocate db data & fill it */
ovs_db_t *pdb = pdb = calloc(1, sizeof(*pdb));
if (pdb == NULL)
/* store the OVS DB address */
sstrncpy(pdb->node, node, sizeof(pdb->node));
/* store the OVS DB address */
sstrncpy(pdb->node, node, sizeof(pdb->node));
if (pthread_mutexattr_init(&mutex_attr)) {
OVS_ERROR("OVS DB mutex attribute init failed");
sfree(pdb);
if (pthread_mutexattr_init(&mutex_attr)) {
OVS_ERROR("OVS DB mutex attribute init failed");
sfree(pdb);
}
/* set OVS DB mutex as recursive */
if (pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE)) {
OVS_ERROR("Failed to set OVS DB mutex as recursive");
pthread_mutexattr_destroy(&mutex_attr);
sfree(pdb);
}
/* set OVS DB mutex as recursive */
if (pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE)) {
OVS_ERROR("Failed to set OVS DB mutex as recursive");
pthread_mutexattr_destroy(&mutex_attr);
sfree(pdb);
}
/* init OVS DB mutex */
if (pthread_mutex_init(&pdb->mutex, &mutex_attr)) {
OVS_ERROR("OVS DB mutex init failed");
pthread_mutexattr_destroy(&mutex_attr);
sfree(pdb);
}
/* init OVS DB mutex */
if (pthread_mutex_init(&pdb->mutex, &mutex_attr)) {
OVS_ERROR("OVS DB mutex init failed");
pthread_mutexattr_destroy(&mutex_attr);
sfree(pdb);
}
/* destroy mutex attributes */
pthread_mutexattr_destroy(&mutex_attr);
}
/* destroy mutex attributes */
pthread_mutexattr_destroy(&mutex_attr);
/* init event thread */
if (ovs_db_event_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
/* init event thread */
if (ovs_db_event_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
}
/* init polling thread */
pdb->sock = -1;
if (ovs_db_poll_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
}
/* init polling thread */
pdb->sock = -1;
if (ovs_db_poll_thread_init(pdb) < 0) {
ovs_db_destroy(pdb);
/* sanity check */
if (!pdb || !method || !params)
/* sanity check */
if (!pdb || !method || !params)
if ((jgen = yajl_gen_alloc(NULL)) == NULL)
if ((jgen = yajl_gen_alloc(NULL)) == NULL)
/* try to parse params */
if ((jparams = yajl_tree_parse(params, NULL, 0)) == NULL) {
OVS_ERROR("params is not a JSON string");
yajl_gen_clear(jgen);
/* try to parse params */
if ((jparams = yajl_tree_parse(params, NULL, 0)) == NULL) {
OVS_ERROR("params is not a JSON string");
yajl_gen_clear(jgen);
}
/* generate method field */
}
/* generate method field */
/* sanity check */
if (pdb == NULL || tb_name == NULL || update_cb == NULL)
/* sanity check */
if (pdb == NULL || tb_name == NULL || update_cb == NULL)
/* allocate new update callback */
if ((new_cb = calloc(1, sizeof(ovs_callback_t))) == NULL)
/* allocate new update callback */
if ((new_cb = calloc(1, sizeof(ovs_callback_t))) == NULL)
/* init YAJL generator */
if ((jgen = yajl_gen_alloc(NULL)) == NULL) {
sfree(new_cb);
/* init YAJL generator */
if ((jgen = yajl_gen_alloc(NULL)) == NULL) {
sfree(new_cb);
}
/* add new callback to front */
}
/* add new callback to front */
/* sanity check */
if (pdb == NULL)
/* sanity check */
if (pdb == NULL)
/* try to lock the structure before releasing */
if ((ret = pthread_mutex_lock(&pdb->mutex))) {
OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret);
/* try to lock the structure before releasing */
if ((ret = pthread_mutex_lock(&pdb->mutex))) {
OVS_ERROR("pthread_mutex_lock() DB mutex lock failed (%d)", ret);
while (isspace((int)*string))
string++;
if (*string == 0)
while (isspace((int)*string))
string++;
if (*string == 0)
/* A quoted string */
if (*string == '"') {
/* A quoted string */
if (*string == '"') {
string++;
if (*string == 0)
string++;
if (*string == 0)
dst = string;
buffer = string;
dst = string;
buffer = string;
buffer++;
/* Catch a backslash at the end of buffer */
if (*buffer == 0)
buffer++;
/* Catch a backslash at the end of buffer */
if (*buffer == 0)
}
*dst = *buffer;
buffer++;
}
*dst = *buffer;
buffer++;
}
/* No quote sign has been found */
if (*buffer == 0)
}
/* No quote sign has been found */
if (*buffer == 0)
/* Check for trailing spaces. */
if ((*buffer != 0) && !isspace((int)*buffer))
/* Check for trailing spaces. */
if ((*buffer != 0) && !isspace((int)*buffer))
} else /* an unquoted string */
{
buffer = string;
} else /* an unquoted string */
{
buffer = string;
*ret_buffer = buffer;
*ret_string = string;
*ret_buffer = buffer;
*ret_string = string;
} /* int parse_string */
/*
} /* int parse_string */
/*
while (isspace((int)*key))
key++;
if (*key == 0)
while (isspace((int)*key))
key++;
if (*key == 0)
/* Look for the equal sign */
buffer = key;
while (isalnum((int)*buffer) || *buffer == '_' || *buffer == ':')
buffer++;
if ((*buffer != '=') || (buffer == key))
/* Look for the equal sign */
buffer = key;
while (isalnum((int)*buffer) || *buffer == '_' || *buffer == ':')
buffer++;
if ((*buffer != '=') || (buffer == key))
*buffer = 0;
buffer++;
/* Empty values must be written as "" */
if (isspace((int)*buffer) || (*buffer == 0))
*buffer = 0;
buffer++;
/* Empty values must be written as "" */
if (isspace((int)*buffer) || (*buffer == 0))
status = parse_string(&buffer, &value);
if (status != 0)
status = parse_string(&buffer, &value);
if (status != 0)
/* NB: parse_string will have eaten up all trailing spaces. */
/* NB: parse_string will have eaten up all trailing spaces. */
*ret_key = key;
*ret_value = value;
*ret_key = key;
*ret_value = value;
args = calloc(1, sizeof(*args));
if (args == NULL) {
ERROR("srrd_create_args_create: calloc failed.");
args = calloc(1, sizeof(*args));
if (args == NULL) {
ERROR("srrd_create_args_create: calloc failed.");
}
args->filename = NULL;
args->pdp_step = pdp_step;
}
args->filename = NULL;
args->pdp_step = pdp_step;
if (args->filename == NULL) {
ERROR("srrd_create_args_create: strdup failed.");
srrd_create_args_destroy(args);
if (args->filename == NULL) {
ERROR("srrd_create_args_create: strdup failed.");
srrd_create_args_destroy(args);
}
args->argv = calloc((size_t)(argc + 1), sizeof(*args->argv));
if (args->argv == NULL) {
ERROR("srrd_create_args_create: calloc failed.");
srrd_create_args_destroy(args);
}
args->argv = calloc((size_t)(argc + 1), sizeof(*args->argv));
if (args->argv == NULL) {
ERROR("srrd_create_args_create: calloc failed.");
srrd_create_args_destroy(args);
}
for (args->argc = 0; args->argc < argc; args->argc++) {
}
for (args->argc = 0; args->argc < argc; args->argc++) {
if (args->argv[args->argc] == NULL) {
ERROR("srrd_create_args_create: strdup failed.");
srrd_create_args_destroy(args);
if (args->argv[args->argc] == NULL) {
ERROR("srrd_create_args_create: strdup failed.");
srrd_create_args_destroy(args);
}
}
assert(args->argc == argc);
args->argv[args->argc] = NULL;
}
}
assert(args->argc == argc);
args->argv[args->argc] = NULL;
} /* srrd_create_args_t *srrd_create_args_create */
/* * * * * * * * * *
} /* srrd_create_args_t *srrd_create_args_create */
/* * * * * * * * * *
if (cfg->rrarows <= 0) {
*ret = NULL;
if (cfg->rrarows <= 0) {
*ret = NULL;
}
if ((cfg->xff < 0) || (cfg->xff >= 1.0)) {
*ret = NULL;
}
if ((cfg->xff < 0) || (cfg->xff >= 1.0)) {
*ret = NULL;
ss = (int)CDTIME_T_TO_TIME_T(vl->interval);
if (ss <= 0) {
*ret = NULL;
ss = (int)CDTIME_T_TO_TIME_T(vl->interval);
if (ss <= 0) {
*ret = NULL;
}
/* Use the configured timespans or fall back to the built-in defaults */
}
/* Use the configured timespans or fall back to the built-in defaults */
assert(rra_max > 0);
if ((rra_def = calloc(rra_max + 1, sizeof(*rra_def))) == NULL)
assert(rra_max > 0);
if ((rra_def = calloc(rra_max + 1, sizeof(*rra_def))) == NULL)
rra_num = 0;
cdp_len = 0;
rra_num = 0;
cdp_len = 0;
if (rra_num <= 0) {
sfree(rra_def);
if (rra_num <= 0) {
sfree(rra_def);
} /* }}} int rra_get */
static void ds_free(int ds_num, char **ds_def) /* {{{ */
} /* }}} int rra_get */
static void ds_free(int ds_num, char **ds_def) /* {{{ */
char errbuf[1024];
ERROR("rrdtool plugin: calloc failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("rrdtool plugin: calloc failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
for (ds_num = 0; ds_num < ds->ds_num; ds_num++) {
}
for (ds_num = 0; ds_num < ds->ds_num; ds_num++) {
if (ds_num != ds->ds_num) {
ds_free(ds_num, ds_def);
if (ds_num != ds->ds_num) {
ds_free(ds_num, ds_def);
}
if (ds_num == 0) {
sfree(ds_def);
}
if (ds_num == 0) {
sfree(ds_def);
} /* }}} int ds_get */
#if HAVE_THREADSAFE_LIBRRD
} /* }}} int ds_get */
#if HAVE_THREADSAFE_LIBRRD
char *filename_copy;
if ((filename == NULL) || (argv == NULL))
char *filename_copy;
if ((filename == NULL) || (argv == NULL))
/* Some versions of librrd don't have the `const' qualifier for the first
* argument, so we have to copy the pointer here to avoid warnings. It sucks,
/* Some versions of librrd don't have the `const' qualifier for the first
* argument, so we have to copy the pointer here to avoid warnings. It sucks,
filename_copy = strdup(filename);
if (filename_copy == NULL) {
ERROR("srrd_create: strdup failed.");
filename_copy = strdup(filename);
if (filename_copy == NULL) {
ERROR("srrd_create: strdup failed.");
}
optind = 0; /* bug in librrd? */
}
optind = 0; /* bug in librrd? */
} /* }}} int srrd_create */
/* #endif HAVE_THREADSAFE_LIBRRD */
} /* }}} int srrd_create */
/* #endif HAVE_THREADSAFE_LIBRRD */
new_argv = malloc((new_argc + 1) * sizeof(*new_argv));
if (new_argv == NULL) {
ERROR("rrdtool plugin: malloc failed.");
new_argv = malloc((new_argc + 1) * sizeof(*new_argv));
if (new_argv == NULL) {
ERROR("rrdtool plugin: malloc failed.");
} /* }}} int srrd_create */
#endif /* !HAVE_THREADSAFE_LIBRRD */
} /* }}} int srrd_create */
#endif /* !HAVE_THREADSAFE_LIBRRD */
if (ptr != NULL) {
pthread_mutex_unlock(&async_creation_lock);
if (ptr != NULL) {
pthread_mutex_unlock(&async_creation_lock);
}
status = stat(filename, &sb);
if ((status == 0) || (errno != ENOENT)) {
pthread_mutex_unlock(&async_creation_lock);
}
status = stat(filename, &sb);
if ((status == 0) || (errno != ENOENT)) {
pthread_mutex_unlock(&async_creation_lock);
}
ptr = malloc(sizeof(*ptr));
if (ptr == NULL) {
pthread_mutex_unlock(&async_creation_lock);
}
ptr = malloc(sizeof(*ptr));
if (ptr == NULL) {
pthread_mutex_unlock(&async_creation_lock);
}
ptr->filename = strdup(filename);
if (ptr->filename == NULL) {
pthread_mutex_unlock(&async_creation_lock);
sfree(ptr);
}
ptr->filename = strdup(filename);
if (ptr->filename == NULL) {
pthread_mutex_unlock(&async_creation_lock);
sfree(ptr);
}
ptr->next = async_creation_list;
}
ptr->next = async_creation_list;
pthread_mutex_unlock(&async_creation_lock);
pthread_mutex_unlock(&async_creation_lock);
} /* }}} int lock_file */
static int unlock_file(char const *filename) /* {{{ */
} /* }}} int lock_file */
static int unlock_file(char const *filename) /* {{{ */
if (this == NULL) {
pthread_mutex_unlock(&async_creation_lock);
if (this == NULL) {
pthread_mutex_unlock(&async_creation_lock);
sfree(this->filename);
sfree(this);
sfree(this->filename);
sfree(this);
} /* }}} int unlock_file */
static void *srrd_create_thread(void *targs) /* {{{ */
} /* }}} int unlock_file */
static void *srrd_create_thread(void *targs) /* {{{ */
else
ERROR("srrd_create_thread: Unable to lock file \"%s\".", args->filename);
srrd_create_args_destroy(args);
else
ERROR("srrd_create_thread: Unable to lock file \"%s\".", args->filename);
srrd_create_args_destroy(args);
}
ssnprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename);
}
ssnprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename);
unlink(tmpfile);
unlock_file(args->filename);
srrd_create_args_destroy(args);
unlink(tmpfile);
unlock_file(args->filename);
srrd_create_args_destroy(args);
}
status = rename(tmpfile, args->filename);
}
status = rename(tmpfile, args->filename);
unlink(tmpfile);
unlock_file(args->filename);
srrd_create_args_destroy(args);
unlink(tmpfile);
unlock_file(args->filename);
srrd_create_args_destroy(args);
}
DEBUG("srrd_create_thread: Successfully created RRD file \"%s\".",
}
DEBUG("srrd_create_thread: Successfully created RRD file \"%s\".",
unlock_file(args->filename);
srrd_create_args_destroy(args);
unlock_file(args->filename);
srrd_create_args_destroy(args);
} /* }}} void *srrd_create_thread */
static int srrd_create_async(const char *filename, /* {{{ */
} /* }}} void *srrd_create_thread */
static int srrd_create_async(const char *filename, /* {{{ */
args = srrd_create_args_create(filename, pdp_step, last_up, argc, argv);
if (args == NULL)
args = srrd_create_args_create(filename, pdp_step, last_up, argc, argv);
if (args == NULL)
status = pthread_attr_init(&attr);
if (status != 0) {
srrd_create_args_destroy(args);
status = pthread_attr_init(&attr);
if (status != 0) {
srrd_create_args_destroy(args);
}
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (status != 0) {
pthread_attr_destroy(&attr);
srrd_create_args_destroy(args);
}
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (status != 0) {
pthread_attr_destroy(&attr);
srrd_create_args_destroy(args);
}
status = pthread_create(&thread, &attr, srrd_create_thread, args);
}
status = pthread_create(&thread, &attr, srrd_create_thread, args);
sstrerror(status, errbuf, sizeof(errbuf)));
pthread_attr_destroy(&attr);
srrd_create_args_destroy(args);
sstrerror(status, errbuf, sizeof(errbuf)));
pthread_attr_destroy(&attr);
srrd_create_args_destroy(args);
}
pthread_attr_destroy(&attr);
/* args is freed in srrd_create_thread(). */
}
pthread_attr_destroy(&attr);
/* args is freed in srrd_create_thread(). */
} /* }}} int srrd_create_async */
/*
} /* }}} int srrd_create_async */
/*
unsigned long stepsize;
if (check_create_dir(filename))
unsigned long stepsize;
if (check_create_dir(filename))
if ((rra_num = rra_get(&rra_def, vl, cfg)) < 1) {
ERROR("cu_rrd_create_file failed: Could not calculate RRAs");
if ((rra_num = rra_get(&rra_def, vl, cfg)) < 1) {
ERROR("cu_rrd_create_file failed: Could not calculate RRAs");
}
if ((ds_num = ds_get(&ds_def, ds, vl, cfg)) < 1) {
ERROR("cu_rrd_create_file failed: Could not calculate DSes");
rra_free(rra_num, rra_def);
}
if ((ds_num = ds_get(&ds_def, ds, vl, cfg)) < 1) {
ERROR("cu_rrd_create_file failed: Could not calculate DSes");
rra_free(rra_num, rra_def);
}
argc = ds_num + rra_num;
}
argc = ds_num + rra_num;
sstrerror(errno, errbuf, sizeof(errbuf)));
rra_free(rra_num, rra_def);
ds_free(ds_num, ds_def);
sstrerror(errno, errbuf, sizeof(errbuf)));
rra_free(rra_num, rra_def);
ds_free(ds_num, ds_def);
}
memcpy(argv, ds_def, ds_num * sizeof(char *));
}
memcpy(argv, ds_def, ds_num * sizeof(char *));
ds_free(ds_num, ds_def);
rra_free(rra_num, rra_def);
ds_free(ds_num, ds_def);
rra_free(rra_num, rra_def);
} /* }}} int cu_rrd_create_file */
} /* }}} int cu_rrd_create_file */
char errbuf[1024];
ERROR("utils_tail: stat (%s) failed: %s", obj->file,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("utils_tail: stat (%s) failed: %s", obj->file,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
/* The file is already open.. */
}
/* The file is already open.. */
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(obj->fh);
obj->fh = NULL;
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(obj->fh);
obj->fh = NULL;
}
}
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
}
}
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
}
/* Seek to the end if we re-open the same file again or the file opened
}
/* Seek to the end if we re-open the same file again or the file opened
char errbuf[1024];
ERROR("utils_tail: fopen (%s) failed: %s", obj->file,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("utils_tail: fopen (%s) failed: %s", obj->file,
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("utils_tail: fseek (%s) failed: %s", obj->file,
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(fh);
ERROR("utils_tail: fseek (%s) failed: %s", obj->file,
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(fh);
obj->fh = fh;
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
obj->fh = fh;
memcpy(&obj->stat, &stat_buf, sizeof(struct stat));
} /* int cu_tail_reopen */
cu_tail_t *cu_tail_create(const char *file) {
} /* int cu_tail_reopen */
cu_tail_t *cu_tail_create(const char *file) {
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
obj->file = strdup(file);
if (obj->file == NULL) {
free(obj);
obj->file = strdup(file);
if (obj->file == NULL) {
free(obj);
} /* cu_tail_t *cu_tail_create */
int cu_tail_destroy(cu_tail_t *obj) {
} /* cu_tail_t *cu_tail_create */
int cu_tail_destroy(cu_tail_t *obj) {
free(obj->file);
free(obj);
free(obj->file);
free(obj);
} /* int cu_tail_destroy */
int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) {
} /* int cu_tail_destroy */
int cu_tail_readline(cu_tail_t *obj, char *buf, int buflen) {
if (buflen < 1) {
ERROR("utils_tail: cu_tail_readline: buflen too small: %i bytes.", buflen);
if (buflen < 1) {
ERROR("utils_tail: cu_tail_readline: buflen too small: %i bytes.", buflen);
}
if (obj->fh == NULL) {
status = cu_tail_reopen(obj);
if (status < 0)
}
if (obj->fh == NULL) {
status = cu_tail_reopen(obj);
if (status < 0)
}
assert(obj->fh != NULL);
}
assert(obj->fh != NULL);
clearerr(obj->fh);
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
clearerr(obj->fh);
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
}
/* Check if we encountered an error */
}
/* Check if we encountered an error */
status = cu_tail_reopen(obj);
/* error -> return with error */
if (status < 0)
status = cu_tail_reopen(obj);
/* error -> return with error */
if (status < 0)
/* file end reached and file not reopened -> nothing more to read */
else if (status > 0) {
buf[0] = 0;
/* file end reached and file not reopened -> nothing more to read */
else if (status > 0) {
buf[0] = 0;
}
/* If we get here: file was re-opened and there may be more to read.. Let's
* try again. */
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
}
/* If we get here: file was re-opened and there may be more to read.. Let's
* try again. */
if (fgets(buf, buflen, obj->fh) != NULL) {
buf[buflen - 1] = 0;
}
if (ferror(obj->fh) != 0) {
}
if (ferror(obj->fh) != 0) {
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(obj->fh);
obj->fh = NULL;
sstrerror(errno, errbuf, sizeof(errbuf)));
fclose(obj->fh);
obj->fh = NULL;
}
/* EOf, well, apparently the new file is empty.. */
buf[0] = 0;
}
/* EOf, well, apparently the new file is empty.. */
buf[0] = 0;
} /* int cu_tail_readline */
int cu_tail_read(cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
} /* int cu_tail_readline */
int cu_tail_read(cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback,
match_value = (cu_match_value_t *)match_get_user_data(match);
if (match_value == NULL)
match_value = (cu_match_value_t *)match_get_user_data(match);
if (match_value == NULL)
if ((match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) &&
(match_value->values_num == 0))
if ((match_value->ds_type & UTILS_MATCH_DS_TYPE_GAUGE) &&
(match_value->values_num == 0))
plugin_dispatch_values(&vl);
match_value_reset(match_value);
plugin_dispatch_values(&vl);
match_value_reset(match_value);
} /* int simple_submit_match */
static int latency_submit_match(cu_match_t *match, void *user_data) {
} /* int simple_submit_match */
static int latency_submit_match(cu_match_t *match, void *user_data) {
match_value = (cu_match_value_t *)match_get_user_data(match);
if (match_value == NULL)
match_value = (cu_match_value_t *)match_get_user_data(match);
if (match_value == NULL)
sstrncpy(vl.host, hostname_g, sizeof(vl.host));
sstrncpy(vl.plugin, data->plugin, sizeof(vl.plugin));
sstrncpy(vl.host, hostname_g, sizeof(vl.host));
sstrncpy(vl.plugin, data->plugin, sizeof(vl.plugin));
match_value->values_num = 0;
latency_counter_reset(match_value->latency);
match_value->values_num = 0;
latency_counter_reset(match_value->latency);
} /* int latency_submit_match */
static int tail_callback(void *data, char *buf,
} /* int latency_submit_match */
static int tail_callback(void *data, char *buf,
for (size_t i = 0; i < obj->matches_num; i++)
match_apply(obj->matches[i].match, buf);
for (size_t i = 0; i < obj->matches_num; i++)
match_apply(obj->matches[i].match, buf);
} /* int tail_callback */
static void tail_match_simple_free(void *data) {
} /* int tail_callback */
static void tail_match_simple_free(void *data) {
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
obj = calloc(1, sizeof(*obj));
if (obj == NULL)
obj->tail = cu_tail_create(filename);
if (obj->tail == NULL) {
sfree(obj);
obj->tail = cu_tail_create(filename);
if (obj->tail == NULL) {
sfree(obj);
} /* cu_tail_match_t *tail_match_create */
void tail_match_destroy(cu_tail_match_t *obj) {
} /* cu_tail_match_t *tail_match_create */
void tail_match_destroy(cu_tail_match_t *obj) {
temp = realloc(obj->matches,
sizeof(cu_tail_match_match_t) * (obj->matches_num + 1));
if (temp == NULL)
temp = realloc(obj->matches,
sizeof(cu_tail_match_match_t) * (obj->matches_num + 1));
if (temp == NULL)
obj->matches = temp;
obj->matches_num++;
obj->matches = temp;
obj->matches_num++;
temp->submit = submit_match;
temp->free = free_user_data;
temp->submit = submit_match;
temp->free = free_user_data;
} /* int tail_match_add_match */
int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex,
} /* int tail_match_add_match */
int tail_match_add_match_simple(cu_tail_match_t *obj, const char *regex,
match = match_create_simple(regex, excluderegex, ds_type);
if (match == NULL)
match = match_create_simple(regex, excluderegex, ds_type);
if (match == NULL)
user_data = calloc(1, sizeof(*user_data));
if (user_data == NULL) {
match_destroy(match);
user_data = calloc(1, sizeof(*user_data));
if (user_data == NULL) {
match_destroy(match);
}
sstrncpy(user_data->plugin, plugin, sizeof(user_data->plugin));
}
sstrncpy(user_data->plugin, plugin, sizeof(user_data->plugin));
} /* int tail_match_add_match_simple */
int tail_match_read(cu_tail_match_t *obj) {
} /* int tail_match_add_match_simple */
int tail_match_read(cu_tail_match_t *obj) {
(void *)obj);
if (status != 0) {
ERROR("tail_match: cu_tail_read failed.");
(void *)obj);
if (status != 0) {
ERROR("tail_match: cu_tail_read failed.");
}
for (size_t i = 0; i < obj->matches_num; i++) {
}
for (size_t i = 0; i < obj->matches_num; i++) {
(*lt_match->submit)(lt_match->match, lt_match->user_data);
}
(*lt_match->submit)(lt_match->match, lt_match->user_data);
}
} /* int tail_match_read */
} /* int tail_match_read */
if (match->is_regex) {
/* Short cut popular catch-all regex. */
if (strcmp(".*", match->str) == 0)
if (match->is_regex) {
/* Short cut popular catch-all regex. */
if (strcmp(".*", match->str) == 0)
int status = regexec(&match->regex, str,
/* nmatch = */ 0, /* pmatch = */ NULL,
/* flags = */ 0);
if (status == 0)
int status = regexec(&match->regex, str,
/* nmatch = */ 0, /* pmatch = */ NULL,
/* flags = */ 0);
if (status == 0)
} else if (strcmp(match->str, str) == 0)
} else if (strcmp(match->str, str) == 0)
} /* }}} _Bool lu_part_matches */
static int lu_copy_ident_to_match_part(part_match_t *match_part, /* {{{ */
} /* }}} _Bool lu_part_matches */
static int lu_copy_ident_to_match_part(part_match_t *match_part, /* {{{ */
if ((len < 3) || (ident_part[0] != '/') || (ident_part[len - 1] != '/')) {
sstrncpy(match_part->str, ident_part, sizeof(match_part->str));
match_part->is_regex = 0;
if ((len < 3) || (ident_part[0] != '/') || (ident_part[len - 1] != '/')) {
sstrncpy(match_part->str, ident_part, sizeof(match_part->str));
match_part->is_regex = 0;
}
/* Copy string without the leading slash. */
}
/* Copy string without the leading slash. */
regerror(status, &match_part->regex, errbuf, sizeof(errbuf));
ERROR("utils_vl_lookup: Compiling regular expression \"%s\" failed: %s",
match_part->str, errbuf);
regerror(status, &match_part->regex, errbuf, sizeof(errbuf));
ERROR("utils_vl_lookup: Compiling regular expression \"%s\" failed: %s",
match_part->str, errbuf);
}
match_part->is_regex = 1;
}
match_part->is_regex = 1;
} /* }}} int lu_copy_ident_to_match_part */
static int lu_copy_ident_to_match(identifier_match_t *match, /* {{{ */
} /* }}} int lu_copy_ident_to_match_part */
static int lu_copy_ident_to_match(identifier_match_t *match, /* {{{ */
do { \
int status = lu_copy_ident_to_match_part(&match->field, ident->field); \
if (status != 0) \
do { \
int status = lu_copy_ident_to_match_part(&match->field, ident->field); \
if (status != 0) \
} while (0)
COPY_FIELD(host);
} while (0)
COPY_FIELD(host);
} /* }}} int lu_copy_ident_to_match */
/* user_class->lock must be held when calling this function */
} /* }}} int lu_copy_ident_to_match */
/* user_class->lock must be held when calling this function */
user_obj = calloc(1, sizeof(*user_obj));
if (user_obj == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
user_obj = calloc(1, sizeof(*user_obj));
if (user_obj == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
if (user_obj->user_obj == NULL) {
sfree(user_obj);
WARNING("utils_vl_lookup: User-provided constructor failed.");
if (user_obj->user_obj == NULL) {
sfree(user_obj);
WARNING("utils_vl_lookup: User-provided constructor failed.");
}
#define COPY_FIELD(field, group_mask) \
}
#define COPY_FIELD(field, group_mask) \
} /* }}} void *lu_create_user_obj */
/* user_class->lock must be held when calling this function */
} /* }}} void *lu_create_user_obj */
/* user_class->lock must be held when calling this function */
(strcmp(vl->type_instance, ptr->ident.type_instance) != 0))
continue;
(strcmp(vl->type_instance, ptr->ident.type_instance) != 0))
continue;
} /* }}} user_obj_t *lu_find_user_obj */
static int lu_handle_user_class(lookup_t *obj, /* {{{ */
} /* }}} user_obj_t *lu_find_user_obj */
static int lu_handle_user_class(lookup_t *obj, /* {{{ */
vl->plugin_instance) ||
!lu_part_matches(&user_class->match.plugin, vl->plugin) ||
!lu_part_matches(&user_class->match.host, vl->host))
vl->plugin_instance) ||
!lu_part_matches(&user_class->match.plugin, vl->plugin) ||
!lu_part_matches(&user_class->match.host, vl->host))
pthread_mutex_lock(&user_class->lock);
user_obj = lu_find_user_obj(user_class, vl);
pthread_mutex_lock(&user_class->lock);
user_obj = lu_find_user_obj(user_class, vl);
user_obj = lu_create_user_obj(obj, ds, vl, user_class);
if (user_obj == NULL) {
pthread_mutex_unlock(&user_class->lock);
user_obj = lu_create_user_obj(obj, ds, vl, user_class);
if (user_obj == NULL) {
pthread_mutex_unlock(&user_class->lock);
}
}
pthread_mutex_unlock(&user_class->lock);
}
}
pthread_mutex_unlock(&user_class->lock);
status);
/* Returning a negative value means: abort! */
if (status < 0)
status);
/* Returning a negative value means: abort! */
if (status < 0)
} /* }}} int lu_handle_user_class */
static int lu_handle_user_class_list(lookup_t *obj, /* {{{ */
} /* }}} int lu_handle_user_class */
static int lu_handle_user_class_list(lookup_t *obj, /* {{{ */
status = lu_handle_user_class(obj, ds, vl, &ptr->entry);
if (status < 0)
status = lu_handle_user_class(obj, ds, vl, &ptr->entry);
if (status < 0)
else if (status == 0)
retval++;
}
else if (status == 0)
retval++;
}
} /* }}} int lu_handle_user_class_list */
static by_type_entry_t *lu_search_by_type(lookup_t *obj, /* {{{ */
} /* }}} int lu_handle_user_class_list */
static by_type_entry_t *lu_search_by_type(lookup_t *obj, /* {{{ */
status = c_avl_get(obj->by_type_tree, type, (void *)&by_type);
if (status == 0)
status = c_avl_get(obj->by_type_tree, type, (void *)&by_type);
if (status == 0)
if (!allocate_if_missing)
if (!allocate_if_missing)
type_copy = strdup(type);
if (type_copy == NULL) {
ERROR("utils_vl_lookup: strdup failed.");
type_copy = strdup(type);
if (type_copy == NULL) {
ERROR("utils_vl_lookup: strdup failed.");
}
by_type = calloc(1, sizeof(*by_type));
if (by_type == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
sfree(type_copy);
}
by_type = calloc(1, sizeof(*by_type));
if (by_type == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
sfree(type_copy);
}
by_type->wildcard_plugin_list = NULL;
}
by_type->wildcard_plugin_list = NULL;
ERROR("utils_vl_lookup: c_avl_create failed.");
sfree(by_type);
sfree(type_copy);
ERROR("utils_vl_lookup: c_avl_create failed.");
sfree(by_type);
sfree(type_copy);
}
status = c_avl_insert(obj->by_type_tree,
}
status = c_avl_insert(obj->by_type_tree,
c_avl_destroy(by_type->by_plugin_tree);
sfree(by_type);
sfree(type_copy);
c_avl_destroy(by_type->by_plugin_tree);
sfree(by_type);
sfree(type_copy);
} /* }}} by_type_entry_t *lu_search_by_type */
static int lu_add_by_plugin(by_type_entry_t *by_type, /* {{{ */
} /* }}} by_type_entry_t *lu_search_by_type */
static int lu_add_by_plugin(by_type_entry_t *by_type, /* {{{ */
if (match->plugin.is_regex) {
if (by_type->wildcard_plugin_list == NULL) {
by_type->wildcard_plugin_list = user_class_list;
if (match->plugin.is_regex) {
if (by_type->wildcard_plugin_list == NULL) {
by_type->wildcard_plugin_list = user_class_list;
}
ptr = by_type->wildcard_plugin_list;
}
ptr = by_type->wildcard_plugin_list;
if (plugin_copy == NULL) {
ERROR("utils_vl_lookup: strdup failed.");
sfree(user_class_list);
if (plugin_copy == NULL) {
ERROR("utils_vl_lookup: strdup failed.");
sfree(user_class_list);
plugin_copy, status);
sfree(plugin_copy);
sfree(user_class_list);
plugin_copy, status);
sfree(plugin_copy);
sfree(user_class_list);
}
} /* if (plugin not yet in tree) */
} /* if (plugin is not wildcard) */
}
} /* if (plugin not yet in tree) */
} /* if (plugin is not wildcard) */
ptr = ptr->next;
ptr->next = user_class_list;
ptr = ptr->next;
ptr->next = user_class_list;
} /* }}} int lu_add_by_plugin */
static void lu_destroy_user_obj(lookup_t *obj, /* {{{ */
} /* }}} int lu_add_by_plugin */
static void lu_destroy_user_obj(lookup_t *obj, /* {{{ */
lookup_t *obj = calloc(1, sizeof(*obj));
if (obj == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
lookup_t *obj = calloc(1, sizeof(*obj));
if (obj == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
}
obj->by_type_tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (obj->by_type_tree == NULL) {
ERROR("utils_vl_lookup: c_avl_create failed.");
sfree(obj);
}
obj->by_type_tree = c_avl_create((int (*)(const void *, const void *))strcmp);
if (obj->by_type_tree == NULL) {
ERROR("utils_vl_lookup: c_avl_create failed.");
sfree(obj);
}
obj->cb_user_class = cb_user_class;
}
obj->cb_user_class = cb_user_class;
obj->cb_free_class = cb_free_class;
obj->cb_free_obj = cb_free_obj;
obj->cb_free_class = cb_free_class;
obj->cb_free_obj = cb_free_obj;
} /* }}} lookup_t *lookup_create */
void lookup_destroy(lookup_t *obj) /* {{{ */
} /* }}} lookup_t *lookup_create */
void lookup_destroy(lookup_t *obj) /* {{{ */
by_type = lu_search_by_type(obj, ident->type, /* allocate = */ 1);
if (by_type == NULL)
by_type = lu_search_by_type(obj, ident->type, /* allocate = */ 1);
if (by_type == NULL)
user_class_obj = calloc(1, sizeof(*user_class_obj));
if (user_class_obj == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
user_class_obj = calloc(1, sizeof(*user_class_obj));
if (user_class_obj == NULL) {
ERROR("utils_vl_lookup: calloc failed.");
}
pthread_mutex_init(&user_class_obj->entry.lock, /* attr = */ NULL);
user_class_obj->entry.user_class = user_class;
}
pthread_mutex_init(&user_class_obj->entry.lock, /* attr = */ NULL);
user_class_obj->entry.user_class = user_class;
user_class_obj->entry.user_obj_list = NULL;
user_class_obj->next = NULL;
user_class_obj->entry.user_obj_list = NULL;
user_class_obj->next = NULL;
- return (lu_add_by_plugin(by_type, user_class_obj));
+ return lu_add_by_plugin(by_type, user_class_obj);
} /* }}} int lookup_add */
/* returns the number of successful calls to the callback function */
} /* }}} int lookup_add */
/* returns the number of successful calls to the callback function */
int status;
if ((obj == NULL) || (ds == NULL) || (vl == NULL))
int status;
if ((obj == NULL) || (ds == NULL) || (vl == NULL))
by_type = lu_search_by_type(obj, vl->type, /* allocate = */ 0);
if (by_type == NULL)
by_type = lu_search_by_type(obj, vl->type, /* allocate = */ 0);
if (by_type == NULL)
status =
c_avl_get(by_type->by_plugin_tree, vl->plugin, (void *)&user_class_list);
if (status == 0) {
status = lu_handle_user_class_list(obj, ds, vl, user_class_list);
if (status < 0)
status =
c_avl_get(by_type->by_plugin_tree, vl->plugin, (void *)&user_class_list);
if (status == 0) {
status = lu_handle_user_class_list(obj, ds, vl, user_class_list);
if (status < 0)
status =
lu_handle_user_class_list(obj, ds, vl, by_type->wildcard_plugin_list);
if (status < 0)
status =
lu_handle_user_class_list(obj, ds, vl, by_type->wildcard_plugin_list);
if (status < 0)
} /* }}} lookup_search */
} /* }}} lookup_search */
memcpy(&last_obj_ident, obj, sizeof(last_obj_ident));
if (strcmp(obj->plugin_instance, "failure") == 0)
memcpy(&last_obj_ident, obj, sizeof(last_obj_ident));
if (strcmp(obj->plugin_instance, "failure") == 0)
}
static void *lookup_class_callback(data_set_t const *ds, value_list_t const *vl,
}
static void *lookup_class_callback(data_set_t const *ds, value_list_t const *vl,
}
static int checked_lookup_add(lookup_t *obj, /* {{{ */
}
static int checked_lookup_add(lookup_t *obj, /* {{{ */
have_new_obj = 0;
status = lookup_search(obj, ds, &vl);
have_new_obj = 0;
status = lookup_search(obj, ds, &vl);
}
DEF_TEST(group_by_specific_host) {
}
DEF_TEST(group_by_specific_host) {
/* expect new = */ 0);
lookup_destroy(obj);
/* expect new = */ 0);
lookup_destroy(obj);
}
DEF_TEST(group_by_any_host) {
}
DEF_TEST(group_by_any_host) {
/* expect new = */ 0);
lookup_destroy(obj);
/* expect new = */ 0);
lookup_destroy(obj);
}
DEF_TEST(multiple_lookups) {
}
DEF_TEST(multiple_lookups) {
assert(status == 2);
lookup_destroy(obj);
assert(status == 2);
lookup_destroy(obj);
/* expect new = */ 1);
lookup_destroy(obj);
/* expect new = */ 1);
lookup_destroy(obj);
}
int main(int argc, char **argv) /* {{{ */
}
int main(int argc, char **argv) /* {{{ */
len = strlen(uuid);
if (len < UUID_PRINTABLE_COMPACT_LENGTH)
len = strlen(uuid);
if (len < UUID_PRINTABLE_COMPACT_LENGTH)
while (*uuid) {
if (!isxdigit((int)*uuid) && *uuid != '-')
while (*uuid) {
if (!isxdigit((int)*uuid) && *uuid != '-')
}
static char *uuid_parse_dmidecode(FILE *file) {
}
static char *uuid_parse_dmidecode(FILE *file) {
if (!looks_like_a_uuid(fields[1]))
continue;
if (!looks_like_a_uuid(fields[1]))
continue;
- return (strdup(fields[1]));
+ return strdup(fields[1]);
}
static char *uuid_get_from_dmidecode(void) {
}
static char *uuid_get_from_dmidecode(void) {
char *uuid;
if (!dmidecode)
char *uuid;
if (!dmidecode)
uuid = uuid_parse_dmidecode(dmidecode);
pclose(dmidecode);
uuid = uuid_parse_dmidecode(dmidecode);
pclose(dmidecode);
}
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
}
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
size_t len = sizeof(uuid);
if (sysctlbyname(name, &uuid, &len, NULL, 0) == -1)
return NULL;
size_t len = sizeof(uuid);
if (sysctlbyname(name, &uuid, &len, NULL, 0) == -1)
return NULL;
}
#elif defined(__OpenBSD__)
static char *uuid_get_from_sysctl(void) {
}
#elif defined(__OpenBSD__)
static char *uuid_get_from_sysctl(void) {
if (sysctl(mib, 2, uuid, &len, NULL, 0) == -1)
return NULL;
if (sysctl(mib, 2, uuid, &len, NULL, 0) == -1)
return NULL;
file = fopen(path, "r");
if (file == NULL)
file = fopen(path, "r");
if (file == NULL)
if (!fgets(uuid, sizeof(uuid), file)) {
fclose(file);
if (!fgets(uuid, sizeof(uuid), file)) {
fclose(file);
}
fclose(file);
strstripnewline(uuid);
}
fclose(file);
strstripnewline(uuid);
}
static char *uuid_get_local(void) {
}
static char *uuid_get_local(void) {
/* Check /etc/uuid / UUIDFile before any other method. */
if ((uuid = uuid_get_from_file(uuidfile ? uuidfile : "/etc/uuid")) != NULL)
/* Check /etc/uuid / UUIDFile before any other method. */
if ((uuid = uuid_get_from_file(uuidfile ? uuidfile : "/etc/uuid")) != NULL)
#if defined(__APPLE__)
if ((uuid = uuid_get_from_sysctlbyname("kern.uuid")) != NULL)
#if defined(__APPLE__)
if ((uuid = uuid_get_from_sysctlbyname("kern.uuid")) != NULL)
#elif defined(__FreeBSD__)
if ((uuid = uuid_get_from_sysctlbyname("kern.hostuuid")) != NULL)
#elif defined(__FreeBSD__)
if ((uuid = uuid_get_from_sysctlbyname("kern.hostuuid")) != NULL)
#elif defined(__NetBSD__)
if ((uuid = uuid_get_from_sysctlbyname("machdep.dmi.system-uuid")) != NULL)
#elif defined(__NetBSD__)
if ((uuid = uuid_get_from_sysctlbyname("machdep.dmi.system-uuid")) != NULL)
#elif defined(__OpenBSD__)
if ((uuid = uuid_get_from_sysctl()) != NULL)
#elif defined(__OpenBSD__)
if ((uuid = uuid_get_from_sysctl()) != NULL)
#elif defined(__linux__)
if ((uuid = uuid_get_from_file("/sys/class/dmi/id/product_uuid")) != NULL)
#elif defined(__linux__)
if ((uuid = uuid_get_from_file("/sys/class/dmi/id/product_uuid")) != NULL)
#endif
if ((uuid = uuid_get_from_dmidecode()) != NULL)
#endif
if ((uuid = uuid_get_from_dmidecode()) != NULL)
#if defined(__linux__)
if ((uuid = uuid_get_from_file("/sys/hypervisor/uuid")) != NULL)
#if defined(__linux__)
if ((uuid = uuid_get_from_file("/sys/hypervisor/uuid")) != NULL)
}
static int uuid_config(const char *key, const char *value) {
if (strcasecmp(key, "UUIDFile") == 0) {
char *tmp = strdup(value);
if (tmp == NULL)
}
static int uuid_config(const char *key, const char *value) {
if (strcasecmp(key, "UUIDFile") == 0) {
char *tmp = strdup(value);
if (tmp == NULL)
sfree(uuidfile);
uuidfile = tmp;
sfree(uuidfile);
uuidfile = tmp;
}
static int uuid_init(void) {
}
static int uuid_init(void) {
if (uuid) {
sstrncpy(hostname_g, uuid, DATA_MAX_NAME_LEN);
sfree(uuid);
if (uuid) {
sstrncpy(hostname_g, uuid, DATA_MAX_NAME_LEN);
sfree(uuid);
}
WARNING("uuid: could not read UUID using any known method");
}
WARNING("uuid: could not read UUID using any known method");
}
void module_register(void) {
}
void module_register(void) {
if (type_instance != NULL)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
if (type_instance != NULL)
sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
} /* }}} int varnish_submit */
static int varnish_submit_gauge(const char *plugin_instance, /* {{{ */
const char *category, const char *type,
const char *type_instance,
uint64_t gauge_value) {
} /* }}} int varnish_submit */
static int varnish_submit_gauge(const char *plugin_instance, /* {{{ */
const char *category, const char *type,
const char *type_instance,
uint64_t gauge_value) {
- return (varnish_submit(plugin_instance, category, type, type_instance,
- (value_t){.gauge = (gauge_t)gauge_value}));
+ return varnish_submit(plugin_instance, category, type, type_instance, (value_t){
+ .gauge=(gauge_t)gauge_value,
+ });
} /* }}} int varnish_submit_gauge */
static int varnish_submit_derive(const char *plugin_instance, /* {{{ */
const char *category, const char *type,
const char *type_instance,
uint64_t derive_value) {
} /* }}} int varnish_submit_gauge */
static int varnish_submit_derive(const char *plugin_instance, /* {{{ */
const char *category, const char *type,
const char *type_instance,
uint64_t derive_value) {
- return (varnish_submit(plugin_instance, category, type, type_instance,
- (value_t){.derive = (derive_t)derive_value}));
+ return varnish_submit(plugin_instance, category, type, type_instance, (value_t){
+ .derive=(derive_t)derive_value,
+ });
} /* }}} int varnish_submit_derive */
#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
} /* }}} int varnish_submit_derive */
#if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
const char *name;
if (pt == NULL)
const char *name;
if (pt == NULL)
name = pt->desc->name;
if (strcmp(class, "MAIN") != 0)
name = pt->desc->name;
if (strcmp(class, "MAIN") != 0)
#elif HAVE_VARNISH_V3
class = pt->class;
name = pt->name;
if (strcmp(class, "") != 0)
#elif HAVE_VARNISH_V3
class = pt->class;
name = pt->name;
if (strcmp(class, "") != 0)
#endif
val = *(const volatile uint64_t *)pt->ptr;
#endif
val = *(const volatile uint64_t *)pt->ptr;
if (conf->collect_connections) {
if (strcmp(name, "client_conn") == 0)
if (conf->collect_connections) {
if (strcmp(name, "client_conn") == 0)
- return varnish_submit_derive(conf->instance, "connections", "connections",
- "accepted", val);
+ return varnish_submit_derive(conf->instance, "connections",
+ "connections", "accepted", val);
else if (strcmp(name, "client_drop") == 0)
else if (strcmp(name, "client_drop") == 0)
- return varnish_submit_derive(conf->instance, "connections", "connections",
- "dropped", val);
+ return varnish_submit_derive(conf->instance, "connections",
+ "connections", "dropped", val);
else if (strcmp(name, "client_req") == 0)
else if (strcmp(name, "client_req") == 0)
- return varnish_submit_derive(conf->instance, "connections", "connections",
- "received", val);
+ return varnish_submit_derive(conf->instance, "connections",
+ "connections", "received", val);
}
#ifdef HAVE_VARNISH_V3
if (conf->collect_dirdns) {
if (strcmp(name, "dir_dns_lookups") == 0)
}
#ifdef HAVE_VARNISH_V3
if (conf->collect_dirdns) {
if (strcmp(name, "dir_dns_lookups") == 0)
- return varnish_submit_derive(conf->instance, "dirdns", "cache_operation",
- "lookups", val);
+ return varnish_submit_derive(conf->instance, "dirdns",
+ "cache_operation", "lookups", val);
else if (strcmp(name, "dir_dns_failed") == 0)
return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
"failed", val);
else if (strcmp(name, "dir_dns_failed") == 0)
return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
"failed", val);
return varnish_submit_gauge(conf->instance, "sms", "requests",
"outstanding", val);
else if (strcmp(name, "sms_nbytes") == 0)
return varnish_submit_gauge(conf->instance, "sms", "requests",
"outstanding", val);
else if (strcmp(name, "sms_nbytes") == 0)
- return varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
- val);
+ return varnish_submit_gauge(conf->instance, "sms", "bytes",
+ "outstanding", val);
else if (strcmp(name, "sms_balloc") == 0)
return varnish_submit_derive(conf->instance, "sms", "total_bytes",
"allocated", val);
else if (strcmp(name, "sms_bfree") == 0)
else if (strcmp(name, "sms_balloc") == 0)
return varnish_submit_derive(conf->instance, "sms", "total_bytes",
"allocated", val);
else if (strcmp(name, "sms_bfree") == 0)
- return varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
- val);
+ return varnish_submit_derive(conf->instance, "sms", "total_bytes",
+ "free", val);
}
if (conf->collect_struct) {
if (strcmp(name, "n_sess_mem") == 0)
}
if (conf->collect_struct) {
if (strcmp(name, "n_sess_mem") == 0)
- return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
- "sess_mem", val);
+ return varnish_submit_gauge(conf->instance, "struct",
+ "current_sessions", "sess_mem", val);
else if (strcmp(name, "n_sess") == 0)
else if (strcmp(name, "n_sess") == 0)
- return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
- "sess", val);
+ return varnish_submit_gauge(conf->instance, "struct",
+ "current_sessions", "sess", val);
else if (strcmp(name, "n_object") == 0)
else if (strcmp(name, "n_object") == 0)
- return varnish_submit_gauge(conf->instance, "struct", "objects", "object",
- val);
+ return varnish_submit_gauge(conf->instance, "struct", "objects",
+ "object", val);
else if (strcmp(name, "n_vampireobject") == 0)
return varnish_submit_gauge(conf->instance, "struct", "objects",
"vampireobject", val);
else if (strcmp(name, "n_vampireobject") == 0)
return varnish_submit_gauge(conf->instance, "struct", "objects",
"vampireobject", val);
return varnish_submit_derive(conf->instance, "totals", "total_requests",
"requests", val);
else if (strcmp(name, "s_pipe") == 0)
return varnish_submit_derive(conf->instance, "totals", "total_requests",
"requests", val);
else if (strcmp(name, "s_pipe") == 0)
- return varnish_submit_derive(conf->instance, "totals", "total_operations",
- "pipe", val);
+ return varnish_submit_derive(conf->instance, "totals",
+ "total_operations", "pipe", val);
else if (strcmp(name, "s_pass") == 0)
else if (strcmp(name, "s_pass") == 0)
- return varnish_submit_derive(conf->instance, "totals", "total_operations",
- "pass", val);
+ return varnish_submit_derive(conf->instance, "totals",
+ "total_operations", "pass", val);
else if (strcmp(name, "s_fetch") == 0)
else if (strcmp(name, "s_fetch") == 0)
- return varnish_submit_derive(conf->instance, "totals", "total_operations",
- "fetches", val);
+ return varnish_submit_derive(conf->instance, "totals",
+ "total_operations", "fetches", val);
else if (strcmp(name, "s_synth") == 0)
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"synth", val);
else if (strcmp(name, "s_synth") == 0)
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"synth", val);
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"pipe_out", val);
else if (strcmp(name, "n_purges") == 0)
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"pipe_out", val);
else if (strcmp(name, "n_purges") == 0)
- return varnish_submit_derive(conf->instance, "totals", "total_operations",
- "purges", val);
+ return varnish_submit_derive(conf->instance, "totals",
+ "total_operations", "purges", val);
else if (strcmp(name, "s_hdrbytes") == 0)
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"header-bytes", val);
else if (strcmp(name, "s_hdrbytes") == 0)
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"header-bytes", val);
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"body-bytes", val);
else if (strcmp(name, "n_gzip") == 0)
return varnish_submit_derive(conf->instance, "totals", "total_bytes",
"body-bytes", val);
else if (strcmp(name, "n_gzip") == 0)
- return varnish_submit_derive(conf->instance, "totals", "total_operations",
- "gzip", val);
+ return varnish_submit_derive(conf->instance, "totals",
+ "total_operations", "gzip", val);
else if (strcmp(name, "n_gunzip") == 0)
else if (strcmp(name, "n_gunzip") == 0)
- return varnish_submit_derive(conf->instance, "totals", "total_operations",
- "gunzip", val);
+ return varnish_submit_derive(conf->instance, "totals",
+ "total_operations", "gunzip", val);
}
if (conf->collect_uptime) {
}
if (conf->collect_uptime) {
return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
val);
else if (strcmp(name, "n_vcl_discard") == 0)
return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
val);
else if (strcmp(name, "n_vcl_discard") == 0)
- return varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
- val);
+ return varnish_submit_gauge(conf->instance, "vcl", "vcl",
+ "discarded_vcl", val);
else if (strcmp(name, "vmods") == 0)
return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
val);
else if (strcmp(name, "vmods") == 0)
return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
val);
return varnish_submit_derive(conf->instance, "workers", "total_threads",
"dropped", val);
else if (strcmp(name, "n_wrk_queue") == 0)
return varnish_submit_derive(conf->instance, "workers", "total_threads",
"dropped", val);
else if (strcmp(name, "n_wrk_queue") == 0)
- return varnish_submit_derive(conf->instance, "workers", "total_requests",
- "queued", val);
+ return varnish_submit_derive(conf->instance, "workers",
+ "total_requests", "queued", val);
else if (strcmp(name, "n_wrk_overflow") == 0)
else if (strcmp(name, "n_wrk_overflow") == 0)
- return varnish_submit_derive(conf->instance, "workers", "total_requests",
- "overflowed", val);
+ return varnish_submit_derive(conf->instance, "workers",
+ "total_requests", "overflowed", val);
else if (strcmp(name, "n_wrk_queued") == 0)
else if (strcmp(name, "n_wrk_queued") == 0)
- return varnish_submit_derive(conf->instance, "workers", "total_requests",
- "queued", val);
+ return varnish_submit_derive(conf->instance, "workers",
+ "total_requests", "queued", val);
else if (strcmp(name, "n_wrk_lqueue") == 0)
else if (strcmp(name, "n_wrk_lqueue") == 0)
- return varnish_submit_derive(conf->instance, "workers", "total_requests",
- "queue_length", val);
+ return varnish_submit_derive(conf->instance, "workers",
+ "total_requests", "queue_length", val);
} /* }}} static int varnish_monitor */
#else /* if HAVE_VARNISH_V2 */
} /* }}} static int varnish_monitor */
#else /* if HAVE_VARNISH_V2 */
user_config_t *conf;
if ((ud == NULL) || (ud->data == NULL))
user_config_t *conf;
if ((ud == NULL) || (ud->data == NULL))
ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed "
"with status %i.",
conf->instance, status);
ERROR("varnish plugin: VSM_n_Arg (\"%s\") failed "
"with status %i.",
conf->instance, status);
VSM_Delete(vd);
ERROR("varnish plugin: Unable to open connection.");
VSM_Delete(vd);
ERROR("varnish plugin: Unable to open connection.");
VSM_Delete(vd);
ERROR("varnish plugin: Unable to get statistics.");
VSM_Delete(vd);
ERROR("varnish plugin: Unable to get statistics.");
} /* }}} */
#else /* if HAVE_VARNISH_V2 */
static int varnish_read(user_data_t *ud) /* {{{ */
} /* }}} */
#else /* if HAVE_VARNISH_V2 */
static int varnish_read(user_data_t *ud) /* {{{ */
user_config_t *conf;
if ((ud == NULL) || (ud->data == NULL))
user_config_t *conf;
if ((ud == NULL) || (ud->data == NULL))
if (stats == NULL) {
ERROR("Varnish plugin : unable to load statistics");
if (stats == NULL) {
ERROR("Varnish plugin : unable to load statistics");
}
varnish_monitor(conf, stats);
}
varnish_monitor(conf, stats);
static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
{
if (conf == NULL)
static int varnish_config_apply_default(user_config_t *conf) /* {{{ */
{
if (conf == NULL)
conf->collect_backend = 1;
conf->collect_cache = 1;
conf->collect_backend = 1;
conf->collect_cache = 1;
conf->collect_vsm = 0;
#endif
conf->collect_vsm = 0;
#endif
} /* }}} int varnish_config_apply_default */
static int varnish_init(void) /* {{{ */
} /* }}} int varnish_config_apply_default */
static int varnish_init(void) /* {{{ */
user_config_t *conf;
if (have_instance)
user_config_t *conf;
if (have_instance)
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
/* Default settings: */
conf->instance = NULL;
/* Default settings: */
conf->instance = NULL;
.data = conf, .free_func = varnish_config_free,
});
.data = conf, .free_func = varnish_config_free,
});
} /* }}} int varnish_init */
static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
} /* }}} int varnish_init */
static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
conf->instance = NULL;
varnish_config_apply_default(conf);
conf->instance = NULL;
varnish_config_apply_default(conf);
status = cf_util_get_string(ci, &conf->instance);
if (status != 0) {
sfree(conf);
status = cf_util_get_string(ci, &conf->instance);
if (status != 0) {
sfree(conf);
}
assert(conf->instance != NULL);
}
assert(conf->instance != NULL);
WARNING("Varnish plugin: \"Instance\" blocks accept only "
"one argument.");
sfree(conf);
WARNING("Varnish plugin: \"Instance\" blocks accept only "
"one argument.");
sfree(conf);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
"instance \"%s\". Disabling this instance.",
(conf->instance == NULL) ? "localhost" : conf->instance);
sfree(conf);
"instance \"%s\". Disabling this instance.",
(conf->instance == NULL) ? "localhost" : conf->instance);
sfree(conf);
}
ssnprintf(callback_name, sizeof(callback_name), "varnish/%s",
}
ssnprintf(callback_name, sizeof(callback_name), "varnish/%s",
} /* }}} int varnish_config_instance */
static int varnish_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int varnish_config_instance */
static int varnish_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int varnish_config */
void module_register(void) /* {{{ */
} /* }}} int varnish_config */
void module_register(void) /* {{{ */
else
verbose_output = 0;
} else {
else
verbose_output = 0;
} else {
} /* int vmem_config */
static int vmem_read(void) {
} /* int vmem_config */
static int vmem_read(void) {
char errbuf[1024];
ERROR("vmem plugin: fopen (/proc/vmstat) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("vmem plugin: fopen (/proc/vmstat) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
submit_two(NULL, "vmpage_io", "swap", pswpin, pswpout);
#endif /* KERNEL_LINUX */
submit_two(NULL, "vmpage_io", "swap", pswpin, pswpout);
#endif /* KERNEL_LINUX */
} /* int vmem_read */
void module_register(void) {
} /* int vmem_read */
void module_register(void) {
* What's the right thing to do, if there is no getpagesize ()? */
pagesize = getpagesize();
* What's the right thing to do, if there is no getpagesize ()? */
pagesize = getpagesize();
} /* static void vserver_init(void) */
static void traffic_submit(const char *plugin_instance,
} /* static void vserver_init(void) */
static void traffic_submit(const char *plugin_instance,
status = parse_value(s, &v, DS_TYPE_DERIVE);
if (status != 0)
status = parse_value(s, &v, DS_TYPE_DERIVE);
if (status != 0)
- return (-1);
- return (v.derive);
+ return -1;
+ return v.derive;
}
static int vserver_read(void) {
}
static int vserver_read(void) {
char errbuf[1024];
ERROR("vserver plugin: fopen (%s): %s", PROCDIR,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("vserver plugin: fopen (%s): %s", PROCDIR,
sstrerror(errno, errbuf, sizeof(errbuf)));
ERROR("vserver plugin: failed to read directory %s: %s", PROCDIR,
sstrerror(errno, errbuf, sizeof(errbuf)));
closedir(proc);
ERROR("vserver plugin: failed to read directory %s: %s", PROCDIR,
sstrerror(errno, errbuf, sizeof(errbuf)));
closedir(proc);
}
if (dent->d_name[0] == '.')
}
if (dent->d_name[0] == '.')
} /* int vserver_read */
void module_register(void) {
} /* int vserver_read */
void module_register(void) {
watt = pow (10.0, (dbm / 10.0)) / 1000.0;
watt = pow (10.0, (dbm / 10.0)) / 1000.0;
static double wireless_percent_to_power(double quality) {
assert((quality >= 0.0) && (quality <= 100.0));
static double wireless_percent_to_power(double quality) {
assert((quality >= 0.0) && (quality <= 100.0));
- return ((quality * (POWER_MAX - POWER_MIN)) + POWER_MIN);
+ return (quality * (POWER_MAX - POWER_MIN)) + POWER_MIN;
} /* double wireless_percent_to_power */
static int wireless_read(void) {
} /* double wireless_percent_to_power */
static int wireless_read(void) {
if ((fh = fopen(WIRELESS_PROC_FILE, "r")) == NULL) {
char errbuf[1024];
WARNING("wireless: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
if ((fh = fopen(WIRELESS_PROC_FILE, "r")) == NULL) {
char errbuf[1024];
WARNING("wireless: fopen: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
/* If no wireless devices are present return an error, so the plugin
* code delays our read function. */
if (devices_found == 0)
/* If no wireless devices are present return an error, so the plugin
* code delays our read function. */
if (devices_found == 0)
#endif /* KERNEL_LINUX */
#endif /* KERNEL_LINUX */
} /* int wireless_read */
void module_register(void) {
} /* int wireless_read */
void module_register(void) {
ssize_t status;
if (cb->sock_fd < 0)
ssize_t status;
if (cb->sock_fd < 0)
status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
if (status != 0) {
status = swrite(cb->sock_fd, cb->send_buf, strlen(cb->send_buf));
if (status != 0) {
close(cb->sock_fd);
cb->sock_fd = -1;
close(cb->sock_fd);
cb->sock_fd = -1;
}
/* NOTE: You must hold cb->send_lock when calling this function! */
}
/* NOTE: You must hold cb->send_lock when calling this function! */
now = cdtime();
if ((cb->send_buf_init_time + timeout) > now)
now = cdtime();
if ((cb->send_buf_init_time + timeout) > now)
}
if (cb->send_buf_fill == 0) {
cb->send_buf_init_time = cdtime();
}
if (cb->send_buf_fill == 0) {
cb->send_buf_init_time = cdtime();
}
status = wg_send_buffer(cb);
wg_reset_buffer(cb);
}
status = wg_send_buffer(cb);
wg_reset_buffer(cb);
}
static int wg_callback_init(struct wg_callback *cb) {
}
static int wg_callback_init(struct wg_callback *cb) {
char connerr[1024] = "";
if (cb->sock_fd > 0)
char connerr[1024] = "";
if (cb->sock_fd > 0)
/* Don't try to reconnect too often. By default, one reconnection attempt
* is made per second. */
now = cdtime();
if ((now - cb->last_connect_time) < WG_MIN_RECONNECT_INTERVAL)
/* Don't try to reconnect too often. By default, one reconnection attempt
* is made per second. */
now = cdtime();
if ((now - cb->last_connect_time) < WG_MIN_RECONNECT_INTERVAL)
cb->last_connect_time = now;
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC,
cb->last_connect_time = now;
struct addrinfo ai_hints = {.ai_family = AF_UNSPEC,
if (status != 0) {
ERROR("write_graphite plugin: getaddrinfo (%s, %s, %s) failed: %s",
cb->node, cb->service, cb->protocol, gai_strerror(status));
if (status != 0) {
ERROR("write_graphite plugin: getaddrinfo (%s, %s, %s) failed: %s",
cb->node, cb->service, cb->protocol, gai_strerror(status));
}
assert(ai_list != NULL);
}
assert(ai_list != NULL);
"write_graphite plugin: Connecting to %s:%s via %s failed. "
"The last error was: %s",
cb->node, cb->service, cb->protocol, connerr);
"write_graphite plugin: Connecting to %s:%s via %s failed. "
"The last error was: %s",
cb->node, cb->service, cb->protocol, connerr);
} else {
c_release(LOG_INFO, &cb->init_complaint,
"write_graphite plugin: Successfully connected to %s:%s via %s.",
} else {
c_release(LOG_INFO, &cb->init_complaint,
"write_graphite plugin: Successfully connected to %s:%s via %s.",
else
cb->reconnect_interval_reached = 0;
else
cb->reconnect_interval_reached = 0;
}
static void wg_callback_free(void *data) {
}
static void wg_callback_free(void *data) {
int status;
if (user_data == NULL)
int status;
if (user_data == NULL)
if (status != 0) {
/* An error message has already been printed. */
pthread_mutex_unlock(&cb->send_lock);
if (status != 0) {
/* An error message has already been printed. */
pthread_mutex_unlock(&cb->send_lock);
}
}
status = wg_flush_nolock(timeout, cb);
pthread_mutex_unlock(&cb->send_lock);
}
}
status = wg_flush_nolock(timeout, cb);
pthread_mutex_unlock(&cb->send_lock);
}
static int wg_send_message(char const *message, struct wg_callback *cb) {
}
static int wg_send_message(char const *message, struct wg_callback *cb) {
if (status != 0) {
/* An error message has already been printed. */
pthread_mutex_unlock(&cb->send_lock);
if (status != 0) {
/* An error message has already been printed. */
pthread_mutex_unlock(&cb->send_lock);
status = wg_flush_nolock(/* timeout = */ 0, cb);
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
status = wg_flush_nolock(/* timeout = */ 0, cb);
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_unlock(&cb->send_lock);
pthread_mutex_unlock(&cb->send_lock);
}
static int wg_write_messages(const data_set_t *ds, const value_list_t *vl,
}
static int wg_write_messages(const data_set_t *ds, const value_list_t *vl,
status = format_graphite(buffer, sizeof(buffer), ds, vl, cb->prefix,
cb->postfix, cb->escape_char, cb->format_flags);
if (status != 0) /* error message has been printed already. */
status = format_graphite(buffer, sizeof(buffer), ds, vl, cb->prefix,
cb->postfix, cb->escape_char, cb->format_flags);
if (status != 0) /* error message has been printed already. */
/* Send the message to graphite */
status = wg_send_message(buffer, cb);
if (status != 0) /* error message has been printed already. */
/* Send the message to graphite */
status = wg_send_message(buffer, cb);
if (status != 0) /* error message has been printed already. */
} /* int wg_write_messages */
static int wg_write(const data_set_t *ds, const value_list_t *vl,
} /* int wg_write_messages */
static int wg_write(const data_set_t *ds, const value_list_t *vl,
int status;
if (user_data == NULL)
int status;
if (user_data == NULL)
cb = user_data->data;
status = wg_write_messages(ds, vl, cb);
cb = user_data->data;
status = wg_write_messages(ds, vl, cb);
}
static int config_set_char(char *dest, oconfig_item_t *ci) {
}
static int config_set_char(char *dest, oconfig_item_t *ci) {
status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
if (status != 0)
status = cf_util_get_string_buffer(ci, buffer, sizeof(buffer));
if (status != 0)
if (buffer[0] == 0) {
ERROR("write_graphite plugin: Cannot use an empty string for the "
"\"EscapeCharacter\" option.");
if (buffer[0] == 0) {
ERROR("write_graphite plugin: Cannot use an empty string for the "
"\"EscapeCharacter\" option.");
}
static int wg_config_node(oconfig_item_t *ci) {
}
static int wg_config_node(oconfig_item_t *ci) {
cb = calloc(1, sizeof(*cb));
if (cb == NULL) {
ERROR("write_graphite plugin: calloc failed.");
cb = calloc(1, sizeof(*cb));
if (cb == NULL) {
ERROR("write_graphite plugin: calloc failed.");
}
cb->sock_fd = -1;
cb->name = NULL;
}
cb->sock_fd = -1;
cb->name = NULL;
status = cf_util_get_string(ci, &cb->name);
if (status != 0) {
wg_callback_free(cb);
status = cf_util_get_string(ci, &cb->name);
if (status != 0) {
wg_callback_free(cb);
if (status != 0) {
wg_callback_free(cb);
if (status != 0) {
wg_callback_free(cb);
}
/* FIXME: Legacy configuration syntax. */
}
/* FIXME: Legacy configuration syntax. */
plugin_register_flush(callback_name, wg_flush, &(user_data_t){.data = cb});
plugin_register_flush(callback_name, wg_flush, &(user_data_t){.data = cb});
}
static int wg_config(oconfig_item_t *ci) {
}
static int wg_config(oconfig_item_t *ci) {
}
void module_register(void) {
}
void module_register(void) {
"status %i: %s",
status, cb->curl_errbuf);
}
"status %i: %s",
status, cb->curl_errbuf);
}
} /* }}} wh_post_nolock */
static int wh_callback_init(wh_callback_t *cb) /* {{{ */
{
if (cb->curl != NULL)
} /* }}} wh_post_nolock */
static int wh_callback_init(wh_callback_t *cb) /* {{{ */
{
if (cb->curl != NULL)
cb->curl = curl_easy_init();
if (cb->curl == NULL) {
ERROR("curl plugin: curl_easy_init failed.");
cb->curl = curl_easy_init();
if (cb->curl == NULL) {
ERROR("curl plugin: curl_easy_init failed.");
}
if (cb->low_speed_limit > 0 && cb->low_speed_time > 0) {
}
if (cb->low_speed_limit > 0 && cb->low_speed_time > 0) {
cb->credentials = malloc(credentials_size);
if (cb->credentials == NULL) {
ERROR("curl plugin: malloc failed.");
cb->credentials = malloc(credentials_size);
if (cb->credentials == NULL) {
ERROR("curl plugin: malloc failed.");
}
ssnprintf(cb->credentials, credentials_size, "%s:%s", cb->user,
}
ssnprintf(cb->credentials, credentials_size, "%s:%s", cb->user,
} /* }}} int wh_callback_init */
static int wh_flush_nolock(cdtime_t timeout, wh_callback_t *cb) /* {{{ */
} /* }}} int wh_callback_init */
static int wh_flush_nolock(cdtime_t timeout, wh_callback_t *cb) /* {{{ */
now = cdtime();
if ((cb->send_buffer_init_time + timeout) > now)
now = cdtime();
if ((cb->send_buffer_init_time + timeout) > now)
}
if (cb->format == WH_FORMAT_COMMAND) {
if (cb->send_buffer_fill == 0) {
cb->send_buffer_init_time = cdtime();
}
if (cb->format == WH_FORMAT_COMMAND) {
if (cb->send_buffer_fill == 0) {
cb->send_buffer_init_time = cdtime();
}
status = wh_post_nolock(cb, cb->send_buffer);
}
status = wh_post_nolock(cb, cb->send_buffer);
} else if (cb->format == WH_FORMAT_JSON || cb->format == WH_FORMAT_KAIROSDB) {
if (cb->send_buffer_fill <= 2) {
cb->send_buffer_init_time = cdtime();
} else if (cb->format == WH_FORMAT_JSON || cb->format == WH_FORMAT_KAIROSDB) {
if (cb->send_buffer_fill <= 2) {
cb->send_buffer_init_time = cdtime();
}
status = format_json_finalize(cb->send_buffer, &cb->send_buffer_fill,
}
status = format_json_finalize(cb->send_buffer, &cb->send_buffer_fill,
ERROR("write_http: wh_flush_nolock: "
"format_json_finalize failed.");
wh_reset_buffer(cb);
ERROR("write_http: wh_flush_nolock: "
"format_json_finalize failed.");
wh_reset_buffer(cb);
}
status = wh_post_nolock(cb, cb->send_buffer);
}
status = wh_post_nolock(cb, cb->send_buffer);
ERROR("write_http: wh_flush_nolock: "
"Unknown format: %i",
cb->format);
ERROR("write_http: wh_flush_nolock: "
"Unknown format: %i",
cb->format);
} /* }}} wh_flush_nolock */
static int wh_flush(cdtime_t timeout, /* {{{ */
} /* }}} wh_flush_nolock */
static int wh_flush(cdtime_t timeout, /* {{{ */
int status;
if (user_data == NULL)
int status;
if (user_data == NULL)
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
}
status = wh_flush_nolock(timeout, cb);
pthread_mutex_unlock(&cb->send_lock);
}
status = wh_flush_nolock(timeout, cb);
pthread_mutex_unlock(&cb->send_lock);
} /* }}} int wh_flush */
static void wh_callback_free(void *data) /* {{{ */
} /* }}} int wh_flush */
static void wh_callback_free(void *data) /* {{{ */
status = FORMAT_VL(key, sizeof(key), vl);
if (status != 0) {
ERROR("write_http plugin: error with format_name");
status = FORMAT_VL(key, sizeof(key), vl);
if (status != 0) {
ERROR("write_http plugin: error with format_name");
}
escape_string(key, sizeof(key));
}
escape_string(key, sizeof(key));
if (status != 0) {
ERROR("write_http plugin: error with "
"wh_value_list_to_string");
if (status != 0) {
ERROR("write_http plugin: error with "
"wh_value_list_to_string");
}
command_len = (size_t)ssnprintf(command, sizeof(command),
}
command_len = (size_t)ssnprintf(command, sizeof(command),
ERROR("write_http plugin: Command buffer too small: "
"Need %zu bytes.",
command_len + 1);
ERROR("write_http plugin: Command buffer too small: "
"Need %zu bytes.",
command_len + 1);
}
pthread_mutex_lock(&cb->send_lock);
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
}
pthread_mutex_lock(&cb->send_lock);
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
}
if (command_len >= cb->send_buffer_free) {
status = wh_flush_nolock(/* timeout = */ 0, cb);
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
}
if (command_len >= cb->send_buffer_free) {
status = wh_flush_nolock(/* timeout = */ 0, cb);
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
}
}
assert(command_len < cb->send_buffer_free);
}
}
assert(command_len < cb->send_buffer_free);
/* Check if we have enough space for this command. */
pthread_mutex_unlock(&cb->send_lock);
/* Check if we have enough space for this command. */
pthread_mutex_unlock(&cb->send_lock);
} /* }}} int wh_write_command */
static int wh_write_json(const data_set_t *ds, const value_list_t *vl, /* {{{ */
} /* }}} int wh_write_command */
static int wh_write_json(const data_set_t *ds, const value_list_t *vl, /* {{{ */
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
if (status != 0) {
wh_reset_buffer(cb);
pthread_mutex_unlock(&cb->send_lock);
if (status != 0) {
wh_reset_buffer(cb);
pthread_mutex_unlock(&cb->send_lock);
}
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
}
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
}
DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
}
DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
/* Check if we have enough space for this command. */
pthread_mutex_unlock(&cb->send_lock);
/* Check if we have enough space for this command. */
pthread_mutex_unlock(&cb->send_lock);
} /* }}} int wh_write_json */
static int wh_write_kairosdb(const data_set_t *ds,
} /* }}} int wh_write_json */
static int wh_write_kairosdb(const data_set_t *ds,
if (status != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
if (status != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
if (status != 0) {
wh_reset_buffer(cb);
pthread_mutex_unlock(&cb->send_lock);
if (status != 0) {
wh_reset_buffer(cb);
pthread_mutex_unlock(&cb->send_lock);
}
status = format_kairosdb_value_list(
}
status = format_kairosdb_value_list(
}
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
}
if (status != 0) {
pthread_mutex_unlock(&cb->send_lock);
}
DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
}
DEBUG("write_http plugin: <%s> buffer %zu/%zu (%g%%)", cb->location,
/* Check if we have enough space for this command. */
pthread_mutex_unlock(&cb->send_lock);
/* Check if we have enough space for this command. */
pthread_mutex_unlock(&cb->send_lock);
} /* }}} int wh_write_kairosdb */
static int wh_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
} /* }}} int wh_write_kairosdb */
static int wh_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
int status;
if (user_data == NULL)
int status;
if (user_data == NULL)
cb = user_data->data;
assert(cb->send_metrics);
cb = user_data->data;
assert(cb->send_metrics);
status = wh_write_command(ds, vl, cb);
break;
}
status = wh_write_command(ds, vl, cb);
break;
}
} /* }}} int wh_write */
static int wh_notify(notification_t const *n, user_data_t *ud) /* {{{ */
} /* }}} int wh_write */
static int wh_notify(notification_t const *n, user_data_t *ud) /* {{{ */
int status;
if ((ud == NULL) || (ud->data == NULL))
int status;
if ((ud == NULL) || (ud->data == NULL))
cb = ud->data;
assert(cb->send_notifications);
cb = ud->data;
assert(cb->send_notifications);
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
if (wh_callback_init(cb) != 0) {
ERROR("write_http plugin: wh_callback_init failed.");
pthread_mutex_unlock(&cb->send_lock);
}
status = wh_post_nolock(cb, alert);
pthread_mutex_unlock(&cb->send_lock);
}
status = wh_post_nolock(cb, alert);
pthread_mutex_unlock(&cb->send_lock);
} /* }}} int wh_notify */
static int config_set_format(wh_callback_t *cb, /* {{{ */
} /* }}} int wh_notify */
static int config_set_format(wh_callback_t *cb, /* {{{ */
WARNING("write_http plugin: The `%s' config option "
"needs exactly one string argument.",
ci->key);
WARNING("write_http plugin: The `%s' config option "
"needs exactly one string argument.",
ci->key);
}
string = ci->values[0].value.string;
}
string = ci->values[0].value.string;
cb->format = WH_FORMAT_KAIROSDB;
else {
ERROR("write_http plugin: Invalid format string: %s", string);
cb->format = WH_FORMAT_KAIROSDB;
else {
ERROR("write_http plugin: Invalid format string: %s", string);
} /* }}} int config_set_format */
static int wh_config_append_string(const char *name,
} /* }}} int config_set_format */
static int wh_config_append_string(const char *name,
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("write_http plugin: `%s' needs exactly one string argument.", name);
struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
WARNING("write_http plugin: `%s' needs exactly one string argument.", name);
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
}
temp = curl_slist_append(*dest, ci->values[0].value.string);
if (temp == NULL)
} /* }}} int wh_config_append_string */
static int wh_config_node(oconfig_item_t *ci) /* {{{ */
} /* }}} int wh_config_append_string */
static int wh_config_node(oconfig_item_t *ci) /* {{{ */
cb = calloc(1, sizeof(*cb));
if (cb == NULL) {
ERROR("write_http plugin: calloc failed.");
cb = calloc(1, sizeof(*cb));
if (cb == NULL) {
ERROR("write_http plugin: calloc failed.");
}
cb->verify_peer = 1;
cb->verify_host = 1;
}
cb->verify_peer = 1;
cb->verify_host = 1;
if (status != 0) {
wh_callback_free(cb);
if (status != 0) {
wh_callback_free(cb);
}
if (cb->location == NULL) {
ERROR("write_http plugin: no URL defined for instance '%s'", cb->name);
wh_callback_free(cb);
}
if (cb->location == NULL) {
ERROR("write_http plugin: no URL defined for instance '%s'", cb->name);
wh_callback_free(cb);
}
if (!cb->send_metrics && !cb->send_notifications) {
}
if (!cb->send_metrics && !cb->send_notifications) {
"are enabled for \"%s\".",
cb->name);
wh_callback_free(cb);
"are enabled for \"%s\".",
cb->name);
wh_callback_free(cb);
}
if (cb->low_speed_limit > 0)
}
if (cb->low_speed_limit > 0)
if (cb->send_buffer == NULL) {
ERROR("write_http plugin: malloc(%zu) failed.", cb->send_buffer_size);
wh_callback_free(cb);
if (cb->send_buffer == NULL) {
ERROR("write_http plugin: malloc(%zu) failed.", cb->send_buffer_size);
wh_callback_free(cb);
}
/* Nulls the buffer and sets ..._free and ..._fill. */
wh_reset_buffer(cb);
}
/* Nulls the buffer and sets ..._free and ..._fill. */
wh_reset_buffer(cb);
user_data.free_func = NULL;
}
user_data.free_func = NULL;
}
} /* }}} int wh_config_node */
static int wh_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int wh_config_node */
static int wh_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int wh_config */
static int wh_init(void) /* {{{ */
} /* }}} int wh_config */
static int wh_init(void) /* {{{ */
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
/* Call this while collectd is still single-threaded to avoid
* initialization issues in libgcrypt. */
curl_global_init(CURL_GLOBAL_SSL);
} /* }}} int wh_init */
void module_register(void) /* {{{ */
} /* }}} int wh_init */
void module_register(void) /* {{{ */
rd_kafka_topic_conf_t *topic_conf;
if (ctx->kafka != NULL && ctx->topic != NULL)
rd_kafka_topic_conf_t *topic_conf;
if (ctx->kafka != NULL && ctx->topic != NULL)
if (ctx->kafka == NULL) {
if ((conf = rd_kafka_conf_dup(ctx->kafka_conf)) == NULL) {
ERROR("write_kafka plugin: cannot duplicate kafka config");
if (ctx->kafka == NULL) {
if ((conf = rd_kafka_conf_dup(ctx->kafka_conf)) == NULL) {
ERROR("write_kafka plugin: cannot duplicate kafka config");
}
if ((ctx->kafka = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errbuf,
}
if ((ctx->kafka = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errbuf,
rd_kafka_topic_name(ctx->topic));
}
rd_kafka_topic_name(ctx->topic));
}
} /* }}} int kafka_handle */
} /* }}} int kafka_handle */
}
if (conf != NULL)
rd_kafka_conf_destroy(conf);
}
if (conf != NULL)
rd_kafka_conf_destroy(conf);
errout:
if (conf != NULL)
rd_kafka_conf_destroy(conf);
errout:
if (conf != NULL)
rd_kafka_conf_destroy(conf);
status = format_graphite(buffer, sizeof(buffer), ds, vl, NULL, NULL, '_', 0);
if (status != 0) /* error message has been printed already. */
status = format_graphite(buffer, sizeof(buffer), ds, vl, NULL, NULL, '_', 0);
if (status != 0) /* error message has been printed already. */
INFO("write_log values:\n%s", buffer);
INFO("write_log values:\n%s", buffer);
} /* int wl_write_graphite */
static int wl_write_json(const data_set_t *ds, const value_list_t *vl) {
} /* int wl_write_graphite */
static int wl_write_json(const data_set_t *ds, const value_list_t *vl) {
INFO("write_log values:\n%s", buffer);
INFO("write_log values:\n%s", buffer);
} /* int wl_write_json */
static int wl_write(const data_set_t *ds, const value_list_t *vl,
} /* int wl_write_json */
static int wl_write(const data_set_t *ds, const value_list_t *vl,
status = wl_write_json(ds, vl);
}
status = wl_write_json(ds, vl);
}
}
static int wl_config(oconfig_item_t *ci) /* {{{ */
}
static int wl_config(oconfig_item_t *ci) /* {{{ */
else {
ERROR("write_log plugin: Unknown format `%s' for option `%s'.", str,
child->key);
else {
ERROR("write_log plugin: Unknown format `%s' for option `%s'.", str,
child->key);
}
} else {
ERROR("write_log plugin: Invalid configuration option: `%s'.",
child->key);
}
} else {
ERROR("write_log plugin: Invalid configuration option: `%s'.",
child->key);
} /* }}} int wl_config */
void module_register(void) {
} /* }}} int wl_config */
void module_register(void) {
node = calloc(1, sizeof(*node));
if (node == NULL)
node = calloc(1, sizeof(*node));
if (node == NULL)
mongoc_init();
node->host = NULL;
node->store_rates = 1;
mongoc_init();
node->host = NULL;
node->store_rates = 1;
if (status != 0) {
sfree(node);
if (status != 0) {
sfree(node);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
if (status != 0)
wm_config_free(node);
if (status != 0)
wm_config_free(node);
} /* }}} int wm_config_node */
static int wm_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int wm_config_node */
static int wm_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int wm_config */
void module_register(void) {
} /* }}} int wm_config */
void module_register(void) {
if (m == NULL)
return -1;
if (m == NULL)
return -1;
- return metric_update(m, vl->values[ds_index], ds->ds[ds_index].type, vl->time,
- vl->interval);
+ return metric_update(m, vl->values[ds_index], ds->ds[ds_index].type,
+ vl->time, vl->interval);
}
/* metric_family_destroy frees the memory used by a metric family. */
}
/* metric_family_destroy frees the memory used by a metric family. */
status = FORMAT_VL(ident, sizeof(ident), vl);
if (status != 0)
status = FORMAT_VL(ident, sizeof(ident), vl);
if (status != 0)
ssnprintf(key, sizeof(key), "%s%s",
(node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX,
ident);
ssnprintf(key, sizeof(key), "%s%s",
(node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX,
ident);
value_ptr = &value[0];
status = format_values(value_ptr, value_size, ds, vl, node->store_rates);
if (status != 0)
value_ptr = &value[0];
status = format_values(value_ptr, value_size, ds, vl, node->store_rates);
if (status != 0)
pthread_mutex_lock(&node->lock);
pthread_mutex_lock(&node->lock);
(node->host != NULL) ? node->host : "localhost",
(node->port != 0) ? node->port : 6379);
pthread_mutex_unlock(&node->lock);
(node->host != NULL) ? node->host : "localhost",
(node->port != 0) ? node->port : 6379);
pthread_mutex_unlock(&node->lock);
} else if (node->conn->err) {
ERROR(
"write_redis plugin: Connecting to host \"%s\" (port %i) failed: %s",
(node->host != NULL) ? node->host : "localhost",
(node->port != 0) ? node->port : 6379, node->conn->errstr);
pthread_mutex_unlock(&node->lock);
} else if (node->conn->err) {
ERROR(
"write_redis plugin: Connecting to host \"%s\" (port %i) failed: %s",
(node->host != NULL) ? node->host : "localhost",
(node->port != 0) ? node->port : 6379, node->conn->errstr);
pthread_mutex_unlock(&node->lock);
}
rr = redisCommand(node->conn, "SELECT %d", node->database);
}
rr = redisCommand(node->conn, "SELECT %d", node->database);
pthread_mutex_unlock(&node->lock);
pthread_mutex_unlock(&node->lock);
} /* }}} int wr_write */
static void wr_config_free(void *ptr) /* {{{ */
} /* }}} int wr_write */
static void wr_config_free(void *ptr) /* {{{ */
node = calloc(1, sizeof(*node));
if (node == NULL)
node = calloc(1, sizeof(*node));
if (node == NULL)
node->host = NULL;
node->port = 0;
node->timeout.tv_sec = 0;
node->host = NULL;
node->port = 0;
node->timeout.tv_sec = 0;
status = cf_util_get_string_buffer(ci, node->name, sizeof(node->name));
if (status != 0) {
sfree(node);
status = cf_util_get_string_buffer(ci, node->name, sizeof(node->name));
if (status != 0) {
sfree(node);
}
for (int i = 0; i < ci->children_num; i++) {
}
for (int i = 0; i < ci->children_num; i++) {
if (status != 0)
wr_config_free(node);
if (status != 0)
wr_config_free(node);
} /* }}} int wr_config_node */
static int wr_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int wr_config_node */
static int wr_config(oconfig_item_t *ci) /* {{{ */
} /* }}} int wr_config */
void module_register(void) {
} /* }}} int wr_config */
void module_register(void) {
static int wrr_disconnect(struct riemann_host *host) /* {{{ */
{
if (!host->client)
static int wrr_disconnect(struct riemann_host *host) /* {{{ */
{
if (!host->client)
riemann_client_free(host->client);
host->client = NULL;
riemann_client_free(host->client);
host->client = NULL;
} /* }}} int wrr_disconnect */
/**
} /* }}} int wrr_disconnect */
/**
if (msg == NULL) {
ERROR("write_riemann plugin: riemann_message_create_with_events() failed.");
riemann_event_free(event);
if (msg == NULL) {
ERROR("write_riemann plugin: riemann_message_create_with_events() failed.");
riemann_event_free(event);
}
DEBUG("write_riemann plugin: Successfully created message for notification: "
"host = \"%s\", service = \"%s\", state = \"%s\"",
event->host, event->service, event->state);
}
DEBUG("write_riemann plugin: Successfully created message for notification: "
"host = \"%s\", service = \"%s\", state = \"%s\"",
event->host, event->service, event->state);
} /* }}} riemann_message_t *wrr_notification_to_message */
static riemann_event_t *
} /* }}} riemann_message_t *wrr_notification_to_message */
static riemann_event_t *
event = riemann_event_new();
if (event == NULL) {
ERROR("write_riemann plugin: riemann_event_new() failed.");
event = riemann_event_new();
if (event == NULL) {
ERROR("write_riemann plugin: riemann_event_new() failed.");
}
format_name(name_buffer, sizeof(name_buffer),
}
format_name(name_buffer, sizeof(name_buffer),
DEBUG("write_riemann plugin: Successfully created message for metric: "
"host = \"%s\", service = \"%s\"",
event->host, event->service);
DEBUG("write_riemann plugin: Successfully created message for metric: "
"host = \"%s\", service = \"%s\"",
event->host, event->service);
} /* }}} riemann_event_t *wrr_value_to_event */
static riemann_message_t *
} /* }}} riemann_event_t *wrr_value_to_event */
static riemann_message_t *
msg = riemann_message_new();
if (msg == NULL) {
ERROR("write_riemann plugin: riemann_message_new failed.");
msg = riemann_message_new();
if (msg == NULL) {
ERROR("write_riemann plugin: riemann_message_new failed.");
}
if (host->store_rates) {
}
if (host->store_rates) {
if (rates == NULL) {
ERROR("write_riemann plugin: uc_get_rate failed.");
riemann_message_free(msg);
if (rates == NULL) {
ERROR("write_riemann plugin: uc_get_rate failed.");
riemann_message_free(msg);
if (event == NULL) {
riemann_message_free(msg);
sfree(rates);
if (event == NULL) {
riemann_message_free(msg);
sfree(rates);
}
riemann_message_append_events(msg, event, NULL);
}
sfree(rates);
}
riemann_message_append_events(msg, event, NULL);
}
sfree(rates);
} /* }}} riemann_message_t *wrr_value_list_to_message */
/*
} /* }}} riemann_message_t *wrr_value_list_to_message */
/*
int status;
if (user_data == NULL)
int status;
if (user_data == NULL)
host = user_data->data;
pthread_mutex_lock(&host->lock);
host = user_data->data;
pthread_mutex_lock(&host->lock);
*/
msg = wrr_notification_to_message(host, n);
if (msg == NULL)
*/
msg = wrr_notification_to_message(host, n);
if (msg == NULL)
status = wrr_send(host, msg);
if (status != 0)
status = wrr_send(host, msg);
if (status != 0)
"write_riemann plugin: riemann_client_send succeeded");
riemann_message_free(msg);
"write_riemann plugin: riemann_client_send succeeded");
riemann_message_free(msg);
} /* }}} int wrr_notification */
static int wrr_write(const data_set_t *ds, /* {{{ */
} /* }}} int wrr_notification */
static int wrr_write(const data_set_t *ds, /* {{{ */
} else {
msg = wrr_value_list_to_message(host, ds, vl, statuses);
if (msg == NULL)
} else {
msg = wrr_value_list_to_message(host, ds, vl, statuses);
if (msg == NULL)
status = wrr_send(host, msg);
status = wrr_send(host, msg);
* holding a reference. */
pthread_mutex_unlock(&host->lock);
wrr_free(host);
* holding a reference. */
pthread_mutex_unlock(&host->lock);
wrr_free(host);
}
host->reference_count--;
}
host->reference_count--;
if (child->values_num != 2) {
WARNING("riemann attributes need both a key and a value.");
if (child->values_num != 2) {
WARNING("riemann attributes need both a key and a value.");
}
if (child->values[0].type != OCONFIG_TYPE_STRING ||
child->values[1].type != OCONFIG_TYPE_STRING) {
WARNING("riemann attribute needs string arguments.");
}
if (child->values[0].type != OCONFIG_TYPE_STRING ||
child->values[1].type != OCONFIG_TYPE_STRING) {
WARNING("riemann attribute needs string arguments.");
}
if ((key = strdup(child->values[0].value.string)) == NULL) {
WARNING("cannot allocate memory for attribute key.");
}
if ((key = strdup(child->values[0].value.string)) == NULL) {
WARNING("cannot allocate memory for attribute key.");
}
if ((val = strdup(child->values[1].value.string)) == NULL) {
WARNING("cannot allocate memory for attribute value.");
sfree(key);
}
if ((val = strdup(child->values[1].value.string)) == NULL) {
WARNING("cannot allocate memory for attribute value.");
sfree(key);
}
strarray_add(&riemann_attrs, &riemann_attrs_num, key);
strarray_add(&riemann_attrs, &riemann_attrs_num, val);
}
strarray_add(&riemann_attrs, &riemann_attrs_num, key);
strarray_add(&riemann_attrs, &riemann_attrs_num, val);
} /* }}} int wrr_config */
void module_register(void) {
} /* }}} int wrr_config */
void module_register(void) {
if (ds != NULL) {
ds_name = ds->ds[ds_index].name;
if ((th->data_source[0] != 0) && (strcmp(ds_name, th->data_source) != 0))
if (ds != NULL) {
ds_name = ds->ds[ds_index].name;
if ((th->data_source[0] != 0) && (strcmp(ds_name, th->data_source) != 0))
}
if ((th->flags & UT_FLAG_INVERT) != 0) {
}
if ((th->flags & UT_FLAG_INVERT) != 0) {
((th->failure_min + th->hysteresis) < values[ds_index])) ||
(!isnan(th->failure_max) &&
((th->failure_max - th->hysteresis) > values[ds_index])))
((th->failure_min + th->hysteresis) < values[ds_index])) ||
(!isnan(th->failure_max) &&
((th->failure_max - th->hysteresis) > values[ds_index])))
else
is_failure++;
case STATE_WARNING:
else
is_failure++;
case STATE_WARNING:
((th->warning_min + th->hysteresis) < values[ds_index])) ||
(!isnan(th->warning_max) &&
((th->warning_max - th->hysteresis) > values[ds_index])))
((th->warning_min + th->hysteresis) < values[ds_index])) ||
(!isnan(th->warning_max) &&
((th->warning_max - th->hysteresis) > values[ds_index])))
- return (STATE_WARNING);
} /* }}} int ut_check_one_data_source */
/*
} /* }}} int ut_check_one_data_source */
/*
}
} /* for (ds->ds_num) */
}
} /* for (ds->ds_num) */
} /* }}} int ut_check_one_threshold */
/*
} /* }}} int ut_check_one_threshold */
/*
th = threshold_search(vl);
pthread_mutex_unlock(&threshold_lock);
if (th == NULL)
th = threshold_search(vl);
pthread_mutex_unlock(&threshold_lock);
if (th == NULL)
DEBUG("ut_check_threshold: Found matching threshold(s)");
values = uc_get_rate(ds, vl);
if (values == NULL)
DEBUG("ut_check_threshold: Found matching threshold(s)");
values = uc_get_rate(ds, vl);
if (values == NULL)
while (th != NULL) {
status = ut_check_one_threshold(ds, vl, th, values, statuses);
if (status < 0) {
ERROR("ut_check_threshold: ut_check_one_threshold failed.");
sfree(values);
while (th != NULL) {
status = ut_check_one_threshold(ds, vl, th, values, statuses);
if (status < 0) {
ERROR("ut_check_threshold: ut_check_one_threshold failed.");
sfree(values);
} /* }}} int ut_check_threshold */
} /* }}} int ut_check_threshold */
do { \
size_t l = strlen(str); \
if (l >= buffer_size) \
do { \
size_t l = strlen(str); \
if (l >= buffer_size) \
memcpy(buffer, (str), l); \
buffer += l; \
buffer_size -= l; \
memcpy(buffer, (str), l); \
buffer += l; \
buffer_size -= l; \
buffer[0] = 0;
#undef APPEND
buffer[0] = 0;
#undef APPEND
} /* int sensu_format_name2 */
static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */
} /* int sensu_format_name2 */
static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */
if ((cb->ai_last_update + resolve_interval + cb->next_random_ttl) >= now) {
DEBUG("write_tsdb plugin: too many getaddrinfo(%s, %s) failures", node,
service);
if ((cb->ai_last_update + resolve_interval + cb->next_random_ttl) >= now) {
DEBUG("write_tsdb plugin: too many getaddrinfo(%s, %s) failures", node,
service);
}
cb->ai_last_update = now;
cb->next_random_ttl = new_random_ttl();
}
cb->ai_last_update = now;
cb->next_random_ttl = new_random_ttl();
xc_handle = xc_interface_open(XC_INTERFACE_INIT_ARGS);
if (!xc_handle) {
ERROR("xencpu: xc_interface_open() failed");
xc_handle = xc_interface_open(XC_INTERFACE_INIT_ARGS);
if (!xc_handle) {
ERROR("xencpu: xc_interface_open() failed");
}
xc_physinfo_t *physinfo;
}
xc_physinfo_t *physinfo;
if (physinfo == NULL) {
ERROR("xencpu plugin: calloc() for physinfo failed.");
xc_interface_close(xc_handle);
if (physinfo == NULL) {
ERROR("xencpu plugin: calloc() for physinfo failed.");
xc_interface_close(xc_handle);
}
if (xc_physinfo(xc_handle, physinfo) < 0) {
ERROR("xencpu plugin: xc_physinfo() failed");
xc_interface_close(xc_handle);
free(physinfo);
}
if (xc_physinfo(xc_handle, physinfo) < 0) {
ERROR("xencpu plugin: xc_physinfo() failed");
xc_interface_close(xc_handle);
free(physinfo);
}
num_cpus = physinfo->nr_cpus;
}
num_cpus = physinfo->nr_cpus;
if (cpu_info == NULL) {
ERROR("xencpu plugin: calloc() for num_cpus failed.");
xc_interface_close(xc_handle);
if (cpu_info == NULL) {
ERROR("xencpu plugin: calloc() for num_cpus failed.");
xc_interface_close(xc_handle);
}
cpu_states = calloc(num_cpus, sizeof(value_to_rate_state_t));
}
cpu_states = calloc(num_cpus, sizeof(value_to_rate_state_t));
ERROR("xencpu plugin: calloc() for cpu_states failed.");
xc_interface_close(xc_handle);
free(cpu_info);
ERROR("xencpu plugin: calloc() for cpu_states failed.");
xc_interface_close(xc_handle);
free(cpu_info);
} /* static int xencpu_init */
static int xencpu_shutdown(void) {
} /* static int xencpu_init */
static int xencpu_shutdown(void) {
if (rc < 0) {
ERROR("xencpu: xc_getcpuinfo() Failed: %d %s\n", rc,
xc_strerror(xc_handle, errno));
if (rc < 0) {
ERROR("xencpu: xc_getcpuinfo() Failed: %d %s\n", rc,
xc_strerror(xc_handle, errno));
} /* static int xencpu_read */
void module_register(void) {
} /* static int xencpu_read */
void module_register(void) {
gint nch;
if (!xmms_remote_is_running(xmms_session))
gint nch;
if (!xmms_remote_is_running(xmms_session))
xmms_remote_get_info(xmms_session, &rate, &freq, &nch);
if ((freq == 0) || (nch == 0))
xmms_remote_get_info(xmms_session, &rate, &freq, &nch);
if ((freq == 0) || (nch == 0))
cxmms_submit("bitrate", rate);
cxmms_submit("frequency", freq);
cxmms_submit("bitrate", rate);
cxmms_submit("frequency", freq);
} /* int read */
void module_register(void) {
} /* int read */
void module_register(void) {
e = llist_search(ksp, key);
if (e == NULL) {
e = llist_search(ksp, key);
if (e == NULL) {
- return ((long long)v->derive);
+ return (long long)v->derive;
}
static void free_zfs_values(kstat_t *ksp) {
}
static void free_zfs_values(kstat_t *ksp) {
static long long get_zfs_value(kstat_t *ksp, char *name) {
static long long get_zfs_value(kstat_t *ksp, char *name) {
- return (get_kstat_value(ksp, name));
+ return get_kstat_value(ksp, name);
}
#elif defined(KERNEL_FREEBSD)
#include <sys/sysctl.h>
}
#elif defined(KERNEL_FREEBSD)
#include <sys/sysctl.h>
rv = sysctlbyname(buffer, (void *)&value, &valuelen,
/* new value = */ NULL, /* new length = */ (size_t)0);
if (rv == 0)
rv = sysctlbyname(buffer, (void *)&value, &valuelen,
/* new value = */ NULL, /* new length = */ (size_t)0);
if (rv == 0)
long long tmp = get_zfs_value(ksp, (char *)kstat_value);
if (tmp == -1LL) {
DEBUG("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value);
long long tmp = get_zfs_value(ksp, (char *)kstat_value);
if (tmp == -1LL) {
DEBUG("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value);
}
za_submit(type, type_instance, &(value_t){.derive = (derive_t)tmp},
/* values_num = */ 1);
}
za_submit(type, type_instance, &(value_t){.derive = (derive_t)tmp},
/* values_num = */ 1);
}
static int za_read_gauge(kstat_t *ksp, const char *kstat_value,
}
static int za_read_gauge(kstat_t *ksp, const char *kstat_value,
long long tmp = get_zfs_value(ksp, (char *)kstat_value);
if (tmp == -1LL) {
DEBUG("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value);
long long tmp = get_zfs_value(ksp, (char *)kstat_value);
if (tmp == -1LL) {
DEBUG("zfs_arc plugin: Reading kstat value \"%s\" failed.", kstat_value);
}
za_submit(type, type_instance, &(value_t){.gauge = (gauge_t)tmp},
/* values_num = */ 1);
}
za_submit(type, type_instance, &(value_t){.gauge = (gauge_t)tmp},
/* values_num = */ 1);
}
static void za_submit_ratio(const char *type_instance, gauge_t hits,
}
static void za_submit_ratio(const char *type_instance, gauge_t hits,
char errbuf[1024];
ERROR("zfs_arc plugin: Opening \"%s\" failed: %s", ZOL_ARCSTATS_FILE,
sstrerror(errno, errbuf, sizeof(errbuf)));
char errbuf[1024];
ERROR("zfs_arc plugin: Opening \"%s\" failed: %s", ZOL_ARCSTATS_FILE,
sstrerror(errno, errbuf, sizeof(errbuf)));
}
ksp = llist_create();
if (ksp == NULL) {
ERROR("zfs_arc plugin: `llist_create' failed.");
fclose(fh);
}
ksp = llist_create();
if (ksp == NULL) {
ERROR("zfs_arc plugin: `llist_create' failed.");
fclose(fh);
}
// Ignore the first two lines because they contain information about
}
// Ignore the first two lines because they contain information about
if (fgets(buffer, sizeof(buffer), fh) == NULL) {
ERROR("zfs_arc plugin: \"%s\" does not contain a single line.", ZOL_ARCSTATS_FILE);
fclose(fh);
if (fgets(buffer, sizeof(buffer), fh) == NULL) {
ERROR("zfs_arc plugin: \"%s\" does not contain a single line.", ZOL_ARCSTATS_FILE);
fclose(fh);
}
if (fgets(buffer, sizeof(buffer), fh) == NULL) {
ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.", ZOL_ARCSTATS_FILE);
fclose(fh);
}
if (fgets(buffer, sizeof(buffer), fh) == NULL) {
ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.", ZOL_ARCSTATS_FILE);
fclose(fh);
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
}
while (fgets(buffer, sizeof(buffer), fh) != NULL) {
get_kstat(&ksp, "zfs", 0, "arcstats");
if (ksp == NULL) {
ERROR("zfs_arc plugin: Cannot find zfs:0:arcstats kstat.");
get_kstat(&ksp, "zfs", 0, "arcstats");
if (ksp == NULL) {
ERROR("zfs_arc plugin: Cannot find zfs:0:arcstats kstat.");
free_zfs_values(ksp);
#endif
free_zfs_values(ksp);
#endif
} /* int za_read */
static int za_init(void) /* {{{ */
} /* int za_read */
static int za_init(void) /* {{{ */
* went fine. */
if (kc == NULL) {
ERROR("zfs_arc plugin: kstat chain control structure not available.");
* went fine. */
if (kc == NULL) {
ERROR("zfs_arc plugin: kstat chain control structure not available.");
} /* }}} int za_init */
void module_register(void) {
} /* }}} int za_init */
void module_register(void) {
static int zone_compare(const void *a, const void *b) {
if (*(const zoneid_t *)a == *(const zoneid_t *)b)
static int zone_compare(const void *a, const void *b) {
if (*(const zoneid_t *)a == *(const zoneid_t *)b)
if (*(const zoneid_t *)a < *(const zoneid_t *)b)
if (*(const zoneid_t *)a < *(const zoneid_t *)b)
- return (-1);
- return (1);
}
static int zone_read_procfile(char const *pidstr, char const *name, void *buf,
}
static int zone_read_procfile(char const *pidstr, char const *name, void *buf,
char procfile[MAX_PROCFS_PATH];
(void)snprintf(procfile, sizeof(procfile), "/proc/%s/%s", pidstr, name);
if ((fd = open(procfile, O_RDONLY)) == -1) {
char procfile[MAX_PROCFS_PATH];
(void)snprintf(procfile, sizeof(procfile), "/proc/%s/%s", pidstr, name);
if ((fd = open(procfile, O_RDONLY)) == -1) {
}
if (sread(fd, buf, bufsize) != 0) {
}
if (sread(fd, buf, bufsize) != 0) {
ERROR("zone plugin: Reading \"%s\" failed: %s", procfile,
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
ERROR("zone plugin: Reading \"%s\" failed: %s", procfile,
sstrerror(errno, errbuf, sizeof(errbuf)));
close(fd);
}
static int zone_submit_value(char *zone, gauge_t value) {
}
static int zone_submit_value(char *zone, gauge_t value) {
sstrncpy(vl.type, "percent", sizeof(vl.type));
sstrncpy(vl.type_instance, zone, sizeof(vl.type_instance));
sstrncpy(vl.type, "percent", sizeof(vl.type));
sstrncpy(vl.type_instance, zone, sizeof(vl.type_instance));
- return (plugin_dispatch_values(&vl));
+ return plugin_dispatch_values(&vl);
}
static zone_stats_t *zone_find_stats(c_avl_tree_t *tree, zoneid_t zoneid) {
}
static zone_stats_t *zone_find_stats(c_avl_tree_t *tree, zoneid_t zoneid) {
if (c_avl_get(tree, (void **)&zoneid, (void **)&ret)) {
if (!(ret = malloc(sizeof(*ret)))) {
WARNING("zone plugin: no memory");
if (c_avl_get(tree, (void **)&zoneid, (void **)&ret)) {
if (!(ret = malloc(sizeof(*ret)))) {
WARNING("zone plugin: no memory");
}
if (!(key = malloc(sizeof(*key)))) {
WARNING("zone plugin: no memory");
free(ret);
}
if (!(key = malloc(sizeof(*key)))) {
WARNING("zone plugin: no memory");
free(ret);
}
*key = zoneid;
if (c_avl_insert(tree, key, ret)) {
WARNING("zone plugin: error inserting into tree");
}
*key = zoneid;
if (c_avl_insert(tree, key, ret)) {
WARNING("zone plugin: error inserting into tree");
}
static void zone_submit_values(c_avl_tree_t *tree) {
}
static void zone_submit_values(c_avl_tree_t *tree) {
if (!(tree = c_avl_create(zone_compare))) {
WARNING("zone plugin: Failed to create tree");
if (!(tree = c_avl_create(zone_compare))) {
WARNING("zone plugin: Failed to create tree");
stats->pctmem += psinfo.pr_pctmem;
}
}
stats->pctmem += psinfo.pr_pctmem;
}
}
}
static int zone_read(void) {
}
static int zone_read(void) {
if ((procdir = opendir("/proc")) == NULL) {
ERROR("zone plugin: cannot open /proc directory\n");
if ((procdir = opendir("/proc")) == NULL) {
ERROR("zone plugin: cannot open /proc directory\n");
}
tree = zone_scandir(procdir);
closedir(procdir);
if (tree == NULL) {
}
tree = zone_scandir(procdir);
closedir(procdir);
if (tree == NULL) {
}
zone_submit_values(tree); /* this also frees tree */
}
zone_submit_values(tree); /* this also frees tree */
}
void module_register(void) {
}
void module_register(void) {
INFO("getaddrinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
INFO("getaddrinfo failed: %s",
(status == EAI_SYSTEM) ? sstrerror(errno, errbuf, sizeof(errbuf))
: gai_strerror(status));
}
for (struct addrinfo *ai = ai_list; ai != NULL; ai = ai->ai_next) {
}
for (struct addrinfo *ai = ai_list; ai != NULL; ai = ai->ai_next) {
} /* int zookeeper_connect */
static int zookeeper_query(char *buffer, size_t buffer_size) {
} /* int zookeeper_connect */
static int zookeeper_query(char *buffer, size_t buffer_size) {
sk = zookeeper_connect();
if (sk < 0) {
ERROR("zookeeper: Could not connect to daemon");
sk = zookeeper_connect();
if (sk < 0) {
ERROR("zookeeper: Could not connect to daemon");
}
status = (int)swrite(sk, "mntr\r\n", strlen("mntr\r\n"));
}
status = (int)swrite(sk, "mntr\r\n", strlen("mntr\r\n"));
ERROR("zookeeper: write(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sk);
ERROR("zookeeper: write(2) failed: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sk);
}
memset(buffer, 0, buffer_size);
}
memset(buffer, 0, buffer_size);
ERROR("zookeeper: Error reading from socket: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sk);
ERROR("zookeeper: Error reading from socket: %s",
sstrerror(errno, errbuf, sizeof(errbuf)));
close(sk);
}
buffer_fill += (size_t)status;
}
buffer_fill += (size_t)status;
} /* int zookeeper_query */
static int zookeeper_read(void) {
} /* int zookeeper_query */
static int zookeeper_read(void) {
char *fields[2];
if (zookeeper_query(buf, sizeof(buf)) < 0) {
char *fields[2];
if (zookeeper_query(buf, sizeof(buf)) < 0) {
} /* zookeeper_read */
void module_register(void) {
} /* zookeeper_read */
void module_register(void) {