Skip to content

Commit

Permalink
python-modules: added set_transport_name() method to LogFetcher & Log…
Browse files Browse the repository at this point in the history
…Source

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Oct 15, 2023
1 parent 5a368eb commit 96c8c57
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/python-modules/syslogng/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ def close_batch(self):
"""
super().close_batch()

def set_transport_name(self, name):
"""Set the transport name used to retrieve messages
This function can be called to customize the $TRANSPORT name-value pair.
"""
super().set_transport_name(name)

def request_exit(self):
"""Request the main loop to exit
Expand Down Expand Up @@ -262,6 +269,13 @@ def request_exit(self):
it has to be interrupted when shutting down syslog-ng.
"""

def set_transport_name(self, name):
"""Set the transport name used to retrieve messages
This function can be called to customize the $TRANSPORT name-value pair.
"""
super().set_transport_name(name)


class InstantAckTracker(InstantAckTracker):
def __init__(self, ack_callback):
Expand Down
19 changes: 19 additions & 0 deletions modules/python/python-fetcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ typedef struct _PyLogFetcher

static PyTypeObject py_log_fetcher_type;

static PyObject *
py_log_fetcher_set_transport_name(PyLogFetcher *self, PyObject *args)
{
const gchar *transport_name;

if (!PyArg_ParseTuple(args, "s", &transport_name))
return NULL;

log_threaded_source_driver_set_transport_name(&self->driver->super.super, transport_name);
Py_RETURN_NONE;
}

PythonBinding *
python_fetcher_get_binding(LogDriver *s)
Expand Down Expand Up @@ -677,6 +688,13 @@ static PyMemberDef py_log_fetcher_members[] =
{NULL}
};

static PyMethodDef py_log_fetcher_methods[] =
{
{ "set_transport_name", (PyCFunction) py_log_fetcher_set_transport_name, METH_VARARGS, "Set transport name" },
{NULL}
};


static PyTypeObject py_log_fetcher_type =
{
PyVarObject_HEAD_INIT(&PyType_Type, 0)
Expand All @@ -686,6 +704,7 @@ static PyTypeObject py_log_fetcher_type =
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_doc = "The LogFetcher class is a base class for custom Python fetchers.",
.tp_new = PyType_GenericNew,
.tp_methods = py_log_fetcher_methods,
.tp_members = py_log_fetcher_members,
0,
};
Expand Down
13 changes: 13 additions & 0 deletions modules/python/python-source.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,18 @@ py_log_source_close_batch(PyObject *s)
Py_RETURN_NONE;
}

static PyObject *
py_log_source_set_transport_name(PyLogSource *self, PyObject *args)
{
const gchar *transport_name;

if (!PyArg_ParseTuple(args, "s", &transport_name))
return NULL;

log_threaded_source_driver_set_transport_name(&self->driver->super, transport_name);
Py_RETURN_NONE;
}

static void
python_sd_run(LogThreadedSourceDriver *s)
{
Expand Down Expand Up @@ -749,6 +761,7 @@ static PyMethodDef py_log_source_methods[] =
{
{ "post_message", (PyCFunction) py_log_source_post, METH_VARARGS | METH_KEYWORDS, "Post message" },
{ "close_batch", (PyCFunction) py_log_source_close_batch, METH_NOARGS, "Close input batch" },
{ "set_transport_name", (PyCFunction) py_log_source_set_transport_name, METH_VARARGS, "Set transport name" },
{NULL}
};

Expand Down

0 comments on commit 96c8c57

Please sign in to comment.