Skip to content
The Sensu Go Slack handler for notifying a channel.
Go Shell
Branch: master
Clone or download
Latest commit 249ed50 Jun 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
testing refactored to eliminate use of reflect, per suggestions from @echlebek! Feb 6, 2019
.bonsai.yml Add .bonsai.yml Jan 3, 2019
.gitignore Removes redundant files, updates travis post deploy script, updates l… Jan 9, 2019
.goreleaser.yml Removes redundant files, updates travis post deploy script, updates l… Jan 9, 2019
.travis.yml Change how Travis setups and runs goreleaser (#15) Feb 25, 2019
CHANGELOG.md Removes redundant files, updates travis post deploy script, updates l… Jan 9, 2019
Gopkg.lock Changes based on review comments: May 25, 2019
Gopkg.toml Adding direct dependency on github.com/sensu/sensu-go library Jun 8, 2019
LICENSE Removes redundant files, updates travis post deploy script, updates l… Jan 9, 2019
README.md grammar fix Jan 5, 2019
build.sh
main.go Changes based on review comments: May 25, 2019
main_test.go Changes based on review comments: May 25, 2019

README.md

Sensu Go Slack Handler

The Sensu Slack handler is a Sensu Event Handler that sends event data to a configured Slack channel.

Installation

Download the latest version of the sensu-slack-handler from releases, or create an executable script from this source.

From the local path of the slack-handler repository:

go build -o /usr/local/bin/sensu-slack-handler main.go

Configuration

Example Sensu Go handler definition:

slack-handler.json

{
    "api_version": "core/v2",
    "type": "Handler",
    "metadata": {
        "namespace": "default",
        "name": "slack"
    },
    "spec": {
        "type": "pipe",
        "command": "sensu-slack-handler --channel '#general' --timeout 20 --username 'sensu' ",
        "env_vars": [
            "SLACK_WEBHOOK_URL=https://www.webhook-url-for-slack.com"
        ],

        "timeout": 30,
        "filters": [
            "is_incident"
        ]
    }
}

sensuctl create -f slack-handler.json

Example Sensu Go check definition:

{
    "api_version": "core/v2",
    "type": "CheckConfig",
    "metadata": {
        "namespace": "default",
        "name": "dummy-app-healthz"
    },
    "spec": {
        "command": "check-http -u http://localhost:8080/healthz",
        "subscriptions":[
            "dummy"
        ],
        "publish": true,
        "interval": 10,
        "handlers": [
            "slack"
        ]
    }
}

Security Note: The Slack webhook url is treated as a security sensitive configuration option in this example and is loaded into the handler config as an env_var instead of as a command argument. Command arguments are commonly readable from the process table by other unprivaledged users on a system (ex: ps and top commands), so it's a better practise to read in sensitive information via environment variables or configuration files on disk. The --webhook-url flag is provided as an override for testing purposes.

Usage examples

Help:

The Sensu Go Slack handler for notifying a channel

Usage:
  sensu-slack-handler [flags]

Flags:
  -c, --channel string       The channel to post messages to (default "#general")
  -h, --help                 help for handler-slack
  -i, --icon-url string      A URL to an image to use as the user avatar (default "http://s3-us-west-2.amazonaws.com/sensuapp.org/sensu.png")
  -t, --timeout int          The amount of seconds to wait before terminating the handler (default 10)
  -u, --username string      The username that messages will be sent as (default "sensu")
  -w, --webhook-url string   The webhook url to send messages to, defaults to value of SLACK_WEBHOOK_URL env variable
You can’t perform that action at this time.