-
Notifications
You must be signed in to change notification settings - Fork 20
/
runstatus_incident_update.go
136 lines (109 loc) · 3.4 KB
/
runstatus_incident_update.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package cmd
import (
"bufio"
"fmt"
"os"
"text/tabwriter"
"github.com/exoscale/egoscale"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)
// runstatusIncidentEventCmd represents the event command
var runstatusIncidentUpdateCmd = &cobra.Command{
Use: "update [page name] <incident name | id>",
Short: "update an existing incident",
Long: `Update an incident.
This is also used to close an incident,
passing a resolved status and flagging the services state as operational`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
pageName := gCurrentAccount.DefaultRunstatusPage
incidentName := args[0]
if gCurrentAccount.DefaultRunstatusPage == "" && len(args) == 1 {
fmt.Fprintf(os.Stderr, `Error: No default runstat.us page is set:
Please specify a page in parameter or add it to %q
`, gConfigFilePath)
return cmd.Usage()
}
if len(args) > 1 {
pageName = args[0]
incidentName = args[1]
}
runstatusPage, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: pageName})
if err != nil {
return err
}
incident, err := getIncidentByNameOrID(*runstatusPage, incidentName)
if err != nil {
return err
}
reader := bufio.NewReader(os.Stdin)
description, err := cmd.Flags().GetString(runstatusFlagDescription)
if err != nil {
return nil
}
if description == "" {
description, err = readInput(reader, "Description of the incident", "none")
if err != nil {
return err
}
}
state, err := cmd.Flags().GetString(runstatusFlagState)
if err != nil {
return nil
}
if state == "" {
prompt := promptui.Select{
Label: "Services State",
Items: []string{"major_outage", "partial_outage", "degraded_performance", "operational"},
}
_, state, err = prompt.Run()
if err != nil {
return fmt.Errorf("prompt failed %v", err)
}
}
status, err := cmd.Flags().GetString(runstatusFlagStatus)
if err != nil {
return nil
}
if status == "" {
prompt := promptui.Select{
Label: "Event Status",
Items: []string{"investigating", "identified", "monitoring", "resolved"},
}
_, status, err = prompt.Run()
if err != nil {
return fmt.Errorf("prompt failed %v", err)
}
}
fmt.Println()
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.TabIndent)
fmt.Fprintf(w, "Description:\t%s\n", description) // nolint: errcheck
fmt.Fprintf(w, "State:\t%s\n", state) // nolint: errcheck
fmt.Fprintf(w, "Status:\t%s\n", status) // nolint: errcheck
if err := w.Flush(); err != nil {
return err
}
if !askQuestion("sure you want to update this incident") {
return nil
}
if err := csRunstatus.UpdateRunstatusIncident(gContext, *incident, egoscale.RunstatusEvent{
Text: description,
Status: status,
State: state,
}); err != nil {
return err
}
fmt.Printf("Incident %q successfully updated\n", incidentName)
return nil
},
}
func init() {
runstatusIncidentCmd.AddCommand(runstatusIncidentUpdateCmd)
//required
runstatusIncidentUpdateCmd.Flags().StringP(runstatusFlagDescription, "d", "", "Description the incident")
runstatusIncidentUpdateCmd.Flags().StringP(runstatusFlagStatus, "s", "", "<investigating | identified | monitoring | resolved>")
runstatusIncidentUpdateCmd.Flags().StringP(runstatusFlagState, "t", "", "<major_outage | partial_outage | degraded_performance | operational>")
}