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
- type Output
- type ProcInfo
- type Results
- type Service
- type ServiceConfig
- type Services
- func (s *Services) APIHandler(req *http.Request) (int, any)
- func (s *Services) Add(services []ServiceConfig) error
- func (s *Services) AddApps(apps *apps.Apps, mysql []snapshot.MySQLConfig)
- func (s *Services) GetResults() []*CheckResult
- func (s *Services) Pause()
- func (s *Services) Resume()
- func (s *Services) RunCheck(ctx context.Context, source website.EventType, name string) error
- func (s *Services) RunChecks(input *common.ActionInput)
- func (s *Services) Running() bool
- func (s *Services) SendResults(results *Results, reqID string)
- func (s *Services) Start(ctx context.Context, plexName string)
- func (s *Services) Stop()
- func (s *Services) SvcCount() int
Constants ¶
const ( MinimumCheckInterval = 10 * time.Second MinimumTimeout = time.Second DefaultTimeout = 10 * MinimumTimeout DefaultBuffer = 1000 )
Services Defaults.
const PlexServerName = "Plex Server"
PlexServerName 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 (s CheckState) String() string
String turns a check status into a human string.
func (CheckState) Value ¶ added in v0.3.0
func (s CheckState) Value() uint
type Config ¶
type Config struct {
Disabled bool `json:"disabled" toml:"disabled" xml:"disabled"`
LogFile string `json:"logFile" toml:"log_file" xml:"log_file"`
Plugins *snapshot.Plugins `json:"-" toml:"-"` // pass this in so we can service-check mysql
}
Config for this Services plugin comes from a config file.
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 {
Output *Output `json:"output"`
State CheckState `json:"state"`
Since time.Time `json:"since"`
LastCheck time.Time `json:"lastCheck"`
*ServiceConfig
// contains filtered or unexported fields
}
type ServiceConfig ¶ added in v0.9.0
type ServiceConfig 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
}
ServiceConfig is a thing we check and report results for.
func (*ServiceConfig) CheckOnly ¶ added in v0.9.0
func (s *ServiceConfig) CheckOnly(ctx context.Context) *CheckResult
CheckOnly runs a service check and returns the result immediately. It is not otherwise stored anywhere.
func (*ServiceConfig) Validate ¶ added in v0.9.0
func (s *ServiceConfig) Validate() error
type Services ¶ added in v0.9.0
type Services struct {
// contains filtered or unexported fields
}
func (*Services) APIHandler ¶ added in v0.9.0
APIHandler is passed into the webserver so services can be accessed by the API.
func (*Services) Add ¶ added in v0.9.0
func (s *Services) Add(services []ServiceConfig) error
func (*Services) AddApps ¶ added in v0.9.0
func (s *Services) AddApps(apps *apps.Apps, mysql []snapshot.MySQLConfig)
AddApps turns app configs into service checks if they have a name.
func (*Services) GetResults ¶ added in v0.9.0
func (s *Services) GetResults() []*CheckResult
GetResults creates a copy of all the results and returns them.
func (*Services) RunChecks ¶ added in v0.9.0
func (s *Services) RunChecks(input *common.ActionInput)
RunChecks runs checks from an external package.
func (*Services) SendResults ¶ added in v0.9.0
SendResults sends a set of Results to Notifiarr.
func (*Services) Start ¶ added in v0.9.0
Start begins the service check routines. Runs Parallel checkers and the check reporter.