Skip to content

Commit

Permalink
Merge pull request #52 from sensu/js/refactor-support-v2
Browse files Browse the repository at this point in the history
Js/refactor support v2
  • Loading branch information
Jef Spaleta committed Jun 16, 2022
2 parents 2b4c658 + d513681 commit f7d4122
Show file tree
Hide file tree
Showing 10 changed files with 395 additions and 219 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Go Lint

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

jobs:
test:
Expand All @@ -13,4 +13,4 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1
uses: golangci/golangci-lint-action@v2
24 changes: 24 additions & 0 deletions .github/workflows/notify-bonsai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Bonsai

on:
workflow_run:
workflows:
- goreleaser
types:
- completed

jobs:
bonsai-recompile:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: get versions
continue-on-error: true
run: >
curl -v -XGET
-H "X-GitHub-Token: ${{ secrets.GITHUB_TOKEN }}"
--url "https://bonsai-asset-index-staging.herokuapp.com/assets/${{ github.repository }}"
- name: bonsai-webhook
continue-on-error: true
run: echo "Trigger recompile on 'completed' workflow_job event matching workflow_job.name 'bonsai-recompile' and workflow.name 'bonsai'"

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.14.x
go-version: 1.18.x
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Go Test

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

jobs:
test:
Expand All @@ -12,10 +12,10 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Go 1.14
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: 1.18
id: go
- name: Test
run: go test -v ./...
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- Added '--bucket', '--token', and '--org' options to work with influxv2

### Deprecated
- Influx v1 arguments '--dbName', '--username', and '--password' deprecated, prefer using influxv1 compatible `--bucket` and `--token`

