Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparations for Release #1

Merged
merged 3 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20
go-version: 1.21

- name: Test
run: go test -v ./...
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ jobs:

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
- forbidigo
- gci
- lll
- godot
- gofumpt
- gochecknoinits
- gochecknoglobals
Expand Down
2 changes: 2 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/NETWAYS/go-check"
)

// Central Configuration for CLI
type Config struct {
BasicAuth string
Hostname string
Expand Down Expand Up @@ -85,6 +86,7 @@ func (c *Config) NewClient() *client.Client {
return client.NewClient(u.String(), c.Token, c.Organization, rt)
}

// Central timeout configuration for anything that needs it
func (c *Config) timeoutContext() (context.Context, func()) {
return context.WithTimeout(context.Background(), 10*time.Second)
}
3 changes: 3 additions & 0 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ API translation:
err error
)

// Uses the major version to determine which API to call.
// Can be extended in the future.
switch apiversion.MajorVersion {
case 1:
health, err = checkV2Health(c.URL, c.Token, c.Client)
Expand All @@ -65,6 +67,7 @@ API translation:
check.ExitError(err)
}

// Is this flexible enough? Might be better to use strings.Contains.
switch health {
case "pass":
rc = 0
Expand Down
2 changes: 2 additions & 0 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ var queryCmd = &cobra.Command{
check.ExitError(versionErr)
}

// Uses the major version to determine which API to call.
// Can be extended in the future.
switch apiversion.MajorVersion {
case 2:
queryFluxV2(fluxQuery, c.URL, c.Organization, c.Token, c.Client)
Expand Down
63 changes: 13 additions & 50 deletions contrib/icinga2-commands.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ object CheckCommand "influxdb" {
order = 1
description = "Timeout for the check"
}
"--tls" = {
"--secure" = {
set_if = "$influxdb_tls$"
order = 1
description = "Use secure connection"
description = "Use a HTTPS connection"
}
"--insecure" = {
set_if = "$influxdb_insecure$"
order = 1
description = "Allow use of self signed certificates when using SSL"
description = "Skip the verification of the TLS certificate"
}
"--token" = {
value = "$influxdb_token$"
required = true
order = 1
description = "The token which allows access to the API"
description = "Token for server authentication"
}
"--org" = {
value = "$influxdb_org$"
Expand All @@ -57,59 +57,22 @@ object CheckCommand "influxdb" {
set_if = {{ macro("$influxdb_query$") == true }}
description = "The bucket where time series data is stored"
}
"--start" = {
value = "$influxdb_start$"
order = 4
description = "Specifies a start time range for your query"
}
"--end" = {
value = "$influxdb_end$"
order = 4
description = "Specifies the end of a time range for your query"
}
"--measurement" = {
value = "$influxdb_measurement$"
order = 5
description = "The data stored in the associated fields, e.g. 'disk'"
}
"--field" = {
value = "$influxdb_field$"
order = 6
description = "The key-value pair that records metadata and the actual data value"
}
"--filter" = {
value = "$influxdb_filter$"
order = 7
repeat_key = true
description = "Add a key=value filter to the query, e.g. 'hostname=example.com'"
}
"--raw-filter" = {
value = "$influxdb_raw_filter$"
order = 8
repeat_key = true
description = "A fully customizable filter which will be added to the query."
}
"--aggregation" = {
value = "$influxdb_aggregation$"
order = 9
description = "Function that returns an aggregated value across a set of points"
}
"--raw-query" = {
value = "$influxdb_raw_query$"
description = "An InfluxQL query which will be performed. Note: Only ONE value result will be evaluated"
}
"--value-by-key" = {
"--flux-query" = {
value = "$influxdb_flux_query$"
description = "Flux script as string"
}
"--flux-file" = {
value = "$influxdb_flux_string$"
description = "Path to flux file"
}
"--perfdata-label-by-key" = {
value = "$influxdb_value_by_key$"
description = "Sets the label for the perfdata of the given column key for the record"
}
"--perfdata-label" = {
value = "$influxdb_perfdata_label$"
description = "Sets as custom label for the perfdata"
}
"--verbose" = {
set_if = "$influxdb_verbose$"
description = "Display verbose output"
}
"--critical" = {
value = "$influxdb_critical$"
description = "The critical threshold for a value"
Expand Down
8 changes: 1 addition & 7 deletions contrib/icinga2-service-example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ apply Service "influx_query" {
vars.influxdb_token = "example_token"
vars.influxdb_bucket = "example_bucket"
vars.influxdb_org = "example_org"
vars.influxdb_start = "-48h"
vars.influxdb_measurement = "example_measurement"
vars.influxdb_field = "value"
vars.influxdb_filter = [ "metric=example_metric" ]
vars.influxdb_raw_filter = [ "group(columns: [\"hostname\"], mode: \"by\")", "aggregateWindow(every: 30m, fn: sum)" ]
vars.influxdb_aggregation = "last"
vars.influxdb_value_by_key = "hostname"
vars.influxdb_flux_query = "flux..."
vars.influxdb_insecure = true
vars.influxdb_critical = 100
vars.influxdb_warning = 50
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/NETWAYS/check_influxdb

go 1.20
go 1.21

require (
github.com/NETWAYS/go-check v0.5.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiu
github.com/golangci/lint-1 v0.0.0-20181222135242-d2cdd8c08219/go.mod h1:/X8TswGSh1pIozq4ZwCfxS0WA5JGXguxk94ar/4c87Y=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
Expand Down
1 change: 1 addition & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
)

// APIVersion is mainly for identifying the API Version of InfluxDB
type APIVersion struct {
Version string `json:"version"`
MajorVersion int
Expand Down
3 changes: 2 additions & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/NETWAYS/check_influxdb/internal/api"
)

// Client is a small wrapper for HTTP connections,
// that is configured and used in the subcommands.
type Client struct {
Organization string
URL string
Expand All @@ -19,7 +21,6 @@ type Client struct {
}

func NewClient(url, token, org string, rt http.RoundTripper) *Client {
// Small wrapper
c := &http.Client{
Transport: rt,
}
Expand Down