filewatch

package module
v3.2.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: BSD-2-Clause Imports: 19 Imported by: 1

Documentation

Overview

************************************************************************

  • Copyright 2017 Gravwell, Inc. All rights reserved.
  • Contact: <legal@gravwell.io> *
  • This software may be modified and distributed under the terms of the
  • BSD 2-clause license. See the LICENSE file for details. *************************************************************************

Index

Constants

View Source
const (
	LineEngine  int = 0
	RegexEngine int = 1
)

Variables

View Source
var (
	ErrNotReady         = errors.New("fsnotify watcher is not ready")
	ErrLocationNotDir   = errors.New("Watched Location is not a directory")
	ErrNoDirsWatched    = errors.New("No locations have been added to the watch list")
	ErrInvalidStateFile = errors.New("State file exists and is not a regular file")
	ErrAlreadyStarted   = errors.New("WatchManager already started")
	ErrFailedSeek       = errors.New("Failed to seek to the start of the states file")
)
View Source
var (
	ErrNotRunning = errors.New("Not running")
)

Functions

func NewFollower

func NewFollower(cfg FollowerConfig) (*follower, error)

func ReadStateFile

func ReadStateFile(p string) (states map[string]int64, err error)

Types

type FileId

type FileId struct {
	Major uint64
	Minor uint64
}

type FileName

type FileName struct {
	BaseName string
	FilePath string
}

a unique name that allows multiple IDs pointing at the same file

type FilterManager

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

func NewFilterManager

func NewFilterManager(stateFile string) (*FilterManager, error)

func (*FilterManager) AddFilter

func (f *FilterManager) AddFilter(bname, loc string, mtchs []string, lh handler, ecfg FollowerEngineConfig) error

func (*FilterManager) Close

func (fm *FilterManager) Close() (err error)

func (*FilterManager) Filters

func (fm *FilterManager) Filters() int

Filters returns the current number of installed filters

func (*FilterManager) FlushStates

func (fm *FilterManager) FlushStates() error

FlushStates flushes the current state of followed files to the disk periodically flushing states is a good idea, incase the device crashes, or the process is abruptly killed

func (*FilterManager) Followed

func (fm *FilterManager) Followed() int

Followed returns the current number of following handles if a file matches multiple filters, it will be followed multiple times. So this is NOT the number of files, but the number of follows

func (*FilterManager) IsWatched

func (f *FilterManager) IsWatched(fpath string) bool

func (*FilterManager) LoadFile

func (f *FilterManager) LoadFile(fpath string) (bool, error)

func (*FilterManager) NewFollower

func (f *FilterManager) NewFollower(fpath string) (bool, error)

func (*FilterManager) RemoveFollower

func (f *FilterManager) RemoveFollower(fpath string) (bool, error)

func (*FilterManager) RenameFollower

func (f *FilterManager) RenameFollower(fpath string) error

RenameFollower is designed to rename a file that is currently being followed We first grab the file id that matches the given fpath Then we scan the base directory for ALL files and attempt to match the fileId if a match is found, we check if it matches the current filter, if not, we delete the follower if it does, we update the name and leave. If no match is found, we delete the follower

func (*FilterManager) SetLogger

func (fm *FilterManager) SetLogger(lgr ingest.IngestLogger)

func (*FilterManager) SetMaxFilesWatched

func (fm *FilterManager) SetMaxFilesWatched(max int)

type FollowerConfig

type FollowerConfig struct {
	FollowerEngineConfig
	BaseName string
	FilePath string
	State    *int64
	FilterID int
	Handler  handler
}

type FollowerEngineConfig

type FollowerEngineConfig struct {
	Engine     int
	EngineArgs string
}

type LineReader

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

func NewLineReader

func NewLineReader(cfg ReaderConfig) (*LineReader, error)

func (*LineReader) Close

func (br *LineReader) Close() error

func (*LineReader) Index

func (br *LineReader) Index() int64

func (*LineReader) ReadEntry

func (lr *LineReader) ReadEntry() (ln []byte, ok bool, wasEOF bool, err error)

func (*LineReader) SeekFile

func (br *LineReader) SeekFile(offset int64) error

type LogHandler

type LogHandler struct {
	LogHandlerConfig
	// contains filtered or unexported fields
}

func NewLogHandler

func NewLogHandler(cfg LogHandlerConfig, ch chan *entry.Entry) (*LogHandler, error)

func (*LogHandler) HandleLog

func (lh *LogHandler) HandleLog(b []byte, catchts time.Time) error

type LogHandlerConfig

type LogHandlerConfig struct {
	Tag                     entry.EntryTag
	IgnoreTS                bool
	AssumeLocalTZ           bool
	IgnorePrefixes          [][]byte
	TimestampFormatOverride string
	TimezoneOverride        string
	Logger                  logger
	Debugger                debugOut
}

type Reader

type Reader interface {
	SeekFile(int64) error
	ReadEntry() ([]byte, bool, bool, error)
	Index() int64
	Close() error
}

func NewReader

func NewReader(cfg ReaderConfig) (Reader, error)

type ReaderConfig

type ReaderConfig struct {
	Fin        *os.File
	MaxLineLen int
	StartIndex int64
	Engine     int
	EngineArgs string
}

type RegexReader

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

func NewRegexReader

func NewRegexReader(cfg ReaderConfig) (*RegexReader, error)

func (*RegexReader) Close

func (br *RegexReader) Close() error

func (*RegexReader) Index

func (br *RegexReader) Index() int64

func (*RegexReader) ReadEntry

func (rr *RegexReader) ReadEntry() (ln []byte, ok bool, wasEOF bool, err error)

func (*RegexReader) SeekFile

func (br *RegexReader) SeekFile(offset int64) error

type WatchConfig

type WatchConfig struct {
	FollowerEngineConfig
	ConfigName string
	BaseDir    string
	FileFilter string
	Hnd        handler
	Recursive  bool
}

type WatchManager

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

func NewWatcher

func NewWatcher(stateFilePath string) (*WatchManager, error)

func (*WatchManager) Add

func (wm *WatchManager) Add(c WatchConfig) error

func (*WatchManager) Close

func (wm *WatchManager) Close() error

func (*WatchManager) Dump

func (wm *WatchManager) Dump() string

Returns a string containing information about the WatchManager

func (*WatchManager) Filters

func (wm *WatchManager) Filters() int

func (*WatchManager) Followers

func (wm *WatchManager) Followers() int

func (*WatchManager) SetLogger

func (wm *WatchManager) SetLogger(lgr ingest.IngestLogger)

func (*WatchManager) SetMaxFilesWatched

func (wm *WatchManager) SetMaxFilesWatched(max int)

func (*WatchManager) Start

func (wm *WatchManager) Start() error

Jump to

Keyboard shortcuts

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