Home

Awesome

slack-notifier

Command line utility to send messages with attachments to Slack channels via Incoming Webhooks.

GitHub Commit Status

Usage

NOTE: The module accepts parameters as command-line arguments or as ENV variables (or any combination of command-line arguments and ENV vars). Command-line arguments take precedence over ENV vars.

NOTE: The module supports up to 8 Fields in an attachment

Command-line argumentENV varDescription
webhook_urlSLACK_WEBHOOK_URLSlack Webhook URL
user_nameSLACK_USER_NAMESlack user name (the username from which the messages will be sent)
icon_emojiSLACK_ICON_EMOJISlack icon emoji for the user's avatar
fallbackSLACK_FALLBACKA plain-text summary of the attachment. This text will be used in clients that don't show formatted text
colorSLACK_COLORAn optional value that can either be one of good, warning, danger, or a color code (e.g. #439FE0)
channelSLACK_CHANNELSlack channel to send to
threadSLACK_THREADSlack channel thread to send to
pretextSLACK_PRETEXTOptional text that appears above the message attachment block
author_nameSLACK_AUTHOR_NAMESmall text to display the attachment author's name
author_linkSLACK_AUTHOR_LINKURL that will hyperlink the author's name. Will only work if author_name is present
author_iconSLACK_AUTHOR_ICONURL of a small 16x16px image to the left of the author's name. Will only work if author_name is present
titleSLACK_TITLEThe title is displayed as larger, bold text near the top of a message attachment
title_linkSLACK_TITLE_LINKURL for the title text to be hyperlinked
textSLACK_TEXTMain text in a message attachment
thumb_urlSLACK_THUMB_URLURL to an image file that will be displayed as a thumbnail on the right side of a message attachment
footerSLACK_FOOTERBrief text to help contextualize and identify an attachment
footer_iconSLACK_FOOTER_ICONURL of a small icon beside the footer text
image_urlSLACK_IMAGE_URLURL to an image file that will be displayed inside a message attachment
field1_titleSLACK_FIELD1_TITLEField1 title
field1_valueSLACK_FIELD1_VALUEField1 value
field1_shortSLACK_FIELD1_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field2_titleSLACK_FIELD2_TITLEField2 title
field2_valueSLACK_FIELD2_VALUEField2 value
field2_shortSLACK_FIELD2_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field3_titleSLACK_FIELD3_TITLEField3 title
field3_valueSLACK_FIELD3_VALUEField3 value
field3_shortSLACK_FIELD3_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field4_titleSLACK_FIELD4_TITLEField4 title
field4_valueSLACK_FIELD4_VALUEField4 value
field4_shortSLACK_FIELD4_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field5_titleSLACK_FIELD5_TITLEField5 title
field5_valueSLACK_FIELD5_VALUEField5 value
field5_shortSLACK_FIELD5_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field6_titleSLACK_FIELD6_TITLEField6 title
field6_valueSLACK_FIELD6_VALUEField6 value
field6_shortSLACK_FIELD6_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field7_titleSLACK_FIELD7_TITLEField7 title
field7_valueSLACK_FIELD7_VALUEField7 value
field7_shortSLACK_FIELD7_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field8_titleSLACK_FIELD8_TITLEField8 title
field8_valueSLACK_FIELD8_VALUEField8 value
field8_shortSLACK_FIELD8_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field9_titleSLACK_FIELD9_TITLEField9 title
field9_valueSLACK_FIELD9_VALUEField9 value
field9_shortSLACK_FIELD9_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)
field10_titleSLACK_FIELD10_TITLEField10 title
field10_valueSLACK_FIELD10_VALUEField10 value
field10_shortSLACK_FIELD10_SHORTAn optional boolean indicating whether the value is short enough to be displayed side-by-side with other values (default false)

build the Go program locally

go get

CGO_ENABLED=0 go build -v -o "./dist/bin/slack-notifier" *.go

run locally with ENV vars

