From 99e8cfb1ce08329210b8c69334466f801d33f872 Mon Sep 17 00:00:00 2001 From: TwinProduction Date: Wed, 27 Jan 2021 18:26:07 -0500 Subject: [PATCH] Changed badge path to leverage ServiceStatus.Key --- README.md | 10 +++++----- controller/badge.go | 16 ++++------------ 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 98759c00..7611edef 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ The main features of Gatus are: - **Alerting**: While having a pretty visual dashboard is useful to keep track of the state of your application(s), you probably don't want to stare at it all day. Thus, notifications via Slack, Mattermost, Messagebird, PagerDuty and Twilio are supported out of the box with the ability to configure a custom alerting provider for any needs you might have, whether it be a different provider or a custom application that manages automated rollbacks. - **Metrics** - **Low resource consumption**: As with most Go applications, the resource footprint that this application requires is negligibly small. -- **GitHub uptime badges** (ALPHA): ![Uptime 1h](https://status.twinnation.org/api/v1/badges/uptime/1h/group-core-service-twinnation%20-%20external.svg) ![Uptime 24h](https://status.twinnation.org/api/v1/badges/uptime/24h/group-core-service-twinnation%20-%20external.svg) ![Uptime 7d](https://status.twinnation.org/api/v1/badges/uptime/7d/group-core-service-twinnation%20-%20external.svg) +- **GitHub uptime badges** (ALPHA): ![Uptime 1h](https://status.twinnation.org/api/v1/badges/uptime/1h/core_twinnation---external.svg) ![Uptime 24h](https://status.twinnation.org/api/v1/badges/uptime/24h/core_twinnation---external.svg) ![Uptime 7d](https://status.twinnation.org/api/v1/badges/uptime/7d/core_twinnation---external.svg) - **Service auto discovery in Kubernetes** (ALPHA) @@ -708,9 +708,9 @@ web: ``` ### Uptime badges -![Uptime 1h](https://status.twinnation.org/api/v1/badges/uptime/1h/group-core-service-twinnation%20-%20external.svg) -![Uptime 24h](https://status.twinnation.org/api/v1/badges/uptime/24h/group-core-service-twinnation%20-%20external.svg) -![Uptime 7d](https://status.twinnation.org/api/v1/badges/uptime/7d/group-core-service-twinnation%20-%20external.svg) +![Uptime 1h](https://status.twinnation.org/api/v1/badges/uptime/1h/core_twinnation---external.svg) +![Uptime 24h](https://status.twinnation.org/api/v1/badges/uptime/24h/core_twinnation---external.svg) +![Uptime 7d](https://status.twinnation.org/api/v1/badges/uptime/7d/core_twinnation---external.svg) > **NOTE**: This feature is currently in ALPHA @@ -737,7 +737,7 @@ If you want to display a service that is not part of a group, you must leave the http://example.com/api/v1/badges/uptime/7d/group--service-frontend.svg ``` -Example: ![Uptime 24h](https://status.twinnation.org/api/v1/badges/uptime/24h/group-core-service-twinnation%20-%20external.svg) +Example: ![Uptime 24h](https://status.twinnation.org/api/v1/badges/uptime/24h/core_twinnation---external.svg) ``` ![Uptime 24h](https://status.twinnation.org/api/v1/badges/uptime/24h/group-core-service-twinnation%20-%20external.svg) ``` diff --git a/controller/badge.go b/controller/badge.go index 2a689f09..68c4d63f 100644 --- a/controller/badge.go +++ b/controller/badge.go @@ -14,26 +14,18 @@ import ( // badgeHandler handles the automatic generation of badge based on the group name and service name passed. // // Valid values for {duration}: 7d, 24h, 1h -// Pattern for {identifier}: group--service-.svg +// Pattern for {identifier}: .svg func badgeHandler(writer http.ResponseWriter, request *http.Request) { variables := mux.Vars(request) duration := variables["duration"] - // group--service-.svg - identifier := variables["identifier"] if duration != "7d" && duration != "24h" && duration != "1h" { writer.WriteHeader(http.StatusBadRequest) _, _ = writer.Write([]byte("Durations supported: 7d, 24h, 1h")) return } - parts := strings.Split(identifier, "-service-") - if len(parts) != 2 || !strings.HasPrefix(identifier, "group-") || !strings.HasSuffix(identifier, ".svg") { - writer.WriteHeader(http.StatusBadRequest) - _, _ = writer.Write([]byte("Invalid path: Pattern should look like /group--service-.svg")) - return - } - groupName := strings.TrimPrefix(parts[0], "group-") - serviceName := strings.TrimSuffix(parts[1], ".svg") - uptime := watchdog.GetUptimeByServiceGroupAndName(groupName, serviceName) + identifier := variables["identifier"] + key := strings.TrimSuffix(identifier, ".svg") + uptime := watchdog.GetUptimeByKey(key) if uptime == nil { writer.WriteHeader(http.StatusNotFound) _, _ = writer.Write([]byte("Requested service not found"))