-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
adds name, value, SlackConfirmationField to slack action #1557
Conversation
b63cf76
to
b3e5e16
Compare
Hmm, I'm definitely baffled by the lack of consistency in the Stack documentation. https://api.slack.com/docs/interactive-message-field-guide#action_fields says that @stuartnelson3 any thoughts on this? |
I agree the slack API is quite confusing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need to add a test to notifiers_test.go
similar to
alertmanager/config/notifiers_test.go
Line 325 in 3558e6f
func TestSlackFieldConfigValidation(t *testing.T) { |
config/notifiers.go
Outdated
@@ -252,9 +255,13 @@ func (c *SlackAction) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||
if c.Text == "" { | |||
return fmt.Errorf("missing value in Slack text configuration") | |||
} | |||
if c.URL == "" { | |||
// either URL or Name and Value need to be provided | |||
if c.URL != "" && c.Name != "" && c.Value != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on your last comment, the code should be:
if c.URL == "" && c.Name == "" {
return fmt.Errorf("missing 'name' or 'url' in Slack action configuration")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right. adjusted
config/notifiers.go
Outdated
@@ -252,9 +255,13 @@ func (c *SlackAction) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||
if c.Text == "" { | |||
return fmt.Errorf("missing value in Slack text configuration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with L250, this should read "missing 'text' in Slack action configuration"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
1ebb855
to
56c79a0
Compare
Done @simonpasquier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort! You would need to extend the unit tests too, see there:
alertmanager/config/notifiers_test.go
Line 325 in 30aae38
func TestSlackFieldConfigValidation(t *testing.T) { |
config/notifiers.go
Outdated
@@ -232,12 +232,16 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error | |||
|
|||
// SlackAction configures a single Slack action that is sent with each notification. | |||
// Each action must contain a type, text, and url. | |||
// See https://api.slack.com/docs/message-attachments#action_fields for more information. | |||
// See https://api.slack.com/docs/message-attachments#action_fields and https://api.slack.com/docs/message-buttons | |||
// for more information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) missing dot at the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added dot
config/notifiers.go
Outdated
} | ||
if c.URL == "" { | ||
return fmt.Errorf("missing value in Slack url configuration") | ||
// either URL or Name and Value need to be provided |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing dot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added dot
config/notifiers.go
Outdated
} | ||
if (c.Name == "" || c.Value == "") && c.URL == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure that it is the correct approach: AFAIU value
isn't mandatory. Also what happens if the configuration defines url
and name
at the same time? What is the result in Slack?
Maybe do something like this instead?
if c.URL != "" {
// Clear all message action fields.
c.Name = ""
c.Value = ""
c.ConfirmField = nil
} else if c.Name != "" {
c.URL = ""
} else {
return fmt.Errorf("missing name or url in Slack action configuration")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using both url, name seems to be no error to slack. However, your approach ensures we're not having both as per API spec. Using that
config/notifiers.go
Outdated
DismissText string `yaml:"dismiss_text,omitempty" json:"dismiss_text,omitempty"` | ||
} | ||
|
||
// UnmarshalYAML implements the yaml.Unmarshaler interface for SlackConfirmationField |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing dot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dotted
Also extended tests. LGTY @simonpasquier? |
Anything else that needs to be done @simonpasquier? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConfirmField
is declared in the configuration but not used by the receiver AFAICT
config/notifiers.go
Outdated
@@ -250,10 +254,39 @@ func (c *SlackAction) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||
return fmt.Errorf("missing type in Slack action configuration") | |||
} | |||
if c.Text == "" { | |||
return fmt.Errorf("missing value in Slack text configuration") | |||
return fmt.Errorf("missing text value in Slack text configuration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"missing text in Slack action configuration"
config/notifiers.go
Outdated
return err | ||
} | ||
if c.Text == "" { | ||
return fmt.Errorf("missing text in slack action confirm") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"missing text in slack configuration configuration"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM though SlackConfirmationField
fields could be templated too for consistency.
uses |
Thanks a lot for all the helpful guidance! |
Thanks for your patience @auhlig. I'll give it a try as I happen to have access to a Slack instance... |
notify/impl.go
Outdated
@@ -747,6 +747,14 @@ func (n *Slack) Notify(ctx context.Context, as ...*types.Alert) (bool, error) { | |||
Text: tmplText(action.Text), | |||
URL: tmplText(action.URL), | |||
Style: tmplText(action.Style), | |||
Name: tmplText(action.Name), | |||
Value: tmplText(action.Value), | |||
ConfirmField: &config.SlackConfirmationField{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to test if action.ConfirmField
is nil otherwise it will panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Added check and opened PR for docs @simonpasquier |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
c073c3c
to
8a4f363
Compare
Rebased after conflicts. Did slack attachments ever work @simonpasquier? While trying this I slack told me the |
1e7a462
to
ac52517
Compare
ac52517
to
f61c50d
Compare
Not sure why (only) travis complains. Do I need to run |
Tested with slack. Works for me (TM). |
Tested with slack. Works for me (TM). |
1 similar comment
Tested with slack. Works for me (TM). |
They surely did. TBH Slack is terrible at dealing with backward compatibility: things that used to work at time T may break at time T+N for some users and continue to work for the others. I wouldn't include f61c50d in this PR as it is unrelated. If it is broken with the current |
db2cdc3
to
958197a
Compare
Ewww slack -.- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last nit and this is ok for me.
config/notifiers.go
Outdated
@@ -247,12 +247,16 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error | |||
|
|||
// SlackAction configures a single Slack action that is sent with each notification. | |||
// Each action must contain a type, text, and url. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah the comment is outdated. Just remove it please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's gone
Signed-off-by: Arno Uhlig <arno.uhlig@sap.com>
👍 cc @mxinden @stuartnelson3 |
Not pushing. Just want to know whether anything else needs to be done to get this merged? @mxinden @stuartnelson3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution and bearing with us!
Yes thanks for the work @auhlig. That was more involved than expected! |
Thanks guys ❤️ |
Fixes #1556. Either
URL
orName
andValue
need to be provided in slack action. LGTY @simonpasquier? Thanks in advance