healthcheck

package
v0.0.0-...-17edc22 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Automatic = Status(iota)
	Online
	Offline
	Maintenance
)

Status values of a check

Variables

View Source
var IntToStatusType = map[int]Status{
	0: Automatic,
	1: Online,
	2: Offline,
	3: Maintenance,
}

IntToStatusType converts int to status

View Source
var StatusTypeToString = map[Status]string{
	Automatic:   "automatic",
	Online:      "online",
	Offline:     "offline",
	Maintenance: "maintance",
}

StatusTypeToString converts status to string

View Source
var StringToStatusType = map[string]Status{
	"automatic":   Automatic,
	"online":      Online,
	"offline":     Offline,
	"maintenance": Maintenance,
}

StringToStatusType converts string to status

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	PoolName       string   `json:"poolname" toml:"poolname"`             // pool this check belongs to
	BackendName    string   `json:"backendname" toml:"backendname"`       // backend this check belongs to
	NodeName       string   `json:"nodename" toml:"nodename"`             // node name of the check
	NodeUUID       string   `json:"nodeuuid" toml:"nodeuuid"`             // node uuid for the check
	WorkerUUID     string   `json:"workeruuid" toml:"workeruuid"`         // worker uuid who performed the check
	Description    string   `json:"description" toml:"description"`       // description of the check (?)
	ActualStatus   Status   `json:"actualstatus" toml:"actualstatus"`     // status of the check as it is performed
	ReportedStatus Status   `json:"reportedstatus" toml:"reportedstatus"` // status of the check after applying state processing
	ErrorMsg       []string `json:"errormsg" toml:"errormsg"`             // error message if any
}

CheckResult holds the check result output

type HealthCheck

type HealthCheck struct {
	Type               string              `json:"type" toml:"type"`                             // check type
	TCPRequest         string              `json:"tcprequest" toml:"tcprequest"`                 // tcp request to send
	TCPReply           string              `json:"tcpreply" toml:"tcpreply"`                     // tcp reply to expect
	HTTPRequest        string              `json:"httprequest" toml:"httprequest"`               // http request to send
	HTTPPostData       string              `json:"httppostdata" toml:"httppostdata"`             // http post data to send
	HTTPHeaders        []string            `json:"httpheaders" toml:"httpheaders"`               // http headers to send
	HTTPStatus         int                 `json:"httpstatus" toml:"httpstatus"`                 // http status expected
	HTTPReply          string              `json:"httpreply" toml:"httpreply"`                   // http reply expected
	HTTPFollowRedirect string              `json:"httpfollowredirect" toml:"httpfollowredirect"` // http follow redirects
	SSHUser            string              `json:"sshuser" toml:"sshuser"`                       // ssh user
	SSHPassword        string              `json:"sshpassword" toml:"sshpassword"`               // ssh password
	SSHKey             string              `json:"sshkey" toml:"sshkey"`                         // ssh key
	PINGpackets        int                 `json:"pingpackets" toml:"pingpackets"`               // ping packets to send
	PINGtimeout        int                 `json:"pingtimeout" toml:"pingtimeout"`               // ping timeout
	Interval           int                 `json:"interval" toml:"interval"`                     // how often to cechk
	Timeout            int                 `json:"timeout" toml:"timeout"`                       // timeout performing check
	ActivePassiveID    string              `json:"activepassiveid" toml:"activepassiveid"`       // used to link active/passive backends
	TLSConfig          tlsconfig.TLSConfig `json:"tls" toml:"tls"`                               // tls config
	DisableAutoCheck   bool                `json:"disableautocheck" toml:"disableautocheck"`     // only respond to check requests
	IP                 string              `json:"ip" toml:"ip"`                                 // specific ip
	SourceIP           string              `json:"sourceip" toml:"sourceip"`                     // specific ip
	Port               int                 `json:"port" toml:"port"`                             // specific port
	OnlineState        StatusType          `json:"online_state" toml:"online_state"`             // alternative online_state - default: online / optional: offline / maintenance
	OfflineState       StatusType          `json:"offline_state" toml:"offline_state"`           // alternative offline_state - default: offline
	// contains filtered or unexported fields
}

HealthCheck custom HealthCheck

func (HealthCheck) UUID

func (h HealthCheck) UUID() string

UUID returns a uuid of a healthcheck

type HealthPool

type HealthPool struct {
	PoolName    string   `json:"poolname" toml:"poolname"`       // name of the vip pool
	BackendName string   `json:"backendname" toml:"backendname"` // name of the backend
	NodeName    string   `json:"nodename" toml:"nodename"`       // name of the node
	Match       string   `json:"match" toml:"match"`             // all/any
	Checks      []string `json:"checks" toml:"checks"`           // []checkuuid
}

HealthPool contains a per nodeuuid information about all checks that apply to this node

type HealthStatus

type HealthStatus struct {
	CheckStatus  Status   `json:"checkstatus" toml:"checkstatus"`   // map[checkuuid]status - status returned by worker
	ManualStatus Status   `json:"manualstatus" toml:"manualstatus"` // manual override
	ErrorMsg     []string `json:"errormsg" toml:"errormsg"`         // error message
}

HealthStatus keeps track of the status of each workers health check

type Manager

