Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(icmp) support DoNotFragment + Size #633

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ Have any feedback or questions? [Create a discussion](https://github.com/TwiN/ga
- [Storage](#storage)
- [Client configuration](#client-configuration)
- [Alerting](#alerting)
- [Configuring AWS SES alerts](#configuring-aws-ses-alerts)
- [Configuring Discord alerts](#configuring-discord-alerts)
- [Configuring Email alerts](#configuring-email-alerts)
- [Configuring GitHub alerts](#configuring-github-alerts)
Expand All @@ -66,6 +65,7 @@ Have any feedback or questions? [Create a discussion](https://github.com/TwiN/ga
- [Configuring Teams alerts](#configuring-teams-alerts)
- [Configuring Telegram alerts](#configuring-telegram-alerts)
- [Configuring Twilio alerts](#configuring-twilio-alerts)
- [Configuring AWS SES alerts](#configuring-aws-ses-alerts)
- [Configuring custom alerts](#configuring-custom-alerts)
- [Setting a default alert](#setting-a-default-alert)
- [Maintenance](#maintenance)
Expand Down Expand Up @@ -110,7 +110,6 @@ Have any feedback or questions? [Create a discussion](https://github.com/TwiN/ga
- [API](#api)
- [Installing as binary](#installing-as-binary)
- [High level design overview](#high-level-design-overview)
- [Sponsors](#sponsors)


## Why Gatus?
Expand Down Expand Up @@ -353,6 +352,8 @@ the client used to send the request.
| `client.ignore-redirect` | Whether to ignore redirects (true) or follow them (false, default). | `false` |
| `client.timeout` | Duration before timing out. | `10s` |
| `client.dns-resolver` | Override the DNS resolver using the format `{proto}://{host}:{port}`. | `""` |
| `client.icmp.df` | Option to set the DoNotFragement bit for ICMP packet | `false` |
| `client.icmp.size` | Size of the ICMP packet | `25` |
| `client.oauth2` | OAuth2 client configuration. | `{}` |
| `client.oauth2.token-url` | The token endpoint URL | required `""` |
| `client.oauth2.client-id` | The client id which should be used for the `Client credentials flow` | required `""` |
Expand All @@ -364,6 +365,8 @@ the client used to send the request.
> 📝 Some of these parameters are ignored based on the type of endpoint. For instance, there's no certificate involved
in ICMP requests (ping), therefore, setting `client.insecure` to `true` for an endpoint of that type will not do anything.

> 📝 The ICMP parameters, including size and the 'Don't Fragment' (DF) flag, are utilized exclusively for ICMP pings. [These parameters can be used to validate MTU](https://stackoverflow.com/questions/45953716/when-to-set-dont-fragment-flag-in-ip-header)

This default configuration is as follows:
```yaml
client:
Expand Down
4 changes: 4 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ func Ping(address string, config *Config) (bool, time.Duration) {
}
pinger.Count = 1
pinger.Timeout = config.Timeout
pinger.Size = config.ICMPConfig.Size
// Set the pinger's privileged mode to true for every GOOS except darwin
// See https://github.com/TwiN/gatus/issues/132
//
// Note that for this to work on Linux, Gatus must run with sudo privileges.
// See https://github.com/prometheus-community/pro-bing#linux
pinger.SetPrivileged(runtime.GOOS != "darwin")
if config.ICMPConfig.DF {
pinger.SetDoNotFragment(true)
}
err = pinger.Run()
if err != nil {
return false, 0
Expand Down
26 changes: 26 additions & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var (
Insecure: false,
IgnoreRedirect: false,
Timeout: defaultTimeout,
ICMPConfig: &ICMPConfig{
DF: false,
},
}
)

Expand All @@ -54,6 +57,9 @@ type Config struct {
// Expected format is {protocol}://{host}:{port}, e.g. tcp://8.8.8.8:53
DNSResolver string `yaml:"dns-resolver,omitempty"`

// See ICMP for more details.
ICMPConfig *ICMPConfig `yaml:"icmp,omitempty"`

// OAuth2Config is the OAuth2 configuration used for the client.
//
// If non-nil, the http.Client returned by getHTTPClient will automatically retrieve a token if necessary.
Expand All @@ -73,6 +79,12 @@ type DNSResolverConfig struct {
Port string
}

// ICMP is the configuration for the ICMP client specific config
type ICMPConfig struct {
DF bool `yaml:"df"` // Don't Fragment flag used for the ICMP client
Size int `yaml:"size"` // Size of the packet
}

// OAuth2Config is the configuration for the OAuth2 client credentials flow
type OAuth2Config struct {
TokenURL string `yaml:"token-url"` // e.g. https://dev-12345678.okta.com/token
Expand All @@ -91,6 +103,20 @@ func (c *Config) ValidateAndSetDefaults() error {
if c.Timeout < time.Millisecond {
c.Timeout = 10 * time.Second
}

// Only validate or set defaults for Icmp if it's not nil
if c.ICMPConfig != nil {
// limit for pro-ping, below 24 it's not working
if c.ICMPConfig.Size < 24 {
c.ICMPConfig.Size = 24
}
} else {
// If Icmp is nil, let's initialize it with default values
c.ICMPConfig = &ICMPConfig{
DF: false,
Size: 24,
}
}
if c.HasCustomDNSResolver() {
// Validate the DNS resolver now to make sure it will not return an error later.
if _, err := c.parseDNSResolver(); err != nil {
Expand Down
Loading