export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXX"
export SLACK_USER_NAME="CodeFresh"
export SLACK_ICON_EMOJI=":white_check_mark:"
export SLACK_FALLBACK="Deployed to Staging environment"
export SLACK_COLOR="good"
export SLACK_PRETEXT="Added XYZ to feature-104"
export SLACK_AUTHOR_NAME="Auto Deploy Robot"
export SLACK_AUTHOR_LINK="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/small-cute-robot-square.png"
export SLACK_AUTHOR_ICON="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/small-cute-robot-square.png"
export SLACK_TITLE="Environment Updated"
export SLACK_TITLE_LINK="http://demo1.cloudposse.com"
export SLACK_TEXT="The latest changes have been deployed"
export SLACK_THUMB_URL="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/SquareLogo2.png"
export SLACK_FOOTER="Helm Deployment"
export SLACK_FOOTER_ICON="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/kubernetes.png"
export SLACK_FIELD1_TITLE="Environment"
export SLACK_FIELD1_VALUE="Staging"
export SLACK_FIELD1_SHORT="true"
export SLACK_FIELD2_TITLE="Namespace"
export SLACK_FIELD2_VALUE="feature-104"
export SLACK_FIELD2_SHORT="true"

./dist/bin/slack-notifier

run locally with command-line arguments

./dist/bin/slack-notifier \
    -webhook_url "https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXX" \
    -user_name "CodeFresh" \
    -icon_emoji ":white_check_mark:" \
    -fallback "Deployed to Staging environment" \
    -color "good" \
    -pretext "Added XYZ to feature-104" \
    -author_name "Auto Deploy Robot" \
    -author_link "https://cloudposse.com/wp-content/uploads/sites/29/2018/02/small-cute-robot-square.png" \
    -author_icon "https://cloudposse.com/wp-content/uploads/sites/29/2018/02/small-cute-robot-square.png" \
    -title "Environment Updated" \
    -title_link "http://demo1.cloudposse.com" \
    -text "The latest changes have been deployed" \
    -thumb_url "https://cloudposse.com/wp-content/uploads/sites/29/2018/02/SquareLogo2.png" \
    -footer "Helm Deployment" \
    -footer_icon "https://cloudposse.com/wp-content/uploads/sites/29/2018/02/kubernetes.png" \
    -field1_title "Environment" \
    -field1_value "Staging" \
    -field1_short true \
    -field2_title "Namespace" \
    -field2_value "feature-104" \
    -field2_short true

build the Docker image

NOTE: it will download all Go dependencies and then build the program inside the container (see Dockerfile)

docker build --tag slack-notifier  --no-cache=true .

run in a Docker container with ENV vars

docker run -i --rm \
    -e SLACK_WEBHOOK_URL="https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXXXXXXXXXXXXX" \
    -e SLACK_USER_NAME="CodeFresh" \
    -e SLACK_ICON_EMOJI=":white_check_mark:" \
    -e SLACK_FALLBACK="Deployed to Staging environment" \
    -e SLACK_COLOR="good" \
    -e SLACK_PRETEXT="Added XYZ to feature-104" \
    -e SLACK_AUTHOR_NAME="Auto Deploy Robot" \
    -e SLACK_AUTHOR_LINK="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/small-cute-robot-square.png" \
    -e SLACK_AUTHOR_ICON="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/small-cute-robot-square.png" \
    -e SLACK_TITLE="Environment Updated" \
    -e SLACK_TITLE_LINK="http://demo1.cloudposse.com" \
    -e SLACK_TEXT="The latest changes have been deployed" \
    -e SLACK_THUMB_URL="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/SquareLogo2.png" \
    -e SLACK_FOOTER="Helm Deployment" \
    -e SLACK_FOOTER_ICON="https://cloudposse.com/wp-content/uploads/sites/29/2018/02/kubernetes.png" \
    -e SLACK_FIELD1_TITLE="Environment" \
    -e SLACK_FIELD1_VALUE="Staging" \
    -e SLACK_FIELD1_SHORT="true" \
    -e SLACK_FIELD2_TITLE="Namespace" \
    -e SLACK_FIELD2_VALUE="feature-104" \
    -e SLACK_FIELD2_SHORT="true" \
    slack-notifier

References

Help

Got a question?

File a GitHub issue, send us an email or reach out to us on Gitter.

Contributing

Bug Reports & Feature Requests

Please use the issue tracker to report any bugs or file feature requests.

Developing

If you are interested in being a contributor and want to get involved in developing slack-notifier, we would love to hear from you! Shoot us an email.

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

License

APACHE 2.0 © 2018 Cloud Posse, LLC

See LICENSE for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.

About

slack-notifier is maintained and funded by Cloud Posse, LLC.

Cloud Posse

Like it? Please let us know at hello@cloudposse.com

We love Open Source Software!

See our other projects or hire us to help build your next cloud platform.

Contributors

Erik Osterman<br/>Erik OstermanAndriy Knysh<br/>Andriy Knysh