erpel

package
v0.0.0-...-e896b0b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

func Process(rules []Rules, rd io.Reader, f HandleFunc) error

Process extracts all log messages from the reader, ignores those matched by the rules and hands the remaining lines to f. When f returns an error, processing stops and this error is returned. Empty lines are always ignored.

Types

type Config

type Config struct {
	Options map[string]string
	Fields  map[string]Field
}

Config holds all information parsed from a configuration file.

func ParseConfig

func ParseConfig(data string) (Config, error)

ParseConfig parses data as an erpel config file.

func ParseConfigFile

func ParseConfigFile(filename string) (Config, error)

ParseConfigFile loads a config from a file.

type Field

type Field struct {
	Name     string
	Template string
	Pattern  *regexp.Regexp
	Samples  []string
}

Field is a dynamic section in a log message.

func (*Field) Check

func (f *Field) Check() error

Check returns an error if the field's pattern does not match the samples.

func (Field) Equals

func (f Field) Equals(other Field) bool

Equals returns true iff f equals other.

type FieldView

type FieldView struct {
	S      string
	F      Field
	Global bool
}

FieldView is used within a RuleView for a field.

func (FieldView) String

func (fv FieldView) String() string

type HandleFunc

type HandleFunc func(lines []string) error

HandleFunc handles lines than have not been filtered out by any rules.

type Marker

type Marker struct {
	Inode  uint64 `json:"inode"`
	Offset int64  `json:"offset"`
}

Marker is a position within a file.

func Position

func Position(f *os.File) (Marker, error)

Position returns a Marker for the given file.

func ProcessFile

func ProcessFile(rules []Rules, filename string, last Marker, fn HandleFunc) (m Marker, err error)

ProcessFile extracts all log messages starting at the marker from the file by opening it and calling Process(). Returned is a marker for the last position within the file.

func (Marker) Seek

func (m Marker) Seek(f *os.File) error

Seek moves f to the position of the marker, so that new bytes can be read. When the file has been replaced by a new file, calling Seek() does nothing.

type RuleView

type RuleView []fmt.Stringer

RuleView is the semantic representation of a rule, constructed by replacing all fields in a template.

func View

func View(rules Rules, template string) RuleView

View renders a template into a RuleView by applying the rules.

type Rules

type Rules struct {
	Prefix string

	Fields       map[string]Field
	GlobalFields map[string]Field
	Templates    []string
	Samples      []string
	// contains filtered or unexported fields
}

Rules holds all information parsed from a rules file.

func ParseAllRulesFiles

func ParseAllRulesFiles(global map[string]Field, dir string) (rules []Rules, err error)

ParseAllRulesFiles loads rules from all files in the directory.

func ParseRules

func ParseRules(global map[string]Field, data string) (Rules, error)

ParseRules parses the data as an erpel rule file.

func ParseRulesFile

func ParseRulesFile(global map[string]Field, filename string) (Rules, error)

ParseRulesFile loads rules from a file and parses it.

func (*Rules) Check

func (r *Rules) Check() error

Check runs self-tests on the Rules, it returns an error if a message in the samples section is not matched by the rules.

func (*Rules) Match

func (r *Rules) Match(s string) bool

Match tests if a rule matches s completely.

func (*Rules) RegExps

func (r *Rules) RegExps() (rules []*regexp.Regexp)

RegExps returns the rules as a list of regexps. These are cached internally.

func (Rules) Views

func (r Rules) Views() (views []RuleView)

Views returns all views for all templates of r.

type Text

type Text string

Text is used within a RuleView for verbatim text.

func (Text) String

func (t Text) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL