Skip to content

Commit c1abfd3

Browse files
committed
fix: indent and spacing
1 parent 327a399 commit c1abfd3

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,14 +1902,15 @@ endpoints:
19021902

19031903

19041904
#### Configuring Slack alerts
1905-
| Parameter | Description | Default |
1906-
|:-----------------------------------|:-------------------------------------------------------------------------------------------|:--------------|
1907-
| `alerting.slack` | Configuration for alerts of type `slack` | `{}` |
1908-
| `alerting.slack.webhook-url` | Slack Webhook URL | Required `""` |
1909-
| `alerting.slack.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
1910-
| `alerting.slack.overrides` | List of overrides that may be prioritized over the default configuration | `[]` |
1911-
| `alerting.slack.overrides[].group` | Endpoint group for which the configuration will be overridden by this configuration | `""` |
1912-
| `alerting.slack.overrides[].*` | See `alerting.slack.*` parameters | `{}` |
1905+
| Parameter | Description | Default |
1906+
|:-----------------------------------|:-------------------------------------------------------------------------------------------|:------------------------------------|
1907+
| `alerting.slack` | Configuration for alerts of type `slack` | `{}` |
1908+
| `alerting.slack.title` | Title of the notification | `":helmet_with_white_cross: Gatus"` |
1909+
| `alerting.slack.webhook-url` | Slack Webhook URL | Required `""` |
1910+
| `alerting.slack.default-alert` | Default alert configuration. <br />See [Setting a default alert](#setting-a-default-alert) | N/A |
1911+
| `alerting.slack.overrides` | List of overrides that may be prioritized over the default configuration | `[]` |
1912+
| `alerting.slack.overrides[].group` | Endpoint group for which the configuration will be overridden by this configuration | `""` |
1913+
| `alerting.slack.overrides[].*` | See `alerting.slack.*` parameters | `{}` |
19131914

19141915
```yaml
19151916
alerting:

alerting/provider/slack/slack.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121

2222
type Config struct {
2323
WebhookURL string `yaml:"webhook-url"` // Slack webhook URL
24+
Title string `yaml:"title,omitempty"` // Title of the message that will be sent
2425
}
2526

2627
func (cfg *Config) Validate() error {
@@ -34,6 +35,9 @@ func (cfg *Config) Merge(override *Config) {
3435
if len(override.WebhookURL) > 0 {
3536
cfg.WebhookURL = override.WebhookURL
3637
}
38+
if len(override.Title) > 0 {
39+
cfg.Title = override.Title
40+
}
3741
}
3842

3943
// AlertProvider is the configuration necessary for sending an alert using Slack
@@ -73,7 +77,7 @@ func (provider *AlertProvider) Send(ep *endpoint.Endpoint, alert *alert.Alert, r
7377
if err != nil {
7478
return err
7579
}
76-
buffer := bytes.NewBuffer(provider.buildRequestBody(ep, alert, result, resolved))
80+
buffer := bytes.NewBuffer(provider.buildRequestBody(cfg, ep, alert, result, resolved))
7781
request, err := http.NewRequest(http.MethodPost, cfg.WebhookURL, buffer)
7882
if err != nil {
7983
return err
@@ -111,7 +115,7 @@ type Field struct {
111115
}
112116

113117
// buildRequestBody builds the request body for the provider
114-
func (provider *AlertProvider) buildRequestBody(ep *endpoint.Endpoint, alert *alert.Alert, result *endpoint.Result, resolved bool) []byte {
118+
func (provider *AlertProvider) buildRequestBody(cfg *Config, ep *endpoint.Endpoint, alert *alert.Alert, result *endpoint.Result, resolved bool) []byte {
115119
var message, color string
116120
if resolved {
117121
message = fmt.Sprintf("An alert for *%s* has been resolved after passing successfully %d time(s) in a row", ep.DisplayName(), alert.SuccessThreshold)
@@ -134,11 +138,15 @@ func (provider *AlertProvider) buildRequestBody(ep *endpoint.Endpoint, alert *al
134138
if alertDescription := alert.GetDescription(); len(alertDescription) > 0 {
135139
description = ":\n> " + alertDescription
136140
}
141+
title := ":helmet_with_white_cross: Gatus"
142+
if cfg.Title != "" {
143+
title = cfg.Title
144+
}
137145
body := Body{
138146
Text: "",
139147
Attachments: []Attachment{
140148
{
141-
Title: ":helmet_with_white_cross: Gatus",
149+
Title: title,
142150
Text: message + description,
143151
Short: false,
144152
Color: color,

0 commit comments

Comments
 (0)