dont show ccr status if license insufficient

This commit is contained in:
2026-07-05 22:11:01 +02:00
parent a07f38e945
commit 90c7da98ea
2 changed files with 23 additions and 15 deletions

3
.gitignore vendored
View File

@@ -32,3 +32,6 @@ esctl
*.log *.log
cpu.profile cpu.profile
t
single

View File

@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package es package es
import ( import (
"errors"
"fmt" "fmt"
"log/slog" "log/slog"
"strings" "strings"
@@ -118,12 +119,12 @@ func getClusterStatus(conf *cfg.Config) (*apiResponse, error) {
all := apiResponse{} all := apiResponse{}
var err error
for i := 0; i < gocount; i++ { for i := 0; i < gocount; i++ {
r := <-responses r := <-responses
if r.error != nil { err = errors.Join(err, r.error)
return nil, r.error
}
switch r.which { switch r.which {
case ResponseHealth: case ResponseHealth:
@@ -143,27 +144,31 @@ func getClusterStatus(conf *cfg.Config) (*apiResponse, error) {
} }
} }
return &all, nil return &all, err
} }
func ClusterStatus(conf *cfg.Config) error { func ClusterStatus(conf *cfg.Config) error {
res, err := getClusterStatus(conf) res, err := getClusterStatus(conf)
if err != nil { if err != nil && !strings.Contains(err.Error(), "current license is non-compliant") {
return err return err
} }
slog.Debug("ES result", "cluster health", res.health) slog.Debug("ES result", "cluster health", res.health)
isleader := len(res.ccr.AutoFollowStats.AutoFollowedClusters) == 0 var isleader bool
var ccrfollowing string
ccrfollowing := "" if res.ccr != nil {
if len(res.ccr.AutoFollowStats.AutoFollowedClusters) > 0 { isleader = len(res.ccr.AutoFollowStats.AutoFollowedClusters) == 0
// is following another cluster
ccrfollowing = fmt.Sprintf("%s (%d/%d)", if len(res.ccr.AutoFollowStats.AutoFollowedClusters) > 0 {
res.ccr.AutoFollowStats.AutoFollowedClusters[0].ClusterName, // is following another cluster
res.ccr.AutoFollowStats.NumberOfSuccessfulFollowIndices, ccrfollowing = fmt.Sprintf("%s (%d/%d)",
res.ccr.AutoFollowStats.NumberOfFailedFollowIndices, res.ccr.AutoFollowStats.AutoFollowedClusters[0].ClusterName,
) res.ccr.AutoFollowStats.NumberOfSuccessfulFollowIndices,
res.ccr.AutoFollowStats.NumberOfFailedFollowIndices,
)
}
} }
// look for red indices, if any // look for red indices, if any
@@ -200,7 +205,7 @@ func ClusterStatus(conf *cfg.Config) error {
{"Long Running Tasks", fmt.Sprintf("%d", longtasks)}, {"Long Running Tasks", fmt.Sprintf("%d", longtasks)},
} }
if !isleader { if !isleader && res.ccr != nil {
table.Entries = append(table.Entries, [][]string{ table.Entries = append(table.Entries, [][]string{
{"AutoFollow (success/failed indices)", ccrfollowing}, {"AutoFollow (success/failed indices)", ccrfollowing},
{"Followed Indices", fmt.Sprintf("%d", len(res.ccr.FollowStats.Indices))}, {"Followed Indices", fmt.Sprintf("%d", len(res.ccr.FollowStats.Indices))},