Skip to content

Commit 490a9a3

Browse files
committed
examples: add filterx function plugin example
Signed-off-by: shifter <[email protected]>
1 parent 63f058e commit 490a9a3

File tree

8 files changed

+132
-2
lines changed

8 files changed

+132
-2
lines changed

modules/examples/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ add_subdirectory(sources/random-choice-generator)
1414
add_subdirectory(inner-destinations/http-test-slots)
1515
add_subdirectory(inner-destinations/tls-test-validation)
1616
add_subdirectory(destinations/example_destination)
17+
add_subdirectory(filterx/example-filterx-func)
1718

1819
target_link_libraries(examples PRIVATE msg-generator)
1920
target_link_libraries(examples PRIVATE threaded-random-generator)
2021
target_link_libraries(examples PRIVATE threaded-diskq-source)
22+
target_link_libraries(examples PRIVATE example_filterx_func)
2123

2224
if(ENABLE_CPP)
2325
target_link_libraries(examples PRIVATE random-choice-generator)

modules/examples/Makefile.am

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ include modules/examples/inner-destinations/http-test-slots/Makefile.am
77
include modules/examples/inner-destinations/tls-test-validation/Makefile.am
88
include modules/examples/destinations/example_destination/Makefile.am
99
include modules/examples/sources/random-choice-generator/Makefile.am
10+
include modules/examples/filterx/example-filterx-func/Makefile.am
1011

1112
EXAMPLE_PLUGINS = \
1213
$(top_builddir)/modules/examples/sources/libmsg-generator.la \
1314
$(top_builddir)/modules/examples/sources/libthreaded-diskq-source.la \
1415
$(top_builddir)/modules/examples/inner-destinations/http-test-slots/libhttp-test-slots.la \
1516
$(top_builddir)/modules/examples/inner-destinations/tls-test-validation/libtls-test-validation.la \
16-
$(top_builddir)/modules/examples/destinations/example_destination/libexample_destination.la
17+
$(top_builddir)/modules/examples/destinations/example_destination/libexample_destination.la \
18+
$(top_builddir)/modules/examples/filterx/example-filterx-func/libexample-filterx-func.la
1719

1820
if HAVE_GETRANDOM
1921
EXAMPLE_PLUGINS += $(top_builddir)/modules/examples/sources/libthreaded-random-generator.la

modules/examples/example-plugins.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "cfg-parser.h"
2525
#include "plugin.h"
2626
#include "plugin-types.h"
27+
#include "filterx/example-filterx-func/example-filterx-func-plugin.h"
2728

2829
extern CfgParser msg_generator_parser;
2930

@@ -83,7 +84,12 @@ static Plugin example_plugins[] =
8384
.type = LL_CONTEXT_DESTINATION,
8485
.name = "example_destination",
8586
.parser = &example_destination_parser
86-
}
87+
},
88+
{
89+
.type = LL_CONTEXT_FILTERX_FUNC,
90+
.name = "example_echo",
91+
.construct = example_filterx_func_construct_echo,
92+
},
8793
};
8894

