checklogfile

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 7 Imported by: 0

README

checklogfile

NOTE: Work in progress at the moment.

Build Status

LICENSE

BSD

documentation

package documentation at go.pkgdoc.org

quick usage

TODO

build and install

install from source

Install Go 1, either from source or with a prepackaged binary.

Then run

go get github.com/nightlyone/checklogfile
go get github.com/nightlyone/checklogfile/cmd/check_logfile

Usage via

$GOPATH/bin/check_logfile -h

LICENSE

BSD

documentation

TODO contributing

Contributions are welcome. Please open an issue or send me a pull request for a dedicated branch. Make sure the git commit hooks show it works.

git commit hooks

enable commit hooks via

    cd .git ; rm -rf hooks; ln -s ../git-hooks hooks ; cd ..

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStreamSeek = errors.New("cannot seek to this position in stream")

Functions

This section is empty.

Types

type CompressorSeekWrapper

type CompressorSeekWrapper struct {
	// contains filtered or unexported fields
}

We can skip IO and rewind in streams and thus support the io.Seeker interface

func NewCompressorSeekWrapper

func NewCompressorSeekWrapper(backend ReadSeekCloser, compression string) *CompressorSeekWrapper

wrapper around compressors that supports streams

func (*CompressorSeekWrapper) Close

func (c *CompressorSeekWrapper) Close() error

Satisfy io.Closer interface

func (*CompressorSeekWrapper) Read

func (c *CompressorSeekWrapper) Read(p []byte) (n int, err error)

satisfy io.Reader interface

func (*CompressorSeekWrapper) Seek

func (c *CompressorSeekWrapper) Seek(offset int64, whence int) (ret int64, err error)

We can skip IO and rewind in streams and thus support the io.Seeker interface

type Logfile

type Logfile struct {
	// contains filtered or unexported fields
}

Abstracts away a logfile event classificator

func NewLogFile

func NewLogFile(r ReadSeekCloser, start int64) *Logfile

Start managing logfile r at start. If start is invalid, we seek to the current end.

func (*Logfile) AddPattern

func (l *Logfile) AddPattern(level MonitoringResult, pattern string) error

Add a regexp pattern to trigger monitoring alert level. Logfile lines are matched in order of appearance, but which pattern is applied first is not specified.

func (*Logfile) AddPatterns

func (l *Logfile) AddPatterns(level MonitoringResult, patterns []string) error

Add list of a regexp patterns to trigger monitoring alert level. Logfile lines are matched in order of appearance, but which patterns are applied first is not specified.

func (*Logfile) Close

func (l *Logfile) Close() (err error)

Properly close underlying streams.

func (*Logfile) Offset

func (l *Logfile) Offset() int64

Returns current logfile offset. We will start here for the next Scan.

func (*Logfile) Scan

func (l *Logfile) Scan() (res MonitoringResult, counts [MonitorCount]int64, err error)

Scan logfile until end for supplied patterns. In res you can find the monitoring level to be reported, counts contains useful statistics and err is any error that accours. io.EOF is not reported as error, since this function is supposed to scan right until io.EOF in the good case. Empty files generate MonitorOk, unreadable files MonitorUnknown, everything else depends on which pattern the last read line matches.

type MonitoringResult

type MonitoringResult int

Result to be reported to a monitoring system

const (
	MonitorOk MonitoringResult = iota // No remaining issues
	MonitorWarning
	MonitorCritical
	MonitorUnknown // Cannot determine state
	MonitorCount   // Upper bound for arrays based on levels
)

func (MonitoringResult) String

func (m MonitoringResult) String() string

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Closer
	io.Seeker
}

accept and io stream, we can read from, seek into and close

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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