Skip to content

Commit

Permalink
* Updated GitHub Actions: Added Lint action
Browse files Browse the repository at this point in the history
* Updated build to Go 1.14
* Added Secret: true to SMTP password
* Updated Bonsai to fix Windows amd64 build
* Added output log line for email sent
* Updated modules (go get -u && go mod tidy)
* README updates

Signed-off-by: Todd Campbell <todd@sensu.io>
  • Loading branch information
Todd Campbell committed Feb 4, 2021
1 parent b4cb4a5 commit 50c016f
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .bonsai.yml
Expand Up @@ -46,5 +46,5 @@ builds:
asset_filename: "#{repo}_#{version}_windows_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'darwin'"
- "entity.system.os == 'windows'"
- "entity.system.arch == 'amd64'"
16 changes: 16 additions & 0 deletions .github/workflows/lint.yml
@@ -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/test.yml
Expand Up @@ -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 ./...
29 changes: 11 additions & 18 deletions .goreleaser.yml
Expand Up @@ -4,14 +4,12 @@ builds:
env:
- CGO_ENABLED=0
main: main.go
ldflags: '-s -w -X github.com/sensu-community/sensu-plugin-sdk/version.version={{.Version}} -X github.com/sensu-community/sensu-plugin-sdk/version.commit={{.Commit}} -X github.com/sensu-community/sensu-plugin-sdk/version.date={{.Date}}'
# Set the binary output location to bin/ so archive will comply with Sensu Go Asset structure
binary: bin/{{ .ProjectName }}
goos:
- darwin
- freebsd
- linux
- netbsd
- solaris
- windows
goarch:
- amd64
Expand All @@ -22,14 +20,18 @@ builds:
- 5
- 6
- 7
ignore:
# TODO: add freebsd/arm support to gopsutil
- goos: freebsd
goarch: arm
targets:
- darwin_amd64
- linux_386
- linux_amd64
- linux_arm_5
- linux_arm_6
- linux_arm_7
- linux_arm64
- windows_386
- windows_amd64

checksum:
# You can change the name of the checksums file.
# Default is `{{ .ProjectName }}_{{ .Version }}_checksums.txt`.
name_template: "{{ .ProjectName }}_{{ .Version }}_sha512-checksums.txt"
algorithm: sha512

Expand All @@ -40,12 +42,3 @@ archives:
- LICENSE
- README.md
- CHANGELOG.md

# You can change the name of the GitHub release.
# This is parsed with the Go template engine and the following variables
# are available:
# - ProjectName
# - Tag
# - Version (Git tag without `v` prefix)
# Default is ``
#name_template: "{{.ProjectName}}-v{{.Version}}"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,14 @@ Versioning](http://semver.org/spec/v2.0.0.html).

### Changed
- More template information in the README
- Q1 '21 handler maintenance:
- Updated GitHub Actions: Added Lint action
- Updated build to Go 1.14
- Added Secret: true to SMTP password
- Updated Bonsai to fix Windows amd64 build
- Added output log line for email sent
- Updated modules (go get -u && go mod tidy)
- README updates

## [0.9.0] - 2020-10-30

