int parse_identifier (char *str, char **ret_host,
char **ret_plugin, char **ret_plugin_instance,
char **ret_type, char **ret_type_instance);
-int parse_value (char *value, value_t *ret_value, const data_source_t ds);
+int parse_value (const char *value, value_t *ret_value, const data_source_t ds);
int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds);
#if !HAVE_GETPWNAM_R
return;
}
- if (ds->ds[0].type == DS_TYPE_GAUGE)
+ if (0 != parse_value (value, &values[0], ds->ds[0]))
{
- char *endptr = NULL;
-
- values[0].gauge = strtod (value, &endptr);
-
- if (endptr == value)
- {
- ERROR ("powerdns plugin: Cannot convert `%s' "
- "to a floating point number.", value);
- return;
- }
- }
- else
- {
- char *endptr = NULL;
-
- values[0].counter = strtoll (value, &endptr, 0);
- if (endptr == value)
- {
- ERROR ("powerdns plugin: Cannot convert `%s' "
- "to an integer number.", value);
- return;
- }
+ ERROR ("powerdns plugin: Cannot convert `%s' "
+ "to a number.", value);
+ return;
}
vl.values = values;
break;
}
- if (strcmp (ptr, "U") == 0)
+ if ((strcmp (ptr, "U") == 0) && (ds->ds[i].type == DS_TYPE_GAUGE))
vl->values[i].gauge = NAN;
- else if (ds->ds[i].type == DS_TYPE_COUNTER)
- vl->values[i].counter = atoll (ptr);
- else if (ds->ds[i].type == DS_TYPE_GAUGE)
- vl->values[i].gauge = atof (ptr);
+ else if (0 != parse_value (ptr, &vl->values[i], ds->ds[i]))
+ {
+ print_to_socket (fh, "-1 Failed to parse value `%s'.", ptr);
+ return (-1);
+ }
i++;
} /* while (strtok_r) */
{
value_list_t vl = VALUE_LIST_INIT;
value_t value;
- char *endptr;
+ char *value_str;
assert (r->legacy_mode == 1);
assert (r->ds != NULL);
vl.values = &value;
vl.values_len = 1;
- endptr = NULL;
- errno = 0;
- if (r->ds->ds[0].type == DS_TYPE_COUNTER)
- vl.values[0].counter = (counter_t) strtoll (column_values[r->legacy_position],
- &endptr, /* base = */ 0);
- else if (r->ds->ds[0].type == DS_TYPE_GAUGE)
- vl.values[0].gauge = (gauge_t) strtod (column_values[r->legacy_position],
- &endptr);
- else
- errno = EINVAL;
-
- if ((endptr == column_values[r->legacy_position]) || (errno != 0))
+ value_str = column_values[r->legacy_position];
+ if (0 != parse_value (value_str, &vl.values[0], r->ds->ds[0]))
{
- WARNING ("db query utils: udb_result_submit: Parsing `%s' as %s failed.",
- column_values[r->legacy_position],
+ ERROR ("db query utils: udb_legacy_result_handle_result: "
+ "Parsing `%s' as %s failed.", value_str,
(r->ds->ds[0].type == DS_TYPE_COUNTER) ? "counter" : "gauge");
- vl.values[0].gauge = NAN;
+ errno = EINVAL;
+ return (-1);
}
sstrncpy (vl.host, q->host, sizeof (vl.host));
/*
* Result private functions
*/
-static void udb_result_submit (udb_result_t *r, udb_query_t *q) /* {{{ */
+static int udb_result_submit (udb_result_t *r, udb_query_t *q) /* {{{ */
{
value_list_t vl = VALUE_LIST_INIT;
size_t i;
if (vl.values == NULL)
{
ERROR ("db query utils: malloc failed.");
- return;
+ return (-1);
}
vl.values_len = r->ds->ds_num;
for (i = 0; i < r->values_num; i++)
{
- char *endptr;
-
- endptr = NULL;
- errno = 0;
- if (r->ds->ds[i].type == DS_TYPE_COUNTER)
- vl.values[i].counter = (counter_t) strtoll (r->values_buffer[i],
- &endptr, /* base = */ 0);
- else if (r->ds->ds[i].type == DS_TYPE_GAUGE)
- vl.values[i].gauge = (gauge_t) strtod (r->values_buffer[i], &endptr);
- else
- errno = EINVAL;
+ char *value_str = r->values_buffer[i];
- if ((endptr == r->values_buffer[i]) || (errno != 0))
+ if (0 != parse_value (value_str, &vl.values[i], r->ds->ds[i]))
{
- WARNING ("db query utils: udb_result_submit: Parsing `%s' as %s failed.",
- r->values_buffer[i],
+ ERROR ("db query utils: udb_result_submit: Parsing `%s' as %s failed.",
+ value_str,
(r->ds->ds[i].type == DS_TYPE_COUNTER) ? "counter" : "gauge");
- vl.values[i].gauge = NAN;
+ errno = EINVAL;
+ return (-1);
}
}
plugin_dispatch_values (&vl);
sfree (vl.values);
+ return (0);
} /* }}} void udb_result_submit */
static void udb_result_finish_result (udb_result_t *r) /* {{{ */
for (i = 0; i < r->values_num; i++)
r->values_buffer[i] = column_values[r->values_pos[i]];
- udb_result_submit (r, q);
-
- return (0);
+ return udb_result_submit (r, q);
} /* }}} int udb_result_handle_result */
static int udb_result_prepare_result (udb_result_t *r, /* {{{ */