mirror of
https://github.com/prometheus-community/json_exporter
synced 2025-03-11 06:48:12 +00:00
Add ignore_status (#161)
* Add ignore_status Signed-off-by: Alexander Ryabov <alexander.ryabov@jetbrains.com> * Use valid_status_codes slice Signed-off-by: Alexander Ryabov <alexander.ryabov@jetbrains.com> Co-authored-by: Alexander Ryabov <alexander.ryabov@jetbrains.com>
This commit is contained in:
parent
a03b913a00
commit
f8ddc2fa84
@ -57,6 +57,7 @@ type Module struct {
|
||||
Metrics []Metric `yaml:"metrics"`
|
||||
HTTPClientConfig pconfig.HTTPClientConfig `yaml:"http_client_config,omitempty"`
|
||||
Body Body `yaml:"body,omitempty"`
|
||||
ValidStatusCodes []int `yaml:"valid_status_codes,omitempty"`
|
||||
}
|
||||
|
||||
type Body struct {
|
||||
|
@ -43,3 +43,6 @@ modules:
|
||||
# username: myuser
|
||||
# #password: veryverysecret
|
||||
# password_file: /tmp/mysecret.txt
|
||||
|
||||
# Accepted status codes for this probe. Defaults to 2xx.
|
||||
# valid_status_codes: [ <int>, ... | default = 2xx ]
|
@ -179,7 +179,18 @@ func (f *JSONFetcher) FetchJSON(endpoint string) ([]byte, error) {
|
||||
resp.Body.Close()
|
||||
}()
|
||||
|
||||
if resp.StatusCode/100 != 2 {
|
||||
if len(f.module.ValidStatusCodes) != 0 {
|
||||
success := false
|
||||
for _, code := range f.module.ValidStatusCodes {
|
||||
if resp.StatusCode == code {
|
||||
success = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !success {
|
||||
return nil, errors.New(resp.Status)
|
||||
}
|
||||
} else if resp.StatusCode/100 != 2 {
|
||||
return nil, errors.New(resp.Status)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user