mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-04-02 14:32:21 +00:00
Merge e441b6d76b
into 30f82b9cb4
This commit is contained in:
commit
bdacccd9d1
3 changed files with 50 additions and 13 deletions
|
@ -70,10 +70,12 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
||||||
try {
|
try {
|
||||||
let heartbeatList = {};
|
let heartbeatList = {};
|
||||||
let uptimeList = {};
|
let uptimeList = {};
|
||||||
|
let certificateExpiryList = {};
|
||||||
|
|
||||||
let slug = request.params.slug;
|
let slug = request.params.slug;
|
||||||
slug = slug.toLowerCase();
|
slug = slug.toLowerCase();
|
||||||
let statusPageID = await StatusPage.slugToID(slug);
|
let statusPageID = await StatusPage.slugToID(slug);
|
||||||
|
let showCertificateExpiry = !!(await R.getCell("SELECT show_certificate_expiry FROM status_page WHERE id = ? ", [ statusPageID ]));
|
||||||
|
|
||||||
let monitorIDList = await R.getCol(`
|
let monitorIDList = await R.getCol(`
|
||||||
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
|
SELECT monitor_group.monitor_id FROM monitor_group, \`group\`
|
||||||
|
@ -99,11 +101,34 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
|
||||||
|
|
||||||
const uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID);
|
const uptimeCalculator = await UptimeCalculator.getUptimeCalculator(monitorID);
|
||||||
uptimeList[`${monitorID}_24`] = uptimeCalculator.get24Hour().uptime;
|
uptimeList[`${monitorID}_24`] = uptimeCalculator.get24Hour().uptime;
|
||||||
|
|
||||||
|
// Get Certificate Status (Copied from monitor.js getCertExpiry())
|
||||||
|
if (showCertificateExpiry) {
|
||||||
|
let tlsInfoBean = await R.findOne("monitor_tls_info", "monitor_id = ?", [
|
||||||
|
monitorID,
|
||||||
|
]);
|
||||||
|
let tlsInfo;
|
||||||
|
if (tlsInfoBean) {
|
||||||
|
tlsInfo = JSON.parse(tlsInfoBean?.info_json);
|
||||||
|
if (tlsInfo?.valid && tlsInfo?.certInfo?.daysRemaining) {
|
||||||
|
certificateExpiryList[monitorID] = {
|
||||||
|
certExpiryDaysRemaining: tlsInfo.certInfo.daysRemaining,
|
||||||
|
validCert: true
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
certificateExpiryList[monitorID] = {
|
||||||
|
certExpiryDaysRemaining: "",
|
||||||
|
validCert: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.json({
|
response.json({
|
||||||
heartbeatList,
|
heartbeatList,
|
||||||
uptimeList
|
uptimeList,
|
||||||
|
certificateExpiryList
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -63,8 +63,19 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="extra-info">
|
<div class="extra-info">
|
||||||
<div v-if="showCertificateExpiry && monitor.element.certExpiryDaysRemaining">
|
<div
|
||||||
<Tag :item="{name: $t('Cert Exp.'), value: formattedCertExpiryMessage(monitor), color: certExpiryColor(monitor)}" :size="'sm'" />
|
v-if="showCertificateExpiry &&
|
||||||
|
$root.certificateExpiryList &&
|
||||||
|
$root.certificateExpiryList[monitor.element.id].certExpiryDaysRemaining"
|
||||||
|
>
|
||||||
|
<Tag
|
||||||
|
:item="{
|
||||||
|
name: $t('Cert Exp.'),
|
||||||
|
value: formattedCertExpiryMessage($root.certificateExpiryList[monitor.element.id]),
|
||||||
|
color: certExpiryColor($root.certificateExpiryList[monitor.element.id])
|
||||||
|
}"
|
||||||
|
:size="'sm'"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="showTags">
|
<div v-if="showTags">
|
||||||
<Tag v-for="tag in monitor.element.tags" :key="tag" :item="tag" :size="'sm'" data-testid="monitor-tag" />
|
<Tag v-for="tag in monitor.element.tags" :key="tag" :item="tag" :size="'sm'" data-testid="monitor-tag" />
|
||||||
|
@ -169,13 +180,13 @@ export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns formatted certificate expiry or Bad cert message
|
* Returns formatted certificate expiry or Bad cert message
|
||||||
* @param {object} monitor Monitor to show expiry for
|
* @param {object} info Certificate information to show
|
||||||
* @returns {string} Certificate expiry message
|
* @returns {string} Certificate expiry message
|
||||||
*/
|
*/
|
||||||
formattedCertExpiryMessage(monitor) {
|
formattedCertExpiryMessage(info) {
|
||||||
if (monitor?.element?.validCert && monitor?.element?.certExpiryDaysRemaining) {
|
if (info.validCert && info.certExpiryDaysRemaining) {
|
||||||
return monitor.element.certExpiryDaysRemaining + " " + this.$tc("day", monitor.element.certExpiryDaysRemaining);
|
return info.certExpiryDaysRemaining + " " + this.$tc("day", info.certExpiryDaysRemaining);
|
||||||
} else if (monitor?.element?.validCert === false) {
|
} else if (info.validCert === false) {
|
||||||
return this.$t("noOrBadCertificate");
|
return this.$t("noOrBadCertificate");
|
||||||
} else {
|
} else {
|
||||||
return this.$t("Unknown") + " " + this.$tc("day", 2);
|
return this.$t("Unknown") + " " + this.$tc("day", 2);
|
||||||
|
@ -184,11 +195,11 @@ export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns certificate expiry color based on days remaining
|
* Returns certificate expiry color based on days remaining
|
||||||
* @param {object} monitor Monitor to show expiry for
|
* @param {object} info Certificate information to show
|
||||||
* @returns {string} Color for certificate expiry
|
* @returns {string} Color for certificate expiry
|
||||||
*/
|
*/
|
||||||
certExpiryColor(monitor) {
|
certExpiryColor(info) {
|
||||||
if (monitor?.element?.validCert && monitor.element.certExpiryDaysRemaining > 7) {
|
if (info.validCert && info.certExpiryDaysRemaining > 7) {
|
||||||
return "#059669";
|
return "#059669";
|
||||||
}
|
}
|
||||||
return "#DC2626";
|
return "#DC2626";
|
||||||
|
|
|
@ -765,17 +765,18 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the heartbeat list and update favicon if necessary
|
* Update the heartbeat list along with the favicon and certificate expiry if necessary
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
updateHeartbeatList() {
|
updateHeartbeatList() {
|
||||||
// If editMode, it will use the data from websocket.
|
// If editMode, it will use the data from websocket.
|
||||||
if (! this.editMode) {
|
if (! this.editMode) {
|
||||||
axios.get("/api/status-page/heartbeat/" + this.slug).then((res) => {
|
axios.get("/api/status-page/heartbeat/" + this.slug).then((res) => {
|
||||||
const { heartbeatList, uptimeList } = res.data;
|
const { heartbeatList, uptimeList, certificateExpiryList } = res.data;
|
||||||
|
|
||||||
this.$root.heartbeatList = heartbeatList;
|
this.$root.heartbeatList = heartbeatList;
|
||||||
this.$root.uptimeList = uptimeList;
|
this.$root.uptimeList = uptimeList;
|
||||||
|
this.$root.certificateExpiryList = certificateExpiryList;
|
||||||
|
|
||||||
const heartbeatIds = Object.keys(heartbeatList);
|
const heartbeatIds = Object.keys(heartbeatList);
|
||||||
const downMonitors = heartbeatIds.reduce((downMonitorsAmount, currentId) => {
|
const downMonitors = heartbeatIds.reduce((downMonitorsAmount, currentId) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue