core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPlaceholder       = "[STATUS]"
	IPPlaceHolder           = "[IP]"
	ResponseTimePlaceHolder = "[RESPONSE_TIME]"
	BodyPlaceHolder         = "[BODY]"

	LengthFunctionPrefix = "len("
	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 AlertingConfig added in v0.1.1

type AlertingConfig struct {
	Slack     string               `yaml:"slack"`
	PagerDuty string               `yaml:"pagerduty"`
	Twilio    *TwilioAlertProvider `yaml:"twilio"`
	Custom    *CustomAlertProvider `yaml:"custom"`
}

type Condition

type Condition string

type ConditionResult

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

type CustomAlertProvider added in v0.1.1

type CustomAlertProvider struct {
	Url     string            `yaml:"url"`
	Method  string            `yaml:"method,omitempty"`
	Body    string            `yaml:"body,omitempty"`
	Headers map[string]string `yaml:"headers,omitempty"`
}

func CreatePagerDutyCustomAlertProvider added in v0.1.6

func CreatePagerDutyCustomAlertProvider(routingKey, eventAction, resolveKey string, service *Service, message string) *CustomAlertProvider

https://developer.pagerduty.com/docs/events-api-v2/trigger-events/

func CreateSlackCustomAlertProvider added in v0.1.2

func CreateSlackCustomAlertProvider(slackWebHookUrl string, service *Service, alert *Alert, result *Result, resolved bool) *CustomAlertProvider

func CreateTwilioCustomAlertProvider added in v0.1.2

func CreateTwilioCustomAlertProvider(provider *TwilioAlertProvider, message string) *CustomAlertProvider

func (*CustomAlertProvider) IsValid added in v0.1.2

func (provider *CustomAlertProvider) IsValid() bool

func (*CustomAlertProvider) Send added in v0.1.1

func (provider *CustomAlertProvider) Send(serviceName, alertDescription string, resolved bool) ([]byte, error)

Send a request to the alert provider and return the body

type HealthStatus

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

type Result

type Result struct {
	HttpStatus       int                `json:"status"`
	Body             []byte             `json:"-"`
	Hostname         string             `json:"hostname"`
	Ip               string             `json:"-"`
	Duration         time.Duration      `json:"duration"`
	Errors           []string           `json:"errors"`
	ConditionResults []*ConditionResult `json:"condition-results"`
	Success          bool               `json:"success"`
	Timestamp        time.Time          `json:"timestamp"`
}

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

	NumberOfFailuresInARow  int
	NumberOfSuccessesInARow int
}

Service is the configuration of a monitored endpoint

func (*Service) EvaluateConditions

func (service *Service) EvaluateConditions() *Result

func (*Service) GetAlertsTriggered added in v0.1.0

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

func (*Service) Validate added in v0.0.4

func (service *Service) Validate()

type TwilioAlertProvider added in v0.1.2

type TwilioAlertProvider struct {
	SID   string `yaml:"sid"`
	Token string `yaml:"token"`
	From  string `yaml:"from"`
	To    string `yaml:"to"`
}

func (*TwilioAlertProvider) IsValid added in v0.1.2

func (provider *TwilioAlertProvider) IsValid() bool

Jump to

Keyboard shortcuts

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