static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_list, user_data_t *data) {
int i;
cpy_callback_t *c = data->data;
- PyObject *ret, *list;
+ PyObject *ret, *list, *temp, *dict = NULL;
Values *v;
CPY_LOCK_THREADS
CPY_RETURN_FROM_THREADS 0;
}
}
+ dict = PyDict_New();
+ if (value_list->meta) {
+ int i, num;
+ char **table;
+ meta_data_t *meta = value_list->meta;
+
+ num = meta_data_toc(meta, &table);
+ for (i = 0; i < num; ++i) {
+ int type;
+ char *string;
+ int64_t si;
+ uint64_t ui;
+ double d;
+ _Bool b;
+
+ type = meta_data_type(meta, table[i]);
+ if (type == MD_TYPE_STRING) {
+ if (meta_data_get_string(meta, table[i], &string))
+ continue;
+ temp = cpy_string_to_unicode_or_bytes(string);
+ free(string);
+ PyDict_SetItemString(dict, table[i], temp);
+ Py_XDECREF(temp);
+ } else if (type == MD_TYPE_SIGNED_INT) {
+ if (meta_data_get_signed_int(meta, table[i], &si))
+ continue;
+ temp = PyLong_FromLongLong(si);
+ PyDict_SetItemString(dict, table[i], temp);
+ Py_XDECREF(temp);
+ } else if (type == MD_TYPE_UNSIGNED_INT) {
+ if (meta_data_get_unsigned_int(meta, table[i], &ui))
+ continue;
+ temp = PyLong_FromUnsignedLongLong(ui);
+ PyDict_SetItemString(dict, table[i], temp);
+ Py_XDECREF(temp);
+ } else if (type == MD_TYPE_DOUBLE) {
+ if (meta_data_get_double(meta, table[i], &d))
+ continue;
+ temp = PyFloat_FromDouble(d);
+ PyDict_SetItemString(dict, table[i], temp);
+ Py_XDECREF(temp);
+ } else if (type == MD_TYPE_BOOLEAN) {
+ if (meta_data_get_boolean(meta, table[i], &b))
+ continue;
+ if (b)
+ temp = Py_True;
+ else
+ temp = Py_False;
+ PyDict_SetItemString(dict, table[i], temp);
+ }
+ free(table[i]);
+ }
+ free(table);
+ }
v = PyObject_New(Values, (void *) &ValuesType);
sstrncpy(v->data.host, value_list->host, sizeof(v->data.host));
sstrncpy(v->data.type, value_list->type, sizeof(v->data.type));
v->data.time = value_list->time;
v->interval = value_list->interval;
v->values = list;
+ v->meta = dict;
ret = PyObject_CallFunctionObjArgs(c->callback, v, c->data, (void *) 0); /* New reference. */
if (ret == NULL) {
cpy_log_exception("write callback");
"exception will be raised. If the content of the sequence is not a number,\n"
"a TypeError exception will be raised.";
+static char meta_doc[] = "These are the meta data for this Value object.\n"
+ "It has to be a dictionary of numbers, strings or bools.\n"
+ "If the dict contains anything else a TypeError exception will be raised.";
+
static char dispatch_doc[] = "dispatch([type][, values][, plugin_instance][, type_instance]"
"[, plugin][, host][, time][, interval]) -> None. Dispatch a value list.\n"
"\n"
Values *self = (Values *) s;
int interval = 0;
double time = 0;
- PyObject *values = NULL, *tmp;
+ PyObject *values = NULL, *meta = NULL, *tmp;
const char *type = "", *plugin_instance = "", *type_instance = "", *plugin = "", *host = "";
static char *kwlist[] = {"type", "values", "plugin_instance", "type_instance",
- "plugin", "host", "time", "interval", NULL};
+ "plugin", "host", "time", "interval", "meta", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etOetetetetdi", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etOetetetetdiO", kwlist,
NULL, &type, &values, NULL, &plugin_instance, NULL, &type_instance,
- NULL, &plugin, NULL, &host, &time, &interval))
+ NULL, &plugin, NULL, &host, &time, &interval, &meta))
return -1;
if (type[0] != 0 && plugin_get_ds(type) == NULL) {
Py_INCREF(values);
}
+ if (meta == NULL) {
+ meta = PyDict_New();
+ PyErr_Clear();
+ } else {
+ Py_INCREF(meta);
+ }
+
tmp = self->values;
self->values = values;
+ self->meta = meta;
Py_XDECREF(tmp);
self->interval = interval;
static PyObject *Values_repr(PyObject *s) {
PyObject *ret, *tmp;
- static PyObject *l_interval = NULL, *l_values = NULL, *l_closing = NULL;
+ static PyObject *l_interval = NULL, *l_values = NULL, *l_meta = NULL, *l_closing = NULL;
Values *self = (Values *) s;
if (l_interval == NULL)
l_interval = cpy_string_to_unicode_or_bytes(",interval=");
if (l_values == NULL)
l_values = cpy_string_to_unicode_or_bytes(",values=");
+ if (l_meta == NULL)
+ l_meta = cpy_string_to_unicode_or_bytes(",meta=");
if (l_closing == NULL)
l_closing = cpy_string_to_unicode_or_bytes(")");
- if (l_interval == NULL || l_values == NULL || l_closing == NULL)
+ if (l_interval == NULL || l_values == NULL || l_meta == NULL || l_closing == NULL)
return NULL;
ret = cpy_common_repr(s);
CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp);
CPY_STRCAT_AND_DEL(&ret, tmp);
}
- if (self->values != NULL && PySequence_Length(self->values) > 0) {
+ if (self->values && (!PyList_Check(self->values) || PySequence_Length(self->values) > 0)) {
CPY_STRCAT(&ret, l_values);
tmp = PyObject_Repr(self->values);
CPY_STRCAT_AND_DEL(&ret, tmp);
}
+ if (self->meta && (!PyDict_Check(self->meta) || PyDict_Size(self->meta) > 0)) {
+ CPY_STRCAT(&ret, l_meta);
+ tmp = PyObject_Repr(self->meta);
+ CPY_STRCAT_AND_DEL(&ret, tmp);
+ }
CPY_STRCAT(&ret, l_closing);
return ret;
}
static int Values_traverse(PyObject *self, visitproc visit, void *arg) {
Values *v = (Values *) self;
Py_VISIT(v->values);
+ Py_VISIT(v->meta);
return 0;
}
static int Values_clear(PyObject *self) {
Values *v = (Values *) self;
Py_CLEAR(v->values);
+ Py_CLEAR(v->meta);
return 0;
}
static PyMemberDef Values_members[] = {
{"interval", T_INT, offsetof(Values, interval), 0, interval_doc},
{"values", T_OBJECT_EX, offsetof(Values, values), 0, values_doc},
+ {"meta", T_OBJECT_EX, offsetof(Values, meta), 0, meta_doc},
{NULL}
};