Expand Down
134 changes: 82 additions & 52 deletions README.md
Expand Up @@ -3,14 +3,16 @@
# Sensu Email Handler
- [Overview](#overview)
- [Usage examples](#usage-examples)
- [Help output](#help-output)
- [Environment variables](#environment-variables)
- [Annotations](#annotations)
- [Templates](#templates)
- [Formatting Timestamps in Templates](#formatting-timestamps-in-templates)
- [Formatting the Event ID in Templates](#formatting-the-event-id-in-templates)
- [Configuration](#configuration)
- [Asset registration](#asset-registration)
- [Asset definition](#asset-definition)
- [Handler definition](#handler-definition)
- [Annotations](#annotations)
- [Templates](#templates)
- [Formatting Timestamps in Templates](#formatting-timestamps-in-templates)
- [Formatting the Event ID in Templates](#formatting-the-event-id-in-templates)
- [Debugging](#debugging)
- [Installing from source and contributing](#installing-from-source-and-contributing)

Expand All @@ -19,9 +21,9 @@
The Sensu Go Email Handler is a [Sensu Event Handler][2] for sending
incident notification emails.

## Usage Examples
## Usage examples

### Help
### Help output

```
The Sensu Email handler sends an email notifications
Expand All @@ -45,63 +47,33 @@ Flags:
-k, --tlsSkipVerify Do not verify TLS certificates
-t, --toEmail string The 'to' email address (accepts comma delimited and/or multiple flags)
```
## 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:
### Environment variables

`sensuctl asset add sensu/sensu-email-handler`

If you're using an earlier version of sensuctl, you can download the asset definition from [this project's Bonsai Asset Index page](https://bonsai.sensu.io/assets/sensu/sensu-email-handler).

### Asset definition

```yml
---
type: Asset
api_version: core/v2
metadata:
name: sensu-email-handler_linux_amd64
labels:
annotations:
io.sensu.bonsai.url: https://bonsai.sensu.io/assets/sensu/sensu-email-handler
io.sensu.bonsai.api_url: https://bonsai.sensu.io/api/v1/assets/sensu/sensu-email-handler
io.sensu.bonsai.tier: Supported
io.sensu.bonsai.version: 0.2.0
io.sensu.bonsai.namespace: sensu
io.sensu.bonsai.name: sensu-email-handler
io.sensu.bonsai.tags: handler
spec:
url: https://assets.bonsai.sensu.io/45eaac0851501a19475a94016a4f8f9688a280f6/sensu-email-handler_0.2.0_linux_amd64.tar.gz
sha512: d69df76612b74acd64aef8eed2ae10d985f6073f9b014c8115b7896ed86786128c20249fd370f30672bf9a11b041a99adb05e3a23342d3ad80d0c346ec23a946
filters:
- entity.system.os == 'linux'
- entity.system.arch == 'amd64'
```
|Argument |Environment Variable |
|---------------|---------------------|
|--smtpUsername |SMTP_USERNAME |
|--smtpPassword |SMTP_PASSWORD |

### Handler definition
**Security Note:** Care should be taken to not expose the password 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
---
api_version: core/v2
type: Handler
type: Secret
api_version: secrets/v1
metadata:
namespace: default
name: email
name: smtp_password
spec:
type: pipe
command: sensu-email-handler -f from@example.com -t to@example.com -t "to2@example.com, to3@example.com" -s smtp.example.com
-u user -p password
timeout: 10
filters:
- is_incident
- not_silenced
runtime_assets:
- sensu/sensu-email-handler
provider: env
id: SMTP_PASSWORD
```

### Annotations

All of the above command line arguments can be overridden by check or entity annotations.
The annotation consists of the key formed by appending the "long" argument specification
to the string sensu.io/plugins/email/config (e.g. sensu.io/plugins/email/config/toEmail).
Expand Down Expand Up @@ -210,6 +182,62 @@ below shows its use:
<b>Check Output</b>: {{.Check.Output}}
```

## 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-email-handler`

If you're using an earlier version of sensuctl, you can download the asset definition from [this project's Bonsai Asset Index page](https://bonsai.sensu.io/assets/sensu/sensu-email-handler).

### Asset definition

```yml
---
type: Asset
api_version: core/v2
metadata:
name: sensu-email-handler_linux_amd64
labels:
annotations:
io.sensu.bonsai.url: https://bonsai.sensu.io/assets/sensu/sensu-email-handler
io.sensu.bonsai.api_url: https://bonsai.sensu.io/api/v1/assets/sensu/sensu-email-handler
io.sensu.bonsai.tier: Supported
io.sensu.bonsai.version: 0.2.0
io.sensu.bonsai.namespace: sensu
io.sensu.bonsai.name: sensu-email-handler
io.sensu.bonsai.tags: handler
spec:
url: https://assets.bonsai.sensu.io/45eaac0851501a19475a94016a4f8f9688a280f6/sensu-email-handler_0.2.0_linux_amd64.tar.gz
sha512: d69df76612b74acd64aef8eed2ae10d985f6073f9b014c8115b7896ed86786128c20249fd370f30672bf9a11b041a99adb05e3a23342d3ad80d0c346ec23a946
filters:
- entity.system.os == 'linux'
- entity.system.arch == 'amd64'
```

### Handler definition

```yml
---
api_version: core/v2
type: Handler
metadata:
namespace: default
name: email
spec:
type: pipe
command: sensu-email-handler -f from@example.com -t to@example.com -t "to2@example.com, to3@example.com" -s smtp.example.com
-u user -p password
timeout: 10
filters:
- is_incident
- not_silenced
runtime_assets:
- sensu/sensu-email-handler
```

## Debugging

It can be helpful to run from the command line to debug issues such as authentication. For this you will need two things. First you'll need to have the sensu-email-handler binary and sensuctl utility available locally. Second you will need a JSON representation of a Sensu event. You can obtain the JSON event representation using the sensuctl commandline utility. Here is a generalized example you can use to test with:
Expand Down Expand Up @@ -240,3 +268,5 @@ For additional instructions, see [CONTRIBUTING](https://github.com/sensu/sensu-g
[4]: https://golang.org/pkg/time/#Time.Format
[5]: https://yourbasic.org/golang/format-parse-string-time-date-example/
[6]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-process/handler-templates/
[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
33 changes: 25 additions & 8 deletions go.mod
@@ -1,16 +1,33 @@
module github.com/sensu/sensu-email-handler

go 1.13
go 1.14

require (
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/sensu-community/sensu-plugin-sdk v0.10.1
github.com/sensu/sensu-go/api/core/v2 v2.3.0
github.com/spf13/afero v1.2.2 // indirect
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
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-20200114155413-6afb5195e5aa // indirect
golang.org/x/sys v0.0.0-20200120151820-655fe14d7479 // indirect
gopkg.in/ini.v1 v1.51.1 // indirect
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-20210203152818-3206188e46ba // 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
)

0 comments on commit 50c016f

Please sign in to comment.