Skip to content

Commit 49ef27d

Browse files
authored
Merge pull request #1 from CESNET/devel
JSON output: replace the internal JSON converter with libfds converter
2 parents f9c1b2b + 224421d commit 49ef27d

File tree

11 files changed

+218
-1008
lines changed

11 files changed

+218
-1008
lines changed

src/plugins/output/json/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ add_library(json-output MODULE
55
src/Config.hpp
66
src/Storage.cpp
77
src/Storage.hpp
8-
src/protocols.hpp
9-
src/protocols.cpp
108
src/Printer.cpp
119
src/Printer.hpp
1210
src/File.cpp

src/plugins/output/json/README.rst

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ Each flow record is converted individually and send to outputs where at least on
1010
method must be configured. All fields in an IPFIX record are formatted as: <field name>:<value>,
1111
where the *field name* represents a name of a corresponding Information Element as
1212
"<Enterprise Name>:<Information Element Name>" and *value* is a number, string,
13-
boolean or null (if conversion from IPFIX to JSON fails). The enterprise name is a name of an
13+
boolean or null (if conversion from IPFIX to JSON fails). The Enterprise Name is a name of an
1414
organization that manages the field, such as IANA, CISCO, etc.
1515

1616
If the field name and type is unknown and "ignoreUnknown" option is disabled, the field name
1717
use format 'enXX:idYY' where XX is an Enterprise Number and YY is an Information Element ID.
1818
See notes for instructions on how to add missing definitions of Information Elements.
1919

20+
Structured data types (basicList, subTemplateList and subTemplateMultiList) are supported. See
21+
the particular section below for information about their formatting.
22+
2023
Example output
2124
--------------
2225

@@ -65,6 +68,8 @@ Don't forget to remove (or comment) outputs that you don't want to use!
6568
<ignoreUnknown>true</ignoreUnknown>
6669
<ignoreOptions>true</ignoreOptions>
6770
<nonPrintableChar>true</nonPrintableChar>
71+
<numericNames>false</numericNames>
72+
<splitBiflow>false</splitBiflow>
6873
6974
<outputs>
7075
<server>
@@ -127,6 +132,16 @@ Formatting parameters:
127132
Ignore non-printable characters (newline, tab, control characters, etc.) in IPFIX strings.
128133
If disabled, these characters are escaped on output. [values: true/false, default: true]
129134

135+
:``numericNames``:
136+
Use only short identification of Information Elements (i.e. "enXX:idYY"). If enabled, the
137+
short version is used even if the definition of the field is known. This option can help to
138+
create a shorter JSON records with key identifiers which are independent on the internal
139+
configuration. [values: true/false, default: false]
140+
141+
:``splitBiflow``:
142+
In case of Biflow records, split the record to two unidirectional flow records. Non-biflow
143+
records are unaffected. [values: true/false, default: false]
144+
130145
----
131146

132147
Output types: At least one of the following output must be configured. Multiple server/send/file
@@ -189,7 +204,75 @@ If one or more Information Element definitions are missing, you can easily add t
189204
All definitions are provided by `libfds <https://github.com/CESNET/libfds/>`_ library.
190205
See the project website for help.
191206

207+
If a flow record contains multiple occurrences of the same Information Element,
208+
their values are stored into a single name/value pair as JSON array. Order of the values
209+
in the array corresponds to their order in the flow record.
210+
192211
For higher performance, it is advisable to use non-formatted conversion of IPFIX data types.
193-
If performance matters, you should prefer, for example, timestamps as numbers over ISO 8601 strings.
212+
In that case, you should prefer, for example, timestamps as numbers over ISO 8601 strings
213+
and numeric identifiers of fields as they are usually shorted.
214+
215+
Structured data types
216+
---------------------
217+
218+
Flow records can be extended with structured data types (as described in RFC6313).
219+
Each of these types are formatted as JSON objects with "@type" field which helps to distinguish
220+
its formatting. Moreover, as the standard describes, the semantic of the list is also included.
221+
222+
Converted *basicList* contains "fieldID" with the Information Element identifier of zero or more
223+
Information Element(s) contained in the list. All values are stored as a JSON array in "data" field.
224+
225+
.. code-block:: json
226+
227+
{
228+
"example:blField": {
229+
"@type": "basicList",
230+
"semantic": "anyOf",
231+
"fieldID": "iana:octetDeltaCount",
232+
"data": [23, 34, 23]
233+
}
234+
}
235+
236+
Converted *subTemplateList* contains only additional "data" field with array of zero or more
237+
JSON objects. As all nested JSON object are described by the same IPFIX Template, it's guaranteed
238+
the their structure is also the same. The "semantic" field indicates the relationship among the
239+
different JSON objects.
240+
241+
.. code-block:: json
242+
243+
{
244+
"example:stlField": {
245+
"@type": "subTemplateList",
246+
"semantic": "allOf",
247+
"data": [
248+
{"keyA.1": "value1", "keyA.2": "value2"},
249+
{"keyB.1": "value1", "keyB.2": "value2"},
250+
]
251+
}
252+
}
253+
254+
Converted *subTemplateMultiList* is similar to the previous type, however, sub-records can be
255+
even more nested. The "data" field contains a JSON array with zero or more nested JSON arrays.
256+
Each nested array contains zero or more JSON objects and it's guaranteed that JSON objects in
257+
the same array have the same structure. The "semantic" field indicates top-level relationship
258+
among the nested arrays.
259+
260+
.. code-block:: json
261+
262+
{
263+
"example:stmlField": {
264+
"@type": "subTemplateMultiList",
265+
"semantic": "allOf",
266+
"data" : [
267+
[
268+
{"keyA.1": "value1", "keyA.2": "value2"},
269+
{"keyB.1": "value1", "keyB.2": "value2"},
270+
],
271+
[
272+
{"idA.1": "something", "idB.1": 123}
273+
]
274+
]
275+
}
276+
}
194277
195-
Structured data types (basicList, subTemplateList, etc.) are not supported yet.
278+
Keep on mind that all structures can be nested in each other.

src/plugins/output/json/doc/ipfixcol2-json-output.7.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ JSON (output plugin)
99
:Author: Lukáš Huták ([email protected])
1010
:Author: Petr Velan ([email protected])
1111
:Date: 2018-09-20
12-
:Copyright: Copyright © 2018 CESNET, z.s.p.o.
13-
:Version: 2.0
12+
:Copyright: Copyright © 2019 CESNET, z.s.p.o.
13+
:Version: 2.1
1414
:Manual section: 7
1515
:Manual group: IPFIXcol collector
1616

src/plugins/output/json/src/Config.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ enum params_xml_nodes {
5757
FMT_UNKNOWN, /**< Unknown definitions */
5858
FMT_OPTIONS, /**< Ignore Options Template Records */
5959
FMT_NONPRINT, /**< Non-printable chars */
60+
FMT_NUMERIC, /**< Use numeric names */
61+
FMT_BFSPLIT, /**< Split biflow */
6062
// Common output
6163
OUTPUT_LIST, /**< List of output types */
6264
OUTPUT_PRINT, /**< Print to standard output */
@@ -135,6 +137,8 @@ static const struct fds_xml_args args_params[] = {
135137
FDS_OPTS_ELEM(FMT_UNKNOWN, "ignoreUnknown", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
136138
FDS_OPTS_ELEM(FMT_OPTIONS, "ignoreOptions", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
137139
FDS_OPTS_ELEM(FMT_NONPRINT, "nonPrintableChar", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
140+
FDS_OPTS_ELEM(FMT_NUMERIC, "numericNames", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
141+
FDS_OPTS_ELEM(FMT_BFSPLIT, "splitBiflow", FDS_OPTS_T_BOOL, FDS_OPTS_P_OPT),
138142
FDS_OPTS_NESTED(OUTPUT_LIST, "outputs", args_outputs, 0),
139143
FDS_OPTS_END
140144
};
@@ -445,6 +449,14 @@ Config::parse_params(fds_xml_ctx_t *params)
445449
assert(content->type == FDS_OPTS_T_BOOL);
446450
format.white_spaces = content->val_bool;
447451
break;
452+
case FMT_NUMERIC: // Use only numeric identifiers
453+
assert(content->type == FDS_OPTS_T_BOOL);
454+
format.numeric_names = content->val_bool;
455+
break;
456+
case FMT_BFSPLIT: // Split biflow records
457+
assert(content->type == FDS_OPTS_T_BOOL);
458+
format.split_biflow = content->val_bool;
459+
break;
448460
case OUTPUT_LIST: // List of output plugin
449461
assert(content->type == FDS_OPTS_T_CONTEXT);
450462
parse_outputs(content->ptr_ctx);
@@ -467,6 +479,8 @@ Config::default_set()
467479
format.white_spaces = true;
468480
format.ignore_unknown = true;
469481
format.ignore_options = true;
482+
format.numeric_names = false;
483+
format.split_biflow = false;
470484

471485
outputs.prints.clear();
472486
outputs.files.clear();

src/plugins/output/json/src/Config.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ struct cfg_format {
6060
bool white_spaces;
6161
/** Ignore Options Template records */
6262
bool ignore_options;
63+
/** Use only numeric identifiers of Information Elements */
64+
bool numeric_names;
65+
/** Split biflow records */
66+
bool split_biflow;
6367
};
6468

6569
/** Output configuration base structure */

0 commit comments

Comments
 (0)