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 @@ -109,7 +109,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 @@ -351,6 +350,8 @@ the client used to send the request.
| `client.insecure` | Whether to skip verifying the server's certificate chain and host name. | `false` |
| `client.ignore-redirect` | Whether to ignore redirects (true) or follow them (false, default). | `false` |
| `client.timeout` | Duration before timing out. | `10s` |
| `client.df` | Option to set the DoNotFragement bit for ICMP packet | `false` |
| `client.size` | Size of the ICMP packet | `25` |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'In hindsight, maybe this should be under icmp, i.e.

client:
  icmp:
    df: true
    size: 25

What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's done, as you said, it makes more sense that way

| `client.dns-resolver` | Override the DNS resolver using the format `{proto}://{host}:{port}`. | `""` |
| `client.oauth2` | OAuth2 client configuration. | `{}` |
| `client.oauth2.token-url` | The token endpoint URL | required `""` |
Expand All @@ -363,6 +364,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 size and df (Don't Fragment flag) parameters are only use for ICMP requests (ping). [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.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.Df {
pinger.SetDoNotFragment(true)
}
err = pinger.Run()
if err != nil {
return false, 0
Expand Down
14 changes: 14 additions & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (

const (
defaultTimeout = 10 * time.Second
// By default, an ICMP packet can a size of 0
defaultSize = 0
)

var (
Expand All @@ -30,6 +32,8 @@ var (
Insecure: false,
IgnoreRedirect: false,
Timeout: defaultTimeout,
Df: false,
Size: defaultSize,
}
)

Expand All @@ -50,6 +54,12 @@ type Config struct {
// Timeout for the client
Timeout time.Duration `yaml:"timeout"`

// Don't Fragment flag (DF) for the client
Df bool `yaml:"df"`

// Size of the packet
Size int `yaml:"size"`

// DNSResolver override for the HTTP client
// Expected format is {protocol}://{host}:{port}, e.g. tcp://8.8.8.8:53
DNSResolver string `yaml:"dns-resolver,omitempty"`
Expand Down Expand Up @@ -91,6 +101,10 @@ func (c *Config) ValidateAndSetDefaults() error {
if c.Timeout < time.Millisecond {
c.Timeout = 10 * time.Second
}
// limit for pro-ping, below 25 it's not working
if c.Size < 25 {
c.Size = 25
}
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