summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a352986)
raw | patch | inline | side by side (parent: a352986)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Feb 2009 08:48:14 +0000 (09:48 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Feb 2009 08:50:12 +0000 (09:50 +0100) |
Besides cleaning up the code a little, this also adds more verbose error
messages.
messages.
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history | |
src/powerdns.c | patch | blob | history | |
src/utils_cmd_putval.c | patch | blob | history | |
src/utils_db_query.c | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 914857c881df6cdb5728acb80808c49d51b6c78f..c4994a2c2e017e44ae7c2108ed29550698b71f0e 100644 (file)
--- a/src/common.c
+++ b/src/common.c
return (0);
} /* int parse_identifier */
-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)
{
char *endptr = NULL;
diff --git a/src/common.h b/src/common.h
index 2bdc89495e0154b424980330021bc0537a036162..5b9f02cc4d8b1fbdda48fa22f7cf152f9da71dd5 100644 (file)
--- a/src/common.h
+++ b/src/common.h
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
diff --git a/src/powerdns.c b/src/powerdns.c
index 164137ba39da5f9019bf037faff07efbafea1c26..beb49fbb64a1dc7d3fb97d82f31ffe05fad98f7d 100644 (file)
--- a/src/powerdns.c
+++ b/src/powerdns.c
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;
diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c
index 639b8ab1b432b526d7c1815bc86bd9c05c551aa5..be09185ee1c3cb6ee14fa2bde688af23a942b17b 100644 (file)
--- a/src/utils_cmd_putval.c
+++ b/src/utils_cmd_putval.c
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) */
diff --git a/src/utils_db_query.c b/src/utils_db_query.c
index c2897c7c88c51717fde50b4d9c5b97b92b6c5727..5531b25fe7fd60eb5e34300b8f2cfb0ce3cbbf2f 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
{
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, /* {{{ */