Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Slackboard / Slack proxy server in Go

Slackboard / Slack proxy server in Go

Slackboard - Slack proxy server in Go

5d74d743eabd2bf7d4d2f68b9d3c727d?s=128

Tatsuhiko Kubo

March 22, 2016
Tweet

Transcript

  1. Slackboard - Slack proxy server in Go Tatsuhiko Kubo@cubicdaiya Shibuya.go#2

    2016/03/22
  2. @cubicdaiya / Tatsuhiko Kubo Principal Engineer, SRE @ Mercari, Inc.

    ngx_small_light, ngx_dynamic_upstream, nginx-build, slackboard, cachectl, gaurun, widebullet, etc…
  3. nginxຊΛࣥච͠·ͨ͠ʢ2016/01/16ൃചʣ

  4. Slackboard

  5. Slackboard • Slack proxy server in Go • https://github.com/cubicdaiya/slackboard •

    Provides 3 commands • slackboard - proxy server daemon for Slack • slackboard-cli - client for slackboard • slackboard-log - client like cronlog for slackboard
  6. Install Slackboard go get -u github.com/cubicdaiya/slackboard/…

  7. Start Slackboard slackboard -c slackboard.toml

  8. Configuration for slackboard [core] # listen port port = “29800”

    # URL for Incoming Webhooks slack_url = “https://hooks.slack.com/services/…” [log] # access log path or redirector access_log = “stdout” # error log path or redirector error_log = “stderr” # log level level = “error” [ui] # document root for Web UI root = “/var/www/slackboard/ui”
  9. slackboard-cli $ echo mercari | \ slackboard-cli \ -c tech-test

    \ -s slackboard-server:29800 TMBDLCPBSE POST /notify-directly Post to Slack
  10. slackboard-log $ ls $ slackboard-log \ -c tech-test \ -s

    slackboard-server:29800 -- ls not found TMBDLCPBSE POST /notify-directly Post to Slack
  11. Slackboard APIs • POST /notify • POST /notify-directly • GET

    /stat/go • GET /config/app See slackboard/SPEC.md about details
  12. POST /notify { “tag”: “error-s3”, “title”: “failed: aws s3 cp

    …” “text”: “s3://bucket/path/to/xxx.log.gz”, “level”: “warn”, “sync”: false } [[tags]] tag = “error-s3” channel = “#alert-sre” user = “package” ▪ slackboard.toml ▪ request body ▪ posted message
  13. POST /notify-directly { “payload”: { “channel”: “random”, “username”: “slackboard”, “icon_emoji”:

    “:cloud:”, “text”: “:bow:”, “attachments”: […] }, “sync”: false } ▪ request body ▪ posted message
  14. Difference between /notify and /notify-directly • POST /notify • receives

    original payload • tag-based notification • POST /notify-directly • proxies payload to Slack directly • channel-based notification
  15. Asynchronous or synchronousʁ • slackboard proxies message to slack asynchronous

    by default • “sync”: false • slackboard returns 200 OK to client at once • “sync”: true • slackboard return 200 OK after posted message to Slack
  16. Attachments • Slack provides mechanism for rich-formatted message with Attachments

    • coloring, tiltling, authoring • embed image • long text • etc…
  17. Colorize message by POST /notify echo information | slackboard-cli -t

    test -s slackboard-server:29800 -l info echo warning | slackboard-cli -t test -s slackboard-server:29800 -l warn echo critical | slackboard-cli -t test -s slackboard-server:29800 -l crit TMBDLCPBSE POST /notify Post to Slack
  18. Colorize message by POST /notify-directly echo good | slackboard-cli -c

    random -s slackboard-server:29800 -C good echo bad | slackboard-cli -c random -s slackboard-server:29800 -C bad echo warning | slackboard-cli -c random -s slackboard-server:29800 -C warning TMBDLCPBSE POST /notify-directly Post to Slack
  19. Alerting to Slack

  20. Alerting to Slack with slackboard-cli # copy log file to

    Google Cloud Storage gsutil cp 2015-03-05T08.log.gz gs://${bucket}/ result=`echo $?` if [ $result -ne 0 ]; then echo "@channel: failed to copy log to GCS(2015-03-05T08)” | \ slackboard-cli -s slackboard-host:29800 -t error-gcs fi
  21. Alerting to Slack with slackboard-log # copy log file to

    Google Cloud Storage slackboard-log -s slackboard-host:29800 -t error-gcs -- \ gsutil cp 20150305T08.log.gz gs://${bucket}/
  22. fluent-plugin-slackboard https://github.com/cubicdaiya/fluent-plugin-slackboard gem install fluent-plugin-slackboard Alerting to Slack with Fluentd

  23. fluent-plugin-slackboard <match slackboard> # required type slackboard host 127.0.0.1 port

    29800 channel random fetch_key message # optional username slackboard icon_emoji :clipboard: parse full sync false </match> echo ‘{“message”: “bokko”}’ | \ fluent-cat slackboard TMBDLCPBSE qVFOUE
  24. By the way,

  25. Why is proxy server for Slack required? • Messages are

    posted from various servers • Where are messages posted from? • Messages are posted from various programs • Perl?Python?PHP?Ruby? or… Which library? • Different by engineer and team
  26. Slackboard’s approach • Aggregate messages to Slack and logs by

    • slackboard • Unify notification method by • slackboard-cli • slackboard-log
  27. In the case @

  28. Before

  29. It’s painfulʂ • Incoming Webhooks URL is staggled in various

    servers • What if URL is changed? • Each client program uses different language and libraries • (ϊ ʄДʄ)ϊ~~~ᵲᵲ
  30. Now

  31. Summary • Slackboard provides • Proxy server daemon for Slack

    • Client for slackboard • The goal of Slackboard • Aggregate messages to Slack • Unifies method for posting message to Slack
  32. We are hiring Go Engineer! https://www.mercari.com/jp/jobs/