Skip to content
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

TLS configuration for Slack service for Mattermost compatibility #1322

Merged
merged 1 commit into from
Apr 19, 2017

Conversation

seuf
Copy link
Contributor

@seuf seuf commented Apr 13, 2017

Hi,
Mattermost is compatible with slack messages json format so I've patched the slack services to add TLS configuration parameters.
Now alerts can be sent to self hosted Mattermost with custom certificates.

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated
  • Sign CLA (if not already signed)

@seuf seuf force-pushed the slack-tls-options branch 5 times, most recently from da4a899 to 8eb56fc Compare April 13, 2017 14:02
Copy link
Contributor

@nathanielc nathanielc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! It looks great. I have made a few comments suggestions below.

server/server.go Outdated
srv := slack.NewService(c, l)
srv, err := slack.NewService(c, l)
if err != nil {
s.Logger.Println("W! Slack init :", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go ahead and return the error here and check it in NewServer and return it from there. That will cause the server to print the error message and shutdown, which is the behavior we want.

tlsConfig, err := getTLSConfig(c.SSLCA, c.SSLCert, c.SSLKey, c.InsecureSkipVerify)
if err != nil {
return nil, err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a log warn here if the config specifies using InsecureSkipVerify?

s := &Service{
logger: l,
client: &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration can be changed at runtime via the API, there should be an Update method on the service which is in charge of applying new config changes. Can you update that method to allow for creating a new client when the TLS config changes. See the Alerta service for an example.

@seuf
Copy link
Contributor Author

seuf commented Apr 14, 2017

I've updated the pr to add all your requested changes. Is it good to you ?

@@ -99,7 +119,8 @@ func (s *Service) Alert(channel, message, username, iconEmoji string, level aler
if err != nil {
return err
}
resp, err := http.Post(url, "application/json", post)
s.logger.Println("D! Posting event to Slack", post)
resp, err := s.client.Post(url, "application/json", post)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line races with the lines in Update and New that assign to the client. Either add a mutex to the Sensu service or use the sync.Atomic type to synchronizes access to the client.

Other than that this looks good! Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum. I'm not a Go dev. This looks like a bit tricky for me.. O_ô
I will try to do this next tuesday when i go back to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seuf No worries, I can help you out too. The Alerta service does something similar if that helps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I have updated the PR to use atomic value for the http client like Alerta service.

@@ -99,7 +127,9 @@ func (s *Service) Alert(channel, message, username, iconEmoji string, level aler
if err != nil {
return err
}
resp, err := http.Post(url, "application/json", post)
s.logger.Println("D! Posting event to Slack", post)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this debug statement?

Copy link
Contributor

@nathanielc nathanielc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, once the extra log statement is removed.

Before I merge can you rebase/squash and update the CHANGELOG?

Thanks!

@seuf
Copy link
Contributor Author

seuf commented Apr 19, 2017

done

@nathanielc nathanielc merged commit be34a10 into influxdata:master Apr 19, 2017
nathanielc added a commit that referenced this pull request Apr 19, 2017
TLS configuration for Slack service for Mattermost compatibility
@nathanielc
Copy link
Contributor

@seuf Thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants