2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-06-05 15:00:45 +00:00
|
|
|
package api
|
|
|
|
|
2022-03-24 17:58:03 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
)
|
2018-07-24 22:49:55 +00:00
|
|
|
|
2017-06-05 15:00:45 +00:00
|
|
|
func (c *Sys) Health() (*HealthResponse, error) {
|
2022-03-23 21:47:43 +00:00
|
|
|
return c.HealthWithContext(context.Background())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Sys) HealthWithContext(ctx context.Context) (*HealthResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
|
|
|
defer cancelFunc()
|
|
|
|
|
2022-03-24 17:58:03 +00:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/health")
|
2017-08-02 14:01:40 +00:00
|
|
|
// If the code is 400 or above it will automatically turn into an error,
|
|
|
|
// but the sys/health API defaults to returning 5xx when not sealed or
|
|
|
|
// inited, so we force this code to be something else so we parse correctly
|
|
|
|
r.Params.Add("uninitcode", "299")
|
2018-01-18 04:50:37 +00:00
|
|
|
r.Params.Add("sealedcode", "299")
|
|
|
|
r.Params.Add("standbycode", "299")
|
|
|
|
r.Params.Add("drsecondarycode", "299")
|
2018-08-24 16:09:03 +00:00
|
|
|
r.Params.Add("performancestandbycode", "299")
|
2018-07-24 22:49:55 +00:00
|
|
|
|
2022-03-23 21:47:43 +00:00
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2017-06-05 15:00:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result HealthResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type HealthResponse struct {
|
2018-01-23 02:44:38 +00:00
|
|
|
Initialized bool `json:"initialized"`
|
|
|
|
Sealed bool `json:"sealed"`
|
|
|
|
Standby bool `json:"standby"`
|
2019-01-17 23:14:52 +00:00
|
|
|
PerformanceStandby bool `json:"performance_standby"`
|
2018-01-23 02:44:38 +00:00
|
|
|
ReplicationPerformanceMode string `json:"replication_performance_mode"`
|
|
|
|
ReplicationDRMode string `json:"replication_dr_mode"`
|
|
|
|
ServerTimeUTC int64 `json:"server_time_utc"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
ClusterName string `json:"cluster_name,omitempty"`
|
|
|
|
ClusterID string `json:"cluster_id,omitempty"`
|
2018-10-16 13:38:44 +00:00
|
|
|
LastWAL uint64 `json:"last_wal,omitempty"`
|
2017-06-05 15:00:45 +00:00
|
|
|
}
|