Skip to content

Commit

Permalink
Better display of the duration before trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneM committed Apr 12, 2019
1 parent e783b84 commit 8467d4b
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions alerts/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,38 @@ func List(app string) error {
t := tablewriter.NewWriter(os.Stdout)
headers := []string{"ID", "Active", "Container Type", "Metric", "Limit"}
hasRemindEvery := false
hasDurationBeforeTrigger := false
for _, alert := range alerts {
if alert.DurationBeforeTrigger != 0 {
hasDurationBeforeTrigger = true
}
if alert.RemindEvery != "" {
hasRemindEvery = true
}
}
if hasRemindEvery {
headers = append(headers, "Remind Every")
}
if hasDurationBeforeTrigger {
headers = append(headers, "Duration")
}
t.SetHeader(headers)

for _, alert := range alerts {
var above string
if alert.SendWhenBelow {
above = "below"
above = ""
} else {
above = "above"
above = ""
}
var durationString string
if alert.DurationBeforeTrigger != 0 {
durationString = fmt.Sprintf(" (for %s)", alert.DurationBeforeTrigger)
}

row := []string{
alert.ID,
fmt.Sprint(!alert.Disabled),
alert.ContainerType,
alert.Metric,
fmt.Sprintf("triggers %s %.2f", above, alert.Limit),
fmt.Sprintf("%s %.2f%s", above, alert.Limit, durationString),
}
if hasRemindEvery {
row = append(row, alert.RemindEvery)
}
if hasDurationBeforeTrigger {
row = append(row, alert.DurationBeforeTrigger.String())
}
t.Append(row)
}
t.Render()
Expand Down

0 comments on commit 8467d4b

Please sign in to comment.