2023-07-09 00:37:41 +00:00
|
|
|
package api
|
2020-12-30 01:22:17 +00:00
|
|
|
|
|
|
|
import (
|
2024-02-01 05:06:08 +00:00
|
|
|
"encoding/json"
|
2024-04-09 01:00:40 +00:00
|
|
|
"errors"
|
2020-12-30 01:22:17 +00:00
|
|
|
"fmt"
|
2021-08-21 21:38:23 +00:00
|
|
|
"strconv"
|
2020-12-30 01:22:17 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
|
2022-12-06 06:41:09 +00:00
|
|
|
"github.com/TwiN/gatus/v5/config"
|
2024-05-10 02:56:16 +00:00
|
|
|
"github.com/TwiN/gatus/v5/config/endpoint/ui"
|
2022-12-06 06:41:09 +00:00
|
|
|
"github.com/TwiN/gatus/v5/storage/store"
|
|
|
|
"github.com/TwiN/gatus/v5/storage/store/common"
|
|
|
|
"github.com/TwiN/gatus/v5/storage/store/common/paging"
|
2023-07-09 00:37:41 +00:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2020-12-30 01:22:17 +00:00
|
|
|
)
|
|
|
|
|
2021-08-21 21:38:23 +00:00
|
|
|
const (
|
|
|
|
badgeColorHexAwesome = "#40cc11"
|
|
|
|
badgeColorHexGreat = "#94cc11"
|
|
|
|
badgeColorHexGood = "#ccd311"
|
|
|
|
badgeColorHexPassable = "#ccb311"
|
|
|
|
badgeColorHexBad = "#cc8111"
|
|
|
|
badgeColorHexVeryBad = "#c7130a"
|
|
|
|
)
|
|
|
|
|
2022-06-20 17:59:45 +00:00
|
|
|
const (
|
|
|
|
HealthStatusUp = "up"
|
|
|
|
HealthStatusDown = "down"
|
|
|
|
HealthStatusUnknown = "?"
|
|
|
|
)
|
|
|
|
|
2022-08-11 01:05:34 +00:00
|
|
|
var (
|
|
|
|
badgeColors = []string{badgeColorHexAwesome, badgeColorHexGreat, badgeColorHexGood, badgeColorHexPassable, badgeColorHexBad}
|
|
|
|
)
|
|
|
|
|
2021-10-23 20:47:12 +00:00
|
|
|
// UptimeBadge handles the automatic generation of badge based on the group name and endpoint name passed.
|
2020-12-30 01:22:17 +00:00
|
|
|
//
|
2024-08-12 02:40:19 +00:00
|
|
|
// Valid values for :duration -> 30d, 7d, 24h, 1h
|
2023-07-09 00:37:41 +00:00
|
|
|
func UptimeBadge(c *fiber.Ctx) error {
|
|
|
|
duration := c.Params("duration")
|
2021-08-13 01:54:23 +00:00
|
|
|
var from time.Time
|
|
|
|
switch duration {
|
2024-08-12 02:40:19 +00:00
|
|
|
case "30d":
|
|
|
|
from = time.Now().Add(-30 * 24 * time.Hour)
|
2021-08-13 01:54:23 +00:00
|
|
|
case "7d":
|
2021-08-21 21:38:23 +00:00
|
|
|
from = time.Now().Add(-7 * 24 * time.Hour)
|
2021-08-13 01:54:23 +00:00
|
|
|
case "24h":
|
2021-08-21 21:38:23 +00:00
|
|
|
from = time.Now().Add(-24 * time.Hour)
|
2021-08-13 01:54:23 +00:00
|
|
|
case "1h":
|
2021-09-14 03:29:35 +00:00
|
|
|
from = time.Now().Add(-2 * time.Hour) // Because uptime metrics are stored by hour, we have to cheat a little
|
2021-08-13 01:54:23 +00:00
|
|
|
default:
|
2024-08-12 02:40:19 +00:00
|
|
|
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h, 1h")
|
2020-12-30 01:22:17 +00:00
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
key := c.Params("key")
|
2021-10-28 23:35:46 +00:00
|
|
|
uptime, err := store.Get().GetUptimeByKey(key, from, time.Now())
|
2021-08-13 01:54:23 +00:00
|
|
|
if err != nil {
|
2024-04-09 01:00:40 +00:00
|
|
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(404).SendString(err.Error())
|
2024-04-09 01:00:40 +00:00
|
|
|
} else if errors.Is(err, common.ErrInvalidTimeRange) {
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(400).SendString(err.Error())
|
2021-08-13 01:54:23 +00:00
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(500).SendString(err.Error())
|
2021-02-25 03:41:36 +00:00
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
c.Set("Content-Type", "image/svg+xml")
|
|
|
|
c.Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
c.Set("Expires", "0")
|
|
|
|
return c.Status(200).Send(generateUptimeBadgeSVG(duration, uptime))
|
2020-12-30 01:22:17 +00:00
|
|
|
}
|
|
|
|
|
2021-10-23 20:47:12 +00:00
|
|
|
// ResponseTimeBadge handles the automatic generation of badge based on the group name and endpoint name passed.
|
2021-09-12 22:39:09 +00:00
|
|
|
//
|
2024-08-12 02:40:19 +00:00
|
|
|
// Valid values for :duration -> 30d, 7d, 24h, 1h
|
2024-04-09 01:00:40 +00:00
|
|
|
func ResponseTimeBadge(cfg *config.Config) fiber.Handler {
|
2023-07-09 00:37:41 +00:00
|
|
|
return func(c *fiber.Ctx) error {
|
|
|
|
duration := c.Params("duration")
|
2022-08-11 01:05:34 +00:00
|
|
|
var from time.Time
|
|
|
|
switch duration {
|
2024-08-12 02:40:19 +00:00
|
|
|
case "30d":
|
|
|
|
from = time.Now().Add(-30 * 24 * time.Hour)
|
2022-08-11 01:05:34 +00:00
|
|
|
case "7d":
|
|
|
|
from = time.Now().Add(-7 * 24 * time.Hour)
|
|
|
|
case "24h":
|
|
|
|
from = time.Now().Add(-24 * time.Hour)
|
|
|
|
case "1h":
|
|
|
|
from = time.Now().Add(-2 * time.Hour) // Because response time metrics are stored by hour, we have to cheat a little
|
|
|
|
default:
|
2024-08-12 02:40:19 +00:00
|
|
|
return c.Status(400).SendString("Durations supported: 30d, 7d, 24h, 1h")
|
2021-09-12 22:39:09 +00:00
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
key := c.Params("key")
|
2022-08-11 01:05:34 +00:00
|
|
|
averageResponseTime, err := store.Get().GetAverageResponseTimeByKey(key, from, time.Now())
|
|
|
|
if err != nil {
|
2024-04-09 01:00:40 +00:00
|
|
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(404).SendString(err.Error())
|
2024-04-09 01:00:40 +00:00
|
|
|
} else if errors.Is(err, common.ErrInvalidTimeRange) {
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(400).SendString(err.Error())
|
2022-08-11 01:05:34 +00:00
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(500).SendString(err.Error())
|
2022-08-11 01:05:34 +00:00
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
c.Set("Content-Type", "image/svg+xml")
|
|
|
|
c.Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
c.Set("Expires", "0")
|
2024-04-09 01:00:40 +00:00
|
|
|
return c.Status(200).Send(generateResponseTimeBadgeSVG(duration, averageResponseTime, key, cfg))
|
2021-09-12 22:39:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:59:45 +00:00
|
|
|
// HealthBadge handles the automatic generation of badge based on the group name and endpoint name passed.
|
2023-07-09 00:37:41 +00:00
|
|
|
func HealthBadge(c *fiber.Ctx) error {
|
|
|
|
key := c.Params("key")
|
2022-06-20 17:59:45 +00:00
|
|
|
pagingConfig := paging.NewEndpointStatusParams()
|
|
|
|
status, err := store.Get().GetEndpointStatusByKey(key, pagingConfig.WithResults(1, 1))
|
|
|
|
if err != nil {
|
2024-04-09 01:00:40 +00:00
|
|
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(404).SendString(err.Error())
|
2024-04-09 01:00:40 +00:00
|
|
|
} else if errors.Is(err, common.ErrInvalidTimeRange) {
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(400).SendString(err.Error())
|
2022-06-20 17:59:45 +00:00
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
return c.Status(500).SendString(err.Error())
|
2022-06-20 17:59:45 +00:00
|
|
|
}
|
|
|
|
healthStatus := HealthStatusUnknown
|
|
|
|
if len(status.Results) > 0 {
|
|
|
|
if status.Results[0].Success {
|
|
|
|
healthStatus = HealthStatusUp
|
|
|
|
} else {
|
|
|
|
healthStatus = HealthStatusDown
|
|
|
|
}
|
|
|
|
}
|
2023-07-09 00:37:41 +00:00
|
|
|
c.Set("Content-Type", "image/svg+xml")
|
|
|
|
c.Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
c.Set("Expires", "0")
|
|
|
|
return c.Status(200).Send(generateHealthBadgeSVG(healthStatus))
|
2022-06-20 17:59:45 +00:00
|
|
|
}
|
|
|
|
|
2024-02-01 05:06:08 +00:00
|
|
|
func HealthBadgeShields(c *fiber.Ctx) error {
|
|
|
|
key := c.Params("key")
|
|
|
|
pagingConfig := paging.NewEndpointStatusParams()
|
|
|
|
status, err := store.Get().GetEndpointStatusByKey(key, pagingConfig.WithResults(1, 1))
|
|
|
|
if err != nil {
|
2024-04-09 01:00:40 +00:00
|
|
|
if errors.Is(err, common.ErrEndpointNotFound) {
|
2024-02-01 05:06:08 +00:00
|
|
|
return c.Status(404).SendString(err.Error())
|
2024-04-09 01:00:40 +00:00
|
|
|
} else if errors.Is(err, common.ErrInvalidTimeRange) {
|
2024-02-01 05:06:08 +00:00
|
|
|
return c.Status(400).SendString(err.Error())
|
|
|
|
}
|
|
|
|
return c.Status(500).SendString(err.Error())
|
|
|
|
}
|
|
|
|
healthStatus := HealthStatusUnknown
|
|
|
|
if len(status.Results) > 0 {
|
|
|
|
if status.Results[0].Success {
|
|
|
|
healthStatus = HealthStatusUp
|
|
|
|
} else {
|
|
|
|
healthStatus = HealthStatusDown
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.Set("Content-Type", "application/json")
|
|
|
|
c.Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
|
|
|
c.Set("Expires", "0")
|
|
|
|
jsonData, err := generateHealthBadgeShields(healthStatus)
|
|
|
|
if err != nil {
|
|
|
|
return c.Status(500).SendString(err.Error())
|
|
|
|
}
|
|
|
|
return c.Status(200).Send(jsonData)
|
|
|
|
}
|
|
|
|
|
2021-08-21 21:38:23 +00:00
|
|
|
func generateUptimeBadgeSVG(duration string, uptime float64) []byte {
|
2020-12-30 01:22:17 +00:00
|
|
|
var labelWidth, valueWidth, valueWidthAdjustment int
|
|
|
|
switch duration {
|
2024-08-12 02:40:19 +00:00
|
|
|
case "30d":
|
|
|
|
labelWidth = 70
|
2020-12-30 01:22:17 +00:00
|
|
|
case "7d":
|
|
|
|
labelWidth = 65
|
|
|
|
case "24h":
|
|
|
|
labelWidth = 70
|
|
|
|
case "1h":
|
|
|
|
labelWidth = 65
|
|
|
|
default:
|
|
|
|
}
|
2021-08-13 01:54:23 +00:00
|
|
|
color := getBadgeColorFromUptime(uptime)
|
|
|
|
sanitizedValue := strings.TrimRight(strings.TrimRight(fmt.Sprintf("%.2f", uptime*100), "0"), ".") + "%"
|
2020-12-30 01:22:17 +00:00
|
|
|
if strings.Contains(sanitizedValue, ".") {
|
|
|
|
valueWidthAdjustment = -10
|
|
|
|
}
|
|
|
|
valueWidth = (len(sanitizedValue) * 11) + valueWidthAdjustment
|
|
|
|
width := labelWidth + valueWidth
|
|
|
|
labelX := labelWidth / 2
|
|
|
|
valueX := labelWidth + (valueWidth / 2)
|
|
|
|
svg := []byte(fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="20">
|
|
|
|
<linearGradient id="b" x2="0" y2="100%%">
|
|
|
|
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
|
|
|
<stop offset="1" stop-opacity=".1"/>
|
|
|
|
</linearGradient>
|
|
|
|
<mask id="a">
|
|
|
|
<rect width="%d" height="20" rx="3" fill="#fff"/>
|
|
|
|
</mask>
|
|
|
|
<g mask="url(#a)">
|
|
|
|
<path fill="#555" d="M0 0h%dv20H0z"/>
|
|
|
|
<path fill="%s" d="M%d 0h%dv20H%dz"/>
|
|
|
|
<path fill="url(#b)" d="M0 0h%dv20H0z"/>
|
|
|
|
</g>
|
|
|
|
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
|
|
|
<text x="%d" y="15" fill="#010101" fill-opacity=".3">
|
|
|
|
uptime %s
|
|
|
|
</text>
|
|
|
|
<text x="%d" y="14">
|
|
|
|
uptime %s
|
|
|
|
</text>
|
|
|
|
<text x="%d" y="15" fill="#010101" fill-opacity=".3">
|
|
|
|
%s
|
|
|
|
</text>
|
|
|
|
<text x="%d" y="14">
|
|
|
|
%s
|
|
|
|
</text>
|
|
|
|
</g>
|
|
|
|
</svg>`, width, width, labelWidth, color, labelWidth, valueWidth, labelWidth, width, labelX, duration, labelX, duration, valueX, sanitizedValue, valueX, sanitizedValue))
|
|
|
|
return svg
|
|
|
|
}
|
2021-08-12 01:05:51 +00:00
|
|
|
|
|
|
|
func getBadgeColorFromUptime(uptime float64) string {
|
|
|
|
if uptime >= 0.975 {
|
2021-08-21 21:38:23 +00:00
|
|
|
return badgeColorHexAwesome
|
2021-08-12 01:05:51 +00:00
|
|
|
} else if uptime >= 0.95 {
|
2021-08-21 21:38:23 +00:00
|
|
|
return badgeColorHexGreat
|
2021-08-12 01:05:51 +00:00
|
|
|
} else if uptime >= 0.9 {
|
2021-08-21 21:38:23 +00:00
|
|
|
return badgeColorHexGood
|
2021-08-12 01:05:51 +00:00
|
|
|
} else if uptime >= 0.8 {
|
2021-08-21 21:38:23 +00:00
|
|
|
return badgeColorHexPassable
|
2021-08-20 01:52:03 +00:00
|
|
|
} else if uptime >= 0.65 {
|
2021-08-21 21:38:23 +00:00
|
|
|
return badgeColorHexBad
|
|
|
|
}
|
|
|
|
return badgeColorHexVeryBad
|
|
|
|
}
|
|
|
|
|
2022-08-11 01:05:34 +00:00
|
|
|
func generateResponseTimeBadgeSVG(duration string, averageResponseTime int, key string, cfg *config.Config) []byte {
|
2021-08-21 21:38:23 +00:00
|
|
|
var labelWidth, valueWidth int
|
|
|
|
switch duration {
|
2024-08-12 02:40:19 +00:00
|
|
|
case "30d":
|
|
|
|
labelWidth = 110
|
2021-08-21 21:38:23 +00:00
|
|
|
case "7d":
|
|
|
|
labelWidth = 105
|
|
|
|
case "24h":
|
|
|
|
labelWidth = 110
|
|
|
|
case "1h":
|
|
|
|
labelWidth = 105
|
|
|
|
default:
|
|
|
|
}
|
2022-08-11 01:05:34 +00:00
|
|
|
color := getBadgeColorFromResponseTime(averageResponseTime, key, cfg)
|
2021-08-21 21:38:23 +00:00
|
|
|
sanitizedValue := strconv.Itoa(averageResponseTime) + "ms"
|
|
|
|
valueWidth = len(sanitizedValue) * 11
|
|
|
|
width := labelWidth + valueWidth
|
|
|
|
labelX := labelWidth / 2
|
|
|
|
valueX := labelWidth + (valueWidth / 2)
|
|
|
|
svg := []byte(fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="20">
|
|
|
|
<linearGradient id="b" x2="0" y2="100%%">
|
|
|
|
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
|
|
|
<stop offset="1" stop-opacity=".1"/>
|
|
|
|
</linearGradient>
|
|
|
|
<mask id="a">
|
|
|
|
<rect width="%d" height="20" rx="3" fill="#fff"/>
|
|
|
|
</mask>
|
|
|
|
<g mask="url(#a)">
|
|
|
|
<path fill="#555" d="M0 0h%dv20H0z"/>
|
|
|
|
<path fill="%s" d="M%d 0h%dv20H%dz"/>
|
|
|
|
<path fill="url(#b)" d="M0 0h%dv20H0z"/>
|
|
|
|
</g>
|
|
|
|
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
|
|
|
<text x="%d" y="15" fill="#010101" fill-opacity=".3">
|
|
|
|
response time %s
|
|
|
|
</text>
|
|
|
|
<text x="%d" y="14">
|
|
|
|
response time %s
|
|
|
|
</text>
|
|
|
|
<text x="%d" y="15" fill="#010101" fill-opacity=".3">
|
|
|
|
%s
|
|
|
|
</text>
|
|
|
|
<text x="%d" y="14">
|
|
|
|
%s
|
|
|
|
</text>
|
|
|
|
</g>
|
|
|
|
</svg>`, width, width, labelWidth, color, labelWidth, valueWidth, labelWidth, width, labelX, duration, labelX, duration, valueX, sanitizedValue, valueX, sanitizedValue))
|
|
|
|
return svg
|
|
|
|
}
|
|
|
|
|
2022-08-11 01:05:34 +00:00
|
|
|
func getBadgeColorFromResponseTime(responseTime int, key string, cfg *config.Config) string {
|
2024-04-09 01:00:40 +00:00
|
|
|
thresholds := ui.GetDefaultConfig().Badge.ResponseTime.Thresholds
|
|
|
|
if endpoint := cfg.GetEndpointByKey(key); endpoint != nil {
|
|
|
|
thresholds = endpoint.UIConfig.Badge.ResponseTime.Thresholds
|
|
|
|
}
|
2022-08-11 01:05:34 +00:00
|
|
|
// the threshold config requires 5 values, so we can be sure it's set here
|
|
|
|
for i := 0; i < 5; i++ {
|
2024-04-09 01:00:40 +00:00
|
|
|
if responseTime <= thresholds[i] {
|
2022-08-11 01:05:34 +00:00
|
|
|
return badgeColors[i]
|
|
|
|
}
|
2021-08-12 01:05:51 +00:00
|
|
|
}
|
2021-08-21 21:38:23 +00:00
|
|
|
return badgeColorHexVeryBad
|
2021-08-12 01:05:51 +00:00
|
|
|
}
|
2022-06-20 17:59:45 +00:00
|
|
|
|
|
|
|
func generateHealthBadgeSVG(healthStatus string) []byte {
|
|
|
|
var labelWidth, valueWidth int
|
|
|
|
switch healthStatus {
|
|
|
|
case HealthStatusUp:
|
2022-06-20 18:27:05 +00:00
|
|
|
valueWidth = 28
|
2022-06-20 17:59:45 +00:00
|
|
|
case HealthStatusDown:
|
2022-06-20 18:27:05 +00:00
|
|
|
valueWidth = 44
|
2022-06-20 17:59:45 +00:00
|
|
|
case HealthStatusUnknown:
|
|
|
|
valueWidth = 10
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
color := getBadgeColorFromHealth(healthStatus)
|
|
|
|
labelWidth = 48
|
|
|
|
|
|
|
|
width := labelWidth + valueWidth
|
|
|
|
labelX := labelWidth / 2
|
|
|
|
valueX := labelWidth + (valueWidth / 2)
|
|
|
|
svg := []byte(fmt.Sprintf(`<svg xmlns="http://www.w3.org/2000/svg" width="%d" height="20">
|
|
|
|
<linearGradient id="b" x2="0" y2="100%%">
|
|
|
|
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
|
|
|
|
<stop offset="1" stop-opacity=".1"/>
|
|
|
|
</linearGradient>
|
|
|
|
<mask id="a">
|
|
|
|
<rect width="%d" height="20" rx="3" fill="#fff"/>
|
|
|
|
</mask>
|
|
|
|
<g mask="url(#a)">
|
|
|
|
<path fill="#555" d="M0 0h%dv20H0z"/>
|
|
|
|
<path fill="%s" d="M%d 0h%dv20H%dz"/>
|
|
|
|
<path fill="url(#b)" d="M0 0h%dv20H0z"/>
|
|
|
|
</g>
|
|
|
|
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
|
|
|
|
<text x="%d" y="15" fill="#010101" fill-opacity=".3">
|
2022-06-20 18:27:05 +00:00
|
|
|
health
|
2022-06-20 17:59:45 +00:00
|
|
|
</text>
|
|
|
|
<text x="%d" y="14">
|
2022-06-20 18:27:05 +00:00
|
|
|
health
|
2022-06-20 17:59:45 +00:00
|
|
|
</text>
|
|
|
|
<text x="%d" y="15" fill="#010101" fill-opacity=".3">
|
|
|
|
%s
|
|
|
|
</text>
|
|
|
|
<text x="%d" y="14">
|
|
|
|
%s
|
|
|
|
</text>
|
|
|
|
</g>
|
|
|
|
</svg>`, width, width, labelWidth, color, labelWidth, valueWidth, labelWidth, width, labelX, labelX, valueX, healthStatus, valueX, healthStatus))
|
|
|
|
|
|
|
|
return svg
|
|
|
|
}
|
|
|
|
|
2024-02-01 05:06:08 +00:00
|
|
|
func generateHealthBadgeShields(healthStatus string) ([]byte, error) {
|
|
|
|
color := getBadgeShieldsColorFromHealth(healthStatus)
|
|
|
|
data := map[string]interface{}{
|
|
|
|
"schemaVersion": 1,
|
|
|
|
"label": "gatus",
|
|
|
|
"message": healthStatus,
|
|
|
|
"color": color,
|
|
|
|
}
|
|
|
|
return json.Marshal(data)
|
|
|
|
}
|
|
|
|
|
2022-06-20 17:59:45 +00:00
|
|
|
func getBadgeColorFromHealth(healthStatus string) string {
|
|
|
|
if healthStatus == HealthStatusUp {
|
|
|
|
return badgeColorHexAwesome
|
|
|
|
} else if healthStatus == HealthStatusDown {
|
|
|
|
return badgeColorHexVeryBad
|
|
|
|
}
|
|
|
|
return badgeColorHexPassable
|
|
|
|
}
|
2024-02-01 05:06:08 +00:00
|
|
|
|
|
|
|
func getBadgeShieldsColorFromHealth(healthStatus string) string {
|
|
|
|
if healthStatus == HealthStatusUp {
|
|
|
|
return "brightgreen"
|
|
|
|
} else if healthStatus == HealthStatusDown {
|
|
|
|
return "red"
|
|
|
|
}
|
|
|
|
return "yellow"
|
|
|
|
}
|