}
int handle_getthreshold(FILE *fh, char *buffer) {
- char *command = NULL;
- char *identifier = NULL;
- char *identifier_copy = NULL;
-
- char *host = NULL;
- char *plugin = NULL;
- char *type = NULL;
- char *data_source = NULL;
-
- threshold_t threshold;
-
- int status;
- size_t i;
-
if ((fh == NULL) || (buffer == NULL))
return -1;
DEBUG("utils_cmd_getthreshold: handle_getthreshold (fh = %p, buffer = %s);",
(void *)fh, buffer);
- status = parse_string(&buffer, &command);
+ char *command = NULL;
+ int status = parse_string(&buffer, &command);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse command.\n");
return -1;
return -1;
}
+ char *identifier = NULL;
status = parse_string(&buffer, &identifier);
if (status != 0) {
print_to_socket(fh, "-1 Cannot parse identifier.\n");
/* parse_identifier() modifies its first argument,
* returning pointers into it */
- identifier_copy = sstrdup(identifier);
+ char *identifier_copy = sstrdup(identifier);
+ char *host = NULL;
+ char *plugin = NULL;
+ char *type = NULL;
+ char *data_source = NULL;
status = parse_identifier(identifier_copy, &host, &plugin,
&type, &data_source,
/* default_host = */ NULL);
return -1;
}
- metric_t metric = METRIC_STRUCT_INIT;
- metric.identity = identity_create_legacy(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);
+ char *plugin_instance = strchr(plugin, '-');
+ if (plugin_instance != NULL) {
+ *plugin_instance = 0;
+ plugin_instance++;
+ }
+ char *type_instance = strchr(type, '-');
+ if (type_instance != NULL) {
+ *type_instance = 0;
+ type_instance++;
+ }
+
+ metric_t m = {
+ .identity = identity_create_legacy(plugin, type, data_source, host),
+ };
+ if (plugin_instance != NULL) {
+ identity_add_label(m.identity, "plugin_instance", plugin_instance);
+ }
+ if (type_instance != NULL) {
+ identity_add_label(m.identity, "type_instance", type_instance);
+ }
sfree(identifier_copy);
- status = ut_search_threshold(&metric, &threshold);
+ threshold_t threshold;
+ status = ut_search_threshold(&m, &threshold);
if (status == ENOENT) {
print_to_socket(fh, "-1 No threshold found for identifier %s\n",
identifier);
}
/* Lets count the number of lines we'll return. */
- i = 0;
+ int lines_num = 0;
if (threshold.host[0] != 0)
- i++;
+ lines_num++;
if (threshold.plugin[0] != 0)
- i++;
+ lines_num++;
if (threshold.type[0] != 0)
- i++;
+ lines_num++;
if (threshold.data_source[0] != 0)
- i++;
+ lines_num++;
if (!isnan(threshold.warning_min))
- i++;
+ lines_num++;
if (!isnan(threshold.warning_max))
- i++;
+ lines_num++;
if (!isnan(threshold.failure_min))
- i++;
+ lines_num++;
if (!isnan(threshold.failure_max))
- i++;
+ lines_num++;
if (threshold.hysteresis > 0.0)
- i++;
+ lines_num++;
if (threshold.hits > 1)
- i++;
+ lines_num++;
/* Print the response */
- print_to_socket(fh, "%" PRIsz " Threshold found\n", i);
+ print_to_socket(fh, "%d Threshold found\n", lines_num);
if (threshold.host[0] != 0)
print_to_socket(fh, "Host: %s\n", threshold.host);