$30 off During Our Annual Pro Sale. View Details »

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. Slackboard - Slack proxy server in Go
    Tatsuhiko Kubo@cubicdaiya
    Shibuya.go#2 2016/03/22

    View Slide

  2. @cubicdaiya / Tatsuhiko Kubo
    Principal Engineer, SRE @ Mercari, Inc.
    ngx_small_light, ngx_dynamic_upstream,
    nginx-build, slackboard, cachectl, gaurun, widebullet, etc…

    View Slide

  3. nginxຊΛࣥච͠·ͨ͠ʢ2016/01/16ൃചʣ

    View Slide

  4. Slackboard

    View Slide

  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

    View Slide

  6. Install Slackboard
    go get -u github.com/cubicdaiya/slackboard/…

    View Slide

  7. Start Slackboard
    slackboard -c slackboard.toml

    View Slide

  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”

    View Slide

  9. slackboard-cli
    $ echo mercari | \
    slackboard-cli \
    -c tech-test \
    -s slackboard-server:29800
    TMBDLCPBSE
    POST /notify-directly
    Post to Slack

    View Slide

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

    View Slide

  11. Slackboard APIs
    • POST /notify
    • POST /notify-directly
    • GET /stat/go
    • GET /config/app
    See slackboard/SPEC.md about details

    View Slide

  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

    View Slide

  13. POST /notify-directly
    {
    “payload”: {
    “channel”: “random”,
    “username”: “slackboard”,
    “icon_emoji”: “:cloud:”,
    “text”: “:bow:”,
    “attachments”: […]
    },
    “sync”: false
    }
    ■ request body ■ posted message

    View Slide

  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

    View Slide

  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

    View Slide

  16. Attachments
    • Slack provides mechanism for rich-formatted
    message with Attachments
    • coloring, tiltling, authoring
    • embed image
    • long text
    • etc…

    View Slide

  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

    View Slide

  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

    View Slide

  19. Alerting to Slack

    View Slide

  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

    View Slide

  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}/

    View Slide

  22. fluent-plugin-slackboard
    https://github.com/cubicdaiya/fluent-plugin-slackboard
    gem install fluent-plugin-slackboard
    Alerting to Slack with Fluentd

    View Slide

  23. fluent-plugin-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

    echo ‘{“message”: “bokko”}’ | \
    fluent-cat slackboard
    TMBDLCPBSE
    qVFOUE

    View Slide

  24. By the way,

    View Slide

  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

    View Slide

  26. Slackboard’s approach
    • Aggregate messages to Slack and logs by
    • slackboard
    • Unify notification method by
    • slackboard-cli
    • slackboard-log

    View Slide

  27. In the case @

    View Slide

  28. Before

    View Slide

  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
    • (ϊ ʄДʄ)ϊ~~~ᵲᵲ

    View Slide

  30. Now

    View Slide

  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

    View Slide

  32. We are hiring
    Go Engineer!
    https://www.mercari.com/jp/jobs/

    View Slide