services

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 24 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.

View Source
const PlexServerName = "Plex Server"

This name is hard coded as the service name for Plex.

Variables

View Source
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.

View Source
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.

View Source
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.

View Source
var ErrSvcsStopped = errors.New("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      *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 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 `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

func (c *Config) APIHandler(req *http.Request) (int, any)

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) 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) SetWebsite added in v0.8.2

func (c *Config) SetWebsite(website *website.Server)

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 Output added in v0.8.0

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

func (*Output) MarshalJSON added in v0.8.0

func (o *Output) MarshalJSON() ([]byte, error)

func (*Output) String added in v0.8.0

func (o *Output) String() string

func (*Output) UnmarshalJSON added in v0.8.0

func (o *Output) UnmarshalJSON(input []byte) error

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         `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.

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