8995
gboolean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module_switch(ENABLE_EXAMPLE_FILTERX_FUNC "Enable example-filterx-func")
2+
if (NOT ENABLE_EXAMPLE_FILTERX_FUNC)
3+
return()
4+
endif()
5+
6+
set(EXAMPLE_FILTERX_FUNC_SOURCES
7+
example-filterx-func-plugin.c
8+
)
9+
10+
add_module(
11+
TARGET example_filterx_func
12+
SOURCES ${EXAMPLE_FILTERX_FUNC_SOURCES}
13+
LIBRARY_TYPE STATIC
14+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# noinst: Built as part of a larger libexamples module as static library
2+
noinst_LTLIBRARIES += modules/examples/filterx/example-filterx-func/libexample-filterx-func.la
3+
modules_examples_filterx_example_filterx_func_libexample_filterx_func_la_SOURCES = \
4+
modules/examples/filterx/example-filterx-func/example-filterx-func-plugin.h \
5+
modules/examples/filterx/example-filterx-func/example-filterx-func-plugin.c
6+
7+
EXTRA_DIST += \
8+
modules/examples/filterx/example-filterx-func/CMakeLists.txt
9+
10+
modules_examples_filterx_example_filterx_func_libexample_filterx_func_la_CPPFLAGS = \
11+
$(AM_CPPFLAGS) \
12+
-I$(top_srcdir)/modules/examples/filterx/example-filterx-func \
13+
-I$(top_builddir)/modules/examples/filterx/example-filterx-func
14+
modules_examples_filterx_example_filterx_func_libexample_filterx_func_la_LIBADD = $(MODULE_DEPS_LIBS)
15+
modules_examples_filterx_example_filterx_func_libexample_filterx_func_la_LDFLAGS = $(MODULE_LDFLAGS)
16+
modules_examples_filterx_example_filterx_func_libexample_filterx_func_la_DEPENDENCIES= $(MODULE_DEPS_LIBS)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2023 shifter
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License version 2 as published
6+
* by the Free Software Foundation, or (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*
17+
* As an additional exemption you are allowed to compile & link against the
18+
* OpenSSL libraries as published by the OpenSSL project. See the file
19+
* COPYING for details.
20+
*
21+
*/
22+
23+
#include "cfg-parser.h"
24+
#include "plugin.h"
25+
#include "plugin-types.h"
26+
#include "filterx/filterx-object.h"
27+
#include "scratch-buffers.h"
28+
#include "example-filterx-func-plugin.h"
29+
#include "filterx/object-primitive.h"
30+
31+
static FilterXObject *
32+
echo(GPtrArray *args)
33+
{
34+
GString *buf = scratch_buffers_alloc();
35+
LogMessageValueType t;
36+
37+
if (args == NULL ||
38+
args->len < 1)
39+
{
40+
return NULL;
41+
}
42+
43+
for (int i = 0; i < args->len; i++)
44+
{
45+
if (!filterx_object_marshal(args->pdata[i], buf, &t))
46+
goto exit;
47+
msg_debug("FILTERX EXAMPLE ECHO",
48+
evt_tag_str("value", buf->str),
49+
evt_tag_str("type", log_msg_value_type_to_str(t)));
50+
}
51+
if (args->len > 0)
52+
return filterx_object_ref(args->pdata[0]);
53+
exit:
54+
return filterx_boolean_new(FALSE);
55+
}
56+
57+
gpointer
58+
example_filterx_func_construct_echo(Plugin *self)
59+
{
60+
return (gpointer) &echo;
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2023 shifter
3+
*
4+
* This program is free software; you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License version 2 as published
6+
* by the Free Software Foundation, or (at your option) any later version.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program; if not, write to the Free Software
15+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*
17+
* As an additional exemption you are allowed to compile & link against the
18+
* OpenSSL libraries as published by the OpenSSL project. See the file
19+
* COPYING for details.
20+
*
21+
*/
22+
23+
#ifndef EXAMPLE_FILTERX_FUNC_PLUGIN_H_INCLUDED
24+
#define EXAMPLE_FILTERX_FUNC_PLUGIN_H_INCLUDED
25+
26+
gpointer example_filterx_func_construct_echo(Plugin *self);
27+
28+
#endif

tests/copyright/policy

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ modules/correlation/id-counter\.[ch]$
248248
modules/correlation/group-lines.h
249249
modules/xml/windows-eventlog-xml-parser\.h
250250
modules/xml/tests/test_windows_eventlog_xml_parser\.c
251+
modules/examples/filterx/example-filterx-func/example-filterx-func-plugin\.[ch]
251252

252253
###########################################################################
253254
# These files are GPLd with Balabit origin.

0 commit comments

Comments
 (0)