Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
refactored to use sensu-plugin-sdk & the sensu-mutator-plugin template
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Hailey committed Sep 14, 2020
0 parents commit 6e154aa
Show file tree
Hide file tree
Showing 13 changed files with 829 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .bonsai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
description: "#{repo}"
builds:
- platform: "linux"
arch: "amd64"
asset_filename: "#{repo}_#{version}_linux_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'amd64'"

- platform: "linux"
arch: "386"
asset_filename: "#{repo}_#{version}_linux_386.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == '386'"

- platform: "linux"
arch: "arm64"
asset_filename: "#{repo}_#{version}_linux_arm64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'arm64'"

- platform: "linux"
arch: "armv7"
asset_filename: "#{repo}_#{version}_linux_armv7.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'linux'"
- "entity.system.arch == 'armv7'"

- platform: "OSX"
arch: "amd64"
asset_filename: "#{repo}_#{version}_darwin_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'darwin'"
- "entity.system.arch == 'amd64'"

- platform: "Windows"
arch: "amd64"
asset_filename: "#{repo}_#{version}_windows_amd64.tar.gz"
sha_filename: "#{repo}_#{version}_sha512-checksums.txt"
filter:
- "entity.system.os == 'windows'"
- "entity.system.arch == 'amd64'"

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]

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
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13.x
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Go Test

on: [push]

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- name: Test
run: go test -v ./...
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
sensu-metric-tag-mutator

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# dep
vendor/

# deploy
bonsai/
dist/
44 changes: 44 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
builds:
# List of builds
- # First Build
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
- linux
- windows
goarch:
- amd64
- 386
- arm
- arm64
goarm:
- 5
- 6
- 7
targets:
- darwin_amd64
- linux_386
- linux_amd64
- linux_arm_5
- linux_arm_6
- linux_arm_7
- linux_arm64
- windows_386
- windows_amd64

checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_sha512-checksums.txt"
algorithm: sha512

archives:
- id: tar
format: tar.gz
files:
- LICENSE
- README.md
- CHANGELOG.md
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

## [0.0.1] - 2000-01-01

### Added
- Initial release
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2020 Caleb Hailey

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[![Sensu Bonsai Asset](https://img.shields.io/badge/Bonsai-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/calebhailey/sensu-metric-tag-mutator)
![Go Test](https://github.com/calebhailey/sensu-metric-tag-mutator/workflows/Go%20Test/badge.svg)
![goreleaser](https://github.com/calebhailey/sensu-metric-tag-mutator/workflows/goreleaser/badge.svg)

# Sensu Metric Tag Mutator

## Table of Contents
- [Overview](#overview)
- [Usage examples](#usage)
- [Configuration](#configuration)
- [Asset registration](#asset-registration)
- [Mutator definition](#mutator-definition)
- [Installation from source](#installation-from-source)
- [Additional notes](#additional-notes)
- [Contributing](#contributing)

## Overview

The Sensu Metric Tag Mutator is a Sensu Go plugin for enriching metric points
with [Entity metadata][entity-metadata] (e.g. entity name, labels) and
[Check metadata][check-metadata] (e.g. check name, labels), adding them as
[Metric Tags][metric-tags]. The Sensu Metric Tag Mutator is useful for adding
context to generic metrics collected from plugins that generate metrics in
formats that don't support tags (e.g. Nagios Perfdata).

[entity-metadata]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-entities/entities/#metadata-attributes
[check-metadata]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-schedule/checks/#metadata-attributes
[metric-tags]: https://docs.sensu.io/sensu-go/latest/observability-pipeline/observe-events/events/#points-attributes

## Usage

```
Enrich Sensu Metrics with Event, Entity, and Check labels as metric tags.
Usage:
sensu-metric-tag-mutator [flags]
sensu-metric-tag-mutator [command]
Available Commands:
help Help about any command
version Print the version number of this plugin
Flags:
-c, --check Add a "check" tag containing the check name to every metric.
--check-labels Add a tag for every check label to every metric.
-e, --entity Add an "entity" tag containing the entity name to every metric.
--entity-labels Add a tag for every entity label to every metric.
--event-labels Add a tag for every event label to every metric.
-f, --filter string Comma separated list of tags to exclude. (default "sensu.io/managed_by")
-h, --help help for sensu-metric-tag-mutator
-n, --namespace Add a "namespace" tag containing the entity namespace to every metric.
-r, --require string Comma separated list of tags to include on all metrics, even if no matching labels are found
Use "sensu-metric-tag-mutator [command] --help" for more information about a command.
```

## Configuration

### Asset registration

[Sensu Assets][10] 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 Sensu Backend 5.13 or later, you can use the
following command to add the asset:

```
$ sensuctl asset add calebhailey/sensu-metric-tag-mutator
```

If you're using an earlier version of sensuctl, you can find the asset on the [Bonsai Asset Index][https://bonsai.sensu.io/assets/calebhailey/sensu-metric-tag-mutator].

### Mutator definition

```yml
---
type: Mutator
api_version: core/v2
metadata:
name: sensu-metric-tag-mutator
spec:
command: >-
sensu-metric-tag-mutator
--namespace
--entity
--check
--event-labels
--entity-labels
--check-labels
--filter sensu.io/managed_by,foo,bar
runtime_assets:
- calebhailey/sensu-metric-tag-mutator
```
## Installation from source
The preferred way of installing and deploying this plugin is to use it as an Asset. If you would
like to compile and install the plugin from source or contribute to it, download the latest version
or create an executable script from this source.
From the local path of the sensu-metric-tag-mutator repository:
```
go build
```

## Additional notes

## Contributing

For more information about contributing to this plugin, see [Contributing][1].

[1]: https://github.com/sensu/sensu-go/blob/master/CONTRIBUTING.md
[2]: https://github.com/sensu-community/sensu-plugin-sdk
[3]: https://github.com/sensu-plugins/community/blob/master/PLUGIN_STYLEGUIDE.md
[4]: https://github.com/sensu-community/mutator-plugin-template/blob/master/.github/workflows/release.yml
[5]: https://github.com/sensu-community/mutator-plugin-template/actions
[6]: https://docs.sensu.io/sensu-go/latest/reference/mutators/
[7]: https://github.com/sensu-community/mutator-plugin-template/blob/master/main.go
[8]: https://bonsai.sensu.io/
[9]: https://github.com/sensu-community/sensu-plugin-tool
[10]: https://docs.sensu.io/sensu-go/latest/reference/assets/
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/calebhailey/sensu-metric-tag-mutator

go 1.13

require (
github.com/sensu-community/sensu-plugin-sdk v0.6.0
github.com/sensu/sensu-go v0.0.0-20200131164840-40b1d5938251
)
Loading

0 comments on commit 6e154aa

Please sign in to comment.