-
Notifications
You must be signed in to change notification settings - Fork 20
/
status.go
98 lines (82 loc) · 2.08 KB
/
status.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
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
89
90
91
92
93
94
95
96
97
98
package cmd
import (
"bytes"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/status"
"github.com/exoscale/cli/table"
)
// REF: https://www.statuspal.io/api-docs#tag/Status/operation/getStatusPageStatus
const (
statusPageSubdomain = "exoscalestatus"
)
func init() {
// Global flags have no effect here, hide them
statusCmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
for _, flags := range []string{"quiet", "output-format", "output-template"} {
err := cmd.Flags().MarkHidden(flags)
if err != nil {
fmt.Print(err)
}
}
cmd.Parent().HelpFunc()(cmd, args)
})
RootCmd.AddCommand(statusCmd)
}
var statusCmd = &cobra.Command{
Use: "status",
Short: "Exoscale status",
RunE: func(cmd *cobra.Command, args []string) error {
return statusShow()
},
}
func statusShow() error {
status, err := status.GetStatusPage(statusPageSubdomain)
if err != nil {
return err
}
// First show the global status per zone
global, err := status.GetStatusByZone()
if err != nil {
return err
}
t := table.NewTable(os.Stdout)
t.SetHeader([]string{"Exoscale Status"})
buf := bytes.NewBuffer(nil)
st := table.NewEmbeddedTable(buf)
st.Table.AppendBulk(global)
st.Render()
t.Append([]string{"Services", buf.String()})
buf.Reset()
// Get the active incidents with impacted services by zone
incidents, err := status.Incidents.GetActiveEvents(status.Services)
if err != nil {
return err
}
// Show incidents currently taking place
if len(incidents) > 0 {
it := table.NewEmbeddedTable(buf)
it.Table.AppendBulk(incidents)
it.Render()
} else {
buf = bytes.NewBuffer([]byte("n/a"))
}
t.Append([]string{"Incidents", buf.String()})
buf.Reset()
// Get the active maintenances with impacted services by zone
maintenances, err := status.Maintenances.GetActiveEvents(status.Services)
if err != nil {
return err
}
if len(maintenances) > 0 {
mt := table.NewEmbeddedTable(buf)
mt.Table.AppendBulk(maintenances)
mt.Render()
} else {
buf = bytes.NewBuffer([]byte("n/a"))
}
t.Append([]string{"Maintenances", buf.String()})
t.Render()
return nil
}