From: Gregory Szorc Date: Sat, 5 Mar 2011 06:25:45 +0000 (-0800) Subject: dispatch proper values in Python write plugin X-Git-Tag: collectd-4.9.5~3 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=27cd1bfc12b4c3c81ccd2d3f2cc1f6ef5028a94f dispatch proper values in Python write plugin 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. --- diff --git a/src/python.c b/src/python.c index 16de81d4..622160a5 100644 --- a/src/python.c +++ b/src/python.c @@ -342,26 +342,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;