chkok

package
v0.0.0-...-64b5bcc Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ExConfig = 78

ExConfig exit code when invlaid configurations

View Source
const ExDataErr = 65

ExDataErr exit code for invalid data

View Source
const ExNoInput = 72

ExNoInput exit code for when no input provided

View Source
const ExOK = 0

ExOK exit code for successful run

View Source
const ExSoftware = 70

ExSoftware generic failure exit code

View Source
const ExTempFail = 75

ExTempFail exit code when a runtime error

View Source
const (
	// ShutdownTimeout is the time to wait for server to shutdown
	ShutdownTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

func RunModeCLI

func RunModeCLI(checkGroups *CheckSuites, conf *ConfRunner, output io.Writer, logger *log.Logger) int

RunModeCLI run app in CLI mode using the provided configs, return exit code

func RunModeHTTP

func RunModeHTTP(checkGroups *CheckSuites, conf *ConfRunner, logger *log.Logger) int

RunModeHTTP runs app in http server mode using the provided config, return exit code

Types

type Check

type Check interface {
	Suite() string
	Name() string
	Run() Result
	Result() Result
	Status() Status
}

Check is the interface that all checks implement

func CheckFromSpec

func CheckFromSpec(spec *ConfCheckSpec) (Check, error)

CheckFromSpec creates a check from a given ConfCheckSpec

type CheckDial

type CheckDial struct {
	Network string
	Address string
	Absent  bool
	// contains filtered or unexported fields
}

CheckDial checks for a net resource by dialing

func CheckDialFromSpec

func CheckDialFromSpec(spec *ConfCheckSpec) (*CheckDial, error)

CheckDialFromSpec creates a CheckDial from a ConfCheckSpec

func NewCheckDial

func NewCheckDial() *CheckDial

NewCheckDial returns a checkDial for local http availability by default

func (*CheckDial) GetTimeout

func (chk *CheckDial) GetTimeout() time.Duration

GetTimeout gets the max duration for the check to timeout

func (*CheckDial) Name

func (chk *CheckDial) Name() string

Name returns the unique name of the check

func (*CheckDial) Result

func (bc *CheckDial) Result() Result

func (*CheckDial) Run

func (chk *CheckDial) Run() Result

Run runs the check and returns the results

func (*CheckDial) SetTimeout

func (chk *CheckDial) SetTimeout(timeout time.Duration)

SetTimeout sets the max duration for the check to timeout

func (*CheckDial) Status

func (bc *CheckDial) Status() Status

func (*CheckDial) Suite

func (bc *CheckDial) Suite() string

type CheckFile

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

CheckFile checks for file/dir existence/type/uid/gid/size

func CheckFileFromSpec

func CheckFileFromSpec(spec *ConfCheckSpec) (*CheckFile, error)

CheckFileFromSpec creates a CheckFile from a ConfCheckSpec

func NewCheckFile

func NewCheckFile(path string) *CheckFile

NewCheckFile returns a new checkFile without a uid/gid/size checks

func (*CheckFile) Name

func (chk *CheckFile) Name() string

Name returns the unique name of the check

func (*CheckFile) Result

func (bc *CheckFile) Result() Result

func (*CheckFile) Run

func (chk *CheckFile) Run() Result

Run runs the check

func (*CheckFile) Status

func (bc *CheckFile) Status() Status

func (*CheckFile) Suite

func (bc *CheckFile) Suite() string

type CheckSuites

type CheckSuites map[string][]Check

CheckSuites is list of checks, grouped by suite name

func CheckSuitesFromSpecSuites

func CheckSuitesFromSpecSuites(specSuites ConfCheckSpecSuites) (CheckSuites, error)

CheckSuitesFromSpecSuites creates checksuites from config check spec suites

type Conf

type Conf struct {
	Runners     ConfRunners
	CheckSuites ConfCheckSpecSuites `yaml:"check_suites"`
}

Conf is app configurations struct

func ReadConf

func ReadConf(path string) (*Conf, error)

ReadConf reads the configuration file and returns a pointer to Conf struct

type ConfCheckSpec

type ConfCheckSpec struct {
	Type    string
	Path    string
	Mode    *uint32
	User    *string
	Group   *string
	MinSize int32  `yaml:"min_size"`
	MaxSize *int64 `yaml:"max_size"`
	Absent  bool
	Network string
	Address string
	Timeout time.Duration
}

ConfCheckSpec is the spec for each check configuration

type ConfCheckSpecSuites

type ConfCheckSpecSuites map[string][]ConfCheckSpec

ConfCheckSpecSuites is list of ConfCheckSpec grouped by name

type ConfRunner

type ConfRunner struct {
	Timeout                *time.Duration
	ShutdownSignalHeader   *string           `yaml:"shutdown_signal_header"`
	MaxHeaderBytes         *int              `yaml:"max_header_bytes"`
	MaxConcurrentRequests  *int              `yaml:"max_concurrent_requests"`
	ListenAddress          string            `yaml:"listen_address"`
	RequestReadTimeout     *time.Duration    `yaml:"request_read_timeout"`
	RequestRequiredHeaders map[string]string `yaml:"request_required_headers"`
	ResponseWriteTimeout   *time.Duration    `yaml:"response_write_timeout"`
	ResponseOK             *string           `yaml:"response_ok"`
	ResponseFailed         *string           `yaml:"response_failed"`
	ResponseTimeout        *string           `yaml:"response_timeout"`
	ResponseUnavailable    *string           `yaml:"response_unavailable"`
	ResponseInvalidRequest *string           `yaml:"response_invalid_request"`
}

ConfRunner is config for the check runners

func CopyConfRunner

func CopyConfRunner(conf *ConfRunner) ConfRunner

CopyConfRunner returns a copy of the ConfRunner with the same values

func GetBaseConfRunner

func GetBaseConfRunner() ConfRunner

GetBaseConfRunner returns a base ConfRunner with default literal values

func GetConfRunner

func GetConfRunner(runners *ConfRunners, name string) (ConfRunner, bool)

GetConfRunner returns the runner config for the name merged with the default, and bool if it exists

func GetDefaultConfRunner

func GetDefaultConfRunner(runners *ConfRunners) ConfRunner

GetDefaultConfRunner returns a ConfRunner based on the default configuration

func MergedConfRunners

func MergedConfRunners(baseConf, overrideConf *ConfRunner) ConfRunner

MergedConfRunners merges the baseConf with the overrideConf and returns the merged ConfRunner

type ConfRunners

type ConfRunners map[string]ConfRunner

ConfRunners is a map of runner name to its config ConfRunner

type FileType

type FileType uint8

FileType is the type of a file resources, use Type* contants

const (
	// TypeAny is when a file type is not important
	TypeAny FileType = iota
	// TypeFile is used when a path should be a regular file
	TypeFile
	// TypeDir is used when a path should be a directory
	TypeDir
)

type Result

type Result struct {
	IsOK   bool
	Issues []error
}

Result is the results of a Check

type Runner

type Runner struct {
	Log     *log.Logger
	Timeout time.Duration
}

Runner runs all the checks logging details

func (*Runner) RunChecks

func (r *Runner) RunChecks(suites CheckSuites) []Check

RunChecks runs all the checks in the suite and returns slice of check

type Status

type Status uint8

Status is status of a given check (use Status* contants)

const (
	// StatusUnknown is when a check has not started
	StatusUnknown Status = iota
	// StatusRunning is when a check started to run
	StatusRunning
	// StatusStopped is when a check stopped before completion (timeout, etc.)
	StatusStopped
	// StatusDone is when a check successfully ran
	StatusDone
)

type TimedCheck

type TimedCheck interface {
	GetTimeout() time.Duration
	SetTimeout(t time.Duration)
}

TimedCheck is the interface for checks that accept a timeout

Jump to

Keyboard shortcuts

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