display context with alert

This commit is contained in:
alteredCoder 2022-04-14 12:03:51 +02:00
parent 186d5c3aa5
commit eb0fb243a3

View file

@ -185,6 +185,28 @@ func DisplayOneAlert(alert *models.Alert, withDetail bool) error {
table.Render() // Send output
}
fmt.Printf("\n - Context :\n")
sort.Slice(alert.Meta, func(i, j int) bool {
return alert.Meta[i].Key < alert.Meta[j].Key
})
table = tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Key", "Value"})
for _, meta := range alert.Meta {
var valSlice []string
if err := json.Unmarshal([]byte(meta.Value), &valSlice); err != nil {
log.Fatalf("unknown context value type '%s' : %s", meta.Value, err)
}
for _, value := range valSlice {
table.Append([]string{
meta.Key,
value,
})
}
}
table.SetAutoMergeCells(true)
table.SetRowLine(true)
table.Render() // Send output
}
}
return nil