(ctx context.Context, app string)
| 13 | ) |
| 14 | |
| 15 | func 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 | } |
no test coverage detected