-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcat.go
More file actions
88 lines (75 loc) · 1.9 KB
/
cat.go
File metadata and controls
88 lines (75 loc) · 1.9 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"context"
"fmt"
"strings"
"github.com/olivere/elastic/v7"
"github.com/urfave/cli/v2"
)
type catAliasesSvc interface {
Do(ctx context.Context) (elastic.CatAliasesResponse, error)
}
type catIndicesSvc interface {
Do(ctx context.Context) (elastic.CatIndicesResponse, error)
}
func prettyCatAliases(service catAliasesSvc) (*string, error) {
res, err := service.Do(context.Background())
if err != nil {
return nil, err
}
var buf strings.Builder
buf.WriteString(fmt.Sprintln("alias\tindex\trouting.index\trouting.search\tis_write_index"))
for _, v := range res {
row := fmt.Sprintf(
"%s\t%s\t%s\t%s\t%s\n",
v.Alias,
v.Index,
v.RoutingIndex,
v.RoutingSearch,
v.IsWriteIndex,
)
buf.WriteString(row)
}
output := buf.String()
return &output, nil
}
func prettyCatIndices(service catIndicesSvc) (*string, error) {
res, err := service.Do(context.Background())
if err != nil {
return nil, err
}
var buf strings.Builder
headers := []string{
"health", "status", "index", "uuid", "pri", "rep", "docs.count",
"docs.deleted", "store.size", "pri.store.size",
}
buf.WriteString(strings.Join(headers, "\t") + "\n")
for _, v := range res {
row := fmt.Sprintf(
"%s\t%s\t%s\t%s\t%d\t%d\t%d\t%d\t%s\t%s\n",
v.Health, v.Status, v.Index, v.UUID, v.Pri, v.Rep, v.DocsCount,
v.DocsDeleted, v.StoreSize, v.PriStoreSize,
)
buf.WriteString(row)
}
output := buf.String()
return &output, nil
}
func cmdCatAliases(c *cli.Context) error {
client := c.Context.Value("client").(*elastic.Client)
res, err := prettyCatAliases(client.CatAliases().Sort("alias").Human(true))
if err != nil {
return err
}
fmt.Print(*res)
return nil
}
func cmdCatIndices(c *cli.Context) error {
client := c.Context.Value("client").(*elastic.Client)
res, err := prettyCatIndices(client.CatIndices().Sort("index").Human(true))
if err != nil {
return err
}
fmt.Print(*res)
return nil
}