Skip to content

Commit 5e90d0d

Browse files
authored
Merge pull request #33 from NETWAYS/chore/cleanup
Some various cleanup
2 parents 57e4efe + ed7ad65 commit 5e90d0d

File tree

12 files changed

+76
-33
lines changed

12 files changed

+76
-33
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ jobs:
1919
- name: Set up Go
2020
uses: actions/setup-go@v5
2121
with:
22-
go-version: 1.24
22+
go-version: stable
23+
check-latest: true
2324

2425
- name: Test
2526
run: go test -v ./...

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.idea
1+
.idea/
22
check_influxdb
33
vendor/
44
coverage.html

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ builds:
88
- CGO_ENABLED=0
99
goarch:
1010
- amd64
11+
- arm64
1112
goos:
1213
- linux
1314
- windows
@@ -30,6 +31,7 @@ archives:
3031
{{- if eq .Os "windows" }}Windows{{ end }}
3132
{{- if eq .Os "darwin" }}Darwin{{ end }}
3233
{{- if eq .Arch "amd64" }}_x86_64{{ end }}
34+
{{- if eq .Arch "arm64" }}_arm64{{ end }}
3335
checksum:
3436
name_template: 'checksums.txt'
3537
snapshot:

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/check_influxdb.iml

Lines changed: 0 additions & 9 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Global Flags:
3131
--key-file string Specify the Key File for TLS authentication (CHECK_INFLUXDB_KEY_FILE)
3232
-i, --insecure Skip the verification of the server's TLS certificate
3333
-t, --timeout int Timeout in seconds for the CheckPlugin (default 30)
34+
--header strings Additional HTTP header to include in the request. Can be used multiple times.
35+
Keys and values are separated by a colon (--header "X-Custom: example").
3436
-h, --help help for check_influxdb
3537
-v, --version version for check_influxdb
3638
```

cmd/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Config struct {
2424
KeyFile string `env:"CHECK_INFLUXDB_KEY_FILE"`
2525
Token string `env:"CHECK_INFLUXDB_TOKEN"`
2626
Organization string `env:"CHECK_INFLUXDB_ORGANISATION"`
27+
Headers []string
2728
Port int
2829
Insecure bool
2930
Secure bool
@@ -82,6 +83,20 @@ func (c *Config) NewClient() *client.Client {
8283
rt = checkhttpconfig.NewBasicAuthRoundTripper(u, p, rt)
8384
}
8485

86+
// If extra headers are set, parse them and add them to the request
87+
if len(c.Headers) > 0 {
88+
headers := make(map[string]string)
89+
90+
for _, h := range c.Headers {
91+
head := strings.Split(h, ":")
92+
if len(head) == 2 {
93+
headers[strings.TrimSpace(head[0])] = strings.TrimSpace(head[1])
94+
}
95+
}
96+
97+
rt = client.NewHeadersRoundTripper(headers, rt)
98+
}
99+
85100
return client.NewClient(u.String(), c.Token, c.Organization, rt)
86101
}
87102

cmd/health_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ func TestHealthCmd(t *testing.T) {
6363
args: []string{"run", "../main.go", "health"},
6464
expected: "[UNKNOWN] - InfluxDB Version 3 not supported (*errors.errorString)\nexit status 3\n",
6565
},
66+
{
67+
name: "health-extra-header",
68+
httpreturn: func(w http.ResponseWriter, r *http.Request) {
69+
foobar := r.Header.Get("X-Foobar")
70+
if foobar == "Barfoo" {
71+
w.WriteHeader(http.StatusOK)
72+
w.Write([]byte(`{"checks":[],"message":"ready for queries and writes","name":"influxdb","status":"pass","version":"1.8.10"}`))
73+
return
74+
}
75+
w.WriteHeader(http.StatusUnauthorized)
76+
w.Write([]byte(`Wrong Header!`))
77+
},
78+
args: []string{"run", "../main.go", "--header", "X-Foobar: Barfoo", "health"},
79+
expected: "[OK] - InfluxDB Status: pass\n",
80+
},
6681
}
6782

6883
for _, test := range tests {

0 commit comments

Comments
 (0)