-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: Gatus | ||
description: Gatus Widget Configuration | ||
--- | ||
|
||
Allowed fields: `["up", "down", "uptime"]`. | ||
|
||
```yaml | ||
widget: | ||
type: gatus | ||
url: http://gatus.host.or.ip:port | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useTranslation } from "next-i18next"; | ||
|
||
import Container from "components/services/widget/container"; | ||
import useWidgetAPI from "utils/proxy/use-widget-api"; | ||
import Block from "components/services/widget/block"; | ||
|
||
export default function Component({ service }) { | ||
const { t } = useTranslation(); | ||
|
||
const { widget } = service; | ||
|
||
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status"); | ||
|
||
if (statusError) { | ||
return <Container service={service} error={statusError} />; | ||
} | ||
|
||
if (!statusData) { | ||
return ( | ||
<Container service={service}> | ||
<Block label="gatus.up" /> | ||
<Block label="gatus.down" /> | ||
<Block label="gatus.uptime" /> | ||
</Container> | ||
); | ||
} | ||
|
||
let sitesUp = 0; | ||
let sitesDown = 0; | ||
Object.values(statusData).forEach((site) => { | ||
const lastResult = site.results[site.results.length - 1]; | ||
if (lastResult?.success === true) { | ||
sitesUp += 1; | ||
} else { | ||
sitesDown += 1; | ||
} | ||
}); | ||
|
||
// Adapted from https://github.com/bastienwirtz/homer/blob/b7cd8f9482e6836a96b354b11595b03b9c3d67cd/src/components/services/UptimeKuma.vue#L105 | ||
const resultsList = Object.values(statusData).reduce((a, b) => a.concat(b.results), []); | ||
const percent = resultsList.reduce((a, b) => a + (b?.success === true ? 1 : 0), 0) / resultsList.length; | ||
const uptime = (percent * 100).toFixed(1); | ||
|
||
return ( | ||
<Container service={service}> | ||
<Block label="gatus.up" value={t("common.number", { value: sitesUp })} /> | ||
<Block label="gatus.down" value={t("common.number", { value: sitesDown })} /> | ||
<Block label="gatus.uptime" value={t("common.percent", { value: uptime })} /> | ||
</Container> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; | ||
import genericProxyHandler from "utils/proxy/handlers/generic"; | ||
|
||
const widget = { | ||
api: "{url}/{endpoint}", | ||
proxyHandler: genericProxyHandler, | ||
|
||
mappings: { | ||
status: { | ||
endpoint: "api/v1/endpoints/statuses", | ||
}, | ||
}, | ||
}; | ||
|
||
export default widget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters