MCPcopy Create free account
hub / github.com/Scalingo/cli / List

Function List

alerts/list.go:15–65  ·  view source on GitHub ↗
(ctx context.Context, app string)

Source from the content-addressed store, hash-verified

13)
14
15func List(ctx context.Context, app string) error {
16 c, err := config.ScalingoClient(ctx)
17 if err != nil {
18 return errors.Wrap(ctx, err, "get Scalingo client")
19 }
20
21 alerts, err := c.AlertsList(ctx, app)
22 if err != nil {
23 return errors.Wrap(ctx, err, "list alerts")
24 }
25
26 t := tablewriter.NewWriter(os.Stdout)
27 headers := []string{"ID", "Active", "Container Type", "Metric", "Limit"}
28 hasRemindEvery := false
29 for _, alert := range alerts {
30 if alert.RemindEvery != "" {
31 hasRemindEvery = true
32 }
33 }
34 if hasRemindEvery {
35 headers = append(headers, "Remind Every")
36 }
37 t.Header(headers)
38
39 for _, alert := range alerts {
40 var above string
41 if alert.SendWhenBelow {
42 above = "≤"
43 } else {
44 above = "≥"
45 }
46 var durationString string
47 if alert.DurationBeforeTrigger != 0 {
48 durationString = fmt.Sprintf(" (for %s)", alert.DurationBeforeTrigger)
49 }
50
51 row := []string{
52 alert.ID,
53 strconv.FormatBool(!alert.Disabled),
54 alert.ContainerType,
55 alert.Metric,
56 fmt.Sprintf("%s %.2f%s", above, alert.Limit, durationString),
57 }
58 if hasRemindEvery {
59 row = append(row, alert.RemindEvery)
60 }
61 t.Append(row)
62 }
63 t.Render()
64 return nil
65}

Callers 1

alerts.goFile · 0.92

Calls 2

ScalingoClientFunction · 0.92
RenderMethod · 0.65

Tested by

no test coverage detected