From b4b9f5c1beb6eb8e085bc5ac0c7402aae91a4a51 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Sat, 26 Sep 2020 15:15:50 -0400 Subject: [PATCH] Improve documentation --- alerting/provider/custom/custom.go | 4 ++++ alerting/provider/pagerduty/pagerduty.go | 2 ++ alerting/provider/provider.go | 4 ++++ alerting/provider/slack/slack.go | 3 +++ alerting/provider/twilio/twilio.go | 3 +++ config/config.go | 3 +++ 6 files changed, 19 insertions(+) diff --git a/alerting/provider/custom/custom.go b/alerting/provider/custom/custom.go index 6563f252..73d7e90a 100644 --- a/alerting/provider/custom/custom.go +++ b/alerting/provider/custom/custom.go @@ -10,6 +10,8 @@ import ( "strings" ) +// AlertProvider is the configuration necessary for sending an alert using a custom HTTP request +// Technically, all alert providers should be reachable using the custom alert provider type AlertProvider struct { Url string `yaml:"url"` Method string `yaml:"method,omitempty"` @@ -17,10 +19,12 @@ type AlertProvider struct { Headers map[string]string `yaml:"headers,omitempty"` } +// IsValid returns whether the provider's configuration is valid func (provider *AlertProvider) IsValid() bool { return len(provider.Url) > 0 } +// ToCustomAlertProvider converts the provider into a custom.AlertProvider func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *AlertProvider { return provider } diff --git a/alerting/provider/pagerduty/pagerduty.go b/alerting/provider/pagerduty/pagerduty.go index fbda22f2..29e0412a 100644 --- a/alerting/provider/pagerduty/pagerduty.go +++ b/alerting/provider/pagerduty/pagerduty.go @@ -6,10 +6,12 @@ import ( "github.com/TwinProduction/gatus/core" ) +// AlertProvider is the configuration necessary for sending an alert using PagerDuty type AlertProvider struct { IntegrationKey string `yaml:"integration-key"` } +// IsValid returns whether the provider's configuration is valid func (provider *AlertProvider) IsValid() bool { return len(provider.IntegrationKey) == 32 } diff --git a/alerting/provider/provider.go b/alerting/provider/provider.go index f9783a7b..41e8b0fd 100644 --- a/alerting/provider/provider.go +++ b/alerting/provider/provider.go @@ -5,7 +5,11 @@ import ( "github.com/TwinProduction/gatus/core" ) +// AlertProvider is the interface that each providers should implement type AlertProvider interface { + // IsValid returns whether the provider's configuration is valid IsValid() bool + + // ToCustomAlertProvider converts the provider into a custom.AlertProvider ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *custom.AlertProvider } diff --git a/alerting/provider/slack/slack.go b/alerting/provider/slack/slack.go index fad3d57e..621145da 100644 --- a/alerting/provider/slack/slack.go +++ b/alerting/provider/slack/slack.go @@ -6,14 +6,17 @@ import ( "github.com/TwinProduction/gatus/core" ) +// AlertProvider is the configuration necessary for sending an alert using Slack type AlertProvider struct { WebhookUrl string `yaml:"webhook-url"` } +// IsValid returns whether the provider's configuration is valid func (provider *AlertProvider) IsValid() bool { return len(provider.WebhookUrl) > 0 } +// ToCustomAlertProvider converts the provider into a custom.AlertProvider func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *custom.AlertProvider { var message string var color string diff --git a/alerting/provider/twilio/twilio.go b/alerting/provider/twilio/twilio.go index 6e5e06aa..011e5487 100644 --- a/alerting/provider/twilio/twilio.go +++ b/alerting/provider/twilio/twilio.go @@ -8,6 +8,7 @@ import ( "net/url" ) +// AlertProvider is the configuration necessary for sending an alert using Twilio type AlertProvider struct { SID string `yaml:"sid"` Token string `yaml:"token"` @@ -15,10 +16,12 @@ type AlertProvider struct { To string `yaml:"to"` } +// IsValid returns whether the provider's configuration is valid func (provider *AlertProvider) IsValid() bool { return len(provider.Token) > 0 && len(provider.SID) > 0 && len(provider.From) > 0 && len(provider.To) > 0 } +// ToCustomAlertProvider converts the provider into a custom.AlertProvider func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *custom.AlertProvider { var message string if resolved { diff --git a/config/config.go b/config/config.go index cc3e3e09..09e0bfcb 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,8 @@ import ( ) const ( + // DefaultConfigurationFilePath is the default path that will be used to search for the configuration file + // if a custom path isn't configured through the GATUS_CONFIG_FILE environment variable DefaultConfigurationFilePath = "config/config.yaml" ) @@ -22,6 +24,7 @@ var ( config *Config ) +// Config is the main configuration structure type Config struct { Metrics bool `yaml:"metrics"` Debug bool `yaml:"debug"`