/* The raw identifier as provided by the user. */
char *raw_identifier;
- /* An array of the fully parsed identifier and all value lists, and their
+ /* An array of the fully parsed identifier and all metrics, and their
* options as provided by the user. */
- value_list_t *vl;
- size_t vl_num;
+ metrics_list_t *ml;
} cmd_putval_t;
/*
id = ret_flush->identifiers + ret_flush->identifiers_num;
ret_flush->identifiers_num++;
if (parse_identifier(opt_value, &id->host, &id->plugin,
- &id->plugin_instance, &id->type, &id->type_instance,
+ &id->type, &id->data_source,
opts->identifier_default_host) != 0) {
cmd_error(CMD_PARSE_ERROR, err, "Invalid identifier `%s'.", opt_value);
cmd_destroy_flush(ret_flush);
if (cmd.cmd.flush.identifiers_num != 0) {
identifier_t *id = cmd.cmd.flush.identifiers + j;
- if (format_name(buf, sizeof(buf), id->host, id->plugin,
- id->plugin_instance, id->type,
- id->type_instance) != 0) {
+ if (snprintf(
+ buf, sizeof(buf), "%s/%s/%s/%s", (id->host == NULL) ? "" : id->host,
+ (id->plugin == NULL) ? "" : id->plugin,
+ (id->type == NULL) ? "" : id->type,
+ (id->data_source == NULL) ? "" : id->data_source) > sizeof(buf)) {
error++;
continue;
}
}
int handle_getthreshold(FILE *fh, char *buffer) {
- char *command;
- char *identifier;
- char *identifier_copy;
+ char *command = NULL;
+ char *identifier = NULL;
+ char *identifier_copy = NULL;
- char *host;
- char *plugin;
- char *plugin_instance;
- char *type;
- char *type_instance;
+ char *host = NULL;
+ char *plugin = NULL;
+ char *type = NULL;
+ char *data_source = NULL;
threshold_t threshold;
DEBUG("utils_cmd_getthreshold: handle_getthreshold (fh = %p, buffer = %s);",
(void *)fh, buffer);
- command = NULL;
status = parse_string(&buffer, &command);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse command.\n");
return -1;
}
- identifier = NULL;
status = parse_string(&buffer, &identifier);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse identifier.\n");
* returning pointers into it */
identifier_copy = sstrdup(identifier);
- status = parse_identifier(identifier_copy, &host, &plugin, &plugin_instance,
- &type, &type_instance,
+ status = parse_identifier(identifier_copy, &host, &plugin,
+ &type, &data_source,
/* default_host = */ NULL);
if (status != 0) {
DEBUG("handle_getthreshold: Cannot parse identifier `%s'.", identifier);
return -1;
}
- value_list_t vl = {.values = NULL};
- sstrncpy(vl.host, host, sizeof(vl.host));
- sstrncpy(vl.plugin, plugin, sizeof(vl.plugin));
- if (plugin_instance != NULL)
- sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
- sstrncpy(vl.type, type, sizeof(vl.type));
- if (type_instance != NULL)
- sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
+ metric_t metric = METRIC_STRUCT_INIT;
+ metric.identity = create_identity(plugin, type, data_source, host);
+ sstrncpy(metric.plugin, plugin, sizeof(metric.plugin));
+ sstrncpy(metric.type, type, sizeof(metric.type));
+ metric.ds = plugin_get_ds(metric.type);
+
sfree(identifier_copy);
- /* TODO(octo): pass a metric_t* to ut_search_threshold(). */
- status = ut_search_threshold(NULL, &threshold);
+ status = ut_search_threshold(&metric, &threshold);
if (status == ENOENT) {
print_to_socket(fh, "-1 No threshold found for identifier %s\n",
identifier);
i++;
if (threshold.plugin[0] != 0)
i++;
- if (threshold.plugin_instance[0] != 0)
- i++;
if (threshold.type[0] != 0)
i++;
- if (threshold.type_instance[0] != 0)
- i++;
if (threshold.data_source[0] != 0)
i++;
if (!isnan(threshold.warning_min))
print_to_socket(fh, "Host: %s\n", threshold.host);
if (threshold.plugin[0] != 0)
print_to_socket(fh, "Plugin: %s\n", threshold.plugin);
- if (threshold.plugin_instance[0] != 0)
- print_to_socket(fh, "Plugin Instance: %s\n", threshold.plugin_instance);
if (threshold.type[0] != 0)
print_to_socket(fh, "Type: %s\n", threshold.type);
- if (threshold.type_instance[0] != 0)
- print_to_socket(fh, "Type Instance: %s\n", threshold.type_instance);
if (threshold.data_source[0] != 0)
print_to_socket(fh, "Data Source: %s\n", threshold.data_source);
if (!isnan(threshold.warning_min))
status = parse_identifier(
argv[0], &ret_getval->identifier.host, &ret_getval->identifier.plugin,
- &ret_getval->identifier.plugin_instance, &ret_getval->identifier.type,
- &ret_getval->identifier.type_instance, opts->identifier_default_host);
+ &ret_getval->identifier.type, &ret_getval->identifier.data_source,
+ opts->identifier_default_host);
if (status != 0) {
DEBUG("cmd_parse_getval: Cannot parse identifier `%s'.", identifier_copy);
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse identifier `%s'.",
}
gauge_t value;
- size_t values_num = 1;
- status =
- uc_get_rate_by_name(cmd.cmd.getval.raw_identifier, &value);
+ status = uc_get_rate_by_name(cmd.cmd.getval.raw_identifier, &value);
if (status != 0) {
cmd_error(CMD_ERROR, &err, "No such value.");
cmd_destroy(&cmd);
return CMD_ERROR;
}
- if (ds->ds_num != values_num) {
- ERROR("ds[%s]->ds_num = %" PRIsz ", "
- "but uc_get_rate_by_name returned %" PRIsz " values.",
- ds->type, ds->ds_num, values_num);
- cmd_error(CMD_ERROR, &err, "Error reading value from cache.");
- cmd_destroy(&cmd);
- return CMD_ERROR;
- }
-
- print_to_socket(fh, "%" PRIsz " Value%s found\n", values_num,
- (values_num == 1) ? "" : "s");
- for (size_t i = 0; i < values_num; i++) {
- print_to_socket(fh, "%s=", ds->ds[i].name);
- if (isnan(value)) {
- print_to_socket(fh, "NaN\n");
- } else {
- print_to_socket(fh, "%12e\n", value);
- }
+ print_to_socket(fh, "Value found\n");
+ print_to_socket(fh, "%s=", cmd.cmd.getval.identifier.data_source);
+ if (isnan(value)) {
+ print_to_socket(fh, "NaN\n");
+ } else {
+ print_to_socket(fh, "%12e\n", value);
}
cmd_destroy(&cmd);
return (str[0] == '"' && str[len - 1] == '"');
}
-static int set_option(value_list_t *vl, const char *key, const char *value,
+static int set_option(metric_t *metric_p, const char *key, const char *value,
cmd_error_handler_t *err) {
- if ((vl == NULL) || (key == NULL) || (value == NULL))
+ if ((metric_p == NULL) || (key == NULL) || (value == NULL))
return -1;
if (strcasecmp("interval", key) == 0) {
tmp = strtod(value, &endptr);
if ((errno == 0) && (endptr != NULL) && (endptr != value) && (tmp > 0.0))
- vl->interval = DOUBLE_TO_CDTIME_T(tmp);
+ metric_p->interval = DOUBLE_TO_CDTIME_T(tmp);
} else if (strncasecmp("meta:", key, 5) == 0) {
const char *meta_key = key + 5;
size_t value_len = strlen(value);
- if (vl->meta == NULL) {
- vl->meta = meta_data_create();
- if (vl->meta == NULL) {
+ if (metric_p->meta == NULL) {
+ metric_p->meta = meta_data_create();
+ if (metric_p->meta == NULL) {
return CMD_ERROR;
}
}
if (value_str == NULL) {
return CMD_ERROR;
}
- metadata_err = meta_data_add_string(vl->meta, meta_key, value_str);
+ metadata_err = meta_data_add_string(metric_p->meta, meta_key, value_str);
free((void *)value_str);
if (metadata_err != 0) {
return CMD_ERROR;
char *identifier;
char *hostname;
char *plugin;
- char *plugin_instance;
char *type;
- char *type_instance;
+ char *data_source;
int status;
char *identifier_copy;
const data_set_t *ds;
- value_list_t vl = VALUE_LIST_INIT;
+ metric_t metric = METRIC_STRUCT_INIT;
if ((ret_putval == NULL) || (opts == NULL)) {
errno = EINVAL;
identifier_copy = sstrdup(identifier);
status =
- parse_identifier(identifier, &hostname, &plugin, &plugin_instance, &type,
- &type_instance, opts->identifier_default_host);
+ parse_identifier(identifier, &hostname, &plugin, &type,
+ &data_source, opts->identifier_default_host);
if (status != 0) {
DEBUG("cmd_handle_putval: Cannot parse identifier `%s'.", identifier_copy);
cmd_error(CMD_PARSE_ERROR, err, "Cannot parse identifier `%s'.",
return CMD_PARSE_ERROR;
}
- if ((strlen(hostname) >= sizeof(vl.host)) ||
- (strlen(plugin) >= sizeof(vl.plugin)) ||
- ((plugin_instance != NULL) &&
- (strlen(plugin_instance) >= sizeof(vl.plugin_instance))) ||
- ((type_instance != NULL) &&
- (strlen(type_instance) >= sizeof(vl.type_instance)))) {
+ if ((strlen(type) >= sizeof(metric.type)) ||
+ (strlen(plugin) >= sizeof(metric.plugin))
+ ) {
cmd_error(CMD_PARSE_ERROR, err, "Identifier too long.");
sfree(identifier_copy);
return CMD_PARSE_ERROR;
}
- sstrncpy(vl.host, hostname, sizeof(vl.host));
- sstrncpy(vl.plugin, plugin, sizeof(vl.plugin));
- sstrncpy(vl.type, type, sizeof(vl.type));
- if (plugin_instance != NULL)
- sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance));
- if (type_instance != NULL)
- sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
+ metric.identity = create_identity(plugin, type, data_source, hostname);
+ if (metric.identity == NULL) {
+ sfree(identifier_copy);
+ return CMD_PARSE_ERROR;
+ }
- ds = plugin_get_ds(type);
- if (ds == NULL) {
+ sstrncpy(metric.plugin, plugin, sizeof(metric.plugin));
+ sstrncpy(metric.type, type, sizeof(metric.type));
+
+
+ metric.ds = plugin_get_ds(type);
+ if (metric.ds == NULL) {
cmd_error(CMD_PARSE_ERROR, err, "1 Type `%s' isn't defined.", type);
+ destroy_identity(metric.identity);
sfree(identifier_copy);
return CMD_PARSE_ERROR;
}
hostname = NULL;
plugin = NULL;
- plugin_instance = NULL;
type = NULL;
- type_instance = NULL;
+ data_source = NULL;
ret_putval->raw_identifier = identifier_copy;
if (ret_putval->raw_identifier == NULL) {
cmd_error(CMD_ERROR, err, "malloc failed.");
cmd_destroy_putval(ret_putval);
- sfree(vl.values);
+ destroy_identity(metric.identity);
return CMD_ERROR;
}
status = cmd_parse_option(argv[i], &key, &value, err);
if (status == CMD_OK) {
- int option_err;
-
assert(key != NULL);
assert(value != NULL);
- option_err = set_option(&vl, key, value, err);
+ int option_err = set_option(&metric, key, value, err);
if (option_err != CMD_OK && option_err != CMD_NO_OPTION) {
result = option_err;
break;
break;
}
/* else: cmd_parse_option did not find an option; treat this as a
- * value list. */
+ * value. */
- vl.values_len = ds->ds_num;
- vl.values = calloc(vl.values_len, sizeof(*vl.values));
- if (vl.values == NULL) {
- cmd_error(CMD_ERROR, err, "malloc failed.");
- result = CMD_ERROR;
- break;
- }
-
- status = parse_values(argv[i], &vl, ds);
+ status = parse_values(argv[i], &metric);
if (status != 0) {
cmd_error(CMD_PARSE_ERROR, err, "Parsing the values string failed.");
result = CMD_PARSE_ERROR;
- vl.values_len = 0;
- sfree(vl.values);
break;
}
cmd_error(CMD_ERROR, err, "realloc failed.");
cmd_destroy_putval(ret_putval);
result = CMD_ERROR;
- vl.values_len = 0;
- sfree(vl.values);
break;
}
return;
sfree(putval->raw_identifier);
-
- for (size_t i = 0; i < putval->vl_num; ++i) {
- sfree(putval->vl[i].values);
- meta_data_destroy(putval->vl[i].meta);
- putval->vl[i].meta = NULL;
- }
- sfree(putval->vl);
- putval->vl = NULL;
- putval->vl_num = 0;
+ destroy_metrics_list(putval->ml);
+ putval->ml = NULL;
} /* void cmd_destroy_putval */
cmd_status_t cmd_handle_putval(FILE *fh, char *buffer) {
} /* int cmd_handle_putval */
int cmd_create_putval(char *ret, size_t ret_len, /* {{{ */
- const data_set_t *ds, const value_list_t *vl) {
+ const metric_t *metric_p) {
char buffer_ident[6 * DATA_MAX_NAME_LEN];
char buffer_values[1024];
int status;
return status;
escape_string(buffer_ident, sizeof(buffer_ident));
- status = format_values(buffer_values, sizeof(buffer_values), ds, vl,
+ status = format_values(buffer_values, sizeof(buffer_values), metric_p,
/* store rates = */ false);
if (status != 0)
return status;
escape_string(buffer_values, sizeof(buffer_values));
snprintf(ret, ret_len, "PUTVAL %s interval=%.3f %s", buffer_ident,
- (vl->interval > 0) ? CDTIME_T_TO_DOUBLE(vl->interval)
+ (metric_p->interval > 0) ? CDTIME_T_TO_DOUBLE(metric_p->interval)
: CDTIME_T_TO_DOUBLE(plugin_get_interval()),
buffer_values);
void cmd_destroy_putval(cmd_putval_t *putval);
-int cmd_create_putval(char *ret, size_t ret_len, const data_set_t *ds,
- const value_list_t *vl);
+int cmd_create_putval(char *ret, size_t ret_len, const metric_t *metric_p);
#endif /* UTILS_CMD_PUTVAL_H */