Skip to content
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
8 changes: 2 additions & 6 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Ready: Checks the readiness of an endpoint, which returns OK if the Prometheus s
check.ExitError(fmt.Errorf(output))
}
p := perfdata.PerfdataList{
{Label: "statuscode", Value: sc},
{Label: "statuscode", Value: float64(sc)},
}

check.ExitRaw(rc, output, "|", p.String())
Expand All @@ -68,10 +68,6 @@ Ready: Checks the readiness of an endpoint, which returns OK if the Prometheus s

p := perfdata.PerfdataList{
{Label: "statuscode", Value: 200},
{Label: "version", Value: info.Version},
{Label: "builddate", Value: info.BuildDate},
{Label: "builduser", Value: info.BuildUser},
{Label: "revision", Value: info.Revision},
}

check.ExitRaw(rc, output, "|", p.String())
Expand All @@ -85,7 +81,7 @@ Ready: Checks the readiness of an endpoint, which returns OK if the Prometheus s
}

p := perfdata.PerfdataList{
{Label: "statuscode", Value: sc},
{Label: "statuscode", Value: float64(sc)},
}

check.ExitRaw(rc, output, "|", p.String())
Expand Down
2 changes: 1 addition & 1 deletion cmd/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestHealthCmd(t *testing.T) {
w.Write([]byte(`{"status":"success","data":{"version":"2.30.3","revision":"foo","branch":"HEAD","buildUser":"root@foo","buildDate":"20211005-16:10:52","goVersion":"go1.17.1"}}`))
})),
args: []string{"run", "../main.go", "health", "--info"},
expected: "[OK] - Prometheus Server information\n\nVersion: 2.30.3\nBranch: HEAD\nBuildDate: 20211005-16:10:52\nBuildUser: root@foo\nRevision: foo | statuscode=200 version=2.30.3 builddate=20211005-16:10:52 builduser=root@foo revision=foo\n",
expected: "[OK] - Prometheus Server information\n\nVersion: 2.30.3\nBranch: HEAD\nBuildDate: 20211005-16:10:52\nBuildUser: root@foo\nRevision: foo | statuscode=200\n",
},
{
name: "health-bearer-ok",
Expand Down
6 changes: 3 additions & 3 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func generateMetricOutput(rc int, metric string, value string) string {
return fmt.Sprintf(" \\_[%s] %s - value: %s\n", check.StatusText(rc), metric, value)
}

func generatePerfdata(metric, value string, warning, critical *check.Threshold) perfdata.Perfdata {
func generatePerfdata(metric string, value float64, warning, critical *check.Threshold) perfdata.Perfdata {
// We trim the trailing "} from the string, so that the Perfdata won't have a trailing _
return perfdata.Perfdata{
Label: replacer.Replace(metric),
Expand Down Expand Up @@ -138,7 +138,7 @@ Note: Time range values e.G. 'go_memstats_alloc_bytes_total[0s]' only the latest
metricOutput.WriteString(generateMetricOutput(rc, sample.Metric.String(), sample.Value.String()))

// Generate Perfdata from API return
perf := generatePerfdata(sample.Metric.String(), sample.Value.String(), warn, crit)
perf := generatePerfdata(sample.Metric.String(), float64(sample.Value), warn, crit)
perfList.Add(&perf)
}
states = vStates
Expand Down Expand Up @@ -172,7 +172,7 @@ Note: Time range values e.G. 'go_memstats_alloc_bytes_total[0s]' only the latest
metricOutput.WriteString(generateMetricOutput(rc, samplepair.String(), samplepair.Value.String()))

// Generate Perfdata from API return
perf := generatePerfdata(samplestream.Metric.String(), samplepair.Value.String(), warn, crit)
perf := generatePerfdata(samplestream.Metric.String(), float64(samplepair.Value), warn, crit)
perfList.Add(&perf)
}
states = mStates
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/NETWAYS/check_prometheus
go 1.21

require (
github.com/NETWAYS/go-check v0.6.1
github.com/NETWAYS/go-check v0.6.2
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/common v0.53.0
github.com/spf13/cobra v1.8.1
Expand Down
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/NETWAYS/go-check v0.6.1 h1:fwya2nBWoRTUt2U6j3BCe0aUvNw+EbFYji4t1JrloC4=
github.com/NETWAYS/go-check v0.6.1/go.mod h1:3G1p9ZCv41UcKirl+nZWne8oKVPUY5HbtyjRwGgyw6A=
github.com/NETWAYS/go-check v0.6.2 h1:H/9Q/+rVzLbSUV/6QS9eDhyMUml7sf67TF4nSuHBwJo=
github.com/NETWAYS/go-check v0.6.2/go.mod h1:qx8m3s2Xul9wqfUjrCSArEFkOdtwxIyUmBYYrCkqA/8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
Expand Down Expand Up @@ -54,11 +54,13 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
Expand Down