## [3.7.0] - 2021-02-26
### Changed
- Q1 '21 handler maintenance:
Expand Down
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Bonsai Asset Badge](https://img.shields.io/badge/Sensu%20InfluxDB%20Handler-Download%20Me-brightgreen.svg?colorB=89C967&logo=sensu)](https://bonsai.sensu.io/assets/sensu/sensu-influxdb-handler)

# Sensu InfluxDB Handler
# Sensu InfluxDBv2 Handler

- [Overview](#overview)
- [Usage examples](#usage-examples)
Expand All @@ -19,7 +19,7 @@
## Overview

The Sensu InfluxDB Handler is a [Sensu Event Handler][3] that sends metrics to
the time series database [InfluxDB][2]. [Sensu][1] can collect metrics using
the time series database [InfluxDBv2][2]. [Sensu][1] can collect metrics using
check output metric extraction or the StatsD listener. Those collected metrics
pass through the event pipeline, allowing Sensu to deliver the metrics to the
configured metric event handlers. This InfluxDB handler will allow you to
Expand All @@ -40,16 +40,19 @@ Usage:
sensu-influxdb-handler [flags]
Flags:
-a, --addr string the address of the influxdb server, should be of the form 'http://host:port', defaults to 'http://localhost:8086' or value of INFLUXDB_ADDR env variable (default "http://localhost:8086")
-a, --addr string the url of the influxdb server, should be of the form 'http://host:port/dbname', defaults to 'http://localhost:8086' or value of INFLUXDB_ADDR env variable (default "http://localhost:8086")
-b, --bucket string the influxdbv2 bucket, use '<database>/<retention-policy>' as bucket for influxdb v1.8 compatibility
-c, --check-status-metric if true, the check status result will be captured as a metric
-d, --db-name string the influxdb to send metrics to
-d, --db-name string (Deprecated) influx v1.8 database to send metrics to. Transition to influxdb v1.8 compatible bucket name
-h, --help help for sensu-influxdb-handler
-i, --insecure-skip-verify if true, the influx client skips https certificate verification
-l, --legacy-format if true, parse the metric w/ legacy format
-p, --password string the password for the given db, defaults to value of INFLUXDB_PASS env variable
-l, --legacy (Deprecated) if true, parse the metric w/ legacy format
-o, --org string the influxdbv2 org, leave empty for influxdb v1.8 compatibility
-p, --password string (Deprecated) the password for the given db. Transition to influxdb v1.8 compatible authentication token
--precision string the precision value of the metric (default "s")
--strip-host if true, we strip the host from the metric
-u, --username string the username for the given db, defaults to value of INFLUXDB_USER env variable
-t, --token string the authentication token needed for influxdbv2, use '<user>:<password>' as token for influxdb 1.8 compatibility
-u, --username string (Deprecated) the username for the given db, Transition to influxdb v1.8 compatible authentication token
```

Expand All @@ -60,6 +63,9 @@ Flags:
|--addr |INFLUXDB_ADDR |
|--username |INFLUXDB_USER |
|--password |INFLUXDB_PASS |
|--bucket |INFLUXDB_BUCKET |
|--token |INFLUXDB_TOKEN |
|--org |INFLUXDB_ORG |

**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
Expand Down Expand Up @@ -183,13 +189,12 @@ them, and this handler will populate them into your InfluxDB.

**Security Note:** The InfluxDB addr, username and password are treated as a security sensitive configuration options in this example and are loaded into the handler config as env_vars instead of as a command arguments. Command arguments are commonly readable from the process table by other unprivileged users on a system (ex: `ps` and `top` commands), so it's a better practice to read in sensitive information via environment variables or configuration files as part of command execution. The command flags for these configuration options are provided as an override for testing purposes.

## InfluxDBv2 Compatibility
This plugin was written for InfluxDB 1.x databases, but it is possible to have it work with InfluxDB 2.0 buckets by configuring an Influx DBRP mapping in your InfluxDB 2.0 server.

Ref: https://docs.influxdata.com/influxdb/v2.0/tools/grafana/?t=InfluxQL#view-and-create-influxdb-dbrp-mappings

When using InfluxQL to query InfluxDB, the query must specify a database and a retention policy. InfluxDB DBRP mappings associate database and retention policy combinations with InfluxDB 2.0 buckets. DBRP mappings do not affect the retention period of the target bucket. These mappings allow queries following InfluxDB 1.x conventions to successfully query InfluxDB 2.0 buckets.
## InfluxDBv1.8 Compatibility
It's possible to use this plugin with InfluxDB v1.8 by specifying the approporate compatible bucket and token values.
ref: https://github.com/influxdata/influxdb-client-go#influxdb-18-api-compatibility

* Use the form 'username:password' as the token value
* Use the form 'database/retention-policy' as the bucket value

## Installation from source and contributing

Expand Down
52 changes: 37 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
module github.com/sensu/sensu-influxdb-handler

go 1.14
go 1.18

require (
github.com/coreos/etcd v3.3.25+incompatible // indirect
github.com/influxdata/influxdb-client-go/v2 v2.9.0
github.com/sensu/sensu-go/api/core/v2 v2.14.0
github.com/sensu/sensu-plugin-sdk v0.16.0
github.com/stretchr/testify v1.6.0
)

require (
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deepmap/oapi-codegen v1.8.2 // indirect
github.com/echlebek/timeproxy v1.0.0 // 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/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.7 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20200827194710-b269163b24ab
github.com/json-iterator/go v1.1.10 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/magefile/mage v1.11.0 // 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/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // 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/robfig/cron/v3 v3.0.1 // indirect
github.com/sensu/sensu-go/types v0.10.0 // indirect
github.com/sensu/sensu-licensing v0.1.2 // indirect
github.com/sirupsen/logrus v1.8.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/cobra v1.4.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.1 // indirect
github.com/stretchr/testify v1.6.0
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d // indirect
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect
golang.org/x/text v0.3.5 // indirect
google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c // indirect
google.golang.org/grpc v1.35.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.etcd.io/etcd/api/v3 v3.5.0 // indirect
golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/ini.v1 v1.62.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

0 comments on commit f7d4122

Please sign in to comment.