logchecker

package
v0.0.0-...-4389925 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2015 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package logchecker is a simple library to check a list of logs files and send notification about their abnormal activities.

Error logger is activated by default, use DebugMode method to turn on debug mode:

DebugMode(true)

Initialization from file:

logger := logchecker.New()
if err := logchecker.InitConfig(logger, "filiename"); err != nil {
    // error detected
}

Index

Constants

This section is empty.

Variables

View Source
var (
	// LoggerError implements error logger.
	LoggerError = log.New(os.Stderr, "ERROR [logchecker]: ", log.Ldate|log.Ltime|log.Lshortfile)
	// LoggerInfo implements info logger.
	LoggerInfo = log.New(os.Stderr, "INFO [logchecker]: ", log.Ldate|log.Ltime|log.Lshortfile)
	// LoggerDebug implements debug logger, it's disabled by default.
	LoggerDebug = log.New(ioutil.Discard, "DEBUG [logchecker]: ", log.Ldate|log.Lmicroseconds|log.Lshortfile)
	// MoveWait is waiting period before a check that a file was again created.
	MoveWait = 2 * time.Second
	// EmailSimulator is a file path to verify sent emails during debug mode.
	EmailSimulator string
)

Functions

func DebugMode

func DebugMode(debugmode bool)

DebugMode is a initialization of Logger handlers.

func FilePath

func FilePath(name string) (string, error)

FilePath validates file name, converts its path from relative to absolute using current directory address.

func InitConfig

func InitConfig(logger *LogChecker, name string) error

InitConfig initializes configuration from a file.

func IsMoved

func IsMoved(filename string, oldw *inotify.Watcher) (*inotify.Watcher, error)

IsMoved creates new inotify watcher if a file was moved, instead returns an error.

Types

type Backender

type Backender interface {
	String() string
}

Backender is an interface to handle data storage operations.

type Config

type Config struct {
	Path     string
	Sender   map[string]string `json:"sender"`
	Observed []Service         `json:"observed"`
	Storage  string            `json:"storage"`
}

Config is main configuration settings.

func (Config) String

func (cfg Config) String() string

String return a details about the configuration.

type File

type File struct {
	Log         string         `json:"file"`
	Pattern     string         `json:"pattern"`
	Boundary    uint64         `json:"boundary"`
	Increase    bool           `json:"increase"`
	Emails      []string       `json:"emails"`
	Limit       uint64         `json:"limit"`
	Period      uint64         `json:"period"`
	RgPattern   *regexp.Regexp // regexp expression from the pattern
	Pos         uint64         // file posision after last check
	LogStart    time.Time      // time of logger start
	Granularity uint64         // number of a period after last check
	Found       uint64         // found lines by the Pattern
	Counter     uint64         // cases counter for time period
	ExtBoundary uint64         // extended boundary value if Increase is set
	// contains filtered or unexported fields
}

File is a type of settings for a watched file.

func (*File) Base

func (f *File) Base() string

Base returns the last element of log file path.

func (*File) Check

func (f *File) Check(group *sync.WaitGroup, logger *LogChecker) error

Check validates conditions before sending email notifications.

func (*File) Duration

func (f *File) Duration() uint64

Duration identifies user's time period after watcher start.

func (*File) String

func (f *File) String() string

String returns absolute file's path.

func (*File) Validate

func (f *File) Validate() error

Validate checks that File is correct: has absolute path and exists.

func (*File) Watch

func (f *File) Watch(group *sync.WaitGroup, finish chan bool, logger *LogChecker)

Watch implements a file watcher.

type LogChecker

type LogChecker struct {
	Name    string
	Cfg     Config
	Backend Backender
	Running time.Time
	InWork  int
	// contains filtered or unexported fields
}

LogChecker is a main object for logging.

func New

func New() *LogChecker

New created new LogChecker object and returns its reference.

func (*LogChecker) AddService

func (logger *LogChecker) AddService(serv *Service) error

AddService includes a new Service to the LogChecker.

func (*LogChecker) HasService

func (logger *LogChecker) HasService(serv *Service, lock bool) int

HasService checks that the Service is included to the LogChecker. It can use locked mode to guarantee that service array will be immutable during reading.

func (*LogChecker) IsWorking

func (logger *LogChecker) IsWorking() bool

IsWorking return "true" if LogChecker process is already running.

func (*LogChecker) Notify

func (logger *LogChecker) Notify(msg string, to []string)

Notify sends a prepared email message.

func (*LogChecker) RemoveService

func (logger *LogChecker) RemoveService(serv *Service) error

RemoveService includes a new Service to the LogChecker.

func (*LogChecker) Start

func (logger *LogChecker) Start(group *sync.WaitGroup) (chan bool, error)

Start runs LogChecker processes.

func (*LogChecker) Stop

func (logger *LogChecker) Stop(finish chan bool, group *sync.WaitGroup) error

Stop terminated running process.

func (*LogChecker) String

func (logger *LogChecker) String() string

String returns main info about LogChecker.

func (*LogChecker) Validate

func (logger *LogChecker) Validate() error

Validate checks the configuration.

type MemoryBackend

type MemoryBackend struct {
	Name   string
	Active bool
}

MemoryBackend is a type for the implementation of memory storage methods.

func (*MemoryBackend) String

func (bk *MemoryBackend) String() string

String of MemoryBackend returns a name of the logger back-end.

type Notifier

type Notifier interface {
	String() string
	Notify(string, []string)
}

Notifier is an interface to notify users about file changes.

type Service

type Service struct {
	Name  string `json:"name"`
	Files []File `json:"files"`
}

Service is a type of settings for a watched service.

func (*Service) String

func (s *Service) String() string

String service name.

Jump to

Keyboard shortcuts

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