Skip to content

Commit af52603

Browse files
authored
Missing YAML examples for parsers docs. Fixes #1865. (#1866)
* Adding YAML examples to configuring parser doc. Part of issue #1865. Signed-off-by: Eric D. Schabell <[email protected]> * Fixed type on yaml parser types field in configuring parser doc. Part of issue #1865. Signed-off-by: Eric D. Schabell <[email protected]> * Adding YAML examples to regular expression parser doc. Part of issue #1865. Signed-off-by: Eric D. Schabell <[email protected]> * Adding YAML examples to logfmt parser doc. Part of issue #1865. Signed-off-by: Eric D. Schabell <[email protected]> * Adding YAML examples to JSON parser doc. Part of issue #1865. Signed-off-by: Eric D. Schabell <[email protected]> * Adding YAML examples to LTSV parser doc. Part of issue #1865. Signed-off-by: Eric D. Schabell <[email protected]> * Adding YAML examples to decoders parser doc. Part of issue #1865. Signed-off-by: Eric D. Schabell <[email protected]> --------- Signed-off-by: Eric D. Schabell <[email protected]>
1 parent 472a679 commit af52603

File tree

6 files changed

+196
-19
lines changed

6 files changed

+196
-19
lines changed

pipeline/parsers/configuring-parser.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ By default, Fluent Bit provides a set of pre-configured parsers that can be used
1818
Parsers are defined in one or more configuration files that are loaded at start time, either from the command line or through the main Fluent Bit configuration file.
1919

