diff --git a/src/pyvalues.c b/src/pyvalues.c
index 36a717e9bfec401b54d8e2b629f110a01a303d7a..44176014fc27dc68de218f00acf6c2e8bf8560d7 100644 (file)
--- a/src/pyvalues.c
+++ b/src/pyvalues.c
#include "cpython.h"
#include "cpython.h"
+#define FreeAll() do {\
+ PyMem_Free(type);\
+ PyMem_Free(plugin_instance);\
+ PyMem_Free(type_instance);\
+ PyMem_Free(plugin);\
+ PyMem_Free(host);\
+} while(0)
+
static PyObject *cpy_common_repr(PyObject *s) {
PyObject *ret, *tmp;
static PyObject *l_type = NULL, *l_type_instance = NULL, *l_plugin = NULL, *l_plugin_instance = NULL;
static PyObject *cpy_common_repr(PyObject *s) {
PyObject *ret, *tmp;
static PyObject *l_type = NULL, *l_type_instance = NULL, *l_plugin = NULL, *l_plugin_instance = NULL;
@@ -143,7 +151,7 @@ static PyObject *PluginData_new(PyTypeObject *type, PyObject *args, PyObject *kw
static int PluginData_init(PyObject *s, PyObject *args, PyObject *kwds) {
PluginData *self = (PluginData *) s;
double time = 0;
static int PluginData_init(PyObject *s, PyObject *args, PyObject *kwds) {
PluginData *self = (PluginData *) s;
double time = 0;
- const char *type = "", *plugin_instance = "", *type_instance = "", *plugin = "", *host = "";
+ char *type = NULL, *plugin_instance = NULL, *type_instance = NULL, *plugin = NULL, *host = NULL;
static char *kwlist[] = {"type", "plugin_instance", "type_instance",
"plugin", "host", "time", NULL};
static char *kwlist[] = {"type", "plugin_instance", "type_instance",
"plugin", "host", "time", NULL};
NULL, &plugin_instance, NULL, &type_instance, NULL, &plugin, NULL, &host, &time))
return -1;
NULL, &plugin_instance, NULL, &type_instance, NULL, &plugin, NULL, &host, &time))
return -1;
- if (type[0] != 0 && plugin_get_ds(type) == NULL) {
+ if (type && plugin_get_ds(type) == NULL) {
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
+ FreeAll();
return -1;
}
return -1;
}
- sstrncpy(self->host, host, sizeof(self->host));
- sstrncpy(self->plugin, plugin, sizeof(self->plugin));
- sstrncpy(self->plugin_instance, plugin_instance, sizeof(self->plugin_instance));
- sstrncpy(self->type, type, sizeof(self->type));
- sstrncpy(self->type_instance, type_instance, sizeof(self->type_instance));
-
+ sstrncpy(self->host, host ? host : "", sizeof(self->host));
+ sstrncpy(self->plugin, plugin ? plugin : "", sizeof(self->plugin));
+ sstrncpy(self->plugin_instance, plugin_instance ? plugin_instance : "", sizeof(self->plugin_instance));
+ sstrncpy(self->type, type ? type : "", sizeof(self->type));
+ sstrncpy(self->type_instance, type_instance ? type_instance : "", sizeof(self->type_instance));
self->time = time;
self->time = time;
+
+ FreeAll();
+
return 0;
}
return 0;
}
Values *self = (Values *) s;
double interval = 0, time = 0;
PyObject *values = NULL, *meta = NULL, *tmp;
Values *self = (Values *) s;
double interval = 0, time = 0;
PyObject *values = NULL, *meta = NULL, *tmp;
- const char *type = "", *plugin_instance = "", *type_instance = "", *plugin = "", *host = "";
+ char *type = NULL, *plugin_instance = NULL, *type_instance = NULL, *plugin = NULL, *host = NULL;
static char *kwlist[] = {"type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
static char *kwlist[] = {"type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
NULL, &plugin, NULL, &host, &time, &interval, &meta))
return -1;
NULL, &plugin, NULL, &host, &time, &interval, &meta))
return -1;
- if (type[0] != 0 && plugin_get_ds(type) == NULL) {
+ if (type && plugin_get_ds(type) == NULL) {
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
+ FreeAll();
return -1;
}
return -1;
}
- sstrncpy(self->data.host, host, sizeof(self->data.host));
- sstrncpy(self->data.plugin, plugin, sizeof(self->data.plugin));
- sstrncpy(self->data.plugin_instance, plugin_instance, sizeof(self->data.plugin_instance));
- sstrncpy(self->data.type, type, sizeof(self->data.type));
- sstrncpy(self->data.type_instance, type_instance, sizeof(self->data.type_instance));
+ sstrncpy(self->data.host, host ? host : "", sizeof(self->data.host));
+ sstrncpy(self->data.plugin, plugin ? plugin : "", sizeof(self->data.plugin));
+ sstrncpy(self->data.plugin_instance, plugin_instance ? plugin_instance : "", sizeof(self->data.plugin_instance));
+ sstrncpy(self->data.type, type ? type : "", sizeof(self->data.type));
+ sstrncpy(self->data.type_instance, type_instance ? type_instance : "", sizeof(self->data.type_instance));
self->data.time = time;
self->data.time = time;
+ FreeAll();
+
if (values == NULL) {
values = PyList_New(0);
PyErr_Clear();
if (values == NULL) {
values = PyList_New(0);
PyErr_Clear();
meta_data_t *m = NULL;
PyObject *l;
meta_data_t *m = NULL;
PyObject *l;
- if (!meta)
+ if ((meta == NULL) || (meta == Py_None))
return NULL;
return NULL;
- m = meta_data_create();
- l = PyDict_Items(meta);
+ l = PyDict_Items(meta); /* New reference. */
+ if (!l) {
+ cpy_log_exception("building meta data");
+ return NULL;
+ }
s = PyList_Size(l);
s = PyList_Size(l);
+ if (s <= 0) {
+ Py_XDECREF(l);
+ return NULL;
+ }
+
+ m = meta_data_create();
for (i = 0; i < s; ++i) {
const char *string, *keystring;
PyObject *key, *value, *item, *tmp;
for (i = 0; i < s; ++i) {
const char *string, *keystring;
PyObject *key, *value, *item, *tmp;
Py_XDECREF(value);
Py_DECREF(key);
}
Py_XDECREF(value);
Py_DECREF(key);
}
+ Py_XDECREF(l);
return m;
}
static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
return m;
}
static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
- int i, ret;
+ int ret;
const data_set_t *ds;
const data_set_t *ds;
- int size;
+ size_t size, i;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values, *meta = self->meta;
double time = self->data.time, interval = self->interval;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values, *meta = self->meta;
double time = self->data.time, interval = self->interval;
- const char *host = self->data.host;
- const char *plugin = self->data.plugin;
- const char *plugin_instance = self->data.plugin_instance;
- const char *type = self->data.type;
- const char *type_instance = self->data.type_instance;
+ char *host = NULL, *plugin = NULL, *plugin_instance = NULL, *type = NULL, *type_instance = NULL;
static char *kwlist[] = {"type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
static char *kwlist[] = {"type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
@@ -498,13 +518,20 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
NULL, &plugin, NULL, &host, &time, &interval, &meta))
return NULL;
NULL, &plugin, NULL, &host, &time, &interval, &meta))
return NULL;
- if (type[0] == 0) {
+ sstrncpy(value_list.host, host ? host : self->data.host, sizeof(value_list.host));
+ sstrncpy(value_list.plugin, plugin ? plugin : self->data.plugin, sizeof(value_list.plugin));
+ sstrncpy(value_list.plugin_instance, plugin_instance ? plugin_instance : self->data.plugin_instance, sizeof(value_list.plugin_instance));
+ sstrncpy(value_list.type, type ? type : self->data.type, sizeof(value_list.type));
+ sstrncpy(value_list.type_instance, type_instance ? type_instance : self->data.type_instance, sizeof(value_list.type_instance));
+ FreeAll();
+ if (value_list.type[0] == 0) {
PyErr_SetString(PyExc_RuntimeError, "type not set");
PyErr_SetString(PyExc_RuntimeError, "type not set");
+ FreeAll();
return NULL;
}
return NULL;
}
- ds = plugin_get_ds(type);
+ ds = plugin_get_ds(value_list.type);
if (ds == NULL) {
if (ds == NULL) {
- PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
+ PyErr_Format(PyExc_TypeError, "Dataset %s not found", value_list.type);
return NULL;
}
if (values == NULL || (PyTuple_Check(values) == 0 && PyList_Check(values) == 0)) {
return NULL;
}
if (values == NULL || (PyTuple_Check(values) == 0 && PyList_Check(values) == 0)) {
@@ -515,38 +542,46 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
PyErr_Format(PyExc_TypeError, "meta must be a dict");
return NULL;
}
PyErr_Format(PyExc_TypeError, "meta must be a dict");
return NULL;
}
- size = (int) PySequence_Length(values);
+ size = (size_t) PySequence_Length(values);
if (size != ds->ds_num) {
if (size != ds->ds_num) {
- PyErr_Format(PyExc_RuntimeError, "type %s needs %d values, got %i", type, ds->ds_num, size);
+ PyErr_Format(PyExc_RuntimeError, "type %s needs %zu values, got %zu", value_list.type, ds->ds_num, size);
return NULL;
}
return NULL;
}
- value = malloc(size * sizeof(*value));
+ value = calloc(size, sizeof(*value));
for (i = 0; i < size; ++i) {
PyObject *item, *num;
for (i = 0; i < size; ++i) {
PyObject *item, *num;
- item = PySequence_GetItem(values, i);
+ item = PySequence_Fast_GET_ITEM(values, (int) i); /* Borrowed reference. */
if (ds->ds->type == DS_TYPE_COUNTER) {
if (ds->ds->type == DS_TYPE_COUNTER) {
- num = PyNumber_Long(item);
- if (num != NULL)
+ num = PyNumber_Long(item); /* New reference. */
+ if (num != NULL) {
value[i].counter = PyLong_AsUnsignedLongLong(num);
value[i].counter = PyLong_AsUnsignedLongLong(num);
+ Py_XDECREF(num);
+ }
} else if (ds->ds->type == DS_TYPE_GAUGE) {
} else if (ds->ds->type == DS_TYPE_GAUGE) {
- num = PyNumber_Float(item);
- if (num != NULL)
+ num = PyNumber_Float(item); /* New reference. */
+ if (num != NULL) {
value[i].gauge = PyFloat_AsDouble(num);
value[i].gauge = PyFloat_AsDouble(num);
+ Py_XDECREF(num);
+ }
} else if (ds->ds->type == DS_TYPE_DERIVE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
} else if (ds->ds->type == DS_TYPE_DERIVE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
- num = PyNumber_Long(item);
- if (num != NULL)
+ num = PyNumber_Long(item); /* New reference. */
+ if (num != NULL) {
value[i].derive = PyLong_AsLongLong(num);
value[i].derive = PyLong_AsLongLong(num);
+ Py_XDECREF(num);
+ }
} else if (ds->ds->type == DS_TYPE_ABSOLUTE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
} else if (ds->ds->type == DS_TYPE_ABSOLUTE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
- num = PyNumber_Long(item);
- if (num != NULL)
+ num = PyNumber_Long(item); /* New reference. */
+ if (num != NULL) {
value[i].absolute = PyLong_AsUnsignedLongLong(num);
value[i].absolute = PyLong_AsUnsignedLongLong(num);
+ Py_XDECREF(num);
+ }
} else {
free(value);
} else {
free(value);
- PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, type);
+ PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, value_list.type);
return NULL;
}
if (PyErr_Occurred() != NULL) {
return NULL;
}
if (PyErr_Occurred() != NULL) {
@@ -559,11 +594,6 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
value_list.values_len = size;
value_list.time = DOUBLE_TO_CDTIME_T(time);
value_list.interval = DOUBLE_TO_CDTIME_T(interval);
value_list.values_len = size;
value_list.time = DOUBLE_TO_CDTIME_T(time);
value_list.interval = DOUBLE_TO_CDTIME_T(interval);
- sstrncpy(value_list.host, host, sizeof(value_list.host));
- sstrncpy(value_list.plugin, plugin, sizeof(value_list.plugin));
- sstrncpy(value_list.plugin_instance, plugin_instance, sizeof(value_list.plugin_instance));
- sstrncpy(value_list.type, type, sizeof(value_list.type));
- sstrncpy(value_list.type_instance, type_instance, sizeof(value_list.type_instance));
if (value_list.host[0] == 0)
sstrncpy(value_list.host, hostname_g, sizeof(value_list.host));
if (value_list.plugin[0] == 0)
if (value_list.host[0] == 0)
sstrncpy(value_list.host, hostname_g, sizeof(value_list.host));
if (value_list.plugin[0] == 0)
@@ -571,81 +601,91 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
Py_BEGIN_ALLOW_THREADS;
ret = plugin_dispatch_values(&value_list);
Py_END_ALLOW_THREADS;
Py_BEGIN_ALLOW_THREADS;
ret = plugin_dispatch_values(&value_list);
Py_END_ALLOW_THREADS;
+ meta_data_destroy(value_list.meta);
+ free(value);
if (ret != 0) {
PyErr_SetString(PyExc_RuntimeError, "error dispatching values, read the logs");
return NULL;
}
if (ret != 0) {
PyErr_SetString(PyExc_RuntimeError, "error dispatching values, read the logs");
return NULL;
}
- free(value);
Py_RETURN_NONE;
}
static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) {
Py_RETURN_NONE;
}
static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) {
- int i, ret;
+ int ret;
const data_set_t *ds;
const data_set_t *ds;
- int size;
+ size_t size, i;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values, *meta = self->meta;
double time = self->data.time, interval = self->interval;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values, *meta = self->meta;
double time = self->data.time, interval = self->interval;
- const char *host = self->data.host;
- const char *plugin = self->data.plugin;
- const char *plugin_instance = self->data.plugin_instance;
- const char *type = self->data.type;
- const char *type_instance = self->data.type_instance;
- const char *dest = NULL;
+ char *host = NULL, *plugin = NULL, *plugin_instance = NULL, *type = NULL, *type_instance = NULL, *dest = NULL;
static char *kwlist[] = {"destination", "type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
static char *kwlist[] = {"destination", "type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etOetetetetddO", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|etOetetetetdiO", kwlist, NULL, &dest,
NULL, &type, &values, NULL, &plugin_instance, NULL, &type_instance,
NULL, &plugin, NULL, &host, &time, &interval, &meta))
return NULL;
NULL, &type, &values, NULL, &plugin_instance, NULL, &type_instance,
NULL, &plugin, NULL, &host, &time, &interval, &meta))
return NULL;
- if (type[0] == 0) {
+ sstrncpy(value_list.host, host ? host : self->data.host, sizeof(value_list.host));
+ sstrncpy(value_list.plugin, plugin ? plugin : self->data.plugin, sizeof(value_list.plugin));
+ sstrncpy(value_list.plugin_instance, plugin_instance ? plugin_instance : self->data.plugin_instance, sizeof(value_list.plugin_instance));
+ sstrncpy(value_list.type, type ? type : self->data.type, sizeof(value_list.type));
+ sstrncpy(value_list.type_instance, type_instance ? type_instance : self->data.type_instance, sizeof(value_list.type_instance));
+ FreeAll();
+ if (value_list.type[0] == 0) {
PyErr_SetString(PyExc_RuntimeError, "type not set");
return NULL;
}
PyErr_SetString(PyExc_RuntimeError, "type not set");
return NULL;
}
- ds = plugin_get_ds(type);
+ ds = plugin_get_ds(value_list.type);
if (ds == NULL) {
if (ds == NULL) {
- PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
+ PyErr_Format(PyExc_TypeError, "Dataset %s not found", value_list.type);
return NULL;
}
if (values == NULL || (PyTuple_Check(values) == 0 && PyList_Check(values) == 0)) {
PyErr_Format(PyExc_TypeError, "values must be list or tuple");
return NULL;
}
return NULL;
}
if (values == NULL || (PyTuple_Check(values) == 0 && PyList_Check(values) == 0)) {
PyErr_Format(PyExc_TypeError, "values must be list or tuple");
return NULL;
}
- size = (int) PySequence_Length(values);
+ size = (size_t) PySequence_Length(values);
if (size != ds->ds_num) {
if (size != ds->ds_num) {
- PyErr_Format(PyExc_RuntimeError, "type %s needs %d values, got %i", type, ds->ds_num, size);
+ PyErr_Format(PyExc_RuntimeError, "type %s needs %zu values, got %zu", value_list.type, ds->ds_num, size);
return NULL;
}
return NULL;
}
- value = malloc(size * sizeof(*value));
+ value = calloc(size, sizeof(*value));
for (i = 0; i < size; ++i) {
PyObject *item, *num;
for (i = 0; i < size; ++i) {
PyObject *item, *num;
- item = PySequence_GetItem(values, i);
+ item = PySequence_Fast_GET_ITEM(values, i); /* Borrowed reference. */
if (ds->ds->type == DS_TYPE_COUNTER) {
if (ds->ds->type == DS_TYPE_COUNTER) {
- num = PyNumber_Long(item);
- if (num != NULL)
+ num = PyNumber_Long(item); /* New reference. */
+ if (num != NULL) {
value[i].counter = PyLong_AsUnsignedLongLong(num);
value[i].counter = PyLong_AsUnsignedLongLong(num);
+ Py_XDECREF(num);
+ }
} else if (ds->ds->type == DS_TYPE_GAUGE) {
} else if (ds->ds->type == DS_TYPE_GAUGE) {
- num = PyNumber_Float(item);
- if (num != NULL)
+ num = PyNumber_Float(item); /* New reference. */
+ if (num != NULL) {
value[i].gauge = PyFloat_AsDouble(num);
value[i].gauge = PyFloat_AsDouble(num);
+ Py_XDECREF(num);
+ }
} else if (ds->ds->type == DS_TYPE_DERIVE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
} else if (ds->ds->type == DS_TYPE_DERIVE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
- num = PyNumber_Long(item);
- if (num != NULL)
+ num = PyNumber_Long(item); /* New reference. */
+ if (num != NULL) {
value[i].derive = PyLong_AsLongLong(num);
value[i].derive = PyLong_AsLongLong(num);
+ Py_XDECREF(num);
+ }
} else if (ds->ds->type == DS_TYPE_ABSOLUTE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
} else if (ds->ds->type == DS_TYPE_ABSOLUTE) {
/* This might overflow without raising an exception.
* Not much we can do about it */
- num = PyNumber_Long(item);
- if (num != NULL)
+ num = PyNumber_Long(item); /* New reference. */
+ if (num != NULL) {
value[i].absolute = PyLong_AsUnsignedLongLong(num);
value[i].absolute = PyLong_AsUnsignedLongLong(num);
+ Py_XDECREF(num);
+ }
} else {
free(value);
} else {
free(value);
- PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, type);
+ PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, value_list.type);
return NULL;
}
if (PyErr_Occurred() != NULL) {
return NULL;
}
if (PyErr_Occurred() != NULL) {
value_list.values_len = size;
value_list.time = DOUBLE_TO_CDTIME_T(time);
value_list.interval = DOUBLE_TO_CDTIME_T(interval);
value_list.values_len = size;
value_list.time = DOUBLE_TO_CDTIME_T(time);
value_list.interval = DOUBLE_TO_CDTIME_T(interval);
- sstrncpy(value_list.host, host, sizeof(value_list.host));
- sstrncpy(value_list.plugin, plugin, sizeof(value_list.plugin));
- sstrncpy(value_list.plugin_instance, plugin_instance, sizeof(value_list.plugin_instance));
- sstrncpy(value_list.type, type, sizeof(value_list.type));
- sstrncpy(value_list.type_instance, type_instance, sizeof(value_list.type_instance));
value_list.meta = cpy_build_meta(meta);;
if (value_list.host[0] == 0)
sstrncpy(value_list.host, hostname_g, sizeof(value_list.host));
value_list.meta = cpy_build_meta(meta);;
if (value_list.host[0] == 0)
sstrncpy(value_list.host, hostname_g, sizeof(value_list.host));
Py_BEGIN_ALLOW_THREADS;
ret = plugin_write(dest, NULL, &value_list);
Py_END_ALLOW_THREADS;
Py_BEGIN_ALLOW_THREADS;
ret = plugin_write(dest, NULL, &value_list);
Py_END_ALLOW_THREADS;
+ meta_data_destroy(value_list.meta);
+ free(value);
if (ret != 0) {
PyErr_SetString(PyExc_RuntimeError, "error dispatching values, read the logs");
return NULL;
}
if (ret != 0) {
PyErr_SetString(PyExc_RuntimeError, "error dispatching values, read the logs");
return NULL;
}
- free(value);
Py_RETURN_NONE;
}
Py_RETURN_NONE;
}
}
static PyMemberDef Values_members[] = {
}
static PyMemberDef Values_members[] = {
- {"interval", T_INT, offsetof(Values, interval), 0, interval_doc},
+ {"interval", T_DOUBLE, 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}
{"values", T_OBJECT_EX, offsetof(Values, values), 0, values_doc},
{"meta", T_OBJECT_EX, offsetof(Values, meta), 0, meta_doc},
{NULL}
Notification *self = (Notification *) s;
int severity = 0;
double time = 0;
Notification *self = (Notification *) s;
int severity = 0;
double time = 0;
- const char *message = "";
- const char *type = "", *plugin_instance = "", *type_instance = "", *plugin = "", *host = "";
+ char *message = NULL;
+ char *type = NULL, *plugin_instance = NULL, *type_instance = NULL, *plugin = NULL, *host = NULL;
static char *kwlist[] = {"type", "message", "plugin_instance", "type_instance",
"plugin", "host", "time", "severity", NULL};
static char *kwlist[] = {"type", "message", "plugin_instance", "type_instance",
"plugin", "host", "time", "severity", NULL};
NULL, &plugin, NULL, &host, &time, &severity))
return -1;
NULL, &plugin, NULL, &host, &time, &severity))
return -1;
- if (type[0] != 0 && plugin_get_ds(type) == NULL) {
+ if (type && plugin_get_ds(type) == NULL) {
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
+ FreeAll();
+ PyMem_Free(message);
return -1;
}
return -1;
}
- sstrncpy(self->data.host, host, sizeof(self->data.host));
- sstrncpy(self->data.plugin, plugin, sizeof(self->data.plugin));
- sstrncpy(self->data.plugin_instance, plugin_instance, sizeof(self->data.plugin_instance));
- sstrncpy(self->data.type, type, sizeof(self->data.type));
- sstrncpy(self->data.type_instance, type_instance, sizeof(self->data.type_instance));
+ sstrncpy(self->data.host, host ? host : "", sizeof(self->data.host));
+ sstrncpy(self->data.plugin, plugin ? plugin : "", sizeof(self->data.plugin));
+ sstrncpy(self->data.plugin_instance, plugin_instance ? plugin_instance : "", sizeof(self->data.plugin_instance));
+ sstrncpy(self->data.type, type ? type : "", sizeof(self->data.type));
+ sstrncpy(self->data.type_instance, type_instance ? type_instance : "", sizeof(self->data.type_instance));
+ sstrncpy(self->message, message ? message : "", sizeof(self->message));
self->data.time = time;
self->data.time = time;
-
- sstrncpy(self->message, message, sizeof(self->message));
self->severity = severity;
self->severity = severity;
+
+ FreeAll();
+ PyMem_Free(message);
return 0;
}
return 0;
}
@@ -837,12 +877,8 @@ static PyObject *Notification_dispatch(Notification *self, PyObject *args, PyObj
notification_t notification;
double t = self->data.time;
int severity = self->severity;
notification_t notification;
double t = self->data.time;
int severity = self->severity;
- const char *host = self->data.host;
- const char *plugin = self->data.plugin;
- const char *plugin_instance = self->data.plugin_instance;
- const char *type = self->data.type;
- const char *type_instance = self->data.type_instance;
- const char *message = self->message;
+ char *host = NULL, *plugin = NULL, *plugin_instance = NULL, *type = NULL, *type_instance = NULL;
+ char *message = NULL;
static char *kwlist[] = {"type", "message", "plugin_instance", "type_instance",
"plugin", "host", "time", "severity", NULL};
static char *kwlist[] = {"type", "message", "plugin_instance", "type_instance",
"plugin", "host", "time", "severity", NULL};
@@ -851,25 +887,28 @@ static PyObject *Notification_dispatch(Notification *self, PyObject *args, PyObj
NULL, &plugin, NULL, &host, &t, &severity))
return NULL;
NULL, &plugin, NULL, &host, &t, &severity))
return NULL;
- if (type[0] == 0) {
+ notification.time = DOUBLE_TO_CDTIME_T(t);
+ notification.severity = severity;
+ sstrncpy(notification.message, message ? message : self->message, sizeof(notification.message));
+ sstrncpy(notification.host, host ? host : self->data.host, sizeof(notification.host));
+ sstrncpy(notification.plugin, plugin ? plugin : self->data.plugin, sizeof(notification.plugin));
+ sstrncpy(notification.plugin_instance, plugin_instance ? plugin_instance : self->data.plugin_instance, sizeof(notification.plugin_instance));
+ sstrncpy(notification.type, type ? type : self->data.type, sizeof(notification.type));
+ sstrncpy(notification.type_instance, type_instance ? type_instance : self->data.type_instance, sizeof(notification.type_instance));
+ notification.meta = NULL;
+ FreeAll();
+ PyMem_Free(message);
+
+ if (notification.type[0] == 0) {
PyErr_SetString(PyExc_RuntimeError, "type not set");
return NULL;
}
PyErr_SetString(PyExc_RuntimeError, "type not set");
return NULL;
}
- ds = plugin_get_ds(type);
+ ds = plugin_get_ds(notification.type);
if (ds == NULL) {
if (ds == NULL) {
- PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
+ PyErr_Format(PyExc_TypeError, "Dataset %s not found", notification.type);
return NULL;
}
return NULL;
}
- notification.time = DOUBLE_TO_CDTIME_T(t);
- notification.severity = severity;
- sstrncpy(notification.message, message, sizeof(notification.message));
- sstrncpy(notification.host, host, sizeof(notification.host));
- sstrncpy(notification.plugin, plugin, sizeof(notification.plugin));
- sstrncpy(notification.plugin_instance, plugin_instance, sizeof(notification.plugin_instance));
- sstrncpy(notification.type, type, sizeof(notification.type));
- sstrncpy(notification.type_instance, type_instance, sizeof(notification.type_instance));
- notification.meta = NULL;
if (notification.time == 0)
notification.time = cdtime();
if (notification.host[0] == 0)
if (notification.time == 0)
notification.time = cdtime();
if (notification.host[0] == 0)