Makes more checks for agent availability
parent
79355f039c
commit
474f8fb098
32
main.go
32
main.go
|
@ -272,10 +272,42 @@ func statusHandler(config Config, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Check the status code from the response recorder
|
// Check the status code from the response recorder
|
||||||
if rr.Result().StatusCode == http.StatusOK {
|
if rr.Result().StatusCode == http.StatusOK {
|
||||||
|
// Check if it's json
|
||||||
|
if rr.Header().Get("Content-Type") == "application/json" {
|
||||||
|
var result map[string]interface{}
|
||||||
|
if err := json.NewDecoder(rr.Body).Decode(&result); err == nil {
|
||||||
|
available := true
|
||||||
|
for key, value := range result {
|
||||||
|
if strings.HasSuffix(key, "_state") {
|
||||||
|
// If there is "*_state": "error" - it's accessible, but unavailable
|
||||||
|
if valueStr, ok := value(string); ok && valueStr == "error" {
|
||||||
|
available = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// If there is "*_state": "running" - it's OK
|
||||||
|
if valueStr, ok := value(string); ok && valueStr == "running" {
|
||||||
|
available = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if available {
|
||||||
endpointStatuses[endpoint] = "available"
|
endpointStatuses[endpoint] = "available"
|
||||||
} else {
|
} else {
|
||||||
endpointStatuses[endpoint] = "not available"
|
endpointStatuses[endpoint] = "not available"
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Invalid JSON
|
||||||
|
endpointStatuses[endpoint] = "not available"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// It's not a JSON response
|
||||||
|
endpointStatuses[endpoint] = "not available"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Reply not 200 OK
|
||||||
|
endpointStatuses[endpoint] = "not available"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue