Skip to content

Commit 235bf91

Browse files
committed
Support for multiple status codes
1 parent 860a2c0 commit 235bf91

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ This application can be used to verify whether a server is healthy before perfor
119119

120120
## License
121121

122-
This project is licensed under the Apache License.
122+
This project is licensed under the Apache License.

config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ endpoints:
3030
- name: external-api
3131
url: http://api.example.com
3232
status: 404
33+
- name: other
34+
url: http://something.example.com
35+
statuses:
36+
- 404
37+
- 301
38+
- 302

main.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ type Port struct {
5353
}
5454

5555
type Endpoint struct {
56-
Name string `yaml:"name"`
57-
URL string `yaml:"url"`
58-
Status int `yaml:"status"`
56+
Name string `yaml:"name"`
57+
URL string `yaml:"url"`
58+
Status int `yaml:"status"`
59+
Statuses []int `yaml:"statuses"`
5960
}
6061

6162
var outputMessages []string
@@ -187,7 +188,7 @@ func checkEndpoints(endpoints []Endpoint) bool {
187188
}
188189
defer resp.Body.Close()
189190

190-
if resp.StatusCode == endpoint.Status {
191+
if resp.StatusCode == endpoint.Status || contains(endpoint.Statuses, resp.StatusCode) {
191192
addToOutputMessages("Endpoint Name: %s, URL: %s, Status: %d is as expected", endpoint.Name, endpoint.URL, endpoint.Status)
192193
} else {
193194
addToOutputMessages("Endpoint Name: %s, URL: %s, Status: %d is not as expected, got: %d", endpoint.Name, endpoint.URL, endpoint.Status, resp.StatusCode)
@@ -219,3 +220,12 @@ func GetEnvInt(key string, fallback int) int {
219220
}
220221
return fallback
221222
}
223+
224+
func contains(numbers []int, target int) bool {
225+
for _, num := range numbers {
226+
if num == target {
227+
return true
228+
}
229+
}
230+
return false
231+
}

resources/post_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
getent passwd health > /dev/null || useradd -s /bin/false --no-create-home -r health
44

5-
[ -x /usr/bin/systemctl ] && systemctl daemon-reload
5+
[ -x /usr/bin/systemctl ] && systemctl daemon-reload

0 commit comments

Comments
 (0)