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

Tatsuhiko Kubo

March 22, 2016
Tweet

More Decks by Tatsuhiko Kubo

Other Decks in Technology

Transcript

  1. @cubicdaiya / Tatsuhiko Kubo Principal Engineer, SRE @ Mercari, Inc.

    ngx_small_light, ngx_dynamic_upstream, nginx-build, slackboard, cachectl, gaurun, widebullet, etc…
  2. 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
  3. 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”
  4. slackboard-cli $ echo mercari | \ slackboard-cli \ -c tech-test

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

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

    /stat/go • GET /config/app See slackboard/SPEC.md about details
  7. 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
  8. POST /notify-directly { “payload”: { “channel”: “random”, “username”: “slackboard”, “icon_emoji”:

    “:cloud:”, “text”: “:bow:”, “attachments”: […] }, “sync”: false } ▪ request body ▪ posted message
  9. 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
  10. 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
  11. Attachments • Slack provides mechanism for rich-formatted message with Attachments

    • coloring, tiltling, authoring • embed image • long text • etc…
  12. 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
  13. 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
  14. 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
  15. 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}/
  16. 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
  17. 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
  18. Slackboard’s approach • Aggregate messages to Slack and logs by

    • slackboard • Unify notification method by • slackboard-cli • slackboard-log
  19. It’s painfulʂ • Incoming Webhooks URL is staggled in various

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

  21. 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