diff --git a/cmd/index.go b/cmd/index.go index 943ec0b..03bb624 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -75,10 +75,10 @@ func IndexList(conf *cfg.Config) *cli.Command { Aliases: []string{"H"}, }, &cli.BoolFlag{ - Name: "reds", + Name: "failed", Usage: "include only red failed indicies", Destination: &conf.Failed, - Aliases: []string{"r"}, + Aliases: []string{"f"}, }, &cli.StringSliceFlag{ Name: "filter", diff --git a/pkg/cfg/config.go b/pkg/cfg/config.go index a1588be..628c92a 100644 --- a/pkg/cfg/config.go +++ b/pkg/cfg/config.go @@ -82,8 +82,9 @@ type Config struct { SortBy string // sort: -k Ascending bool // sort: -a + All bool // doc + node ls: -a Exclude string // cluster compare: -e (regexp) - All, Verbose bool // cluster status: -a -v + Verbose bool // cluster status: -v Persistent, Transient, Default bool // cluster settings set: -p -t -D Force bool // ccr follower renew: -f diff --git a/pkg/cfg/transport.go b/pkg/cfg/transport.go index 42e19d8..f5b35eb 100644 --- a/pkg/cfg/transport.go +++ b/pkg/cfg/transport.go @@ -53,10 +53,7 @@ func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) { contentline = buf.String() } - if req.Header.Get("Accept") != "" { - req.Header.Del("Accept") - req.Header.Add("Accept", "application/json") - } + req = fixRequestHeaders(req) slog.Info("req", "host", req.URL.Host, "uri", req.URL.Path, "body", content, "bodyline", contentline, @@ -66,20 +63,31 @@ func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) { return t.Transport.RoundTrip(req) } -// Fixes https://codeberg.org/scip/esctl/issues/79: -// the API client has this Accept header hardcoded everywhere: -// req.Header.Set("Accept", "application/vnd.elasticsearch+json;compatible-with=9") -// While this works pretty well with ES9, it doesn't with ES8. So, we replace -// this header with a new one without the compatibility part. type CompatibilityTransport struct { Transport http.RoundTripper } func (t *CompatibilityTransport) RoundTrip(req *http.Request) (*http.Response, error) { + req = fixRequestHeaders(req) + + return t.Transport.RoundTrip(req) +} + +// Fixes https://codeberg.org/scip/esctl/issues/79: +// the API client has this Accept header hardcoded everywhere: +// req.Header.Set("Accept", "application/vnd.elasticsearch+json;compatible-with=9") +// While this works pretty well with ES9, it doesn't with ES8. So, we replace +// this header with a new one without the compatibility part. +func fixRequestHeaders(req *http.Request) *http.Request { if req.Header.Get("Accept") != "" { req.Header.Del("Accept") req.Header.Add("Accept", "application/json") } - return t.Transport.RoundTrip(req) + if req.Header.Get("Content-Type") != "" { + req.Header.Del("Content-Type") + req.Header.Add("Content-Type", "application/json") + } + + return req } diff --git a/pkg/es/cluster.go b/pkg/es/cluster.go index 8222859..a7e2988 100644 --- a/pkg/es/cluster.go +++ b/pkg/es/cluster.go @@ -174,11 +174,16 @@ func ClusterStatus(conf *cfg.Config) error { } // look for red indices, if any - redindices := 0 + failedIndices := 0 + greenIndices := 0 for _, index := range *res.indices { - if *index.Health == "red" { - redindices++ + switch { + case *index.Health != "green": + failedIndices++ + case !strings.HasPrefix(*index.Index, "."): + // don't count internal indices + greenIndices++ } } @@ -205,7 +210,8 @@ func ClusterStatus(conf *cfg.Config) error { {"Unassigned Primary Shards", res.health.UnassignedPrimaryShards}, {"Pending Tasks", res.health.NumberOfPendingTasks}, {"Nodes", res.health.NumberOfNodes}, - {"Red Indices", redindices}, + {"Green Indices", greenIndices}, + {"Failed Indices", failedIndices}, {"Long Running Tasks", longtasks}, } @@ -233,6 +239,10 @@ func ClusterStatus(conf *cfg.Config) error { for resource, items := range diag.AffectedResources { table.Entries = append(table.Entries, []any{" -> affected " + resource, strings.Join(items, ",")}) } + + if diag.Action != "" { + table.AddRow(" -> suggested action to fix", diag.Action) + } } } }