diff --git a/config/config.go b/config/config.go index c98012b3..319db9cf 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/examples/config.yml b/examples/config.yml index d81785ae..5db61ea7 100644 --- a/examples/config.yml +++ b/examples/config.yml @@ -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: [ , ... | default = 2xx ] \ No newline at end of file diff --git a/exporter/util.go b/exporter/util.go index 0bbad4c6..1a5d8cd5 100644 --- a/exporter/util.go +++ b/exporter/util.go @@ -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) }