Giter Club home page Giter Club logo

slacktee's Introduction

slacktee

slacktee is a bash script that works like tee command. Instead of writing the standard input to files, slacktee posts it to Slack.

Requirements

slacktee uses curl command to communicate with Slack.

Installation

Please execute install.sh as shown below:

bash ./install.sh

install.sh copies slacktee.sh to /usr/local/bin and sets executable permission. After the installation, interactive setup starts automatically.

Configuration

Before start using slacktee, please set following variables in the script configuration file. slacktee reads the global configuration (/etc/slacktee.conf) first, then reads your local configuration (~/.slacktee). You can set up your local configuration file using interactive setup mode (--setup option).

For more details about tokens, visit Slack's API page.

webhook_url=""      # Incoming Webhooks integration URL. See https://my.slack.com/services/new/incoming-webhook
upload_token=""     # The user's API authentication token, only used for file uploads. See https://api.slack.com/#auth
channel=""          # Default channel to post messages. You don't have to add '#'.
tmp_dir="/tmp"      # Temporary file is created in this directory.
username="slacktee" # Default username to post messages.
icon="ghost"        # Default emoji to post messages. You don't have to wrap it with ':'. See http://www.emoji-cheat-sheet.com.

Usage

Feed input to slacktee through the pipe.

usage: slacktee.sh [options]
  options:
    -h, --help                        Show this help.
    -n, --no-buffering                Post input values without buffering.
    -f, --file                        Post input values as a file.
    -l, --link                        Add a URL link to the message.
    -c, --channel channel_name        Post input values to this channel.
    -u, --username user_name          This username is used for posting.
    -i, --icon emoji_name             This icon is used for posting.
    -t, --title title_string          This title is added to posts.
    -m, --message-formatting format   Switch message formatting (none|link_names|full).
                                      See https://api.slack.com/docs/formatting for more details.
    -p, --plain-text                  Don't surround the post with triple backticks.
    --setup                           Set up .slacktee file interactively.

If you'd like to post the output of ls command, you can do it like this.

ls | slacktee.sh

To post the output of tail -f command line by line, use -n option.

tail -f foobar.log | slacktee.sh -n

To post the output of find command as a file, use -f option.

find /var -name "foobar" | slacktee.sh -f

You can specify channel, username, icon, title, and link too.

ls | slacktee.sh -c "general" -u "slacktee" -i "shipit" -t "ls" -l "http://en.wikipedia.org/wiki/Ls"

Of course, you can connect another command with pipe.

ls | slacktee.sh | email "ls" [email protected]

Travis-CI Integration

You may want to integrate slacktee into Travis-CI in order to send additional logging information to your Slack channel. In this case, it is recommended that you do not expose your Incoming WebHook URL and API authentication token as plaintext values inside your slacktee.conf file.

Instead, use the encrypt command of the Travis client to set the SLACKTEE_WEBHOOK and SLACKTEE_TOKEN environment variables, and leave the webhook_url and upload_token values in your slacktee.conf empty. When slacktee runs, it will give priority to the environment variables, which Travis-CI will decrypt and set automatically during the build process. In this way those two values are kept secure.

Example

Modify slacktee.conf

webhook_url=""
upload_token=""
channel="Travis-CI"
tmp_dir="/tmp"
username="slacktee"
icon="ghost"

Add the encrypted environment variables to the .travis.yml file in your git repository

travis encrypt SLACKTEE_WEBHOOK='https://hooks.slack.com/services/afternoonTEE/BMP2vsT72/ohNoDontTellUs' --add
travis encrypt SLACKTEE_TOKEN='yoho-0987654321-1234567890-4488116622-abc123' --add

Looking at your travis.yml you will now see the following added

env:
  global:
  - secure: 2YZabH8+UdzqyBWckojRDP9uudnCSYyxOOx1y85el69YdHwLDMD+dt49rAgIrmCWsWCWpUZ0ZRWV8vU2VFMffIhmikiqG7VoKHuN5PyY8qBwr9hq/ZI8gdwgjgfRIGtv/U89BTjMmc1g/6nJkSvMtiSUSK3Lopg0JCyuZsiyhzs=
  - secure: TKpohmywdOneQkqGxJiF+S1N8oCdTWWGsXgjzNXWSvb23KDtvGq/W2SpWdFdwEHC9Y8NymoAPYRSW8MUQoiJ7NaQ1eZQuyx6/orjHpIgqiAuHrOSaMagzpKVG6Gtb87qDgov65ZOasyex1OtPQdfFtZBX67B6IVXkRPV+IA/+UX=

An example travis.yml section using slacktee may look like:

after_failure:
- ls /path/to/build | ./slacktee.sh -t "$TRAVIS_REPO_SLUG $TRAVIS_JOB_NUMBER build directory"
- cat /path/to/some.log | ./slacktee.sh -t "$TRAVIS_REPO_SLUG $TRAVIS_JOB_NUMBER some.log"

slacktee's People

Contributors

chikashi-kato avatar samskiter avatar rbotzer avatar

Watchers

Marcel Krcah avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.