cmd

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Always added in v0.2.2

func Always(mc *MetaCheck) bool

Always activates the notification

func Never added in v0.2.2

func Never(mc *MetaCheck) bool

Never activates the notification

func OnStateChanged added in v0.2.2

func OnStateChanged(mc *MetaCheck) bool

Activates the notification if the state has changed

func RegisterCheckDetail

func RegisterCheckDetail(name string, checkConstructor func(c *MetaCheck) ICheck)

Types

type Account

type Account struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
}

Represents an email account

type CheckDefaults

type CheckDefaults struct {
	NotifyTargets []NotifyTarget `yaml:"notifyTargets"`
	Interval      *int           `yaml:"interval"`
	Timeout       *int           `yaml:"timeout"`
}

CheckDefaults represents the global default values for checks

func (*CheckDefaults) Validate

func (c *CheckDefaults) Validate() error

type CheckError

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

func (*CheckError) Error

func (c *CheckError) Error() string

type CheckState added in v0.2.2

type CheckState bool

Represents the state of a check

const (
	// CheckOk represents a successful check
	CheckOk CheckState = true

	// CheckFailed represents a failed check
	CheckFailed CheckState = false
)

type Config

type Config struct {
	StartupNotification *StartupNotification `yaml:"startupNotification"`
	CheckConfigDir      string               `yaml:"checkConfigDir"`
	Notification        *Notification        `yaml:"notification"`
	CheckDefaults       *CheckDefaults       `yaml:"checkDefaults"`

	Checks []*MetaCheck
}

Represents the global main configuration

type Email

type Email struct {
	Enabled bool     `yaml:"enabled"`
	Account *Account `yaml:"account"`
	Host    string   `yaml:"host"`
	Port    int      `yaml:"port"`
	From    string   `yaml:"from"`
	To      []string `yaml:"to"`
}

Represents an email configuration for notifications

type ICheck added in v0.2.2

type ICheck interface {
	Validate() error
	SetDefaults(*MetaCheck)
	Run() (CheckState, NotifyFuncSwitch)
}

Represents the interface for a check

type MetaCheck added in v0.2.2

type MetaCheck struct {
	Name          string
	Address       string         `yaml:"address"`
	Interval      int            `yaml:"interval"`
	Timeout       int            `yaml:"timeout"`
	Type          string         `yaml:"type"`
	Config        map[string]any `yaml:"config"`
	NotifyTargets []NotifyTarget `yaml:"notifyTargets"`
	// contains filtered or unexported fields
}

Represents a check configuration

func (*MetaCheck) DefaultNotifyFailedFunc added in v0.2.2

func (mc *MetaCheck) DefaultNotifyFailedFunc(cond func(mc *MetaCheck) bool, err *CheckError) NotifyFuncSwitch

Returns a default notification function for errors If cond() returns true, it returns a func that sends a notification If cond() returns false and the current check state is CheckFailed, it returns a func that prints only a log message Otherwise, it returns nil

func (*MetaCheck) DefaultNotifyOkFunc added in v0.2.2

func (mc *MetaCheck) DefaultNotifyOkFunc(cond func(mc *MetaCheck) bool) NotifyFuncSwitch

Returns a default notification function for OK messages If cond() returns true, it returns a func that sends a notification Otherwise, it returns nil

func (*MetaCheck) HasStateChanged added in v0.2.2

func (mc *MetaCheck) HasStateChanged() bool

Checks if the state has changed

func (*MetaCheck) InitTicker added in v0.2.2

func (mc *MetaCheck) InitTicker(runQueue chan<- func() func(*Notification))

Initializes the ticker for the check

func (*MetaCheck) NewError added in v0.2.2

func (mc *MetaCheck) NewError(err error) *CheckError

Creates a new error for the check

func (*MetaCheck) RollState added in v0.2.2

func (m *MetaCheck) RollState()

Rolls the state of the check

func (*MetaCheck) Run added in v0.2.2

func (mc *MetaCheck) Run() func(*Notification)

Runs the check

func (*MetaCheck) SetDefaults added in v0.2.2

func (mc *MetaCheck) SetDefaults(def *CheckDefaults)

Sets the default values for the check

func (*MetaCheck) SetState added in v0.2.2

func (mc *MetaCheck) SetState(s CheckState)

Sets the previous state of the check

func (*MetaCheck) Validate added in v0.2.2

func (mc *MetaCheck) Validate() error

Validates the check configuration

type Notification

type Notification struct {
	DefaultTarget NotifyTarget       `yaml:"defaultTarget"`
	Targets       map[string]*Target `yaml:"targets"`
}

Represents the notification configuration

func (*Notification) Notify

func (n *Notification) Notify(targets []NotifyTarget, subject, text string)

Sends a notification to the specified targets

func (*Notification) Validate

func (n *Notification) Validate() error

Validates the notification configuration

type NotifyFuncSwitch added in v0.2.2

type NotifyFuncSwitch func() func(*Notification)

type NotifyTarget

type NotifyTarget string

Represents a notification target name

type StartupNotification

type StartupNotification struct {
	Targets []NotifyTarget `yaml:"targets"`
}

Represents the startup notification configuration

type Target

type Target struct {
	Name  string `yaml:"name"`
	Email *Email `yaml:"email"`
}

Represents a notification target

Directories

Path Synopsis
checks
tcp

Jump to

Keyboard shortcuts

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