fix(wiki): validate http_status is numeric before integer comparison
jq outputs "null" for missing JSON fields, which breaks bash integer comparisons. Guard both the main check and the stricter alternative with a regex test, and flag non-numeric values as unavailable.
- commit
- 618e538d19326c0a43638e059154379117a667b1
- author
- brice · · 2026-03-24 05:39 UTC
- parent
- 759791c
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +7 -3
M wiki/guides/health-monitoring.md +7 -3
| @@ -38,8 +38,10 @@ while IFS= read -r route; do | |||
| 38 | 38 | http_status=$(echo "$route" | jq -r '.http_status') | |
| 39 | 39 | container_status=$(echo "$route" | jq -r '.container_status') | |
| 40 | 40 | ||
| 41 | - | # HTTP status: flag 4xx, 5xx, or 0 (no response) | |
| 42 | - | if [[ "$http_status" -eq 0 ]] || [[ "$http_status" -ge 400 ]]; then | |
| 41 | + | # HTTP status: flag 4xx, 5xx, 0 (no response), or unavailable | |
| 42 | + | if ! [[ "$http_status" =~ ^[0-9]+$ ]]; then | |
| 43 | + | problems+=("$domain: HTTP status unavailable ($http_status)") | |
| 44 | + | elif [[ "$http_status" -eq 0 ]] || [[ "$http_status" -ge 400 ]]; then | |
| 43 | 45 | problems+=("$domain: HTTP $http_status") | |
| 44 | 46 | fi | |
| 45 | 47 | ||
| @@ -170,7 +172,9 @@ StandardError=append:%h/.local/share/gordon-watchdog.log | |||
| 170 | 172 | **Stricter HTTP checks**: if you want to flag anything that isn't exactly 200, replace the HTTP check with: | |
| 171 | 173 | ||
| 172 | 174 | ```bash | |
| 173 | - | if [[ "$http_status" -ne 200 ]]; then | |
| 175 | + | if ! [[ "$http_status" =~ ^[0-9]+$ ]]; then | |
| 176 | + | problems+=("$domain: HTTP status unavailable ($http_status)") | |
| 177 | + | elif [[ "$http_status" -ne 200 ]]; then | |
| 174 | 178 | problems+=("$domain: HTTP $http_status") | |
| 175 | 179 | fi | |
| 176 | 180 | ``` | |
| @@ -38,8 +38,10 @@ while IFS= read -r route; do | |||||
| 38 | http_status=$(echo "$route" | jq -r '.http_status') | 38 | http_status=$(echo "$route" | jq -r '.http_status') | ||
| 39 | container_status=$(echo "$route" | jq -r '.container_status') | 39 | container_status=$(echo "$route" | jq -r '.container_status') | ||
| 40 | 40 | ||||
| 41 | - | # HTTP status: flag 4xx, 5xx, or 0 (no response) | 41 | + | # HTTP status: flag 4xx, 5xx, 0 (no response), or unavailable |
| 42 | - | if [[ "$http_status" -eq 0 ]] || [[ "$http_status" -ge 400 ]]; then | 42 | + | if ! [[ "$http_status" =~ ^[0-9]+$ ]]; then |
| 43 | + | problems+=("$domain: HTTP status unavailable ($http_status)") | |||
| 44 | + | elif [[ "$http_status" -eq 0 ]] || [[ "$http_status" -ge 400 ]]; then | |||
| 43 | problems+=("$domain: HTTP $http_status") | 45 | problems+=("$domain: HTTP $http_status") | ||
| 44 | fi | 46 | fi | ||
| 45 | 47 | ||||
| @@ -170,7 +172,9 @@ StandardError=append:%h/.local/share/gordon-watchdog.log | |||||
| 170 | **Stricter HTTP checks**: if you want to flag anything that isn't exactly 200, replace the HTTP check with: | 172 | **Stricter HTTP checks**: if you want to flag anything that isn't exactly 200, replace the HTTP check with: | ||
| 171 | 173 | ||||
| 172 | ```bash | 174 | ```bash | ||
| 173 | - | if [[ "$http_status" -ne 200 ]]; then | 175 | + | if ! [[ "$http_status" =~ ^[0-9]+$ ]]; then |
| 176 | + | problems+=("$domain: HTTP status unavailable ($http_status)") | |||
| 177 | + | elif [[ "$http_status" -ne 200 ]]; then | |||
| 174 | problems+=("$domain: HTTP $http_status") | 178 | problems+=("$domain: HTTP $http_status") | ||
| 175 | fi | 179 | fi | ||
| 176 | ``` | 180 | ``` | ||