Skip to content

Commit

Permalink
dispatch proper values in Python write plugin
Browse files Browse the repository at this point in the history
Fixes the Python write callback so the appropriate value is dispatched to
Python. Previously, the code only looked at the first element of a data set
to determine which value type (GAUGE, COUNTER, etc) to dispatch. If your data
set consisted of multiple values of different types, then the Python write
plugin was receiving bad values for the elements at position n > 0 whose type
was not the same as that at position 0.
  • Loading branch information
indygreg committed Mar 5, 2011
1 parent 738d948 commit 31bc4bc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/python.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,26 +345,26 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li
CPY_RETURN_FROM_THREADS 0;
}
for (i = 0; i < value_list->values_len; ++i) {
if (ds->ds->type == DS_TYPE_COUNTER) {
if (ds->ds[i].type == DS_TYPE_COUNTER) {
if ((long) value_list->values[i].counter == value_list->values[i].counter)
PyList_SetItem(list, i, PyInt_FromLong(value_list->values[i].counter));
else
PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].counter));
} else if (ds->ds->type == DS_TYPE_GAUGE) {
} else if (ds->ds[i].type == DS_TYPE_GAUGE) {
PyList_SetItem(list, i, PyFloat_FromDouble(value_list->values[i].gauge));
} else if (ds->ds->type == DS_TYPE_DERIVE) {
} else if (ds->ds[i].type == DS_TYPE_DERIVE) {
if ((long) value_list->values[i].derive == value_list->values[i].derive)
PyList_SetItem(list, i, PyInt_FromLong(value_list->values[i].derive));
else
PyList_SetItem(list, i, PyLong_FromLongLong(value_list->values[i].derive));
} else if (ds->ds->type == DS_TYPE_ABSOLUTE) {
} else if (ds->ds[i].type == DS_TYPE_ABSOLUTE) {
if ((long) value_list->values[i].absolute == value_list->values[i].absolute)
PyList_SetItem(list, i, PyInt_FromLong(value_list->values[i].absolute));
else
PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].absolute));
} else {
Py_BEGIN_ALLOW_THREADS
ERROR("cpy_write_callback: Unknown value type %d.", ds->ds->type);
ERROR("cpy_write_callback: Unknown value type %d.", ds->ds[i].type);
Py_END_ALLOW_THREADS
Py_DECREF(list);
CPY_RETURN_FROM_THREADS 0;
Expand Down

2 comments on commit 31bc4bc

@tokkee
Copy link

@tokkee tokkee commented on 31bc4bc Jul 24, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Please open a pull request (for collectd/collectd).

@indygreg
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure I've upstreamed this already...

Please sign in to comment.