type Manager struct {
	Incoming        chan CheckResult
	Workers         []*Worker               `json:"workers" toml:"workers"`
	HealthStatusMap map[string]HealthStatus `json:"healthstatusmap" toml:"healthstatusmap"` // keeps the health of all items
	HealthPoolMap   map[string]HealthPool   `json:"healthpoolmap" toml:"healthpoolmap"`     // keeps a list of uuids and what checks apply to them

	Worker sync.RWMutex
}

Manager manages Health of Node

func NewManager

func NewManager() *Manager

NewManager creates a new healtheck manager

func (*Manager) CleanNodeTracker

func (m *Manager) CleanNodeTracker(expectedNodes []string)

CleanNodeTracker cleans up nodes beeing tracked, but do not exist anymore

func (*Manager) Debug

func (m *Manager) Debug()

Debug shows debug output for all workers

func (*Manager) GetNodeStatus

func (m *Manager) GetNodeStatus(nodeUUID string) (Status, string, string, string, []string)

GetNodeStatus returns the combined status of all checks applicable to a specific backend

func (*Manager) GetPools

func (m *Manager) GetPools(workerUUID string) (s []string)

GetPools returns all nodeUUID's of pools that are linked to a worker

func (*Manager) JSON

func (m *Manager) JSON() ([]byte, error)

JSON returns the healtheck status of the manager in json format

func (*Manager) JSONAuthorized

func (m *Manager) JSONAuthorized(uuid string) ([]byte, error)

JSONAuthorized returns unfiltered the healtheck status of the manager in json format

func (*Manager) RegisterWorker

func (m *Manager) RegisterWorker(w *Worker)

RegisterWorker adds the worker to the health manager

func (*Manager) SetCheckPool

func (m *Manager) SetCheckPool(nodeUUID string, poolName string, backendName string, nodeName string, match string, checks []string) bool

SetCheckPool sets which checks for a specified backend are applicable

func (*Manager) SetCheckStatus

func (m *Manager) SetCheckStatus(workerUUID string, status Status, errorMsg []string)

SetCheckStatus sets the status of a worker check based on the health check result

func (*Manager) SetStatus

func (m *Manager) SetStatus(uuid string, status Status) error

SetStatus sets the status of a uuid to status

func (*Manager) StartWorkers

func (m *Manager) StartWorkers()

StartWorkers starts the workers to do the checking

func (*Manager) StopWorker

func (m *Manager) StopWorker(id int)

StopWorker stops and removes a worker

func (*Manager) StopWorkers

func (m *Manager) StopWorkers()

StopWorkers stops the workers

type Status

type Status uint8

Status holds the status of a check

func (Status) String

func (s Status) String() string

type StatusType

type StatusType struct {
	Status `json:"status" toml:"status"` // status container for toml conversion
}

StatusType contains the status

func (*StatusType) UnmarshalJSON

func (s *StatusType) UnmarshalJSON(text []byte) error

UnmarshalJSON converts json Status to Status uint8

func (*StatusType) UnmarshalText

func (s *StatusType) UnmarshalText(text []byte) error

UnmarshalText converts json Status to Status uint8

type Worker

type Worker struct {
	Pool        string      `json:"pool" toml:"pool"`
	Backend     string      `json:"backend" toml:"backend"`
	NodeName    string      `json:"nodename" toml:"nodename"`
	NodeUUID    string      `json:"nodeuuid" toml:"nodeuuid"`
	IP          string      `json:"ip" toml:"ip"` // IP used for check
	SourceIP    string      `json:"sourceip" toml:"sourceip"`
	Port        int         `json:"port" toml:"port"` // Port used for check
	Check       HealthCheck `json:"check" toml:"check"`
	CheckResult Status      `json:"checkresult" toml:"checkresult"` //
	CheckError  string      `json:"checkerror" toml:"checkerror"`
	UUIDStr     string      `json:"uuid" toml:"uuid"`
	// contains filtered or unexported fields
}

Worker type executes a healthcheck on a single node

func NewWorker

func NewWorker(pool string, backend string, nodeName string, nodeUUID string, ip string, port int, sourceIP string, check HealthCheck, cr chan CheckResult) *Worker

NewWorker creates a new worker for healthchecks

func (*Worker) Debug

func (w *Worker) Debug()

Debug shows debug information for all workers

func (*Worker) Description

func (w *Worker) Description() string

Description provides a description of the check that the worker is managing

func (*Worker) ErrorMsg

func (w *Worker) ErrorMsg() string

ErrorMsg provides a friendly version of the error message

func (*Worker) ExecuteCheck

func (w *Worker) ExecuteCheck() (Status, error, string)

executeCheck directs the check to the executioner and returns the result

func (*Worker) Poll

func (w *Worker) Poll()

Poll sends the current status to the channel

func (*Worker) SendUpdate

func (w *Worker) SendUpdate(result Status, errMsg []string)

SendUpdate sends the updated status to the channel

func (*Worker) Start

func (w *Worker) Start()

Start worker, report check result to manager

func (*Worker) Stop

func (w *Worker) Stop()

Stop the worker

func (*Worker) UUID

func (w *Worker) UUID() string

UUID returns a uniq ID for the worker

Jump to

Keyboard shortcuts

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