various fixes (#70)

- dont show ccr status if license insufficient
- add automated tests
- fix config loading
- fix search output
- fix `license show` panics
- fix `ilm show` completion
- print ask passwd prompt to stderr
This commit is contained in:
T. von Dein
2026-07-06 14:22:59 +02:00
parent a07f38e945
commit 82c017144a
20 changed files with 610 additions and 27 deletions

View File

@@ -102,7 +102,7 @@ func CcrRemoteInfo(conf *cfg.Config, index string) error {
}
if remote == "" {
return fmt.Errorf("cluster doesn't follow any other: %s", err)
return errors.New("cluster doesn't follow any other")
}
mode := "follower"

View File

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

View File

@@ -67,6 +67,7 @@ func IlmNames(conf *cfg.Config) ([]string, error) {
for name := range res {
names[idx] = name
idx++
}
return names, nil

View File

@@ -39,18 +39,28 @@ func LicenseShow(conf *cfg.Config) error {
lic := res.License
var maxnodes = "infinite"
var maxunits = "infinite"
var expire = "never"
if lic.MaxNodes != nil {
maxnodes = fmt.Sprintf("%d", *lic.MaxNodes)
}
if lic.ExpiryDate != nil {
expire = lic.ExpiryDate.(string)
}
if lic.MaxResourceUnits != nil {
maxunits = fmt.Sprintf("%d", *lic.MaxResourceUnits)
}
table.Entries = [][]string{
{"UID", lic.Uid},
{"Issued to", lic.IssuedTo},
{"Expires", lic.ExpiryDate.(string)},
{"Expires", expire},
{"Issued", lic.IssueDate.(string)},
{"Max nodes", maxnodes},
{"Max resource units", fmt.Sprintf("%d", *lic.MaxResourceUnits)},
{"Max resource units", maxunits},
{"Type", lic.Type.Name},
{"Status", lic.Status.Name},
}