services

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 17 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
	NotifiarrEventType   = "service_checks"
)

Defaults.

Variables

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", CheckTCP, CheckHTTP, CheckPROC)
	ErrBadTCP      = fmt.Errorf("tcp checks must have an ip:port or host:port combo; the :port is required")
)

Errors returned by this package.

Functions

This section is empty.

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"`
}

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.

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"
	CheckPROC CheckType = "process"
)

These are our supported Check Types.

type Config

type Config struct {
	Interval     cnfg.Duration     `toml:"interval" xml:"interval"`
	Parallel     uint              `toml:"parallel" xml:"parallel"`
	Disabled     bool              `toml:"disabled" xml:"disabled"`
	LogFile      string            `toml:"log_file" xml:"log_file"`
	Apps         *apps.Apps        `toml:"-"`
	Notifiarr    *notifiarr.Config `toml:"-"`
	*logs.Logger `json:"-"`        // log file writer
	// contains filtered or unexported fields
}

Config for this plugin comes from a config file.

func (*Config) RunChecks

func (c *Config) RunChecks(source *Source)

runChecks runs checks from an external package.

func (*Config) SendResults

func (c *Config) SendResults(url string, results *Results)

SendResults sends a set of Results to Notifiarr.

func (*Config) Start

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

Start begins the service check routines.

func (*Config) Stop

func (c *Config) Stop()

Stop ends all service checker routines.

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() ([]*ProcInfo, error)

GetAllProcesses returns all running process on the host.

type Results

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

Results is sent to Notifiarr.

type Service

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

Service is a thing we check and report results for.

type Source added in v0.1.16

type Source struct {
	Name string
	URL  string
}

Source is used to pass a source and destination for service checks (from a trigger).

Jump to

Keyboard shortcuts

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