handlers

package
v0.0.0-...-59a6a0f Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2016 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package handlers defines kite handlers for performing system checks.

Index

Constants

View Source
const InvalidRemoteResponse = Error("error check gave invalid response")

InvalidRemoteResponse is used when a result from remote check can't be unmarshalled to a boolean value.

View Source
const NoSuchCheckType = Error("no such check type")

NoSuchCheckType is used when the Type value of a check request is not among supported.

View Source
const NoSuchChecker = Error("no such checker")

NoSuchChecker is used when the requested implementation of checks.Checker is not available. The user is expected to call the Checkers() endpoint.

Variables

View Source
var Instance *kite.Kite

Instance is a default Kite instance setup with current hostname.

Functions

func Checkers

func Checkers(request *kite.Request) (interface{}, error)

Checkers returns all implementations of checks.Checker available.

func LocalCheck

func LocalCheck(request *kite.Request) (interface{}, error)

LocalCheck performs given checks with a selected checker.

It expects two arguments:

- Name of the check, which can be gathered from the Chercker handler.

- JSON object with list of objects, unmarshable to map[string]CheckRequest.

func LogRequest

func LogRequest(request *kite.Request) (interface{}, error)

LogRequest is generic pre-handler for logging each request.

func LogResponse

func LogResponse(request *kite.Request) (interface{}, error)

LogResponse is generic post-handler for logging each response.

func NewKite

func NewKite(hostname string) *kite.Kite

NewKite sets up and returns a Kite instance.

func RemoteCheck

func RemoteCheck(request *kite.Request) (interface{}, error)

RemoteCheck takes a slice of machine addresses, checker and a check requests to be fan-outed to those machines.

Types

type CheckRequest

type CheckRequest struct {
	// Name holds the process name expected to be running when `Type` is
	// `"process_is_running"`.
	Name string `json:"name",omitempty`
	// Path holds absolute path to file expected to be existing or containing a
	// substring. Used only when `Type` is `"file_exists`" or
	// `"file_contains"`.
	Path string `json:"path",omitempty`
	// Type holds the type of performed check which essentially defines which
	// Checker method to be executed. Possible values are: `"file_exists`",
	// `"file_contains"` and `"process_is_running"`.
	Type string `json:"type"`
	// Substr is substring expected to be found in given file. Used only when
	// `Type` is `"file_contains"`.
	Substr string `json:"substring",omitempty`
}

CheckRequest is used to describe every single check to be performed.

type CheckResult

type CheckResult struct {
	Result bool  `json:"result"`
	Error  error `json:"error"`
}

CheckResult holds the result of given check.

func (*CheckResult) UnmarshalJSON

func (cr *CheckResult) UnmarshalJSON(data []byte) error

UnmarshalJSON is needed in order to unmarshal the error value from string.

type Error

type Error string

Error is a generic error type used inside this package. It's essentially a string allowing its instances to be constants.

Idea of Dave Cheney: http://dave.cheney.net/2016/04/07/constant-errors

func (Error) Error

func (e Error) Error() string

type RemoteCheckResult

type RemoteCheckResult struct {
	Address string
	Results map[string]CheckResult
	Error   error
}

RemoteCheckResult defines a check result returned from another kite.

Jump to

Keyboard shortcuts

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