summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: eeb86d2)
raw | patch | inline | side by side (parent: eeb86d2)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Feb 2009 08:14:22 +0000 (09:14 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 19 Feb 2009 08:50:12 +0000 (09:50 +0100) |
Some other plugins will find that useful as well.
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history | |
src/table.c | patch | blob | history | |
src/utils_cmd_putval.c | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 3ec4c6e1442947422eff75e5a3ed3f6d24dc7224..914857c881df6cdb5728acb80808c49d51b6c78f 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)
+{
+ char *endptr = NULL;
+
+ if (DS_TYPE_COUNTER == ds.type)
+ ret_value->counter = (counter_t)strtoll (value, &endptr, 0);
+ else if (DS_TYPE_GAUGE == ds.type)
+ ret_value->gauge = (gauge_t)strtod (value, &endptr);
+ else {
+ ERROR ("parse_value: Invalid data source \"%s\" "
+ "(type = %i).", ds.name, ds.type);
+ return -1;
+ }
+
+ if (value == endptr) {
+ ERROR ("parse_value: Failed to parse string as number: %s.", value);
+ return -1;
+ }
+ else if ((NULL != endptr) && ('\0' != *endptr))
+ WARNING ("parse_value: Ignoring trailing garbage after number: %s.",
+ endptr);
+ return 0;
+} /* int parse_value */
+
int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds)
{
int i;
}
else
{
- if (strcmp ("U", ptr) == 0)
+ if ((strcmp ("U", ptr) == 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]))
+ return -1;
}
i++;
diff --git a/src/common.h b/src/common.h
index 8b401d68be1329446632a7b7069497717514a61b..2bdc89495e0154b424980330021bc0537a036162 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_values (char *buffer, value_list_t *vl, const data_set_t *ds);
#if !HAVE_GETPWNAM_R
diff --git a/src/table.c b/src/table.c
index ebd1c4cf75fcb18ec39193a29905a4942a79d496..d48a2ef6fffac02d05acbe8e6a9f2321aee3cb44 100644 (file)
--- a/src/table.c
+++ b/src/table.c
return 0;
} /* tbl_finish */
-static int tbl_parse_value (char *value, value_t *ret_value,
- data_source_t ds)
-{
- char *endptr = NULL;
-
- if (DS_TYPE_COUNTER == ds.type)
- ret_value->counter = (counter_t)strtoll (value, &endptr, 0);
- else if (DS_TYPE_GAUGE == ds.type)
- ret_value->gauge = (gauge_t)strtod (value, &endptr);
- else {
- log_err ("tbl_parse_value: Invalid data source \"%s\" "
- "(type = %i).", ds.name, ds.type);
- return -1;
- }
-
- if (value == endptr) {
- log_err ("Failed to parse string as number: %s.", value);
- return -1;
- }
- else if ((NULL != endptr) && ('\0' != *endptr))
- log_warn ("Ignoring trailing garbage after number: %s.", endptr);
- return 0;
-} /* tbl_parse_value */
-
static int tbl_result_dispatch (tbl_t *tbl, tbl_result_t *res,
char **fields, size_t fields_num)
{
assert (res->values[i] < fields_num);
value = fields[res->values[i]];
- if (0 != tbl_parse_value (value, &values[i], res->ds->ds[i]))
+ if (0 != parse_value (value, &values[i], res->ds->ds[i]))
return -1;
}
diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c
index 5bd6ec738fd2e188b4b253e3e7ce51937383690a..639b8ab1b432b526d7c1815bc86bd9c05c551aa5 100644 (file)
--- a/src/utils_cmd_putval.c
+++ b/src/utils_cmd_putval.c
return -1; \
}
-static int parse_value (const data_set_t *ds, value_list_t *vl,
+static int dispatch_values (const data_set_t *ds, value_list_t *vl,
FILE *fh, char *buffer)
{
char *dummy;
{
char identifier[128];
FORMAT_VL (identifier, sizeof (identifier), vl, ds);
- ERROR ("cmd putval: parse_value: "
+ ERROR ("cmd putval: dispatch_values: "
"Number of values incorrect: "
"Got %i, expected %i. Identifier is `%s'.",
i, vl->values_len, identifier);
plugin_dispatch_values (vl);
return (0);
-} /* int parse_value */
+} /* int dispatch_values */
static int set_option (value_list_t *vl, const char *key, const char *value)
{
}
assert (string != NULL);
- status = parse_value (ds, &vl, fh, string);
+ status = dispatch_values (ds, &vl, fh, string);
if (status != 0)
{
/* An error has already been printed. */