feat(alerting): add monitor alert groups with default routing
This commit is contained in:
1 parent
52819e64bb
commit
8544e5a585
26 files changed
+2938
-1473
No files matched your search
+20
-1
@@ -208,6 +208,7 @@ func (s *Server) sendExport(c *gin.Context, format, name, title string, x any) {
|
||||
}
|
||||
|
||||
type orgExport struct {
|
||||
AlertGroups []alertGroupView `json:"alert_groups"`
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
Organization exportOrg `json:"organization"`
|
||||
Members []exportMember `json:"members"`
|
||||
@@ -255,6 +256,7 @@ type exportGroup struct {
|
||||
}
|
||||
|
||||
type exportMonitor struct {
|
||||
AlertGroupIDs []uuid.UUID `json:"alert_group_ids"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
@@ -391,6 +393,22 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
||||
x.Groups = append(x.Groups, exportGroup{ID: g.ID, Name: g.Name, ParentID: g.ParentID})
|
||||
}
|
||||
|
||||
alertGroups, err := q.ListAlertGroups(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
x.AlertGroups = []alertGroupView{}
|
||||
for _, g := range alertGroups {
|
||||
x.AlertGroups = append(x.AlertGroups, alertGroupView{ID: g.ID, Name: g.Name, IsDefault: g.IsDefault, ChannelIDs: g.ChannelIds})
|
||||
}
|
||||
alertAssignments, err := q.AllMonitorAlertGroups(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
alertGroupsByMonitor := map[uuid.UUID][]uuid.UUID{}
|
||||
for _, a := range alertAssignments {
|
||||
alertGroupsByMonitor[a.MonitorID] = append(alertGroupsByMonitor[a.MonitorID], a.GroupID)
|
||||
}
|
||||
regionRows, err := q.AllMonitorRegions(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -408,7 +426,8 @@ func (s *Server) buildOrgExport(ctx context.Context, p *principal) (orgExport, e
|
||||
x.Monitors = append(x.Monitors, exportMonitor{
|
||||
ID: m.ID, Name: m.Name, Type: m.Type, Target: m.Target, IntervalSeconds: m.IntervalSeconds,
|
||||
TimeoutMS: m.TimeoutMs, Confirmations: m.Confirmations, Enabled: m.Enabled, GroupID: m.GroupID,
|
||||
Regions: orEmpty(regions[m.ID]), Config: rawJSON(first(publicMonitorConfig(m.Config))), CreatedAt: m.CreatedAt,
|
||||
AlertGroupIDs: orEmpty(alertGroupsByMonitor[m.ID]),
|
||||
Regions: orEmpty(regions[m.ID]), Config: rawJSON(first(publicMonitorConfig(m.Config))), CreatedAt: m.CreatedAt,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user