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
  * Output log message from sending event to PagerDuty
  * README updates

Signed-off-by: Todd Campbell <todd@sensu.io>
  • Loading branch information
Todd Campbell committed Feb 11, 2021
1 parent 5d1e674 commit e691507
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 52 deletions.
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/release.yml
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
@@ -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 ./...
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,12 @@ Versioning](http://semver.org/spec/v2.0.0.html).

### Changed
- Updated README for specifying templates in check annotations
- Q1 '21 handler maintenance:
- Updated modules (go get -u && go mod tidy)
- Updated GitHub Actions: Added Lint action
- Updated build to Go 1.14
- Output log message from sending event to PagerDuty
- README updates

## 2.1.0 - 2020-10-29

Expand Down
51 changes: 31 additions & 20 deletions README.md
@@ -1,5 +1,3 @@
# Sensu PagerDuty Handler

[![Bonsai Asset Badge](https://img.shields.io/badge/Sensu%20PagerDuty%20Handler-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/sensu/sensu-pagerduty-handler)
![Go Test](https://github.com/sensu/sensu-pagerduty-handler/workflows/Go%20Test/badge.svg)
![goreleaser](https://github.com/sensu/sensu-pagerduty-handler/workflows/goreleaser/badge.svg)
Expand All @@ -9,14 +7,15 @@
## Table of Contents
- [Overview](#overview)
- [Usage examples](#usage-examples)
- [Help](#help)
- [Deduplication Key](#deduplication-key)
- [PagerDuty Severity Mapping](#pagerduty-severity-mapping)
- [Help output](#help-output)
- [Deduplication key](#deduplication-key)
- [PagerDuty severity mapping](#pagerduty-severity-mapping)
- [Configuration](#configuration)
- [Asset registration](#asset-registration)
- [Handler definition](#handler-definition)
- [Environment Variables](#environment-variables)
- [Argument Annotations](#argument-annotations)
- [Environment variables](#environment-variables)
- [Templates](#templates)
- [Argument annotations](#argument-annotations)
- [Proxy support](#proxy-support)
- [Installation from source](#installation-from-source)
- [Contributing](#contributing)
Expand All @@ -27,9 +26,9 @@ The Sensu PagerDuty Handler is a [Sensu Event Handler][3] which manages
[PagerDuty][2] incidents, for alerting operators. With this handler,
[Sensu][1] can trigger and resolve PagerDuty incidents.

## Usage Examples
## Usage examples

### Help
### Help output
```
The Sensu Go PagerDuty handler for incident management
Expand All @@ -45,20 +44,21 @@ Flags:
-t, --token string The PagerDuty V2 API authentication token, can be set with PAGERDUTY_TOKEN
-k, --dedup-key-template string The PagerDuty V2 API deduplication key template, can be set with PAGERDUTY_DEDUP_KEY_TEMPLATE (default "{{.Entity.Name}}-{{.Check.Name}}")
-S, --summary-template string The template for the alert summary, can be set with PAGERDUTY_SUMMARY_TEMPLATE (default "{{.Entity.Name}}/{{.Check.Name}} : {{.Check.Output}}")
-d, --details-template string The template for the alert details, can be set with PAGERDUTY_DETAILS_TEMPLATE (default full event JSON)
-s, --status-map string The status map used to translate a Sensu check status to a PagerDuty severity, can be set with PAGERDUTY_STATUS_MAP
-h, --help help for sensu-pagerduty-handler
Use "sensu-pagerduty-handler [command] --help" for more information about a command.
```

### Deduplication Key
### Deduplication key

The deduplication key is determined via the `--dedup-key-template` argument. It
is a Golang template containing the event values and defaults to
`{{.Entity.Name}}-{{.Check.Name}}`.

### PagerDuty Severity Mapping
### PagerDuty severity mapping

Optionally you can provide mapping information between the Sensu check status
and the PagerDuty incident severity. To provide the mapping you need to use the
Expand Down Expand Up @@ -97,8 +97,7 @@ The valid [PagerDuty alert severity levels][5] are the following:
* `error`

## Configuration
### Sensu Go
#### Asset registration
### Asset registration

[Sensu Assets][6] are the best way to make use of this plugin. If you're not
using an asset, please consider doing so! If you're using sensuctl 5.13 with
Expand All @@ -111,7 +110,7 @@ sensuctl asset add sensu/sensu-pagerduty-handler
If you're using an earlier version of sensuctl, you can find the asset on the
[Bonsai Asset Index][7].

#### Handler definition
### Handler definition

```yml
---
Expand All @@ -122,7 +121,12 @@ metadata:
namespace: default
spec:
type: pipe
command: sensu-pagerduty-handler
command: >-
sensu-pagerduty-handler
--dedup-key-template "{{.Entity.Namespace}}-{{.Entity.Name}}-{{.Check.Name}}"
--status-map "{\"info\":[0],\"warning\": [1],\"critical\": [2],\"error\": [3,127]}"
--summary-template "[{{.Entity.Namespace}}] {{.Entity.Name}}/{{.Check.Name}}: {{.Check.State}}"
--details-template "{{.Check.Output}}\n\n{{.Check}}"
timeout: 10
runtime_assets:
- sensu/sensu-pagerduty-handler
Expand All @@ -133,7 +137,7 @@ spec:
secret: pagerduty_authtoken
```

#### Environment Variables
### Environment variables

Most arguments for this handler are available to be set via environment
variables. However, any arguments specified directly on the command line
Expand Down Expand Up @@ -164,7 +168,13 @@ spec:
id: PAGERDUTY_TOKEN
```

#### Argument Annotations
### 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][12].

### Argument 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
Expand All @@ -175,7 +185,7 @@ as for `details-template` as a check annotation requires that you place the
desired template as a [golang string literal][11] (enlcosed in backticks)
within another template definition. This does not apply to entity annotations.

###### Examples
##### Examples

To change the `--details-template` argument for a particular check, and taking
into account the note above regarding templates, for that check's metadata add
Expand All @@ -202,7 +212,7 @@ metadata:
[...]
```

#### Proxy Support
### 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
Expand All @@ -213,7 +223,7 @@ assumed.
## Installation from source

Download the latest version of the sensu-pagerduty-handler from [releases][4],
or create an executable script from this source.
or create an executable from this source.

From the local path of the sensu-pagerduty-handler repository:
```
Expand All @@ -235,3 +245,4 @@ See https://github.com/sensu/sensu-go/blob/master/CONTRIBUTING.md
[9]: https://docs.sensu.io/sensu-go/latest/guides/secrets-management/#use-env-for-secrets-management
[10]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-schedule/checks/#check-token-substitution
[11]: https://golang.org/ref/spec#String_literals
[12]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-process/handler-templates/
35 changes: 25 additions & 10 deletions go.mod
@@ -1,18 +1,33 @@
module github.com/sensu/sensu-pagerduty-handler

go 1.13
go 1.14

require (
github.com/PagerDuty/go-pagerduty v0.0.0-20181104233218-fe8f9c4593d0
github.com/google/go-querystring v1.0.0 // indirect
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/PagerDuty/go-pagerduty v1.3.0
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.3 // 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-20210207032614-bba0dbe2a9ea // indirect
google.golang.org/grpc v1.35.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
)

0 comments on commit e691507

Please sign in to comment.