mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-24 17:04:42 +01:00
9d151fcdb4
* refactor: Partially break core package into dns, result and ssh packages * refactor: Move core package to config/endpoint * refactor: Fix warning about overlapping imported package name with endpoint variable * refactor: Rename EndpointStatus to Status * refactor: Merge result pkg back into endpoint pkg, because it makes more sense * refactor: Rename parameter r to result in Condition.evaluate * refactor: Rename parameter r to result * refactor: Revert accidental change to endpoint.TypeDNS * refactor: Rename parameter r to result * refactor: Merge util package into endpoint package * refactor: Rename parameter r to result
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package ui
|
|
|
|
import "errors"
|
|
|
|
// Config is the UI configuration for endpoint.Endpoint
|
|
type Config struct {
|
|
// HideConditions whether to hide the condition results on the UI
|
|
HideConditions bool `yaml:"hide-conditions"`
|
|
|
|
// HideHostname whether to hide the hostname in the Result
|
|
HideHostname bool `yaml:"hide-hostname"`
|
|
|
|
// HideURL whether to ensure the URL is not displayed in the results. Useful if the URL contains a token.
|
|
HideURL bool `yaml:"hide-url"`
|
|
|
|
// DontResolveFailedConditions whether to resolve failed conditions in the Result for display in the UI
|
|
DontResolveFailedConditions bool `yaml:"dont-resolve-failed-conditions"`
|
|
|
|
// Badge is the configuration for the badges generated
|
|
Badge *Badge `yaml:"badge"`
|
|
}
|
|
|
|
type Badge struct {
|
|
ResponseTime *ResponseTime `yaml:"response-time"`
|
|
}
|
|
|
|
type ResponseTime struct {
|
|
Thresholds []int `yaml:"thresholds"`
|
|
}
|
|
|
|
var (
|
|
ErrInvalidBadgeResponseTimeConfig = errors.New("invalid response time badge configuration: expected parameter 'response-time' to have 5 ascending numerical values")
|
|
)
|
|
|
|
// ValidateAndSetDefaults validates the UI configuration and sets the default values
|
|
func (config *Config) ValidateAndSetDefaults() error {
|
|
if config.Badge != nil {
|
|
if len(config.Badge.ResponseTime.Thresholds) != 5 {
|
|
return ErrInvalidBadgeResponseTimeConfig
|
|
}
|
|
for i := 4; i > 0; i-- {
|
|
if config.Badge.ResponseTime.Thresholds[i] < config.Badge.ResponseTime.Thresholds[i-1] {
|
|
return ErrInvalidBadgeResponseTimeConfig
|
|
}
|
|
}
|
|
} else {
|
|
config.Badge = GetDefaultConfig().Badge
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetDefaultConfig retrieves the default UI configuration
|
|
func GetDefaultConfig() *Config {
|
|
return &Config{
|
|
HideHostname: false,
|
|
HideURL: false,
|
|
DontResolveFailedConditions: false,
|
|
HideConditions: false,
|
|
Badge: &Badge{
|
|
ResponseTime: &ResponseTime{
|
|
Thresholds: []int{50, 200, 300, 500, 750},
|
|
},
|
|
},
|
|
}
|
|
}
|