Skip to content

sliide/sensu-slack-handler

 
 

Repository files navigation

Bonsai Asset Badge Build Status

Sensu Slack Handler

Overview

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

Usage examples

Help:

Usage:
  sensu-slack-handler [flags]
  sensu-slack-handler [command]

Available Commands:
  help        Help about any command
  version     Print the version number of this plugin

Flags:
  -c, --channel string                The channel to post messages to (default "#general")
  -t, --description-template string   The Slack notification output template, in Golang text/template format (default "{{ .Check.Output }}")
  -h, --help                          help for sensu-slack-handler
  -i, --icon-url string               A URL to an image to use as the user avatar (default "https://www.sensu.io/img/sensu-logo.png")
  -u, --username string               The username that messages will be sent as (default "sensu")
  -w, --webhook-url string            The webhook url to send messages to

Configuration

Asset registration

Assets are the best way to make use of this handler. If you're not using an asset, please consider doing so! If you're using sensuctl 5.13 or later, you can use the following command to add the asset:

sensuctl asset add sensu/sensu-slack-handler

If you're using an earlier version of sensuctl, you can download the asset definition from this project's Bonsai Asset Index page.

Handler definition

Create the handler using the following handler definition:

---
api_version: core/v2
type: Handler
metadata:
  namespace: default
  name: slack
spec:
  type: pipe
  command: sensu-slack-handler --channel '#general' --username 'sensu'
  filters:
  - is_incident
  runtime_assets:
  - sensu/sensu-slack-handler
  secrets:
  - name: SLACK_WEBHOOK_URL
    secret: slack-webhook-url
  timeout: 10

Security Note: The Slack webhook URL should always be treated as a security sensitive configuration option and in this example, it is loaded into the handler configuration as an environment variable using a secret. 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.

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

Customizing configuration options via checks and entities

All configuration options of this handler can be overridden via the annotations of checks and entities. For example, to customize the channel for a given entity, you could use the following sensu-agent configuration snippet:

# /etc/sensu/agent.yml example
annotations:
  sensu.io/plugins/slack/config/channel: '#monitoring'

Proxy Support

This handler supports the use of the environment variables HTTP_PROXY, HTTPS_PROXY, and NO_PROXY (or the lowercase versions thereof). HTTPS_PROXY takes precedence over HTTP_PROXY for https requests. The environment values may be either a complete URL or a "host[:port]", in which case the "http" scheme is assumed.

Installing from source and contributing

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

Compiling

From the local path of the sensu-slack-handler repository:

go build

To contribute to this plugin, see CONTRIBUTING

About

The Sensu Go Slack handler for notifying a channel.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.9%
  • Shell 1.1%