src/utils/tail/tail.c src/utils/tail/tail.h \
src/utils/match/match.c src/utils/match/match.h \
src/utils/latency/latency.c src/utils/latency/latency.h \
- src/utils/latency/latency_config.c src/utils/latency/latency_config.h
+ src/utils/latency/latency_config.c src/utils/latency/latency_config.h \
+ src/utils/value_list/value_list.c src/utils/value_list/value_list.h
test_utils_message_parser_CPPFLAGS = $(AM_CPPFLAGS)
test_utils_message_parser_LDADD = liboconfig.la libplugin_mock.la -lm
endif
if BUILD_PLUGIN_CEPH
-test_plugin_ceph_SOURCES = src/ceph_test.c
+test_plugin_ceph_SOURCES = src/ceph_test.c \
+ src/utils/value_list/value_list.c \
+ src/utils/value_list/value_list.h
test_plugin_ceph_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
test_plugin_ceph_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS)
test_plugin_ceph_LDADD = libplugin_mock.la $(BUILD_WITH_LIBYAJL_LIBS)
test_utils_cmds_SOURCES = \
src/utils/cmds/cmds_test.c \
+ src/utils/value_list/value_list.c \
+ src/utils/value_list/value_list.h \
src/testing.h
test_utils_cmds_LDADD = \
libcmds.la \
curl_json_la_SOURCES = \
src/curl_json.c \
src/utils/curl_stats/curl_stats.c \
- src/utils/curl_stats/curl_stats.h
+ src/utils/curl_stats/curl_stats.h \
+ src/utils/value_list/value_list.c \
+ src/utils/value_list/value_list.h
curl_json_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS)
curl_json_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
curl_json_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS)
curl_json_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS)
test_plugin_curl_json_SOURCES = src/curl_json_test.c \
- src/utils/curl_stats/curl_stats.c \
src/daemon/configfile.c \
- src/daemon/types_list.c
+ src/daemon/types_list.c \
+ src/utils/curl_stats/curl_stats.c \
+ src/utils/value_list/value_list.c \
+ src/utils/value_list/value_list.h
test_plugin_curl_json_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
test_plugin_curl_json_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS)
test_plugin_curl_json_LDADD = libavltree.la liboconfig.la libplugin_mock.la $(BUILD_WITH_LIBCURL_LIBS) $(BUILD_WITH_LIBYAJL_LIBS)
logparser_la_LDFLAGS = $(PLUGIN_LDFLAGS) -lm
test_plugin_logparser_SOURCES = src/logparser_test.c \
+ src/daemon/configfile.c \
+ src/daemon/types_list.c \
+ src/utils/match/match.c src/utils/match/match.h \
src/utils/message_parser/message_parser.c \
src/utils_tail_match.c src/utils_tail_match.h \
src/utils/tail/tail.c src/utils/tail/tail.h \
- src/utils/match/match.c src/utils/match/match.h \
- src/daemon/configfile.c \
- src/daemon/types_list.c
+ src/utils/value_list/value_list.c \
+ src/utils/value_list/value_list.h
test_plugin_logparser_CPPFLAGS = $(AM_CPPFLAGS)
test_plugin_logparser_LDFLAGS = $(PLUGIN_LDFLAGS)
test_plugin_logparser_LDADD = liboconfig.la libplugin_mock.la liblatency.la
DECLARE_UNREGISTER(log)
DECLARE_UNREGISTER(notification)
-int plugin_dispatch_values(value_list_t const *vl) { return ENOTSUP; }
-
int plugin_dispatch_metric_family(metric_family_t const *fam) {
return ENOTSUP;
}
return 0;
} /* int parse_value */
-int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds) {
- size_t i;
- char *dummy;
- char *ptr;
- char *saveptr;
-
- if ((buffer == NULL) || (vl == NULL) || (ds == NULL))
- return EINVAL;
-
- i = 0;
- dummy = buffer;
- saveptr = NULL;
- vl->time = 0;
- while ((ptr = strtok_r(dummy, ":", &saveptr)) != NULL) {
- dummy = NULL;
-
- if (i >= vl->values_len) {
- /* Make sure i is invalid. */
- i = 0;
- break;
- }
-
- if (vl->time == 0) {
- if (strcmp("N", ptr) == 0)
- vl->time = cdtime();
- else {
- char *endptr = NULL;
- double tmp;
-
- errno = 0;
- tmp = strtod(ptr, &endptr);
- if ((errno != 0) /* Overflow */
- || (endptr == ptr) /* Invalid string */
- || (endptr == NULL) /* This should not happen */
- || (*endptr != 0)) /* Trailing chars */
- return -1;
-
- vl->time = DOUBLE_TO_CDTIME_T(tmp);
- }
-
- continue;
- }
-
- if ((strcmp("U", ptr) == 0) && (ds->ds[i].type == DS_TYPE_GAUGE))
- vl->values[i].gauge = NAN;
- else if (0 != parse_value(ptr, &vl->values[i], ds->ds[i].type))
- return -1;
-
- i++;
- } /* 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) {
FILE *fh;
char buffer[256];
int format_values(strbuf_t *buf, metric_t const *m, bool store_rates);
int parse_value(const char *value, value_t *ret_value, int ds_type);
-int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds);
/* parse_value_file reads "path" and parses its content as an integer or
* floating point, depending on "ds_type". On success, the value is stored in
return 0;
}
-DEF_TEST(parse_values) {
- struct {
- char buffer[64];
- int status;
- gauge_t value;
- } cases[] = {
- {"1435044576:42", 0, 42.0}, {"1435044576:42:23", -1, NAN},
- {"1435044576:U", 0, NAN}, {"N:12.3", 0, 12.3},
- {"N:42.0:23", -1, NAN}, {"N:U", 0, NAN},
- {"T:42.0", -1, NAN},
- };
-
- for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {
- data_source_t dsrc = {
- .name = "value",
- .type = DS_TYPE_GAUGE,
- .min = 0.0,
- .max = NAN,
- };
- data_set_t ds = {
- .type = "example",
- .ds_num = 1,
- .ds = &dsrc,
- };
-
- value_t v = {
- .gauge = NAN,
- };
- value_list_t vl = {
- .values = &v,
- .values_len = 1,
- .time = 0,
- .interval = 0,
- .host = "example.com",
- .plugin = "common_test",
- .type = "example",
- .meta = NULL,
- };
-
- int status = parse_values(cases[i].buffer, &vl, &ds);
- EXPECT_EQ_INT(cases[i].status, status);
- if (status != 0)
- continue;
-
- EXPECT_EQ_DOUBLE(cases[i].value, vl.values[0].gauge);
- }
-
- return 0;
-}
-
DEF_TEST(value_to_rate) {
struct {
time_t t0;
RUN_TEST(escape_slashes);
RUN_TEST(escape_string);
RUN_TEST(strunescape);
- RUN_TEST(parse_values);
RUN_TEST(value_to_rate);
RUN_TEST(format_values);
metric_reset(&m);
return fam;
}
+
+int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds) {
+ size_t i;
+ char *dummy;
+ char *ptr;
+ char *saveptr;
+
+ if ((buffer == NULL) || (vl == NULL) || (ds == NULL))
+ return EINVAL;
+
+ i = 0;
+ dummy = buffer;
+ saveptr = NULL;
+ vl->time = 0;
+ while ((ptr = strtok_r(dummy, ":", &saveptr)) != NULL) {
+ dummy = NULL;
+
+ if (i >= vl->values_len) {
+ /* Make sure i is invalid. */
+ i = 0;
+ break;
+ }
+
+ if (vl->time == 0) {
+ if (strcmp("N", ptr) == 0)
+ vl->time = cdtime();
+ else {
+ char *endptr = NULL;
+ double tmp;
+
+ errno = 0;
+ tmp = strtod(ptr, &endptr);
+ if ((errno != 0) /* Overflow */
+ || (endptr == ptr) /* Invalid string */
+ || (endptr == NULL) /* This should not happen */
+ || (*endptr != 0)) /* Trailing chars */
+ return -1;
+
+ vl->time = DOUBLE_TO_CDTIME_T(tmp);
+ }
+
+ continue;
+ }
+
+ if ((strcmp("U", ptr) == 0) && (ds->ds[i].type == DS_TYPE_GAUGE))
+ vl->values[i].gauge = NAN;
+ else if (0 != parse_value(ptr, &vl->values[i], ds->ds[i].type))
+ return -1;
+
+ i++;
+ } /* while (strtok_r) */
+
+ if ((ptr != NULL) || (i == 0))
+ return -1;
+ return 0;
+} /* int parse_values */
data_set_t const *ds,
size_t index);
+int parse_values(char *buffer, value_list_t *vl, const data_set_t *ds);
+
#endif
--- /dev/null
+/**
+ * collectd - src/utils/value_list/value_list_test.c
+ * Copyright (C) 2013-2023 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "utils/value_list/value_list.h"
+#include "testing.h"
+
+DEF_TEST(parse_values) {
+ struct {
+ char buffer[64];
+ int status;
+ gauge_t value;
+ } cases[] = {
+ {"1435044576:42", 0, 42.0}, {"1435044576:42:23", -1, NAN},
+ {"1435044576:U", 0, NAN}, {"N:12.3", 0, 12.3},
+ {"N:42.0:23", -1, NAN}, {"N:U", 0, NAN},
+ {"T:42.0", -1, NAN},
+ };
+
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE(cases); i++) {
+ data_source_t dsrc = {
+ .name = "value",
+ .type = DS_TYPE_GAUGE,
+ .min = 0.0,
+ .max = NAN,
+ };
+ data_set_t ds = {
+ .type = "example",
+ .ds_num = 1,
+ .ds = &dsrc,
+ };
+
+ value_t v = {
+ .gauge = NAN,
+ };
+ value_list_t vl = {
+ .values = &v,
+ .values_len = 1,
+ .time = 0,
+ .interval = 0,
+ .host = "example.com",
+ .plugin = "common_test",
+ .type = "example",
+ .meta = NULL,
+ };
+
+ int status = parse_values(cases[i].buffer, &vl, &ds);
+ EXPECT_EQ_INT(cases[i].status, status);
+ if (status != 0)
+ continue;
+
+ EXPECT_EQ_DOUBLE(cases[i].value, vl.values[0].gauge);
+ }
+
+ return 0;
+}
+
+int main(void) {
+ RUN_TEST(parse_values);
+
+ END_TEST;
+}