2020
{% hint style="info" %}
21+
2122
Fluent Bit uses Ruby-based regular expressions. You can use [Rubular](http://www.rubular.com) to test your regular expressions for Ruby compatibility.
23+
2224
{% endhint %}
2325

2426
## Configuration parameters
@@ -43,7 +45,30 @@ Multiple parsers can be defined and each section has it own properties. The foll
4345

4446
## Parsers configuration file
4547

46-
All parsers must be defined in a `parsers.conf` file, not in the Fluent Bit global configuration file. The parsers file exposes all parsers available that can be used by the input plugins that are aware of this feature. A parsers file can have multiple entries, like so:
48+
All parsers must be defined in a parsers file (see below for examples), not in the Fluent Bit global configuration file. The parsers file exposes all parsers available that can be used by the input plugins that are aware of this feature. A parsers file can have multiple entries, like so:
49+
50+
{% tabs %}
51+
{% tab title="parsers.yaml" %}
52+
53+
```yaml
54+
parsers:
55+
- name: docker
56+
format: json
57+
time_key: time
58+
time_format: '%Y-%m-%dT%H:%M:%S.%L'
59+
time_keep: on
60+
61+
- name: syslog-rfc5424
62+
format: regex
63+
regex: '^\<(?<pri>[0-9]{1,5})\>1 (?<time>[^ ]+) (?<host>[^ ]+) (?<ident>[^ ]+) (?<pid>[-0-9]+) (?<msgid>[^ ]+) (?<extradata>(\[(.*)\]|-)) (?<message>.+)$'
64+
time_key: time
65+
time_format: '%Y-%m-%dT%H:%M:%S.%L'
66+
time_keep: on
67+
types: pid:integer
68+
```
69+
70+
{% endtab %}
71+
{% tab title="parsers.conf" %}
4772
4873
```text
4974
[PARSER]
@@ -63,6 +88,9 @@ All parsers must be defined in a `parsers.conf` file, not in the Fluent Bit glob
6388
Types pid:integer
6489
```
6590

91+
{% endtab %}
92+
{% endtabs %}
93+
6694
For more information about the parsers available, refer to the [default parsers file](https://github.com/fluent/fluent-bit/blob/master/conf/parsers.conf) distributed with Fluent Bit source code.
6795

6896
## Time resolution and fractional seconds
@@ -72,7 +100,9 @@ Time resolution and its format supported are handled by using the [strftime\(3\)
72100
In addition, Fluent Bit extends its time resolution to support fractional seconds like `017-05-17T15:44:31**.187512963**Z`. The `%L` format option for `Time_Format` is provided as a way to indicate that content must be interpreted as fractional seconds.
73101

74102
{% hint style="info" %}
103+
75104
The option `%L` is only valid when used after seconds (`%S`) or seconds since the epoch (`%s`). For example, `%S.%L` and `%s.%L` are valid strings.
105+
76106
{% endhint %}
77107

78108
## Supported time zone abbreviations
@@ -172,7 +202,9 @@ The following time zone abbreviations are supported.
172202
### Military time zones
173203

174204
{% hint style="info" %}
205+
175206
These are single-letter UTC offset designators. `J` (Juliet) represents local time and is not included. `Z` represents Zulu Time, as listed in the [Universal time zones](#universal-time-zones) list.
207+
176208
{% endhint %}
177209

178210
| Abbreviation | UTC Offset (`HH:MM`) | Offset (seconds) | Is DST | Description |
@@ -200,4 +232,4 @@ These are single-letter UTC offset designators. `J` (Juliet) represents local ti
200232
| `V` | `-09:00` | `-32400` | no | Victor Time Zone |
201233
| `W` | `-10:00` | `-36000` | no | Whiskey Time Zone |
202234
| `X` | `-11:00` | `-43200` | no | X-ray Time Zone |
203-
| `Y` | `-12:00` | `-46800` | no | Yankee Time Zone |
235+
| `Y` | `-12:00` | `-46800` | no | Yankee Time Zone |

pipeline/parsers/decoders.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ definition can optionally set one or more decoders. There are two types of decod
3131

3232
Our pre-defined Docker parser has the following definition:
3333

34+
{% tabs %}
35+
{% tab title="parsers.yaml" %}
36+
37+
```yaml
38+
parsers:
39+
- name: docker
40+
format: json
41+
time_key: time
42+
time_format: '%Y-%m-%dT%H:%M:%S.%L'
43+
time_keep: on
44+
# Command | Decoder | Field | Optional Action |
45+
# ==========|==========|=======|===================|
46+
decode_field_as: escaped log
47+
```
48+
49+
{% endtab %}
50+
{% tab title="parsers.conf" %}
51+
3452
```text
3553
[PARSER]
3654
Name docker
@@ -95,11 +113,32 @@ Example output:
95113
", "stream"=>"stdout", "time"=>"2018-02-19T23:25:29.1845622Z"}]
96114
```
97115

98-
Decoder configuration file:
116+
Decoder example Fluent Bit configuration files:
117+
118+
{% tabs %}
119+
{% tab title="fluent-bit.yaml" %}
120+
121+
```yaml
122+
service:
123+
parsers_file: parsers.yaml
124+
125+
pipeline:
126+
inputs:
127+
- name: tail
128+
parser: docker
129+
path: /path/to/log.log
130+
131+
outputs:
132+
- name: stdout
133+
match: '*'
134+
```
135+
136+
{% endtab %}
137+
{% tab title="fluent-bit.conf" %}
99138
100139
```text
101140
[SERVICE]
102-
Parsers_File fluent-bit-parsers.conf
141+
Parsers_File parsers.conf
103142

104143
[INPUT]
105144
Name tail
@@ -111,7 +150,25 @@ Decoder configuration file:
111150
Match *
112151
```
113152

114-
The `fluent-bit-parsers.conf` file:
153+
{% endtab %}
154+
{% endtabs %}
155+
156+
The example parsers file:
157+
158+
{% tabs %}
159+
{% tab title="parsers.yaml" %}
160+
161+
```yaml
162+
parsers:
163+
- name: docker
164+
format: json
165+
time_key: time
166+
time_format: '%Y-%m-%dT%H:%M:%S %z'
167+
decode_field_as: escaped_utf8 log
168+
```
169+
170+
{% endtab %}
171+
{% tab title="parsers.conf" %}
115172
116173
```text
117174
[PARSER]
@@ -121,3 +178,6 @@ The `fluent-bit-parsers.conf` file:
121178
Time_Format %Y-%m-%dT%H:%M:%S %z
122179
Decode_Field_as escaped_utf8 log
123180
```
181+
182+
{% endtab %}
183+
{% endtabs %}

pipeline/parsers/json.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,34 @@ The _JSON_ parser transforms JSON logs by converting them to internal binary rep
44

55
For example, the default parsers configuration file includes a parser for parsing Docker logs (when the Tail input plugin is used):
66

7-
```python
7+
{% tabs %}
8+
{% tab title="parsers.yaml" %}
9+
10+
```yaml
11+
parsers:
12+
- name: docker
13+
format: json
14+
time_key: time
15+
time_format: '%Y-%m-%dT%H:%M:%S %z'
16+
```
17+
18+
{% endtab %}
19+
{% tab title="parsers.conf" %}
20+
21+
```text
822
[PARSER]
923
Name docker
1024
Format json
1125
Time_Key time
1226
Time_Format %Y-%m-%dT%H:%M:%S %z
1327
```
1428

29+
{% endtab %}
30+
{% endtabs %}
31+
1532
The following log entry is valid content for the previously defined parser:
1633

17-
```javascript
34+
```text
1835
{"key1": 12345, "key2": "abc", "time": "2006-07-28T13:22:04Z"}
1936
```
2037

@@ -24,4 +41,4 @@ After processing, its internal representation will be:
2441
[1154103724, {"key1"=>12345, "key2"=>"abc"}]
2542
```
2643

27-
The time was converted to a UTC timestamp and the map was reduced to each component of the original message.
44+
The time was converted to a UTC timestamp and the map was reduced to each component of the original message.

pipeline/parsers/logfmt.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22

33
The **logfmt** parser allows to parse the logfmt format described in [https://brandur.org/logfmt](https://brandur.org/logfmt) . A more formal description is in [https://godoc.org/github.com/kr/logfmt](https://godoc.org/github.com/kr/logfmt) .
44

5-
Here is an example configuration:
5+
Here is an example parsers configuration:
66

7-
```python
7+
{% tabs %}
8+
{% tab title="parsers.yaml" %}
9+
10+
```yaml
11+
parsers:
12+
- name: logfmt
13+
format: logfmt
14+
```
15+
16+
{% endtab %}
17+
{% tab title="parsers.conf" %}
18+
19+
```text
820
[PARSER]
921
Name logfmt
1022
Format logfmt
1123
```
1224

25+
{% endtab %}
26+
{% endtabs %}
27+
1328
The following log entry is a valid content for the parser defined above:
1429

1530
```text
@@ -27,9 +42,25 @@ After processing, it internal representation will be:
2742
If you want to be more strict than the logfmt standard and not parse lines where some attributes do
2843
not have values (such as `key3`) in the example above, you can configure the parser as follows:
2944

30-
```python
45+
{% tabs %}
46+
{% tab title="parsers.yaml" %}
47+
48+
```yaml
49+
parsers:
50+
- name: logfmt
51+
format: logfmt
52+
logfmt_no_bare_keys: true
53+
```
54+
55+
{% endtab %}
56+
{% tab title="parsers.conf" %}
57+
58+
```text
3159
[PARSER]
3260
Name logfmt
3361
Format logfmt
3462
Logfmt_No_Bare_Keys true
3563
```
64+
65+
{% endtab %}
66+
{% endtabs %}

pipeline/parsers/ltsv.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,24 @@ LogFormat "host:%h\tident:%l\tuser:%u\ttime:%t\treq:%r\tstatus:%>s\tsize:%b\tref
1313
CustomLog "logs/access_log" combined_ltsv
1414
```
1515

16-
The parser.conf:
16+
The following is an example parsers configuration file:
17+
18+
{% tabs %}
19+
{% tab title="parsers.yaml" %}
20+
21+
```yaml
22+
parsers:
23+
- name: access_log_ltsv
24+
format: ltsv
25+
time_key: time
26+
time_format: '[%d/%b/%Y:%H:%M:%S %z]'
27+
types: status:integer size:integer
28+
```
29+
30+
{% endtab %}
31+
{% tab title="parsers.conf" %}
1732
18-
```python
33+
```text
1934
[PARSER]
2035
Name access_log_ltsv
2136
Format ltsv
@@ -24,6 +39,9 @@ The parser.conf:
2439
Types status:integer size:integer
2540
```
2641

42+
{% endtab %}
43+
{% endtabs %}
44+
2745
The following log entry is a valid content for the parser defined above:
2846

2947
```text
@@ -42,5 +60,4 @@ After processing, it internal representation will be:
4260
[1531222025.000000000, {"host"=>"127.0.0.1", "ident"=>"-", "user"=>"-", "req"=>"GET /assets/css/style.css HTTP/1.1", "status"=>200, "size"=>1279, "referer"=>"http://127.0.0.1/", "ua"=>"Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0"}]
4361
```
4462

45-
The time has been converted to Unix timestamp \(UTC\).
46-
63+
The time has been converted to Unix timestamp \(UTC\).

pipeline/parsers/regular-expression.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ across multiple lines from a `tail`. The [Tail](../inputs/tail.md) input plugin
88
treats each line as a separate entity.
99

1010
{% hint style="warning" %}
11+
1112
Security Warning: Onigmo is a backtracking regex engine. When using expensive
1213
regex patterns Onigmo can take a long time to perform pattern matching. Read
13-
["ReDoS"](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS)
14-
on OWASP for additional information.
14+
["ReDoS"](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS) on OWASP for additional information.
15+
1516
{% end hint %}
1617

1718
Setting the format to **regex** requires a `regex` configuration key.
@@ -34,7 +35,23 @@ character. Use the [Rubular](http://rubular.com/) web editor to test your expres
3435
The following parser configuration example provides rules that can be applied to an
3536
Apache HTTP Server log entry:
3637

37-
```python
38+
{% tabs %}
39+
{% tab title="parsers.yaml" %}
40+
41+
```yaml
42+
parsers:
43+
- name: apache
44+
format: regex
45+
regex: '^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$'
46+
time_key: time
47+
time_format: '%d/%b/%Y:%H:%M:%S %z'
48+
types: pid:integer size:integer
49+
```
50+
51+
{% endtab %}
52+
{% tab title="parsers.conf" %}
53+
54+
```text
3855
[PARSER]
3956
Name apache
4057
Format regex
@@ -44,6 +61,9 @@ Apache HTTP Server log entry:
4461
Types code:integer size:integer
4562
```
4663

64+
{% endtab %}
65+
{% endtabs %}
66+
4767
As an example, review the following Apache HTTP Server log entry:
4868

4969
```text
@@ -64,4 +84,4 @@ proper parser can help to make a structured representation of the entry:
6484
"agent"=>""
6585
}
6686
]
67-
```
87+
```

0 commit comments

Comments
 (0)