Skip to content

Commit

Permalink
first try to parse a statusresponse to see wheter we got an error...
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Crauwels committed Aug 8, 2017
1 parent af0a613 commit c72cdae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions clusterHealth.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ func checkClusterHealth(args []string) *checkers.Checker {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)

// check first if we might have gotten a StatusResponse instead of a ClusterDetailResponse (example: "No cluster found for alias")
var status StatusResponse
err = json.Unmarshal(body, &status)

if err == nil {
msg := status.Message
checkSt := checkers.OK

if status.Code != "OK" {
checkSt = checkers.CRITICAL
}

return checkers.NewChecker(checkSt, msg)
}

// The response was not a StatusResponse, so try to process is as a ClusterDetailResponse
var r []ClusterDetailResponse
err = json.Unmarshal(body, &r)

Expand Down
16 changes: 16 additions & 0 deletions clusterInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ func checkClusterInfo(args []string) *checkers.Checker {
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)

// check first if we might have gotten a StatusResponse instead of a ClusterInfoResponse
var status StatusResponse
err = json.Unmarshal(body, &status)

if err == nil {
msg := status.Message
checkSt := checkers.OK

if status.Code != "OK" {
checkSt = checkers.CRITICAL
}

return checkers.NewChecker(checkSt, msg)
}

// The response was not a StatusResponse, so try to process is as a ClusterInfoResponse
var r []ClusterInfoResponse
err = json.Unmarshal(body, &r)

Expand Down

0 comments on commit c72cdae

Please sign in to comment.