X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Futils_match.c;h=2aaeb963bc5451cb3f7c403e0edd75353be53701;hb=27cd1bfc12b4c3c81ccd2d3f2cc1f6ef5028a94f;hp=c19c5ffc3671d7fdd45d581aea4032d949f182cb;hpb=3f391479bfc45d0ff6e0c7b87c899e41a192f392;p=collectd.git diff --git a/src/utils_match.c b/src/utils_match.c index c19c5ffc..2aaeb963 100644 --- a/src/utils_match.c +++ b/src/utils_match.c @@ -81,7 +81,7 @@ static int default_callback (const char __attribute__((unused)) *str, if (matches_num < 2) return (-1); - value = strtod (matches[1], &endptr); + value = (gauge_t) strtod (matches[1], &endptr); if (matches[1] == endptr) return (-1); @@ -129,7 +129,7 @@ static int default_callback (const char __attribute__((unused)) *str, if (matches_num < 2) return (-1); - value = strtoll (matches[1], &endptr, 0); + value = (counter_t) strtoull (matches[1], &endptr, 0); if (matches[1] == endptr) return (-1); @@ -145,6 +145,59 @@ static int default_callback (const char __attribute__((unused)) *str, data->values_num++; } + else if (data->ds_type & UTILS_MATCH_DS_TYPE_DERIVE) + { + derive_t value; + char *endptr = NULL; + + if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC) + { + data->value.counter++; + data->values_num++; + return (0); + } + + if (matches_num < 2) + return (-1); + + value = (derive_t) strtoll (matches[1], &endptr, 0); + if (matches[1] == endptr) + return (-1); + + if (data->ds_type & UTILS_MATCH_CF_DERIVE_SET) + data->value.derive = value; + else if (data->ds_type & UTILS_MATCH_CF_DERIVE_ADD) + data->value.derive += value; + else + { + ERROR ("utils_match: default_callback: obj->ds_type is invalid!"); + return (-1); + } + + data->values_num++; + } + else if (data->ds_type & UTILS_MATCH_DS_TYPE_ABSOLUTE) + { + absolute_t value; + char *endptr = NULL; + + if (matches_num < 2) + return (-1); + + value = (absolute_t) strtoull (matches[1], &endptr, 0); + if (matches[1] == endptr) + return (-1); + + if (data->ds_type & UTILS_MATCH_CF_ABSOLUTE_SET) + data->value.absolute = value; + else + { + ERROR ("utils_match: default_callback: obj->ds_type is invalid!"); + return (-1); + } + + data->values_num++; + } else { ERROR ("utils_match: default_callback: obj->ds_type is invalid!"); @@ -172,7 +225,7 @@ cu_match_t *match_create_callback (const char *regex, return (NULL); memset (obj, '\0', sizeof (cu_match_t)); - status = regcomp (&obj->regex, regex, REG_EXTENDED); + status = regcomp (&obj->regex, regex, REG_EXTENDED | REG_NEWLINE); if (status != 0) { ERROR ("Compiling the regular expression \"%s\" failed.", regex);