mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
Use alert status, inhibitedBy & silencedBy fields instead of silenced & inhibited
This commit is contained in:
@@ -6,6 +6,7 @@ package v04
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/blang/semver"
|
||||
@@ -75,16 +76,26 @@ func (m AlertMapper) GetAlerts() ([]models.AlertGroup, error) {
|
||||
alertList := models.AlertList{}
|
||||
for _, b := range g.Blocks {
|
||||
for _, a := range b.Alerts {
|
||||
status := models.AlertStateActive
|
||||
silencedBy := []string{}
|
||||
if a.Silenced > 0 {
|
||||
silencedBy = append(silencedBy, strconv.Itoa(a.Silenced))
|
||||
status = models.AlertStateSuppressed
|
||||
}
|
||||
inhibitedBy := []string{}
|
||||
if a.Inhibited {
|
||||
inhibitedBy = append(inhibitedBy, "0")
|
||||
status = models.AlertStateSuppressed
|
||||
}
|
||||
us := models.Alert{
|
||||
Annotations: a.Annotations,
|
||||
Labels: a.Labels,
|
||||
StartsAt: a.StartsAt,
|
||||
EndsAt: a.EndsAt,
|
||||
GeneratorURL: a.GeneratorURL,
|
||||
Inhibited: a.Inhibited,
|
||||
}
|
||||
if a.Silenced > 0 {
|
||||
us.Silenced = string(a.Silenced)
|
||||
Status: status,
|
||||
InhibitedBy: inhibitedBy,
|
||||
SilencedBy: silencedBy,
|
||||
}
|
||||
alertList = append(alertList, us)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/blang/semver"
|
||||
@@ -77,7 +78,7 @@ func (m SilenceMapper) GetSilences() ([]models.Silence, error) {
|
||||
|
||||
for _, s := range resp.Data.Silences {
|
||||
us := models.Silence{
|
||||
ID: string(s.ID),
|
||||
ID: strconv.Itoa(s.ID),
|
||||
Matchers: s.Matchers,
|
||||
StartsAt: s.StartsAt,
|
||||
EndsAt: s.EndsAt,
|
||||
|
||||
@@ -73,14 +73,26 @@ func (m AlertMapper) GetAlerts() ([]models.AlertGroup, error) {
|
||||
alertList := models.AlertList{}
|
||||
for _, b := range g.Blocks {
|
||||
for _, a := range b.Alerts {
|
||||
status := models.AlertStateActive
|
||||
silencedBy := []string{}
|
||||
if a.Silenced != "" {
|
||||
silencedBy = append(silencedBy, a.Silenced)
|
||||
status = models.AlertStateSuppressed
|
||||
}
|
||||
inhibitedBy := []string{}
|
||||
if a.Inhibited {
|
||||
inhibitedBy = append(inhibitedBy, "0")
|
||||
status = models.AlertStateSuppressed
|
||||
}
|
||||
us := models.Alert{
|
||||
Annotations: a.Annotations,
|
||||
Labels: a.Labels,
|
||||
StartsAt: a.StartsAt,
|
||||
EndsAt: a.EndsAt,
|
||||
GeneratorURL: a.GeneratorURL,
|
||||
Inhibited: a.Inhibited,
|
||||
Silenced: a.Silenced,
|
||||
Status: status,
|
||||
InhibitedBy: inhibitedBy,
|
||||
SilencedBy: silencedBy,
|
||||
}
|
||||
alertList = append(alertList, us)
|
||||
}
|
||||
|
||||
@@ -75,9 +75,13 @@ func (m AlertMapper) GetAlerts() ([]models.AlertGroup, error) {
|
||||
alertList := models.AlertList{}
|
||||
for _, b := range g.Blocks {
|
||||
for _, a := range b.Alerts {
|
||||
silenceID := ""
|
||||
if len(a.SilencedBy) > 0 {
|
||||
silenceID = a.SilencedBy[0]
|
||||
inhibitedBy := []string{}
|
||||
if a.InhibitedBy != nil {
|
||||
inhibitedBy = a.InhibitedBy
|
||||
}
|
||||
silencedBy := []string{}
|
||||
if a.SilencedBy != nil {
|
||||
silencedBy = a.SilencedBy
|
||||
}
|
||||
us := models.Alert{
|
||||
Annotations: a.Annotations,
|
||||
@@ -85,8 +89,9 @@ func (m AlertMapper) GetAlerts() ([]models.AlertGroup, error) {
|
||||
StartsAt: a.StartsAt,
|
||||
EndsAt: a.EndsAt,
|
||||
GeneratorURL: a.GeneratorURL,
|
||||
Inhibited: len(a.InhibitedBy) > 0,
|
||||
Silenced: silenceID,
|
||||
Status: a.Status,
|
||||
InhibitedBy: inhibitedBy,
|
||||
SilencedBy: silencedBy,
|
||||
}
|
||||
alertList = append(alertList, us)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user