Skip to content

Commit 8de8019

Browse files
committed
doc/devguide: document eve file types
Ticket: OISF#4708 (cherry picked from commit 9fffc09)
1 parent 183cd8a commit 8de8019

3 files changed

Lines changed: 101 additions & 2 deletions

File tree

doc/userguide/devguide/extending/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Extending Suricata
99
app-layer/index.rst
1010
detect/index.rst
1111
output/index.rst
12+
output/eve-filetypes.rst
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
EVE Filetypes
2+
#############
3+
4+
Introduction
5+
************
6+
7+
The Suricata EVE/JSON output supports filetypes to extend how
8+
EVE records are processed and delivered. Custom filetypes
9+
provide alternatives to standard file output by implementing a
10+
file-like interface that Suricata can write to. These filetypes can
11+
send events to databases, sockets, or other destinations, and can even
12+
perform custom processing on the output before storing it.
13+
14+
EVE Filetype Life Cycle
15+
***********************
16+
17+
The life-cycle of an EVE filetype along with the callbacks are
18+
discussed in ``output-eve.h``:
19+
20+
.. literalinclude:: ../../../../../src/output-eve.h
21+
:language: c
22+
:start-at: /** \brief Structure used to define an EVE output
23+
:end-at: } SCEveFileType;
24+
25+
Threading Considerations
26+
************************
27+
28+
It is the user's Suricata EVE output configuration that enables
29+
multi-threaded logging, not the filetype. So all filetypes should be
30+
designed to be thread safe.
31+
32+
If your filetype can absolutely not be made thread safe, it would be
33+
best to error out on initialization. This can be done during the
34+
filetype initialization:
35+
36+
.. code-block:: c
37+
38+
static int MyFiletypeInit(const SCConfNode *node, const bool threaded, void **data)
39+
{
40+
if (threaded) {
41+
FatalError("EVE filetype does not support threaded logging.");
42+
}
43+
44+
/* Continue with initialization. */
45+
}
46+
47+
Write Considerations
48+
********************
49+
50+
The ``Write`` callback is called in a packet processing thread so any
51+
blocking (other than writing to a file) should be avoided. If writing
52+
to a blocking resource it is recommended to copy the buffer into
53+
another thread for further processing to avoid packet loss.
54+
55+
Registration
56+
************
57+
58+
Registering an EVE filetype requires registering the filetype
59+
early in the Suricata start-up or lifecycle, or if a plugin, in the
60+
plugin initialization function.
61+
62+
.. code-block:: c
63+
64+
SCEveFileType *filetype = SCCalloc(1, sizeof(SCEveFileType));
65+
66+
filetype->name = "my-custom-filetype";
67+
filetype->Init = FiletypeInit;
68+
filetype->Deinit = FiletypeDeinit;
69+
filetype->ThreadInit = FiletypeThreadInit;
70+
filetype->ThreadDeinit = FiletypeThreadDeinit;
71+
filetype->Write = FiletypeWrite;
72+
73+
if (!SCRegisterEveFileType(filetype)) {
74+
FatalError("Failed to register EVE filetype");
75+
}
76+
77+
Then to use this filetype, set the ``filetype`` in your
78+
``suricata.yaml`` ``eve-log`` configuration to the name of the
79+
filetype:
80+
81+
.. code-block:: yaml
82+
83+
outputs:
84+
- eve-log:
85+
enabled: true
86+
filetype: my-custom-filetype
87+
88+
Examples
89+
********
90+
91+
Suricata built-ins:
92+
93+
* ``null``: see ``output-eve-null.c`` in the Suricata source code
94+
* ``syslog``: see ``output-eve-syslog.c`` in the Suricata source code
95+
96+
Plugin:
97+
98+
* The Suricata source code contains an example as a plugin, see:
99+
``examples/plugins/c-json-filetype``.

src/output-eve.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636

3737
typedef uint32_t ThreadId;
3838

39-
/**
40-
* \brief Structure used to define an EVE output file type plugin.
39+
/** \brief Structure used to define an EVE output file type.
4140
*
4241
* EVE filetypes implement an object with a file-like interface and
4342
* are used to output EVE log records to files, syslog, or

0 commit comments

Comments
 (0)