* feat(suite): Implement Suites Fixes #1230 * Update docs * Fix variable alignment * Prevent always-run endpoint from running if a context placeholder fails to resolve in the URL * Return errors when a context placeholder path fails to resolve * Add a couple of unit tests * Add a couple of unit tests * fix(ui): Update group count properly Fixes #1233 * refactor: Pass down entire config instead of several sub-configs * fix: Change default suite interval and timeout * fix: Deprecate disable-monitoring-lock in favor of concurrency * fix: Make sure there are no duplicate keys * Refactor some code * Update watchdog/watchdog.go * Update web/app/src/components/StepDetailsModal.vue Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore: Remove useless log * fix: Set default concurrency to 3 instead of 5 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/TwiN/gatus/v5/config"
|
|
"github.com/TwiN/gatus/v5/config/suite"
|
|
"github.com/TwiN/gatus/v5/storage/store"
|
|
"github.com/TwiN/gatus/v5/storage/store/common/paging"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
// SuiteStatuses handles requests to retrieve all suite statuses
|
|
func SuiteStatuses(cfg *config.Config) fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
page, pageSize := extractPageAndPageSizeFromRequest(c, 100)
|
|
params := paging.NewSuiteStatusParams().WithPagination(page, pageSize)
|
|
suiteStatuses, err := store.Get().GetAllSuiteStatuses(params)
|
|
if err != nil {
|
|
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
|
|
"error": fmt.Sprintf("Failed to retrieve suite statuses: %v", err),
|
|
})
|
|
}
|
|
// If no statuses exist yet, create empty ones from config
|
|
if len(suiteStatuses) == 0 {
|
|
for _, s := range cfg.Suites {
|
|
if s.IsEnabled() {
|
|
suiteStatuses = append(suiteStatuses, suite.NewStatus(s))
|
|
}
|
|
}
|
|
}
|
|
return c.Status(fiber.StatusOK).JSON(suiteStatuses)
|
|
}
|
|
}
|
|
|
|
// SuiteStatus handles requests to retrieve a single suite's status
|
|
func SuiteStatus(cfg *config.Config) fiber.Handler {
|
|
return func(c *fiber.Ctx) error {
|
|
page, pageSize := extractPageAndPageSizeFromRequest(c, 100)
|
|
key := c.Params("key")
|
|
params := paging.NewSuiteStatusParams().WithPagination(page, pageSize)
|
|
status, err := store.Get().GetSuiteStatusByKey(key, params)
|
|
if err != nil || status == nil {
|
|
// Try to find the suite in config
|
|
for _, s := range cfg.Suites {
|
|
if s.Key() == key {
|
|
status = suite.NewStatus(s)
|
|
break
|
|
}
|
|
}
|
|
if status == nil {
|
|
return c.Status(404).JSON(fiber.Map{
|
|
"error": fmt.Sprintf("Suite with key '%s' not found", key),
|
|
})
|
|
}
|
|
}
|
|
return c.Status(fiber.StatusOK).JSON(status)
|
|
}
|
|
}
|