@@ -29,7 +29,6 @@ import (
29
29
"github.com/aws/aws-sdk-go/service/sns"
30
30
"github.com/go-kit/log"
31
31
"github.com/go-kit/log/level"
32
- "github.com/pkg/errors"
33
32
commoncfg "github.com/prometheus/common/config"
34
33
35
34
"github.com/prometheus/alertmanager/config"
@@ -64,12 +63,12 @@ func New(c *config.SNSConfig, t *template.Template, l log.Logger, httpOpts ...co
64
63
65
64
func (n * Notifier ) Notify (ctx context.Context , alert ... * types.Alert ) (bool , error ) {
66
65
var (
67
- tmplErr error
68
- data = notify .GetTemplateData (ctx , n .tmpl , alert , n .logger )
69
- tmpl = notify .TmplText (n .tmpl , data , & tmplErr )
66
+ err error
67
+ data = notify .GetTemplateData (ctx , n .tmpl , alert , n .logger )
68
+ tmpl = notify .TmplText (n .tmpl , data , & err )
70
69
)
71
70
72
- client , err := n .createSNSClient (tmpl , & tmplErr )
71
+ client , err := n .createSNSClient (tmpl )
73
72
if err != nil {
74
73
var e awserr.RequestFailure
75
74
if errors .As (err , & e ) {
@@ -78,7 +77,7 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err
78
77
return true , err
79
78
}
80
79
81
- publishInput , err := n .createPublishInput (ctx , tmpl , & tmplErr )
80
+ publishInput , err := n .createPublishInput (ctx , tmpl )
82
81
if err != nil {
83
82
return true , err
84
83
}
@@ -100,7 +99,7 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err
100
99
return false , nil
101
100
}
102
101
103
- func (n * Notifier ) createSNSClient (tmpl func (string ) string , tmplErr * error ) (* sns.SNS , error ) {
102
+ func (n * Notifier ) createSNSClient (tmpl func (string ) string ) (* sns.SNS , error ) {
104
103
var creds * credentials.Credentials
105
104
// If there are provided sigV4 credentials we want to use those to create a session.
106
105
if n .conf .Sigv4 .AccessKey != "" && n .conf .Sigv4 .SecretKey != "" {
@@ -116,9 +115,6 @@ func (n *Notifier) createSNSClient(tmpl func(string) string, tmplErr *error) (*s
116
115
if err != nil {
117
116
return nil , err
118
117
}
119
- if * tmplErr != nil {
120
- return nil , notify .NewErrorWithReason (notify .ClientErrorReason , errors .Wrap (* tmplErr , "execute 'api_url' template" ))
121
- }
122
118
123
119
if n .conf .Sigv4 .RoleARN != "" {
124
120
var stsSess * session.Session
@@ -148,19 +144,13 @@ func (n *Notifier) createSNSClient(tmpl func(string) string, tmplErr *error) (*s
148
144
return client , nil
149
145
}
150
146
151
- func (n * Notifier ) createPublishInput (ctx context.Context , tmpl func (string ) string , tmplErr * error ) (* sns.PublishInput , error ) {
147
+ func (n * Notifier ) createPublishInput (ctx context.Context , tmpl func (string ) string ) (* sns.PublishInput , error ) {
152
148
publishInput := & sns.PublishInput {}
153
149
messageAttributes := n .createMessageAttributes (tmpl )
154
- if * tmplErr != nil {
155
- return nil , notify .NewErrorWithReason (notify .ClientErrorReason , errors .Wrap (* tmplErr , "execute 'attributes' template" ))
156
- }
157
150
// Max message size for a message in a SNS publish request is 256KB, except for SMS messages where the limit is 1600 characters/runes.
158
151
messageSizeLimit := 256 * 1024
159
152
if n .conf .TopicARN != "" {
160
153
topicARN := tmpl (n .conf .TopicARN )
161
- if * tmplErr != nil {
162
- return nil , notify .NewErrorWithReason (notify .ClientErrorReason , errors .Wrap (* tmplErr , "execute 'topic_arn' template" ))
163
- }
164
154
publishInput .SetTopicArn (topicARN )
165
155
// If we are using a topic ARN, it could be a FIFO topic specified by the topic's suffix ".fifo".
166
156
if strings .HasSuffix (topicARN , ".fifo" ) {
@@ -175,24 +165,14 @@ func (n *Notifier) createPublishInput(ctx context.Context, tmpl func(string) str
175
165
}
176
166
if n .conf .PhoneNumber != "" {
177
167
publishInput .SetPhoneNumber (tmpl (n .conf .PhoneNumber ))
178
- if * tmplErr != nil {
179
- return nil , notify .NewErrorWithReason (notify .ClientErrorReason , errors .Wrap (* tmplErr , "execute 'phone_number' template" ))
180
- }
181
168
// If we have an SMS message, we need to truncate to 1600 characters/runes.
182
169
messageSizeLimit = 1600
183
170
}
184
171
if n .conf .TargetARN != "" {
185
172
publishInput .SetTargetArn (tmpl (n .conf .TargetARN ))
186
- if * tmplErr != nil {
187
- return nil , notify .NewErrorWithReason (notify .ClientErrorReason , errors .Wrap (* tmplErr , "execute 'target_arn' template" ))
188
- }
189
173
}
190
174
191
- tmplMessage := tmpl (n .conf .Message )
192
- if * tmplErr != nil {
193
- return nil , notify .NewErrorWithReason (notify .ClientErrorReason , errors .Wrap (* tmplErr , "execute 'message' template" ))
194
- }
195
- messageToSend , isTrunc , err := validateAndTruncateMessage (tmplMessage , messageSizeLimit )
175
+ messageToSend , isTrunc , err := validateAndTruncateMessage (tmpl (n .conf .Message ), messageSizeLimit )
196
176
if err != nil {
197
177
return nil , err
198
178
}
@@ -206,9 +186,6 @@ func (n *Notifier) createPublishInput(ctx context.Context, tmpl func(string) str
206
186
207
187
if n .conf .Subject != "" {
208
188
publishInput .SetSubject (tmpl (n .conf .Subject ))
209
- if * tmplErr != nil {
210
- return nil , notify .NewErrorWithReason (notify .ClientErrorReason , errors .Wrap (* tmplErr , "execute 'subject' template" ))
211
- }
212
189
}
213
190
214
191
return publishInput , nil
0 commit comments