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 ¶
- Variables
- func DebugMode(debugmode bool)
- func FilePath(name string) (string, error)
- func InitConfig(logger *LogChecker, name string) error
- func IsMoved(filename string, oldw *inotify.Watcher) (*inotify.Watcher, error)
- type Backender
- type Config
- type File
- type LogChecker
- func (logger *LogChecker) AddService(serv *Service) error
- func (logger *LogChecker) HasService(serv *Service, lock bool) int
- func (logger *LogChecker) IsWorking() bool
- func (logger *LogChecker) Notify(msg string, to []string)
- func (logger *LogChecker) RemoveService(serv *Service) error
- func (logger *LogChecker) Start(group *sync.WaitGroup) (chan bool, error)
- func (logger *LogChecker) Stop(finish chan bool, group *sync.WaitGroup) error
- func (logger *LogChecker) String() string
- func (logger *LogChecker) Validate() error
- type MemoryBackend
- type Notifier
- type Service
Constants ¶
This section is empty.
Variables ¶
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 FilePath ¶
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.
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.
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) Check ¶
func (f *File) Check(group *sync.WaitGroup, logger *LogChecker) error
Check validates conditions before sending email notifications.
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 (*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 ¶
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.