@@ -2,13 +2,19 @@ package endpoint
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/TwiN/gatus/v5/alerting/alert"
|
||||
"github.com/TwiN/gatus/v5/config/endpoint/heartbeat"
|
||||
"github.com/TwiN/gatus/v5/config/maintenance"
|
||||
)
|
||||
|
||||
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")
|
||||
)
|
||||
|
||||
// ExternalEndpoint is an endpoint whose result is pushed from outside Gatus, which means that
|
||||
@@ -30,6 +36,12 @@ type ExternalEndpoint struct {
|
||||
// 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:"-"`
|
||||
|
||||
@@ -45,6 +57,10 @@ func (externalEndpoint *ExternalEndpoint) ValidateAndSetDefaults() error {
|
||||
if len(externalEndpoint.Token) == 0 {
|
||||
return ErrExternalEndpointWithNoToken
|
||||
}
|
||||
if externalEndpoint.Heartbeat.Interval != 0 && externalEndpoint.Heartbeat.Interval < 10*time.Second {
|
||||
// If the heartbeat interval is set (non-0), it must be at least 10 seconds.
|
||||
return ErrExternalEndpointHeartbeatIntervalTooLow
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
11
config/endpoint/heartbeat/heartbeat.go
Normal file
11
config/endpoint/heartbeat/heartbeat.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package heartbeat
|
||||
|
||||
import "time"
|
||||
|
||||
// Config used to check if the external endpoint has received new results when it should have.
|
||||
// This configuration is used to trigger alerts when an external endpoint has no new results for a defined period of time
|
||||
type Config struct {
|
||||
// Interval is the time interval at which Gatus verifies whether the external endpoint has received new results
|
||||
// If no new result is received within the interval, the endpoint is marked as failed and alerts are triggered
|
||||
Interval time.Duration `yaml:"interval"`
|
||||
}
|
||||
Reference in New Issue
Block a user