MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / fetchGroupData

Function fetchGroupData

controller/uptime_kuma.go:56–128  ·  view source on GitHub ↗
(ctx context.Context, client *http.Client, groupConfig map[string]interface{})

Source from the content-addressed store, hash-verified

54}
55
56func fetchGroupData(ctx context.Context, client *http.Client, groupConfig map[string]interface{}) UptimeGroupResult {
57 url, _ := groupConfig["url"].(string)
58 slug, _ := groupConfig["slug"].(string)
59 categoryName, _ := groupConfig["categoryName"].(string)
60
61 result := UptimeGroupResult{
62 CategoryName: categoryName,
63 Monitors: []Monitor{},
64 }
65
66 if url == "" || slug == "" {
67 return result
68 }
69
70 baseURL := strings.TrimSuffix(url, "/")
71
72 var statusData struct {
73 PublicGroupList []struct {
74 ID int `json:"id"`
75 Name string `json:"name"`
76 MonitorList []struct {
77 ID int `json:"id"`
78 Name string `json:"name"`
79 } `json:"monitorList"`
80 } `json:"publicGroupList"`
81 }
82
83 var heartbeatData struct {
84 HeartbeatList map[string][]struct {
85 Status int `json:"status"`
86 } `json:"heartbeatList"`
87 UptimeList map[string]float64 `json:"uptimeList"`
88 }
89
90 g, gCtx := errgroup.WithContext(ctx)
91 g.Go(func() error {
92 return getAndDecode(gCtx, client, baseURL+apiStatusPath+slug, &statusData)
93 })
94 g.Go(func() error {
95 return getAndDecode(gCtx, client, baseURL+apiHeartbeatPath+slug, &heartbeatData)
96 })
97
98 if g.Wait() != nil {
99 return result
100 }
101
102 for _, pg := range statusData.PublicGroupList {
103 if len(pg.MonitorList) == 0 {
104 continue
105 }
106
107 for _, m := range pg.MonitorList {
108 monitor := Monitor{
109 Name: m.Name,
110 Group: pg.Name,
111 }
112
113 monitorID := strconv.Itoa(m.ID)

Callers 1

GetUptimeKumaStatusFunction · 0.85

Calls 1

getAndDecodeFunction · 0.85

Tested by

no test coverage detected