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
- Variables
- func RemoveSecrets(appURL, message string) string
- type CheckResult
- type CheckState
- type CheckType
- type Config
- func (c *Config) APIHandler(req *http.Request) (int, any)
- func (c *Config) GetResults() []*CheckResult
- func (c *Config) RunCheck(source website.EventType, name string) error
- func (c *Config) RunChecks(source website.EventType)
- func (c *Config) Running() bool
- func (c *Config) SendResults(results *Results)
- func (c *Config) SetWebsite(website *website.Server)
- func (c *Config) Setup(services []*Service) error
- func (c *Config) Start(ctx context.Context)
- func (c *Config) Stop()
- func (c *Config) SvcCount() int
- type Output
- type ProcInfo
- type Results
- type Service
Constants ¶
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.
const PlexServerName = "Plex Server"
This name is hard coded as the service name for Plex.
Variables ¶
var ( ErrPingExpect = errors.New("ping/icmp expect must contain three integers separated by two colons. ex: 3:2:500") ErrNoPingVal = errors.New("ping or icmp 'check' must not be empty") ErrPingCountZero = errors.New("none of the ping expect values may be set to 0") )
Custom errors.
var ( ErrProcExpect = errors.New("invalid process expect type") ErrNoProcVal = errors.New("process 'check' must not be empty") ErrCountZero = errors.New("process 'count' may not be used with 'running'") ErrBSDRestart = errors.New("process 'restart' check does not work on FreeBSD") // one day. )
Custom errors.
var ( ErrNoName = errors.New("service check is missing a unique name") ErrNoCheck = errors.New("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 = errors.New("tcp checks must have an ip:port or host:port combo; the :port is required") )
Errors returned by this Services package.
var ErrSvcsStopped = errors.New("service check routine stopped")
Functions ¶
func RemoveSecrets ¶ added in v0.2.1
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 *Output `json:"output"` // metadata message must never be nil. 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"` // interval in seconds Metadata map[string]any `json:"metadata"` // arbitrary info about the service or result. 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 Config ¶
type Config struct { Interval cnfg.Duration `json:"interval" toml:"interval" xml:"interval"` Parallel uint `json:"parallel" toml:"parallel" xml:"parallel"` Disabled bool `json:"disabled" toml:"disabled" xml:"disabled"` LogFile string `json:"logFile" toml:"log_file" xml:"log_file"` Apps *apps.Apps `json:"-" toml:"-"` Plugins *snapshot.Plugins `json:"-" toml:"-"` // 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) APIHandler ¶ added in v0.8.0
APIHandler is passed into the webserver so services can be accessed by the API.
func (*Config) GetResults ¶
func (c *Config) GetResults() []*CheckResult
GetResults creates a copy of all the results and returns them.
func (*Config) SendResults ¶
SendResults sends a set of Results to Notifiarr.
func (*Config) SetWebsite ¶ added in v0.8.2
func (*Config) Start ¶
Start begins the service check routines. Runs Parallel checkers and the check reporter.
type Output ¶ added in v0.8.0
type Output struct {
// contains filtered or unexported fields
}
func (*Output) MarshalJSON ¶ added in v0.8.0
func (*Output) UnmarshalJSON ¶ added in v0.8.0
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 `json:"name" toml:"name" xml:"name"` // Radarr Type CheckType `json:"type" toml:"type" xml:"type"` // http Value string `json:"value" toml:"check" xml:"check"` // http://some.url Expect string `json:"expect" toml:"expect" xml:"expect"` // 200 Timeout cnfg.Duration `json:"timeout" toml:"timeout" xml:"timeout"` // 10s Interval cnfg.Duration `json:"interval" toml:"interval" xml:"interval"` // 1m Tags map[string]any `json:"tags" toml:"tags" xml:"tags"` // copied to Metadata. // contains filtered or unexported fields }
Service is a thing we check and report results for.