core

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusPlaceholder is a placeholder for a HTTP status.
	//
	// Values that could replace the placeholder: 200, 404, 500, ...
	StatusPlaceholder = "[STATUS]"

	// IPPlaceHolder is a placeholder for an IP.
	//
	// Values that could replace the placeholder: 127.0.0.1, 10.0.0.1, ...
	IPPlaceHolder = "[IP]"

	// ResponseTimePlaceHolder is a placeholder for the request response time, in milliseconds.
	//
	// Values that could replace the placeholder: 1, 500, 1000, ...
	ResponseTimePlaceHolder = "[RESPONSE_TIME]"

	// BodyPlaceHolder is a placeholder for the body of the response
	//
	// Values that could replace the placeholder: {}, {"data":{"name":"john"}}, ...
	BodyPlaceHolder = "[BODY]"

	// ConnectedPlaceHolder is a placeholder for whether a connection was successfully established.
	//
	// Values that could replace the placeholder: true, false
	ConnectedPlaceHolder = "[CONNECTED]"

	LengthFunctionPrefix  = "len("
	PatternFunctionPrefix = "pat("
	FunctionSuffix        = ")"

	InvalidConditionElementSuffix = "(INVALID)"
)

Variables

View Source
var (
	ErrNoCondition = errors.New("you must specify at least one condition per service")
	ErrNoUrl       = errors.New("you must specify an url for each service")
)

Functions

This section is empty.

Types

type Alert added in v0.1.0

type Alert struct {
	// Type of alert
	Type AlertType `yaml:"type"`

	// Enabled defines whether or not the alert is enabled
	Enabled bool `yaml:"enabled"`

	// FailureThreshold is the number of failures in a row needed before triggering the alert
	FailureThreshold int `yaml:"failure-threshold"`

	// Description of the alert. Will be included in the alert sent.
	Description string `yaml:"description"`

	// SendOnResolved defines whether to send a second notification when the issue has been resolved
	SendOnResolved bool `yaml:"send-on-resolved"`

	// SuccessThreshold defines how many successful executions must happen in a row before an ongoing incident is marked as resolved
	SuccessThreshold int `yaml:"success-threshold"`

	// ResolveKey is an optional field that is used by some providers (i.e. PagerDuty's dedup_key) to resolve
	// ongoing/triggered incidents
	ResolveKey string

	// Triggered is used to determine whether an alert has been triggered. When an alert is resolved, this value
	// should be set back to false. It is used to prevent the same alert from going out twice.
	Triggered bool
}

Alert is the service's alert configuration

type AlertType added in v0.1.0

type AlertType string
const (
	SlackAlert     AlertType = "slack"
	PagerDutyAlert AlertType = "pagerduty"
	TwilioAlert    AlertType = "twilio"
	CustomAlert    AlertType = "custom"
)

type Condition

type Condition string

Condition is a condition that needs to be met in order for a Service to be considered healthy.

type ConditionResult

type ConditionResult struct {
	Condition string `json:"condition"`
	Success   bool   `json:"success"`
}

type HealthStatus

type HealthStatus struct {
	Status  string `json:"status"`
	Message string `json:"message,omitempty"`
}

type Result

type Result struct {
	// HttpStatus is the HTTP response status code
	HttpStatus int `json:"status"`

	// Body is the response body
	Body []byte `json:"-"`

	// Hostname extracted from the Service Url
	Hostname string `json:"hostname"`

	// Ip resolved from the Service Url
	Ip string `json:"-"`

	// Connected whether a connection to the host was established successfully
	Connected bool `json:"-"`

	// Duration time that the request took
	Duration time.Duration `json:"duration"`

	// Errors encountered during the evaluation of the service's health
	Errors []string `json:"errors"`

	// ConditionResults results of the service's conditions
	ConditionResults []*ConditionResult `json:"condition-results"`

	// Success whether the result signifies a success or not
	Success bool `json:"success"`

	// Timestamp when the request was sent
	Timestamp time.Time `json:"timestamp"`
}

Result of the evaluation of a Service

type Service

type Service struct {
	// Name of the service. Can be anything.
	Name string `yaml:"name"`

	// URL to send the request to
	Url string `yaml:"url"`

	// Method of the request made to the url of the service
	Method string `yaml:"method,omitempty"`

	// Body of the request
	Body string `yaml:"body,omitempty"`

	// GraphQL is whether to wrap the body in a query param ({"query":"$body"})
	GraphQL bool `yaml:"graphql,omitempty"`

	// Headers of the request
	Headers map[string]string `yaml:"headers,omitempty"`

	// Interval is the duration to wait between every status check
	Interval time.Duration `yaml:"interval,omitempty"`

	// Conditions used to determine the health of the service
	Conditions []*Condition `yaml:"conditions"`

	// Alerts is the alerting configuration for the service in case of failure
	Alerts []*Alert `yaml:"alerts"`

	// Insecure is whether to skip verifying the server's certificate chain and host name
	Insecure bool `yaml:"insecure,omitempty"`

	NumberOfFailuresInARow  int
	NumberOfSuccessesInARow int
}

Service is the configuration of a monitored endpoint

func (*Service) EvaluateHealth added in v1.0.1

func (service *Service) EvaluateHealth() *Result

EvaluateHealth sends a request to the service's URL and evaluates the conditions of the service.

func (*Service) GetAlertsTriggered added in v0.1.0

func (service *Service) GetAlertsTriggered() []Alert

func (*Service) ValidateAndSetDefaults added in v1.0.1

func (service *Service) ValidateAndSetDefaults()

ValidateAndSetDefaults validates the service's configuration and sets the default value of fields that have one

Jump to

Keyboard shortcuts

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