Documentation
¶
Index ¶
- Constants
- Variables
- func ResolvePlaceholder(placeholder string, result *Result, ctx *gontext.Gontext) (string, error)
- type Condition
- type ConditionResult
- type Endpoint
- func (e *Endpoint) Close()
- func (e *Endpoint) DisplayName() string
- func (e *Endpoint) EvaluateHealth() *Result
- func (e *Endpoint) EvaluateHealthWithContext(context *gontext.Gontext) *Result
- func (e *Endpoint) IsEnabled() bool
- func (e *Endpoint) Key() string
- func (e *Endpoint) Type() Type
- func (e *Endpoint) ValidateAndSetDefaults() error
- type Event
- type EventType
- type ExternalEndpoint
- func (externalEndpoint *ExternalEndpoint) DisplayName() string
- func (externalEndpoint *ExternalEndpoint) IsEnabled() bool
- func (externalEndpoint *ExternalEndpoint) Key() string
- func (externalEndpoint *ExternalEndpoint) ToEndpoint() *Endpoint
- func (externalEndpoint *ExternalEndpoint) ValidateAndSetDefaults() error
- type HourlyUptimeStatistics
- type Result
- type Status
- type Type
- type Uptime
Constants ¶
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]" // DNSRCodePlaceholder is a placeholder for DNS_RCODE // // Values that could replace the placeholder: NOERROR, FORMERR, SERVFAIL, NXDOMAIN, NOTIMP, REFUSED DNSRCodePlaceholder = "[DNS_RCODE]" // 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]" // CertificateExpirationPlaceholder is a placeholder for the duration before certificate expiration, in milliseconds. // // Values that could replace the placeholder: 4461677039 (~52 days) CertificateExpirationPlaceholder = "[CERTIFICATE_EXPIRATION]" // DomainExpirationPlaceholder is a placeholder for the duration before the domain expires, in milliseconds. DomainExpirationPlaceholder = "[DOMAIN_EXPIRATION]" // ContextPlaceholder is a placeholder for suite context values // Usage: [CONTEXT].path.to.value ContextPlaceholder = "[CONTEXT]" )
Placeholders
const ( // LengthFunctionPrefix is the prefix for the length function // // Usage: len([BODY].articles) == 10, len([BODY].name) > 5 LengthFunctionPrefix = "len(" // HasFunctionPrefix is the prefix for the has function // // Usage: has([BODY].errors) == true HasFunctionPrefix = "has(" // PatternFunctionPrefix is the prefix for the pattern function // // Usage: [IP] == pat(192.168.*.*) PatternFunctionPrefix = "pat(" // AnyFunctionPrefix is the prefix for the any function // // Usage: [IP] == any(1.1.1.1, 1.0.0.1) AnyFunctionPrefix = "any(" // FunctionSuffix is the suffix for all functions FunctionSuffix = ")" )
Functions
const (
// InvalidConditionElementSuffix is the suffix that will be appended to an invalid condition
InvalidConditionElementSuffix = "(INVALID)"
)
Other constants
Variables ¶
var ( // ErrEndpointWithNoName is the error with which Gatus will panic if an endpoint is configured with no name ErrEndpointWithNoName = errors.New("you must specify a name for each endpoint") // ErrEndpointWithInvalidNameOrGroup is the error with which Gatus will panic if an endpoint has an invalid character where it shouldn't ErrEndpointWithInvalidNameOrGroup = errors.New("endpoint name and group must not have \" or \\") )
var ( // ErrEndpointWithNoCondition is the error with which Gatus will panic if an endpoint is configured with no conditions ErrEndpointWithNoCondition = errors.New("you must specify at least one condition per endpoint") // ErrEndpointWithNoURL is the error with which Gatus will panic if an endpoint is configured with no url ErrEndpointWithNoURL = errors.New("you must specify an url for each endpoint") // ErrUnknownEndpointType is the error with which Gatus will panic if an endpoint has an unknown type ErrUnknownEndpointType = errors.New("unknown endpoint type") // ErrInvalidConditionFormat is the error with which Gatus will panic if a condition has an invalid format ErrInvalidConditionFormat = errors.New("invalid condition format: does not match '<VALUE> <COMPARATOR> <VALUE>'") // ErrInvalidEndpointIntervalForDomainExpirationPlaceholder is the error with which Gatus will panic if an endpoint // has both an interval smaller than 5 minutes and a condition with DomainExpirationPlaceholder. // This is because the free whois service we are using should not be abused, especially considering the fact that // the data takes a while to be updated. ErrInvalidEndpointIntervalForDomainExpirationPlaceholder = errors.New("the minimum interval for an endpoint with a condition using the " + DomainExpirationPlaceholder + " placeholder is 300s (5m)") )
var ( // ErrExternalEndpointWithNoToken is the error with which Gatus will panic if an external endpoint is configured without a token. ErrExternalEndpointWithNoToken = errors.New("you must specify a token for each external endpoint") // ErrExternalEndpointHeartbeatIntervalTooLow is the error with which Gatus will panic if an external endpoint's heartbeat interval is less than 10 seconds. ErrExternalEndpointHeartbeatIntervalTooLow = errors.New("heartbeat interval must be at least 10 seconds") )
Functions ¶
func ResolvePlaceholder ¶ added in v5.24.0
ResolvePlaceholder resolves all types of placeholders to their string values.
Supported placeholders:
- [STATUS]: HTTP status code (e.g., "200", "404")
- [IP]: IP address from the response (e.g., "127.0.0.1")
- [RESPONSE_TIME]: Response time in milliseconds (e.g., "250")
- [DNS_RCODE]: DNS response code (e.g., "NOERROR", "NXDOMAIN")
- [CONNECTED]: Connection status (e.g., "true", "false")
- [CERTIFICATE_EXPIRATION]: Certificate expiration time in milliseconds
- [DOMAIN_EXPIRATION]: Domain expiration time in milliseconds
- [BODY]: Full response body
- [BODY].path: JSONPath expression on response body (e.g., [BODY].status, [BODY].data[0].name)
- [CONTEXT].path: Suite context values (e.g., [CONTEXT].user_id, [CONTEXT].session_token)
Function wrappers:
- len(placeholder): Returns the length of the resolved value
- has(placeholder): Returns "true" if the placeholder exists and is non-empty, "false" otherwise
Examples:
- ResolvePlaceholder("[STATUS]", result, nil) → "200"
- ResolvePlaceholder("len([BODY].items)", result, nil) → "5" (for JSON array with 5 items)
- ResolvePlaceholder("has([CONTEXT].user_id)", result, ctx) → "true" (if context has user_id)
- ResolvePlaceholder("[BODY].user.name", result, nil) → "john" (for {"user":{"name":"john"}})
Case-insensitive: All placeholder names are handled case-insensitively, but paths preserve original case.
Types ¶
type Condition ¶
type Condition string
Condition is a condition that needs to be met in order for an Endpoint to be considered healthy.
type ConditionResult ¶
type ConditionResult struct {
// Condition that was evaluated
Condition string `json:"condition"`
// Success whether the condition was met (successful) or not (failed)
Success bool `json:"success"`
}
ConditionResult result of a Condition
type Endpoint ¶
type Endpoint struct {
// Enabled defines whether to enable the monitoring of the endpoint
Enabled *bool `yaml:"enabled,omitempty"`
// Name of the endpoint. Can be anything.
Name string `yaml:"name"`
// Group the endpoint is a part of. Used for grouping multiple endpoints together on the front end.
Group string `yaml:"group,omitempty"`
// URL to send the request to
URL string `yaml:"url"`
// Method of the request made to the url of the endpoint
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"`
// ExtraLabels are key-value pairs that can be used to metric the endpoint
ExtraLabels map[string]string `yaml:"extra-labels,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 endpoint
Conditions []Condition `yaml:"conditions"`
// Alerts is the alerting configuration for the endpoint in case of failure
Alerts []*alert.Alert `yaml:"alerts,omitempty"`
// MaintenanceWindow is the configuration for per-endpoint maintenance windows
MaintenanceWindows []*maintenance.Config `yaml:"maintenance-windows,omitempty"`
// DNSConfig is the configuration for DNS monitoring
DNSConfig *dns.Config `yaml:"dns,omitempty"`
// SSH is the configuration for SSH monitoring
SSHConfig *sshconfig.Config `yaml:"ssh,omitempty"`
// ClientConfig is the configuration of the client used to communicate with the endpoint's target
ClientConfig *client.Config `yaml:"client,omitempty"`
// UIConfig is the configuration for the UI
UIConfig *ui.Config `yaml:"ui,omitempty"`
// NumberOfFailuresInARow is the number of unsuccessful evaluations in a row
NumberOfFailuresInARow int `yaml:"-"`
// NumberOfSuccessesInARow is the number of successful evaluations in a row
NumberOfSuccessesInARow int `yaml:"-"`
// LastReminderSent is the time at which the last reminder was sent for this endpoint.
LastReminderSent time.Time `yaml:"-"`
// Store is a map of values to extract from the result and store in the suite context
// This field is only used when the endpoint is part of a suite
Store map[string]string `yaml:"store,omitempty"`
// AlwaysRun defines whether to execute this endpoint even if previous endpoints in the suite failed
// This field is only used when the endpoint is part of a suite
AlwaysRun bool `yaml:"always-run,omitempty"`
}
Endpoint is the configuration of a service to be monitored
func (*Endpoint) Close ¶
func (e *Endpoint) Close()
Close HTTP connections between watchdog and endpoints to avoid dangling socket file descriptors on configuration reload. More context on https://github.com/TwiN/gatus/issues/536
func (*Endpoint) DisplayName ¶
DisplayName returns an identifier made up of the Name and, if not empty, the Group.
func (*Endpoint) EvaluateHealth ¶
EvaluateHealth sends a request to the endpoint's URL and evaluates the conditions of the endpoint.
func (*Endpoint) EvaluateHealthWithContext ¶ added in v5.24.0
EvaluateHealthWithContext sends a request to the endpoint's URL with context support and evaluates the conditions
func (*Endpoint) ValidateAndSetDefaults ¶
ValidateAndSetDefaults validates the endpoint's configuration and sets the default value of args that have one
type Event ¶
type Event struct {
// Type is the kind of event
Type EventType `json:"type"`
// Timestamp is the moment at which the event happened
Timestamp time.Time `json:"timestamp"`
}
Event is something that happens at a specific time
func NewEventFromResult ¶
NewEventFromResult creates an Event from a Result
type EventType ¶
type EventType string
EventType is, uh, the types of events?
var ( // EventStart is a type of event that represents when an endpoint starts being monitored EventStart EventType = "START" // EventHealthy is a type of event that represents an endpoint passing all of its conditions EventHealthy EventType = "HEALTHY" // EventUnhealthy is a type of event that represents an endpoint failing one or more of its conditions EventUnhealthy EventType = "UNHEALTHY" )
type ExternalEndpoint ¶
type ExternalEndpoint struct {
// Enabled defines whether to enable the monitoring of the endpoint
Enabled *bool `yaml:"enabled,omitempty"`
// Name of the endpoint. Can be anything.
Name string `yaml:"name"`
// Group the endpoint is a part of. Used for grouping multiple endpoints together on the front end.
Group string `yaml:"group,omitempty"`
// Token is the bearer token that must be provided through the Authorization header to push results to the endpoint
Token string `yaml:"token,omitempty"`
// Alerts is the alerting configuration for the endpoint in case of failure
Alerts []*alert.Alert `yaml:"alerts,omitempty"`
// MaintenanceWindow is the configuration for per-endpoint maintenance windows
MaintenanceWindows []*maintenance.Config `yaml:"maintenance-windows,omitempty"`
// Heartbeat is the configuration that checks if the external endpoint has received new results when it should have.
Heartbeat heartbeat.Config `yaml:"heartbeat,omitempty"`
// NumberOfFailuresInARow is the number of unsuccessful evaluations in a row
NumberOfFailuresInARow int `yaml:"-"`
// NumberOfSuccessesInARow is the number of successful evaluations in a row
NumberOfSuccessesInARow int `yaml:"-"`
}
ExternalEndpoint is an endpoint whose result is pushed from outside Gatus, which means that said endpoints are not monitored by Gatus itself; Gatus only displays their results and takes care of alerting
func (*ExternalEndpoint) DisplayName ¶
func (externalEndpoint *ExternalEndpoint) DisplayName() string
DisplayName returns an identifier made up of the Name and, if not empty, the Group.
func (*ExternalEndpoint) IsEnabled ¶
func (externalEndpoint *ExternalEndpoint) IsEnabled() bool
IsEnabled returns whether the endpoint is enabled or not
func (*ExternalEndpoint) Key ¶
func (externalEndpoint *ExternalEndpoint) Key() string
Key returns the unique key for the Endpoint
func (*ExternalEndpoint) ToEndpoint ¶
func (externalEndpoint *ExternalEndpoint) ToEndpoint() *Endpoint
ToEndpoint converts the ExternalEndpoint to an Endpoint
func (*ExternalEndpoint) ValidateAndSetDefaults ¶
func (externalEndpoint *ExternalEndpoint) ValidateAndSetDefaults() error
ValidateAndSetDefaults validates the ExternalEndpoint and sets the default values
type HourlyUptimeStatistics ¶
type HourlyUptimeStatistics struct {
TotalExecutions uint64 // Total number of checks
SuccessfulExecutions uint64 // Number of successful executions
TotalExecutionsResponseTime uint64 // Total response time for all executions in milliseconds
}
HourlyUptimeStatistics is a struct containing all metrics collected over the course of an hour
type Result ¶
type Result struct {
// HTTPStatus is the HTTP response status code
HTTPStatus int `json:"status,omitempty"`
// DNSRCode is the response code of a DNS query in a human-readable format
//
// Possible values: NOERROR, FORMERR, SERVFAIL, NXDOMAIN, NOTIMP, REFUSED
DNSRCode string `json:"-"`
// Hostname extracted from Endpoint.URL
Hostname string `json:"hostname,omitempty"`
// IP resolved from the Endpoint 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 Endpoint's health
Errors []string `json:"errors,omitempty"`
// ConditionResults are the results of each of the Endpoint's Condition
ConditionResults []*ConditionResult `json:"conditionResults,omitempty"`
// Success whether the result signifies a success or not
Success bool `json:"success"`
// Timestamp when the request was sent
Timestamp time.Time `json:"timestamp"`
// CertificateExpiration is the duration before the certificate expires
CertificateExpiration time.Duration `json:"-"`
// DomainExpiration is the duration before the domain expires
DomainExpiration time.Duration `json:"-"`
// Body is the response body
//
// Note that this field is not persisted in the storage.
// It is used for health evaluation as well as debugging purposes.
Body []byte `json:"-"`
///////////////////////////////////
// BELOW IS ONLY USED FOR SUITES //
///////////////////////////////////
// Name of the endpoint (ONLY USED FOR SUITES)
// Group is not needed because it's inherited from the suite
Name string `json:"name,omitempty"`
// contains filtered or unexported fields
}
Result of the evaluation of an Endpoint
type Status ¶
type Status struct {
// Name of the endpoint
Name string `json:"name,omitempty"`
// Group the endpoint is a part of. Used for grouping multiple endpoints together on the front end.
Group string `json:"group,omitempty"`
// Key of the Endpoint
Key string `json:"key"`
// Results is the list of endpoint evaluation results
Results []*Result `json:"results"`
// Events is a list of events
Events []*Event `json:"events,omitempty"`
// Uptime information on the endpoint's uptime
//
// Used by the memory store.
//
// To retrieve the uptime between two time, use store.GetUptimeByKey.
Uptime *Uptime `json:"-"`
}
Status contains the evaluation Results of an Endpoint This is essentially a DTO
type Type ¶
type Type string
const ( // HostHeader is the name of the header used to specify the host HostHeader = "Host" // ContentTypeHeader is the name of the header used to specify the content type ContentTypeHeader = "Content-Type" // UserAgentHeader is the name of the header used to specify the request's user agent UserAgentHeader = "User-Agent" // GatusUserAgent is the default user agent that Gatus uses to send requests. GatusUserAgent = "Gatus/1.0" TypeDNS Type = "DNS" TypeTCP Type = "TCP" TypeSCTP Type = "SCTP" TypeUDP Type = "UDP" TypeICMP Type = "ICMP" TypeSTARTTLS Type = "STARTTLS" TypeTLS Type = "TLS" TypeHTTP Type = "HTTP" TypeGRPC Type = "GRPC" TypeWS Type = "WEBSOCKET" TypeSSH Type = "SSH" TypeUNKNOWN Type = "UNKNOWN" )
type Uptime ¶
type Uptime struct {
// HourlyStatistics is a map containing metrics collected (value) for every hourly unix timestamps (key)
//
// Used only if the storage type is memory
HourlyStatistics map[int64]*HourlyUptimeStatistics `json:"-"`
}
Uptime is the struct that contains the relevant data for calculating the uptime as well as the uptime itself and some other statistics