-
Notifications
You must be signed in to change notification settings - Fork 3
/
repair.go
51 lines (43 loc) · 997 Bytes
/
repair.go
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
package entity
import (
"fmt"
"html"
"strings"
"time"
)
// RepairResult a result of "nodetool repair" command
type RepairResult struct {
Output string
Duration time.Duration
}
// RepairResults results of "nodetool repair" on multiple database nodes
type RepairResults struct {
TotalNodes int
RepairedNodes int
ByHost map[string]RepairResult
Error error
}
// Report creates a human-readable report string about repair results to be used in a notification
func (r RepairResults) Report() string {
lines := []string{
fmt.Sprintf("Total nodes: %d", r.TotalNodes),
fmt.Sprintf("Repaired nodes: %d", r.RepairedNodes),
"",
}
if r.Error != nil {
lines = append(
lines,
"Error:",
fmt.Sprintf("%s", html.EscapeString(r.Error.Error())),
)
}
lines = append(lines, "Duration:")
for host, result := range r.ByHost {
lines = append(lines, fmt.Sprintf(
"%s: %s",
host,
result.Duration.String(),
))
}
return strings.Join(lines, "\n")
}