Skip to content

Commit abef324

Browse files
authored
add new parameter "URL" to access Prometheus behind reverse proxy (#59)
* add new parameter "URL" to access Prometheus behind reverse proxy
1 parent 20a8cca commit abef324

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Available Commands:
1717
Flags:
1818
-H, --hostname string Hostname of the Prometheus server (CHECK_PROMETHEUS_HOSTNAME) (default "localhost")
1919
-p, --port int Port of the Prometheus server (default 9090)
20+
-U, --url string URL/Path to append to the Promethes Hostname (CHECK_PROMETHEUS_URL) (default "/")
2021
-s, --secure Use a HTTPS connection
2122
-i, --insecure Skip the verification of the server's TLS certificate
2223
-b, --bearer string Specify the Bearer Token for server authentication (CHECK_PROMETHEUS_BEARER)
@@ -161,6 +162,7 @@ CRITICAL - 6 Alerts: 3 Firing - 0 Pending - 3 Inactive
161162
| total=6 firing=3 pending=0 inactive=3
162163
163164
```
165+
164166
#### Checking multiple alerts
165167
166168
```bash
@@ -177,6 +179,17 @@ $ check_prometheus alert --name "HostHighCpuLoad" --name "PrometheusTargetMissin
177179
OK - Alerts inactive | total=2 firing=0 pending=0 inactive=2
178180
```
179181
182+
### Special cases
183+
184+
#### Your Prometheus runs behind a reverse proxy
185+
186+
>Example: <https://monitoring.example.com:443/subpath>
187+
188+
```bash
189+
$ check_prometheus health --hostname 'monitoring.example.com' --port 443 --secure --url /subpath
190+
OK - Prometheus Server is Healthy. | statuscode=200
191+
```
192+
180193
## License
181194
182195
Copyright (c) 2022 [NETWAYS GmbH](mailto:[email protected])

cmd/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Config struct {
2828
CertFile string `env:"CHECK_PROMETHEUS_CERT_FILE"`
2929
KeyFile string `env:"CHECK_PROMETHEUS_KEY_FILE"`
3030
Hostname string `env:"CHECK_PROMETHEUS_HOSTNAME"`
31+
URL string `env:"CHECK_PROMETHEUS_URL"`
3132
Port int
3233
Info bool
3334
Insecure bool
@@ -65,6 +66,7 @@ func (c *Config) NewClient() *client.Client {
6566
u := url.URL{
6667
Scheme: "http",
6768
Host: c.Hostname + ":" + strconv.Itoa(c.Port),
69+
Path: c.URL,
6870
}
6971

7072
if c.Secure {

cmd/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
func TestConfig(t *testing.T) {
88
c := cliConfig.NewClient()
9-
expected := "http://localhost:9090"
10-
if c.URL != "http://localhost:9090" {
9+
expected := "http://localhost:9090/"
10+
if c.URL != "http://localhost:9090/" {
1111
t.Error("\nActual: ", c.URL, "\nExpected: ", expected)
1212
}
1313
}

cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ func init() {
4343
"Hostname of the Prometheus server (CHECK_PROMETHEUS_HOSTNAME)")
4444
pfs.IntVarP(&cliConfig.Port, "port", "p", 9090,
4545
"Port of the Prometheus server")
46+
pfs.StringVarP(&cliConfig.URL, "url", "U", "/",
47+
"URL/Path to append to the Promethes Hostname (CHECK_PROMETHEUS_URL)")
4648
pfs.BoolVarP(&cliConfig.Secure, "secure", "s", false,
4749
"Use a HTTPS connection")
4850
pfs.BoolVarP(&cliConfig.Insecure, "insecure", "i", false,

0 commit comments

Comments
 (0)