services

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package services provides service-checks to the notifiarr client application. This package spins up go routines to check http endpoints, running processes, tcp ports, etc. The configuration comes directly from the config file.

Index

Constants

View Source
const (
	DefaultSendInterval  = 10 * time.Minute
	MinimumSendInterval  = DefaultSendInterval / 2
	DefaultCheckInterval = MinimumSendInterval
	MinimumCheckInterval = 10 * time.Second
	MinimumTimeout       = time.Second
	DefaultTimeout       = 10 * MinimumTimeout
	MaximumParallel      = 10
	DefaultBuffer        = 1000
)

Services Defaults.

Variables

View Source
var (
	ErrPingExpect    = fmt.Errorf("ping/icmp expect must contain three integers separated by two colons. ex: 3:2:500")
	ErrNoPingVal     = fmt.Errorf("ping or icmp 'check' must not be empty")
	ErrPingCountZero = fmt.Errorf("none of the ping expect values may be set to 0")
)

Custom errors.

View Source
var (
	ErrProcExpect = fmt.Errorf("invalid process expect type")
	ErrNoProcVal  = fmt.Errorf("process 'check' must not be empty")
	ErrCountZero  = fmt.Errorf("process 'count' may not be used with 'running'")
	ErrBSDRestart = fmt.Errorf("process 'restart' check does not work on FreeBSD") // one day.
)

Custom errors.

View Source
var (
	ErrNoName      = fmt.Errorf("service check is missing a unique name")
	ErrNoCheck     = fmt.Errorf("service check is missing a check value")
	ErrInvalidType = fmt.Errorf("service check type must be one of %s, %s, %s, %s, %s",
		CheckTCP, CheckHTTP, CheckPROC, CheckPING, CheckICMP)
	ErrBadTCP = fmt.Errorf("tcp checks must have an ip:port or host:port combo; the :port is required")
)

Errors returned by this Services package.

View Source
var ErrSvcsStopped = fmt.Errorf("service check routine stopped")

Functions

func RemoveSecrets added in v0.2.1

func RemoveSecrets(appURL, message string) string

RemoveSecrets removes secret token values in a message parsed from a url.

Types

type CheckResult

type CheckResult struct {
	Name        string        `json:"name"`   // "Radarr"
	State       CheckState    `json:"state"`  // 0 = OK, 1 = Warn, 2 = Crit, 3 = Unknown
	Output      string        `json:"output"` // metadata message
	Type        CheckType     `json:"type"`   // http, tcp, ping
	Time        time.Time     `json:"time"`   // when it was checked, rounded to Microseconds
	Since       time.Time     `json:"since"`  // how long it has been in this state, rounded to Microseconds
	Interval    float64       `json:"interval"`
	Check       string        `json:"-"`
	Expect      string        `json:"-"`
	IntervalDur time.Duration `json:"-"`
}

CheckResult represents the status of a service.

type CheckState

type CheckState uint

CheckState represents the current state of a service check.

const (
	StateOK CheckState = iota
	StateWarning
	StateCritical
	StateUnknown
)

Supported check states.

func (CheckState) String

func (c CheckState) String() string

String turns a check status into a human string.

func (CheckState) Value added in v0.3.0

func (c CheckState) Value() uint

type CheckType

type CheckType string

CheckType locks us into a few specific types of checks.

const (
	CheckHTTP CheckType = "http"
	CheckTCP  CheckType = "tcp"
	CheckPING CheckType = "ping"
	CheckICMP CheckType = "icmp"
	CheckPROC CheckType = "process"
)

These are our supported Check Types.

type Config

type Config struct {
	Interval   cnfg.Duration     `toml:"interval" xml:"interval" json:"interval"`
	Parallel   uint              `toml:"parallel" xml:"parallel" json:"parallel"`
	Disabled   bool              `toml:"disabled" xml:"disabled" json:"disabled"`
	LogFile    string            `toml:"log_file" xml:"log_file" json:"logFile"`
	Apps       *apps.Apps        `toml:"-" json:"-"`
	Website    *website.Server   `toml:"-" json:"-"`
	Plugins    *snapshot.Plugins `toml:"-" json:"-"` // pass this in so we can service-check mysql
	mnd.Logger `json:"-"`        // log file writer
	// contains filtered or unexported fields
}

Config for this Services plugin comes from a config file.

func (*Config) GetResults

func (c *Config) GetResults() []*CheckResult

GetResults creates a copy of all the results and returns them.

func (*Config) RunCheck added in v0.3.0

func (c *Config) RunCheck(source website.EventType, name string) error

RunCheck runs a single check from an external package.

func (*Config) RunChecks

func (c *Config) RunChecks(source website.EventType)

RunChecks runs checks from an external package.

func (*Config) Running added in v0.3.0

func (c *Config) Running() bool

func (*Config) SendResults

func (c *Config) SendResults(results *Results)

SendResults sends a set of Results to Notifiarr.

func (*Config) Setup added in v0.2.0

func (c *Config) Setup(services []*Service) error

func (*Config) Start

func (c *Config) Start(ctx context.Context)

Start begins the service check routines. Runs Parallel checkers and the check reporter.

func (*Config) Stop

func (c *Config) Stop()

Stop sends current states to the website and ends all service checker routines.

func (*Config) SvcCount added in v0.7.0

func (c *Config) SvcCount() int

SvcCount returns the count of services being monitored.

type ProcInfo added in v0.1.4

type ProcInfo struct {
	CmdLine string
	Created time.Time
	PID     int32
}

ProcInfo is derived from a pid.

func GetAllProcesses added in v0.1.4

func GetAllProcesses(ctx context.Context) ([]*ProcInfo, error)

GetAllProcesses returns all running process on the host.

type Results

type Results struct {
	Type     string            `json:"eventType"`
	What     website.EventType `json:"what"`
	Interval float64           `json:"interval"`
	Svcs     []*CheckResult    `json:"services"`
}

Results is sent to website.

type Service

type Service struct {
	Name     string        `toml:"name" xml:"name" json:"name"`             // Radarr
	Type     CheckType     `toml:"type" xml:"type" json:"type"`             // http
	Value    string        `toml:"check" xml:"check" json:"value"`          // http://some.url
	Expect   string        `toml:"expect" xml:"expect" json:"expect"`       // 200
	Timeout  cnfg.Duration `toml:"timeout" xml:"timeout" json:"timeout"`    // 10s
	Interval cnfg.Duration `toml:"interval" xml:"interval" json:"interval"` // 1m
	// contains filtered or unexported fields
}

Service is a thing we check and report results for.

func (*Service) CheckOnly added in v0.3.0

func (s *Service) CheckOnly(ctx context.Context) *CheckResult

CheckOnly runs a service check and returns the result immediately. It is not otherwise stored anywhere.

func (*Service) Due added in v0.3.3

func (s *Service) Due() bool

func (*Service) Validate added in v0.3.0

func (s *Service) Validate() error

Jump to

Keyboard shortcuts

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