watcher

package
v0.0.0-...-a5914f9 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorDatabase represents an error specific to database operations
	ErrorDatabase = errors.New("database error")
	// ErrorNotifier represents an error specific to notifier operations
	ErrorNotifier = errors.New("notifier error")
	// ErrorExecutor represents an error specific to the executor
	ErrorExecutor = errors.New("executor error")
	// ErrorFetch represents an error specific to address fetching operations
	ErrorFetch = errors.New("fetch error")
)

Functions

func GetLogger

func GetLogger() zerolog.Logger

func InitLogger

func InitLogger()

Types

type Executor

type Executor struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

Executor is used to execute actions when an event is triggered. Needs an error channel to be passed, to be able to indicate when errors occur while executing the actions.

func NewExecutor

func NewExecutor(errorChan chan error) *Executor

NewExecutor creates a config.Exec executor.

Usage of a watcher.Executor

	   ex := NewExecutor(errorChannel)
	   action = config.Exec{
	       Type: "python",
        Args: "",
		   Path: "script.py",
	   }
	   ex.Execute(action)

Each execution is associated with a context.ContextWithTimeout delimiting the maximum time the action has to execute, defined on the configuration file.

func (*Executor) Execute

func (e *Executor) Execute(action config.ExecuteAction)

Execute executes the given config.Exec action defined on the configuration file under 'events.<event>.actions'. Runs the action with a timed out context.Context killing the process if a configuration file defined threshold (in seconds) is crossed, limiting the execution time of the action.

func (*Executor) ExecuteSlice

func (e *Executor) ExecuteSlice(actions []config.ExecuteAction)

ExecuteSlice executes, in parallel, a slice of config.Exec actions.

type Fetcher

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

func NewFetcher

func NewFetcher() *Fetcher

func (*Fetcher) RequestAddress

func (f *Fetcher) RequestAddress(version string) (string, string, error)

type Notifier

type Notifier struct {
	// From is the address to send from, obtained from the configuration file at 'watcher.smtp.*'
	From string
	// Recipients is the slice containing the recipients information such as email and name
	Recipients []Recipient
	// contains filtered or unexported fields
}

Notifier allows for email mass notification

func NewNotifier

func NewNotifier() *Notifier

func (*Notifier) NotifyMail

func (n *Notifier) NotifyMail(ctx context.Context) error

type Recipient

type Recipient struct {
	// Name of the recipient
	Name string `mapstructure:"name"`
	// Address is the email address of the recipient
	Address string `mapstructure:"address"`
}

Recipient represents a email recipient defined as per the configuration file

type Watcher

type Watcher struct {
	// Version indicates the versions the watcher is supposed to track (v4|v6|all)
	Version string
	// Timeout represents the duration between each address query
	Timeout time.Duration
	// contains filtered or unexported fields
}

Watcher is the main part of the IP watcher service. According to a defined timeout checks for address changes, invoking handlers to when different actions are triggered (on_change, on_match and on_error).

func NewWatcher

func NewWatcher() *Watcher

NewWatcher creates a new watcher. Its parameters are set according to the values set on the YAML configuration file.

func (*Watcher) HandleEvent

func (w *Watcher) HandleEvent(eventType string, ctx context.Context)

func (*Watcher) Stop

func (w *Watcher) Stop()

func (*Watcher) Watch

func (w *Watcher) Watch()

Jump to

Keyboard shortcuts

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