-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from calyptia/update-docs
Update documentation
- Loading branch information
Showing
3 changed files
with
135 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,112 @@ | ||
# go-fluentbit-config | ||
|
||
Library for parsing a fluentbit configuration file according to the specs presented here [0] | ||
This library parses fluent-bit configuration in three different formats: | ||
|
||
[0] https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/format-schema | ||
* INI: the standard INI like format (legacy). | ||
* YAML: the new YAML format | ||
* JSON: a JSON format derived from the YAML formats structure. | ||
|
||
It consists of 2 functions for each format as well as the NewFromBytes | ||
function which is supported for applications which already use it which | ||
invokes the ParseINI function. | ||
|
||
* INI | ||
* ParseINI([]byte) (*Config, error) | ||
* DumpINI(*Config) ([]byte, error) | ||
* YAML | ||
* ParseYAML([]byte) (*Config, error) | ||
* DumpYAML(*Config) ([]byte, error) | ||
* JSON | ||
* ParseJSON([]byte) (*Config, error) | ||
* DumpJSON(*Config) ([]byte, error) | ||
|
||
The Parse functions return a pointer to a Config structure which holds | ||
a series of sections. | ||
|
||
```go | ||
type Config struct { | ||
Sections []ConfigSection | ||
} | ||
``` | ||
|
||
These sections describe a single section of the configuration file: | ||
|
||
```go | ||
const ( | ||
NoneSection ConfigSectionType = iota | ||
ServiceSection | ||
InputSection | ||
FilterSection | ||
OutputSection | ||
CustomSection | ||
ParserSection | ||
) | ||
|
||
type ConfigSection struct { | ||
Type ConfigSectionType | ||
ID string | ||
Fields []Field | ||
} | ||
``` | ||
|
||
Each Field has a Key and a set of Values. Most fields contain a single, | ||
but some exceptions, like the `Rewrite_Tag` property `Rule`, have | ||
multiple Values. | ||
|
||
```go | ||
type Field struct { | ||
Key string | ||
Values []*Value | ||
} | ||
|
||
type Value struct { | ||
String *string | ||
DateTime *string | ||
Date *string | ||
Time *string | ||
TimeFormat *string | ||
Topic *string | ||
Regex *string | ||
Bool *bool | ||
Number *float64 | ||
Float *float64 | ||
List []*Value | ||
} | ||
``` | ||
|
||
The Value type has a two receiver methods that which make using values | ||
easier. | ||
|
||
```go | ||
func (a *Value) Equals(b *Value) bool | ||
func (v *Value) Value() interface{} | ||
``` | ||
|
||
The `Equals` receiver can be used to compare two `Value`s, and the `Value` | ||
receiver can be used to return an interface{} which can be type switched. | ||
|
||
## example usage | ||
```go | ||
import ( | ||
"github.com/calyptia/go-fluentbit-config" | ||
) | ||
|
||
cfg, err := fluentbit_config.NewFromBytes([]byte(`[INPUT] ....`)) | ||
if err != nil { | ||
} | ||
|
||
for name, filters := range cfg.Filters { | ||
for name, property := range filters { | ||
} | ||
} | ||
import ( | ||
fbitconf "github.com/calyptia/go-fluentbit-config" | ||
) | ||
|
||
cfg, err := fbitconf.ParseINI([]byte(`[INPUT] ....`)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for _, section := range cfg.Sections { | ||
if section.Type == fbitconf.FilterSection { | ||
for _, field := section.Fields { | ||
if field.Key == "Name" { | ||
fmt.Printf("filter: %s\n", field.Key) | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
References: | ||
|
||
* Fluentbit schema: https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/format-schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters