Skip to content

Commit

Permalink
- Q1 '21 handler maintenance:
Browse files Browse the repository at this point in the history
  - Updated modules (go get -u && go mod tidy)
  - Updated GitHub Actions: Added Lint action
  - Updated build to Go 1.14
  - Fix linter error by having template error go to stdout
  - Change return from sendMessage to capture and embellish any error
  - Output log message that message was sent to Slack
  - Fix TestSendMessage to include template
  - README updates

Signed-off-by: Todd Campbell <todd@sensu.io>
  • Loading branch information
Todd Campbell committed Feb 4, 2021
1 parent af64ac1 commit a1181d9
Show file tree
Hide file tree
Showing 10 changed files with 252 additions and 157 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Go Lint

on: [push, pull_request]

jobs:
test:
name: Lint
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
go-version: 1.14.x
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Go Test

on: [push]
on: [push, pull_request]

jobs:
test:
Expand All @@ -12,10 +12,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go 1.13
- name: Set up Go 1.14
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.14
id: go
- name: Test
run: go test -v ./...
run: go test -v ./...
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
sensu-slack-handler

# Test binary, build with `go test -c`
*.test
Expand All @@ -16,4 +17,4 @@ vendor/

# deploy
bonsai/
dist/
dist/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Versioning](http://semver.org/spec/v2.0.0.html).
### Changed
- Update to use plugin sdk 0.8.0
- Mark --webhook-url argument as secret, so if set via SLACK_WEBHOOK_URL, value will not leak into usage message.
- Q1 '21 handler maintenance:
- Updated modules (go get -u && go mod tidy)
- Updated GitHub Actions: Added Lint action
- Updated build to Go 1.14
- Fix linter error by having template error go to stdout
- Change return from sendMessage to capture and embellish any error
- Output log message that message was sent to Slack
- Fix TestSendMessage to include template
- README updates

## [1.3.2] - 2020-05-18

Expand Down
83 changes: 68 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

- [Overview](#overview)
- [Usage examples](#usage-examples)
- [Help output](#help-output)
- [Environment variables](#environment-variables)
- [Templates](#templates)
- [Annotations](#annotations)
- [Configuration](#configuration)
- [Asset registration](#asset-registration)
- [Handler definition](#handler-definition)
- [Check definition](#check-definition)
- [Installation from source and
contributing](#installation-from-source-and-contributing)
- [Installation from source and contributing](#installation-from-source-and-contributing)

## Overview

Expand All @@ -19,6 +22,8 @@ to a configured Slack channel.

## Usage examples

### Help output

Help:

```
Expand All @@ -39,6 +44,63 @@ Flags:
-w, --webhook-url string The webhook url to send messages to
```

### Environment variables

|Argument |Environment Variable |
|-----------------------|---------------------------|
|--webhook-url |SLACK_WEBHOOK_URL |
|--channel |SLACK_CHANNEL |
|--username |SLACK_USERNAME |
|--icon-url |SLACK_ICON_URL |
|--description-template |SLACK_DESCRIPTION_TEMPLATE |


**Security Note:** Care should be taken to not expose the webhook URL for this handler by specifying it
on the command line or by directly setting the environment variable in the handler definition. It is
suggested to make use of [secrets management][7] to surface it as an environment variable. The
handler definition above references it as a secret. Below is an example secrets definition that make
use of the built-in [env secrets provider][8].

```yml
---
type: Secret
api_version: secrets/v1
metadata:
name: slack-webhook-url
spec:
provider: env
id: SLACK_WEBHOOK_URL
```
### Templates
This handler provides options for using templates to populate the values
provided by the event in the message sent via SNS. More information on
template syntax and format can be found in [the documentation][9]
### Annotations
All arguments for this handler are tunable on a per entity or check basis based
on annotations. The annotations keyspace for this handler is
`sensu.io/plugins/slack/config`.

**NOTE**: Due to [check token substituion][9], supplying a template value such
as for `description-template` as a check annotation requires that you place the
desired template as a [golang string literal][10] (enlcosed in backticks)
within another template definition. This does not apply to entity annotations.

#### Examples

To customize the channel for a given entity, you could use the following
sensu-agent configuration snippet:

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

## Configuration

### Asset registration
Expand Down Expand Up @@ -101,18 +163,6 @@ spec:
- 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:
```yml
# /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,
Expand All @@ -123,7 +173,7 @@ either a complete URL or a "host[:port]", in which case the "http" scheme is ass
## Installing from source and contributing
Download the latest version of the sensu-slack-handler from [releases][4],
or create an executable script from this source.
or create an executable from this source.
### Compiling
Expand All @@ -140,3 +190,6 @@ To contribute to this plugin, see [CONTRIBUTING](https://github.com/sensu/sensu-
[4]: https://github.com/sensu/sensu-slack-handler/releases
[5]: https://docs.sensu.io/sensu-go/latest/reference/secrets/
[6]: https://bonsai.sensu.io/assets/sensu/sensu-slack-handler
[7]: https://docs.sensu.io/sensu-go/latest/guides/secrets-management/
[8]: https://docs.sensu.io/sensu-go/latest/guides/secrets-management/#use-env-for-secrets-management
[9]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-process/handler-templates/
30 changes: 27 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
module github.com/sensu/sensu-slack-handler

go 1.13
go 1.14

require (
github.com/bluele/slack v0.0.0-20180528010058-b4b4d354a079
github.com/sensu-community/sensu-plugin-sdk v0.8.0
github.com/sensu/sensu-go/api/core/v2 v2.2.3
github.com/coreos/etcd v3.3.25+incompatible // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/json-iterator/go v1.1.10 // indirect
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/robertkrimen/otto v0.0.0-20200922221731-ef014fd054ac // indirect
github.com/sensu-community/sensu-plugin-sdk v0.11.0
github.com/sensu/sensu-go/api/core/v2 v2.6.0
github.com/sensu/sensu-go/types v0.5.0 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/spf13/afero v1.5.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.1.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.1 // indirect
github.com/stretchr/testify v1.6.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
golang.org/x/text v0.3.5 // indirect
google.golang.org/genproto v0.0.0-20210204154452-deb828366460 // indirect
google.golang.org/grpc v1.35.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit a1181d9

Please sign in to comment.