Compare commits

..

9 Commits

Author SHA1 Message Date
0902b44780 always show actions 2026-07-08 10:20:02 +02:00
5e569b91fc fix transport http headers 2026-07-08 10:19:48 +02:00
82c6d2e7bb show green and failed indices in status, rename red to failed in index ls 2026-07-08 09:57:39 +02:00
03cfeb4336 fix go tool 2026-07-08 09:34:58 +02:00
T. von Dein
3d3dfb7a42 fix #79: remove compatibility header (#80) 2026-07-08 09:33:22 +02:00
1d45a3cd4c set go version for releaser 2026-07-08 00:00:37 +02:00
0104e1bf58 fix go releaser go version 2026-07-07 23:53:47 +02:00
2dc716d1c9 fix version newline 2026-07-07 23:49:57 +02:00
T. von Dein
0d63e7c4d2 satisfy full linter (#77) 2026-07-07 23:46:43 +02:00
6 changed files with 54 additions and 9 deletions

View File

@@ -75,10 +75,10 @@ func IndexList(conf *cfg.Config) *cli.Command {
Aliases: []string{"H"}, Aliases: []string{"H"},
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "reds", Name: "failed",
Usage: "include only red failed indicies", Usage: "include only red failed indicies",
Destination: &conf.Failed, Destination: &conf.Failed,
Aliases: []string{"r"}, Aliases: []string{"f"},
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "filter", Name: "filter",

2
go.mod
View File

@@ -14,7 +14,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
module codeberg.org/scip/esctl module codeberg.org/scip/esctl
go 1.26.4 go 1.26
require ( require (
github.com/MichaelMure/go-term-markdown v0.1.4 github.com/MichaelMure/go-term-markdown v0.1.4

View File

@@ -189,6 +189,7 @@ func (cluster *Cluster) getDefaultOptions() []elasticsearch.Option {
cluster.getTransport(), cluster.getTransport(),
elastictransport.WithHeader(headers), elastictransport.WithHeader(headers),
), ),
elasticsearch.WithCompatibilityMode(),
} }
} }
@@ -203,7 +204,9 @@ func (cluster *Cluster) getTransport() elastictransport.Option {
) )
} }
return elastictransport.WithTransport(transport) return elastictransport.WithTransport(
&CompatibilityTransport{Transport: transport},
)
} }
func (conf *Config) SetupES() error { func (conf *Config) SetupES() error {

View File

@@ -82,8 +82,9 @@ type Config struct {
SortBy string // sort: -k SortBy string // sort: -k
Ascending bool // sort: -a Ascending bool // sort: -a
All bool // doc + node ls: -a
Exclude string // cluster compare: -e (regexp) 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 Persistent, Transient, Default bool // cluster settings set: -p -t -D
Force bool // ccr follower renew: -f Force bool // ccr follower renew: -f

View File

@@ -53,6 +53,8 @@ func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
contentline = buf.String() contentline = buf.String()
} }
req = fixRequestHeaders(req)
slog.Info("req", "host", req.URL.Host, "uri", req.URL.Path, slog.Info("req", "host", req.URL.Host, "uri", req.URL.Path,
"body", content, "bodyline", contentline, "body", content, "bodyline", contentline,
"headers", req.Header, "headers", req.Header,
@@ -60,3 +62,32 @@ func (t *DebugTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return t.Transport.RoundTrip(req) return t.Transport.RoundTrip(req)
} }
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")
}
if req.Header.Get("Content-Type") != "" {
req.Header.Del("Content-Type")
req.Header.Add("Content-Type", "application/json")
}
return req
}

View File

@@ -174,11 +174,16 @@ func ClusterStatus(conf *cfg.Config) error {
} }
// look for red indices, if any // look for red indices, if any
redindices := 0 failedIndices := 0
greenIndices := 0
for _, index := range *res.indices { for _, index := range *res.indices {
if *index.Health == "red" { switch {
redindices++ 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}, {"Unassigned Primary Shards", res.health.UnassignedPrimaryShards},
{"Pending Tasks", res.health.NumberOfPendingTasks}, {"Pending Tasks", res.health.NumberOfPendingTasks},
{"Nodes", res.health.NumberOfNodes}, {"Nodes", res.health.NumberOfNodes},
{"Red Indices", redindices}, {"Green Indices", greenIndices},
{"Failed Indices", failedIndices},
{"Long Running Tasks", longtasks}, {"Long Running Tasks", longtasks},
} }
@@ -233,6 +239,10 @@ func ClusterStatus(conf *cfg.Config) error {
for resource, items := range diag.AffectedResources { for resource, items := range diag.AffectedResources {
table.Entries = append(table.Entries, []any{" -> affected " + resource, strings.Join(items, ",")}) table.Entries = append(table.Entries, []any{" -> affected " + resource, strings.Join(items, ",")})
} }
if diag.Action != "" {
table.AddRow(" -> suggested action to fix", diag.Action)
}
} }
} }
} }