Skip to content

Commit f8ddc2f

Browse files
authored
Add ignore_status (#161)
* Add ignore_status Signed-off-by: Alexander Ryabov <[email protected]> * Use valid_status_codes slice Signed-off-by: Alexander Ryabov <[email protected]> Co-authored-by: Alexander Ryabov <[email protected]>
1 parent a03b913 commit f8ddc2f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Module struct {
5757
Metrics []Metric `yaml:"metrics"`
5858
HTTPClientConfig pconfig.HTTPClientConfig `yaml:"http_client_config,omitempty"`
5959
Body Body `yaml:"body,omitempty"`
60+
ValidStatusCodes []int `yaml:"valid_status_codes,omitempty"`
6061
}
6162

6263
type Body struct {

examples/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ modules:
4343
# username: myuser
4444
# #password: veryverysecret
4545
# password_file: /tmp/mysecret.txt
46+
47+
# Accepted status codes for this probe. Defaults to 2xx.
48+
# valid_status_codes: [ <int>, ... | default = 2xx ]

exporter/util.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,18 @@ func (f *JSONFetcher) FetchJSON(endpoint string) ([]byte, error) {
179179
resp.Body.Close()
180180
}()
181181

182-
if resp.StatusCode/100 != 2 {
182+
if len(f.module.ValidStatusCodes) != 0 {
183+
success := false
184+
for _, code := range f.module.ValidStatusCodes {
185+
if resp.StatusCode == code {
186+
success = true
187+
break
188+
}
189+
}
190+
if !success {
191+
return nil, errors.New(resp.Status)
192+
}
193+
} else if resp.StatusCode/100 != 2 {
183194
return nil, errors.New(resp.Status)
184195
}
185196

0 commit comments

Comments
 (0)