Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

✨ Auto-fetch UptimeKuma monitor labels (#2312)

Alicia Sykes608c57861d9c
diff --git a/docs/widgets.md b/docs/widgets.md
index e684f10c..a586b705 100644
--- a/docs/widgets.md
+++ b/docs/widgets.md
@@ -2837,23 +2837,21 @@ Linkding is a self-hosted bookmarking service, which has a clean interface and i
| ------------------ | -------- | ------------ | --------------------------------------------------------------------------------- |
| **`host`** | `string` | Required | The URL of the Uptime Kuma instance |
| **`slug`** | `string` | Required | The slug of the status page |
-| **`monitorNames`** | `strins` | _Optional_ | Names of monitored services (in the same order as on the kuma uptime status page) |
+| **`monitorNames`** | `string[]` | _Optional_ | Optional labels to override the monitor names from Uptime Kuma, in the same order as they appear on the status page |
#### Example
```yaml
- type: uptime-kuma-status-page
+ useProxy: true
options:
host: http://localhost:3001
slug: another-beautiful-status-page
- monitorNames:
- - "Name1"
- - "Name2"
```
#### Info
-- **CORS**: 🟒 Enabled
+- **CORS**: πŸ”΄ Proxied (Uptime Kuma only sends CORS headers when running in development mode, so `useProxy: true` is required)
- **Auth**: 🟒 Not Needed
- **Price**: 🟒 Free
- **Host**: Self-Hosted (see [Uptime Kuma](https://github.com/louislam/uptime-kuma) )
diff --git a/src/components/Widgets/UptimeKuma.vue b/src/components/Widgets/UptimeKuma.vue
index e7fb312f..9faae0ea 100644
--- a/src/components/Widgets/UptimeKuma.vue
+++ b/src/components/Widgets/UptimeKuma.vue
@@ -197,13 +197,13 @@ export default {
min-width: 64px;
&.up {
- background-color: rgb(92, 221, 139);
- color: black;
+ background-color: var(--success);
+ color: var(--black);
}
&.down {
- background-color: rgb(220, 53, 69);
- color: white;
+ background-color: var(--danger);
+ color: var(--white);
}
}
diff --git a/src/components/Widgets/UptimeKumaStatusPage.vue b/src/components/Widgets/UptimeKumaStatusPage.vue
index be95ff9d..5668daff 100644
--- a/src/components/Widgets/UptimeKumaStatusPage.vue
+++ b/src/components/Widgets/UptimeKumaStatusPage.vue
@@ -13,13 +13,7 @@
>
<div class="item monitor-row">
<div class="title-title">
- <span class="text">
- {{
- monitorNames && monitorNames[index]
- ? monitorNames[index]
- : `Monitor ${index + 1}`
- }}
- </span>
+ <span class="text">{{ heartbeat.name }}</span>
</div>
<div class="monitors-container">
<div class="status-container">
@@ -60,11 +54,15 @@ export default {
return this.parseAsEnvVar(this.options.slug);
},
monitorNames() {
- return this.options.monitorNames || [];
+ return Array.isArray(this.options.monitorNames) ? this.options.monitorNames : [];
},
endpoint() {
return `${this.host}/api/status-page/heartbeat/${this.slug}`;
},
+ /* Monitor names aren't in the heartbeat response, they're only here */
+ configEndpoint() {
+ return `${this.host}/api/status-page/${this.slug}`;
+ },
statusPageUrl() {
return `${this.host}/status/${this.slug}`;
},
@@ -82,24 +80,33 @@ export default {
if (!this.optionsValid({ host, slug })) {
return;
}
- this.makeRequest(this.endpoint)
- .then(this.processData)
+ Promise.all([
+ this.makeRequest(this.endpoint), // Get uptime data
+ this.makeRequest(this.configEndpoint).catch(() => null), // attempt get monitor names
+ ])
+ .then(([heartbeats, statusPage]) => this.processData(heartbeats, statusPage))
.catch((error) => {
this.errorMessage = error.message || 'Failed to fetch data';
});
},
- processData(response) {
+ processData(response, statusPage) {
const { heartbeatList } = response;
- const lastHeartbeats = [];
- // Use Object.keys to safely iterate over heartbeatList
- Object.keys(heartbeatList).forEach((monitorId) => {
- const heartbeats = heartbeatList[monitorId];
- if (heartbeats.length > 0) {
- const lastHeartbeat = heartbeats[heartbeats.length - 1];
- lastHeartbeats.push(lastHeartbeat);
- }
- });
- this.lastHeartbeats = lastHeartbeats;
+ this.lastHeartbeats = this.getOrderedMonitors(statusPage, heartbeatList)
+ .map((monitor, index) => {
+ const heartbeats = heartbeatList[monitor.id];
+ return {
+ ...heartbeats[heartbeats.length - 1],
+ name: this.monitorNames[index] || monitor.name || `Monitor ${index + 1}`,
+ };
+ });
+ },
+ /* Monitors which have heartbeats, in the same order as the status page */
+ getOrderedMonitors(statusPage, heartbeatList) {
+ const groups = statusPage?.publicGroupList;
+ const monitors = groups
+ ? groups.flatMap((group) => group.monitorList)
+ : Object.keys(heartbeatList).map((id) => ({ id }));
+ return monitors.filter((monitor) => heartbeatList[monitor.id]?.length > 0);
},
optionsValid({ host, slug }) {
const errors = [];
@@ -163,24 +170,24 @@ export default {
margin: 0.1em 0.5em;
min-width: 64px;
&.up {
- background-color: #5cdd8b;
- color: black;
+ background-color: var(--success);
+ color: var(--black);
}
&.down {
- background-color: #dc3545;
- color: white;
+ background-color: var(--danger);
+ color: var(--white);
}
&.pending {
- background-color: #f8a306;
- color: black;
+ background-color: var(--warning);
+ color: var(--black);
}
&.maintenance {
- background-color: #1747f5;
- color: white;
+ background-color: var(--info);
+ color: var(--black);
}
&.unknown {
- background-color: gray;
- color: white;
+ background-color: var(--neutral);
+ color: var(--white);
}
}
.monitor-row {
@@ -193,7 +200,7 @@ export default {
font-weight: bold;
}
.error-message {
- color: red;
+ color: var(--danger);
font-weight: bold;
}
</style>