Select Supported Platforms

Select Supported Architectures

Select Tier

Github Name


v0.1.0 · public · Published over 2 years ago

README
Asset Definition
Release Notes
Release Assets

Compact Sensu Slack Handler

This is a Sensu handler for sending messages to Slack.

It's written in Python and uses the
jspaleta/sensu-python-runtime runtime in Sensu Go.

While Sensu provides a Slack handler,
its messages take up too much space. This handler intends to be more condensed and provide more useful information.

Emojis are used to indicate the status and the output is typically a single line:

Screenshot showing Slack output

Optionally, checks that have a URL in its command can provide a link in the
Slack message:

Screenshot showing link to url in check command

Usage

Provide a Sensu handler configuration:

See the example handler config.

This uses the deprecated Slack incoming webhooks because it makes it easy to
send notices to any (private or open) channel specified without having to run a
bot or join channels.

Environment variables

Environment variables can be set for certain configurations, including in a check configuration.

  • SLACK_WEBHOOK_URL: A legacy Slack webhook URL
  • SLACK_USERNAME: The username to send the message as
  • SLACK_CHANNEL: The Slack channel to send to or a fallback channel.
    Labels and annotations take precedence.
  • ICON_URL: A URL to an icon image to use for the Slack user
  • SENSU_BASE_URL: The base URL to the Sensu dashboard to link to. E.g. https://sensu.foo.org

Labels and Annotations

  • slack_link_command_url: Toggles linking to a URL found in the check output.

Slack channels can be configured using a label or annotation. In order of precedence:

  • slack_channel: annotation on entity
  • slack-channel: annotation on entity
  • slack_channel: label on entity
  • slack-channel: label on entity

Build and Deploy

The src/ directory structure is setup for Sensu to function properly. This is done according to the sensu-python-runtime example.

The dependencies are installed to a lib/ sub-directory via pip install -r requirements.txt --target lib. The entire directory is then compressed and uploaded to Artifactory.

cd src
pip install -r requirements.txt --target lib
tar -cvzf ../sensu-slack-alert.tar.gz .
shasum -a 512 sensu-slack-alert.tar.gz

Finally, a handler configuration is created to use the handler.

NOTE: This uses the legacy Slack webhooks
because it's much simpler and possible to send messages to any channel, including private ones.

Resources

Token substitution
is not available in handler configurations due to security concerns (e.g. having a generic web check with the url as
a variable set by an annotation or label), which is why this
handler parses those annotations and labels directly.

See https://github.com/sensu/sensu-go/issues/2528 for more information.

Authors

Are you sure you want to report this asset?

Please describe the reason for reporting this asset. Our moderators will be notified and will disable the asset if it is found to be inappropriate.

×

You must be signed in to report this asset.

Sign In with Github

Download

×

Either download the source code:

Download Source

Or download the asset definition: