-
Notifications
You must be signed in to change notification settings - Fork 53
/
status.go
43 lines (36 loc) · 936 Bytes
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package opensearchdata
import (
"context"
"github.com/rancher/opni/pkg/util"
"github.com/tidwall/gjson"
)
func (m *Manager) GetClusterStatus() ClusterStatus {
if !m.IsInitialized() {
return ClusterStatusNoClient
}
m.Lock()
defer m.Unlock()
resp, err := m.Client.Cluster.GetClusterHealth(context.TODO())
if err != nil {
m.logger.With("err", err).Error("failed to fetch opensearch cluster status")
return ClusterStatusError
}
defer resp.Body.Close()
if resp.IsError() {
m.logger.With("resp", resp.String).Error("failure response from cluster status")
return ClusterStatusError
}
respString := util.ReadString(resp.Body)
status := gjson.Get(respString, "status").String()
switch status {
case "green":
return ClusterStatusGreen
case "yellow":
return ClusterStatusYellow
case "red":
return ClusterStatusRed
default:
m.logger.Errorf("unknown status: %s", status)
return ClusterStatusError
}
}