Skip to content

Commit

Permalink
fix(alerting): Add support for client.insecure in email alerting prov…
Browse files Browse the repository at this point in the history
…ider (#583)

* feat: adding client.insecure flag to email configuration

* chore(review): applying suggested changes

---------

Co-authored-by: TwiN <[email protected]>
  • Loading branch information
mxcd and TwiN authored Oct 3, 2023
1 parent 0fa3c5d commit e88bfa8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ endpoints:
| `alerting.email.port` | Port the mail server is listening to (e.g. `587`) | Required `0` |
| `alerting.email.to` | Email(s) to send the alerts to | Required `""` |
| `alerting.email.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
| `alerting.email.client.insecure` | Whether to skip TLS verification | `false` |
| `alerting.email.overrides` | List of overrides that may be prioritized over the default configuration | `[]` |
| `alerting.email.overrides[].group` | Endpoint group for which the configuration will be overridden by this configuration | `""` |
| `alerting.email.overrides[].to` | Email(s) to send the alerts to | `""` |
Expand All @@ -489,6 +490,8 @@ alerting:
host: "mail.example.com"
port: 587
to: "[email protected],[email protected]"
client:
insecure: false
# You can also add group-specific to keys, which will
# override the to key above for the specified groups
overrides:
Expand Down
8 changes: 8 additions & 0 deletions alerting/provider/email/email.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package email

import (
"crypto/tls"
"fmt"
"math"
"strings"

"github.com/TwiN/gatus/v5/alerting/alert"
"github.com/TwiN/gatus/v5/client"
"github.com/TwiN/gatus/v5/core"
gomail "gopkg.in/mail.v2"
)
Expand All @@ -19,6 +21,9 @@ type AlertProvider struct {
Port int `yaml:"port"`
To string `yaml:"to"`

// ClientConfig is the configuration of the client used to communicate with the provider's target
ClientConfig *client.Config `yaml:"client,omitempty"`

// DefaultAlert is the default alert configuration to use for endpoints with an alert of the appropriate type
DefaultAlert *alert.Alert `yaml:"default-alert,omitempty"`

Expand Down Expand Up @@ -62,6 +67,9 @@ func (provider *AlertProvider) Send(endpoint *core.Endpoint, alert *alert.Alert,
m.SetHeader("Subject", subject)
m.SetBody("text/plain", body)
d := gomail.NewDialer(provider.Host, provider.Port, username, provider.Password)
if provider.ClientConfig != nil && provider.ClientConfig.Insecure {
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
}
return d.DialAndSend(m)
}

Expand Down

0 comments on commit e88bfa8

Please sign in to comment.