Compare commits

...

17 commits

Author SHA1 Message Date
Gero Gerke
a7d2d3cb07
Merge 5026f45871 into 03beef8006 2025-01-22 18:03:51 +00:00
DayShift
03beef8006
BugFix:Regular Expression in parseDuration Function (#5563)
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Auto Test / armv7-simple-test (18, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / check-linters (push) Has been cancelled
Auto Test / e2e-test (push) Has been cancelled
Merge Conflict Labeler / Labeling (push) Has been cancelled
validate / json-yaml-validate (push) Has been cancelled
validate / validate (push) Has been cancelled
Auto Test / auto-test (18, ARM64) (push) Has been cancelled
Auto Test / auto-test (18, macos-latest) (push) Has been cancelled
Auto Test / auto-test (18, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (18, windows-latest) (push) Has been cancelled
Auto Test / auto-test (20, ARM64) (push) Has been cancelled
Auto Test / auto-test (20, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (20, windows-latest) (push) Has been cancelled
Co-authored-by: Frank Elsinga <frank@elsinga.de>
2025-01-22 19:03:38 +01:00
Gero Gerke
5026f45871
Merge branch 'master' into feat/status-page-summary-api 2024-12-23 20:43:27 +01:00
Gero Gerke
0b21ed1acd
Merge branch 'master' into feat/status-page-summary-api 2024-12-13 16:41:37 +01:00
Gero Gerke
8b92dcf34a
Merge branch 'master' into feat/status-page-summary-api 2024-12-10 13:39:54 +01:00
Gero Gerke
a8c30f5ab8
fix lint errors 2024-11-23 16:28:01 +01:00
Gero Gerke
f171e101fd
post-merge adaptations 2024-11-23 16:18:09 +01:00
Gero Gerke
e93418d920
Merge remote-tracking branch 'luislam/master' into feat/status-page-summary-api 2024-11-23 15:52:16 +01:00
Gero Gerke
98d8598052 chore: add jsdocs for missing functions 2023-01-10 10:47:24 +01:00
Gero Gerke
1b5ea7d44e
Update server/model/status_page.js
Co-authored-by: Matthew Nickson <mnickson@sidingsmedia.com>
2023-01-10 10:41:25 +01:00
Gero Gerke
3dbc32b225
Update server/model/monitor.js
Co-authored-by: Matthew Nickson <mnickson@sidingsmedia.com>
2023-01-10 10:41:18 +01:00
Gero Gerke
f33d09918d
Update server/model/group.js
Co-authored-by: Matthew Nickson <mnickson@sidingsmedia.com>
2023-01-10 10:41:04 +01:00
Gero Gerke
1630c01fd9 chore: add support for new monitor states 2023-01-05 15:56:08 +01:00
Gero Gerke
4c701593d4 Merge remote-tracking branch 'origin' into feat/status-page-summary-api 2023-01-05 15:51:11 +01:00
Gero Gerke
2781ff566b Make linter happy 2022-07-28 12:44:06 +02:00
Gero Gerke
80e7400185 Updates 2022-07-26 13:47:23 +02:00
Gero Gerke
3ac752246d Add status page summary API 2022-07-20 00:16:34 +02:00
5 changed files with 76 additions and 14 deletions

View file

@ -4,19 +4,20 @@ const { R } = require("redbean-node");
class Group extends BeanModel {
/**
* Return an object that ready to parse to JSON for public Only show
* necessary data to public
* Return an object that ready to parse to JSON for public
* Only show necessary data to public
* @param {boolean} showTags Should the JSON include monitor tags
* @param {boolean} certExpiry Should JSON include info about
* certificate expiry?
* @param {boolean} showStatus Should the JSON include the status
* @returns {Promise<object>} Object ready to parse
*/
async toPublicJSON(showTags = false, certExpiry = false) {
async toPublicJSON(showTags = false, certExpiry = false, showStatus = false) {
let monitorBeanList = await this.getMonitorList();
let monitorList = [];
for (let bean of monitorBeanList) {
monitorList.push(await bean.toPublicJSON(showTags, certExpiry));
monitorList.push(await bean.toPublicJSON(showTags, certExpiry, showStatus));
}
return {

View file

@ -36,15 +36,31 @@ const rootCertificates = rootCertificatesFingerprints();
*/
class Monitor extends BeanModel {
/**
* Formats the status code to a human readable form
* @param {number} status the internal status code of the monitor
* @returns {string} a human readable string that corresponds to the status code
*/
statusToKey(status) {
switch (status) {
case 0: return "down";
case 1: return "up";
case 2: return "pending";
case 4: return "maintenance";
default: return "unknown";
}
}
/**
* Return an object that ready to parse to JSON for public Only show
* necessary data to public
* @param {boolean} showTags Include tags in JSON
* @param {boolean} certExpiry Include certificate expiry info in
* JSON
* @param {boolean} showStatus Should the JSON show the status
* @returns {Promise<object>} Object ready to parse
*/
async toPublicJSON(showTags = false, certExpiry = false) {
async toPublicJSON(showTags = false, certExpiry = false, showStatus = false) {
let obj = {
id: this.id,
name: this.name,
@ -66,6 +82,11 @@ class Monitor extends BeanModel {
obj.validCert = validCert;
}
if (showStatus) {
const heartbeat = await Monitor.getPreviousHeartbeat(this.id);
obj.status = this.statusToKey(heartbeat.status);
}
return obj;
}

View file

@ -257,12 +257,12 @@ class StatusPage extends BeanModel {
/**
* Get all status page data in one call
* @param {StatusPage} statusPage Status page to get data for
* @returns {object} Status page data
* @param {StatusPage} statusPage the status page to return the data for
* @param {boolean} includeStatus whether each monitor should include the status of the monitor ("up" or "down")
* @param {boolean} includeConfig whether the config for the status page should be included in the returned JSON
* @returns {object} the status page data object
*/
static async getStatusPageData(statusPage) {
const config = await statusPage.toPublicJSON();
static async getStatusPageData(statusPage, includeStatus = false, includeConfig = true) {
// Incident
let incident = await R.findOne("incident", " pin = 1 AND active = 1 AND status_page_id = ? ", [
statusPage.id,
@ -283,13 +283,20 @@ class StatusPage extends BeanModel {
]);
for (let groupBean of list) {
let monitorGroup = await groupBean.toPublicJSON(showTags, config?.showCertificateExpiry);
let monitorGroup = await groupBean.toPublicJSON(showTags, false, includeStatus);
publicGroupList.push(monitorGroup);
}
let config = {};
if (includeConfig) {
config = {
config: await statusPage.toPublicJSON()
};
}
// Response
return {
config,
...config,
incident,
publicGroupList,
maintenanceList,

View file

@ -485,7 +485,7 @@ function ApiCache() {
}
if (typeof duration === "string") {
let split = duration.match(/^([\d\.,]+)\s?(\w+)$/);
let split = duration.match(/^([\d\.,]+)\s?([a-zA-Z]+)$/);
if (split.length === 3) {
let len = parseFloat(split[1]);

View file

@ -2,7 +2,7 @@ let express = require("express");
const apicache = require("../modules/apicache");
const { UptimeKumaServer } = require("../uptime-kuma-server");
const StatusPage = require("../model/status_page");
const { allowDevAllOrigin, sendHttpError } = require("../util-server");
const { allowAllOrigin, allowDevAllOrigin, sendHttpError } = require("../util-server");
const { R } = require("redbean-node");
const { badgeConstants } = require("../../src/util");
const { makeBadge } = require("badge-maker");
@ -35,6 +35,39 @@ router.get("/status-page", cache("5 minutes"), async (request, response) => {
await StatusPage.handleStatusPageResponse(response, server.indexHTML, slug);
});
// Status page config, incident, monitor list with status ("up" or "down")
router.get("/api/status-page/:slug/summary", cache("5 minutes"), async (request, response) => {
allowAllOrigin(response);
let slug = request.params.slug;
try {
// Get Status Page
let statusPage = await R.findOne("status_page", " slug = ? ", [
slug
]);
if (!statusPage) {
return null;
}
let statusPageData = await StatusPage.getStatusPageData(statusPage, true, false);
if (!statusPageData) {
response.statusCode = 404;
response.json({
msg: "Not Found"
});
return;
}
// Response
response.json(statusPageData);
} catch (error) {
sendHttpError(response, error.message);
}
});
// Status page config, incident, monitor list
router.get("/api/status-page/:slug", cache("5 minutes"), async (request, response) => {
allowDevAllOrigin(response);