Skip to content

Commit 57e4efe

Browse files
authored
Merge pull request #32 from NETWAYS/fix/perfdata
No longer returns multiple perfdata data points
2 parents fdc4014 + db8d5cf commit 57e4efe

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

.golangci.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ linters:
1111
- forbidigo
1212
- gochecknoglobals
1313
- gochecknoinits
14+
- funlen
1415
- godot
1516
- godox
1617
- lll
@@ -21,9 +22,6 @@ linters:
2122
- nonamedreturns
2223
- varnamelen
2324
- wrapcheck
24-
settings:
25-
funlen:
26-
lines: 90
2725
exclusions:
2826
generated: lax
2927
presets:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.PHONY: test coverage lint vet
22

33
build:
4-
export CGO_ENABLED=0; go build
4+
CGO_ENABLED=0 go build
55
lint:
66
go fmt $(go list ./... | grep -v /vendor/)
77
vet:

cmd/query.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ func queryFluxV2(fluxQuery, url, org, token string, c *http.Client) {
9696
continue
9797
}
9898

99-
//nolint: gocritic
100-
if crit.DoesViolate(recordValue) {
99+
switch {
100+
case crit.DoesViolate(recordValue):
101101
recordStatus = 2
102-
} else if warn.DoesViolate(recordValue) {
102+
case warn.DoesViolate(recordValue):
103103
recordStatus = 1
104-
} else {
104+
default:
105105
recordStatus = 0
106106
}
107107

@@ -146,7 +146,12 @@ func queryFluxV2(fluxQuery, url, org, token string, c *http.Client) {
146146
rc = check.Unknown
147147
}
148148

149-
check.ExitRaw(rc, "InfluxDB Query Status", "|", perfData.String())
149+
// If we got perfdata we print the only the last value
150+
if len(perfData) > 1 {
151+
check.ExitRaw(rc, "InfluxDB Query Status", "|", perfData[len(perfData)-1].String())
152+
}
153+
154+
check.ExitRaw(rc, "InfluxDB Query Status")
150155
}
151156

152157
var queryCmd = &cobra.Command{

cmd/query_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func TestQueryCmd(t *testing.T) {
9393
))
9494
},
9595
args: []string{"run", "../main.go", "query", "-o", "org", "-b", "bucket", "-T", "token", "--flux-file", "../testdata/mem.flux", "-w", "200", "-c", "500"},
96-
expected: "[CRITICAL] - InfluxDB Query Status | mem.active=501;200;500 mem.active=502;200;500 mem.active=125;200;500",
96+
expected: "[CRITICAL] - InfluxDB Query Status | mem.active=125;200;500",
9797
},
9898
{
9999
name: "query-string-output",
@@ -110,7 +110,7 @@ func TestQueryCmd(t *testing.T) {
110110
))
111111
},
112112
args: []string{"run", "../main.go", "query", "-o", "org", "-b", "bucket", "-T", "token", "--flux-string", "from(bucket:\"monitor\")|>range(start:-1h)", "-w", "1", "-c", "2"},
113-
expected: "[OK] - InfluxDB Query Status | cpu.usage_user=0.078;1;2 cpu.usage_user=0.044;1;2 cpu.usage_user=0.078;1;2 cpu.usage_user=0.044;1;2",
113+
expected: "[OK] - InfluxDB Query Status | cpu.usage_user=0.044;1;2",
114114
},
115115
{
116116
name: "query-perfdata",
@@ -125,7 +125,7 @@ func TestQueryCmd(t *testing.T) {
125125
))
126126
},
127127
args: []string{"run", "../main.go", "query", "-o", "org", "-b", "bucket", "-T", "token", "--flux-string", "from(bucket:\"monitor\")|>range(start:-1h)", "-w", "1", "-c", "2", "--perfdata-label", "foobar"},
128-
expected: "InfluxDB Query Status | foobar=0.078;1;2 foobar=0.044;1;2",
128+
expected: "InfluxDB Query Status | foobar=0.044;1;2",
129129
},
130130
{
131131
name: "query-perfdata-by-key",
@@ -140,7 +140,7 @@ func TestQueryCmd(t *testing.T) {
140140
))
141141
},
142142
args: []string{"run", "../main.go", "query", "-o", "org", "-b", "bucket", "-T", "token", "--flux-string", "from(bucket:\"monitor\")|>range(start:-1h)", "-w", "1", "-c", "2", "--perfdata-label-by-key", "host"},
143-
expected: "InfluxDB Query Status | influx=0.078;1;2 influx=0.044;1;2",
143+
expected: "InfluxDB Query Status | influx=0.044;1;2",
144144
},
145145
{
146146
name: "query-perfdata-by-key-is-nil",
@@ -155,7 +155,7 @@ func TestQueryCmd(t *testing.T) {
155155
))
156156
},
157157
args: []string{"run", "../main.go", "query", "-o", "org", "-b", "bucket", "-T", "token", "--flux-string", "from(bucket:\"monitor\")|>range(start:-1h)", "-w", "1", "-c", "2", "--perfdata-label-by-key", "foobar"},
158-
expected: "InfluxDB Query Status |",
158+
expected: "InfluxDB Query Status",
159159
},
160160
}
161161

0 commit comments

Comments
 (0)