Categorygithub.com/breml/logstash-config
modulepackage
0.5.3
Repository: https://github.com/breml/logstash-config.git
Documentation: pkg.go.dev

# README

logstash-config : parser and abstract syntax tree for Logstash config files

Test Status Go Report Card
GoDoc License

Overview

The Go package config provides a ready to use parser for Logstash (github) configuration files.

The basis of the grammar for the parsing of the Logstash configuration format is the original Logstash Treetop grammar which could be used with only minor changes.

logstash-config uses pigeon to generate the parser from the PEG (parser expression grammar). Special thanks to Martin Angers (mna).

This package is currently under development, no API guaranties.

Install

go get -t github.com/breml/logstash-config/...

Usage

mustache

mustache is a command line tool that allows to syntax check, lint and format Logstash configuration files. The name of the tool is inspired by the original Logstash Logo (wooden character with an eye-catching mustache).

The check command verifies the syntax of Logstash configuration files:

mustache check file.conf

The lint command checks for problems in Logstash configuration files.

The following checks are performed:

  • Valid Logstash configuration file syntax
  • No comments in exceptional places (these are comments, that are valid by the Logstash configuration file syntax, but but are located in exceptional or uncommon locations)
  • Precence of an id attribute for each plugin in the Logstash configuration

If the --auto-fix-id flag is passed, each plugin gets automatically an ID. Be aware, that this potentially reformats the Logstash configuration files.

mustache lint --auto-fix-id file.conf

With the format command, mustache returns the provided configuration files in a standardized format (indentation, location of comments). By default, the reformatted file is print to standard out. If the flag --write-to-source is provided, the Logstash config files are reformatted in place.

mustache format --write-to-source file.conf

Use the --help flag to get more information about the usage of the tool.

Rebuild parser

  1. Get and install pigeon.
  2. Run go generate in the root directory of this repository.

Author

Copyright 2017-2021 by Lucas Bremgartner (breml)

License

Apache 2.0

# Packages

Package ast declares the types used to represent syntax trees for Logstash configurations.
No description provided by the author

# Functions

AllowInvalidUTF8 creates an Option to allow invalid UTF-8 bytes.
Debug creates an Option to set the debug flag to b.
Entrypoint creates an Option to set the rule name to use as entrypoint.
The ExceptionalCommentsWarning option controls if the parser does emit warnings for comments in exceptional locations (true).
GetFarthestFailure returns the farthest position where the parser had a parse error.
GlobalStore creates an Option to set a key to a certain value in the globalStore.
The IgnoreComments option controls if the parse ignores comments (true).
InitState creates an Option to set a key to a certain value in the global "state" store.
MaxExpressions creates an Option to stop parsing after the provided number of expressions have been parsed, if the value is 0 then the parser will parse for as many steps as needed (possibly an infinite number).
Memoize creates an Option to set the memoize flag to b.
Parse parses the data from b using filename as information in the error messages.
ParseFile parses the file identified by filename.
ParseReader parses the data from r using filename as information in the error messages.
Recover creates an Option to set the recover flag to b.
Statistics adds a user provided Stats struct to the parser to allow the user to process the results after the parsing has finished.

# Structs

Stats stores some statistics, gathered during parsing.

# Interfaces

Cloner is implemented by any value that has a Clone method, which returns a copy of the value.

# Type aliases

Option is a function that can set an option on the parser.