2121
2222type 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
2627func (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