Skip to content

Commit

Permalink
Update maintenance logic and overrides
Browse files Browse the repository at this point in the history
- Made maintenances show up in the overall status
- Added override for overall status (Currently does not override maintenances)
  • Loading branch information
imlayered committed Sep 18, 2024
1 parent 6e9f1c1 commit e1e5af2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 19 deletions.
13 changes: 8 additions & 5 deletions data.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"Whitelabel": false,
"RandomOperationalMessage": true,
"OverallStatus": "NoOverride",
"maintenanceAlerts": [
{
"date": "2021-01-16T12:00:00Z",
"message": "Hey!",
"title": "Upgrades to US 1 on July 31st"
"start": "2024-09-17T12:00:00Z",
"end": "2024-09-18T12:00:00Z",
"message": "Demo maintenance (hide by disabling maintenanceAlerts in data.json!.",
"title": "Demo"
}
],
"sections": {
"maintenanceAlerts": true,
"statusUpdates": true
"statusUpdates": true,
"announcementBar": false
},
"services": {
"Example 1": {
Expand All @@ -36,4 +39,4 @@
"title": "This is a demo site!"
}
]
}
}
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Status page developed by UptimeMatrix, a venture by Layeredy LLC (Version 1.0.2). | github.com/layeredy/uptimematrix-statuspage-spark -->
<!-- Status page developed by UptimeMatrix, a venture by Layeredy LLC (Version 1.0.3). | github.com/layeredy/uptimematrix-statuspage-spark -->
<!-- Theme: Spark github.com/layeredy/uptimematrix-statuspage-spark -->
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -34,5 +34,5 @@ <h1><a href="https://layeredy.com"><img src="https://cdn.layeredy.com/uptimematr
<script src="script.js"></script>
</body>
</html>
<!-- Status page developed by UptimeMatrix, a venture by Layeredy LLC (Version 1.0.2). | github.com/layeredy/uptimematrix-statuspage-spark -->
<!-- Status page developed by UptimeMatrix, a venture by Layeredy LLC (Version 1.0.3). | github.com/layeredy/uptimematrix-statuspage-spark -->
<!-- Theme: Spark github.com/layeredy/uptimematrix-statuspage-spark -->
63 changes: 51 additions & 12 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

function setCookie(name, value, days) {
let expires = "";
if (days) {
Expand Down Expand Up @@ -31,7 +32,7 @@ document.addEventListener('DOMContentLoaded', () => {
})
.then(data => {
if (data.sections.announcementBar) updateAnnouncementBar(data.announcement);
updateOverallStatus(data.services, data.RandomOperationalMessage);
updateOverallStatus(data.services, data.RandomOperationalMessage, data);
updateServices(data.services);
if (data.sections.maintenanceAlerts) updateMaintenanceAlerts(data.maintenanceAlerts);
if (data.sections.statusUpdates) updateStatusUpdates(data.statusUpdates);
Expand Down Expand Up @@ -110,15 +111,41 @@ function updateAnnouncementBar(announcement) {
}
}

function updateOverallStatus(services, RandomOperationalMessage) {
function updateOverallStatus(services, RandomOperationalMessage, data) {
const overallStatusElement = document.getElementById('overall-status');
const allStatuses = Object.values(services).flatMap(group => Object.values(group));
let overallStatus = 'Operational';

if (allStatuses.some(status => status === 'Issue')) {
overallStatus = 'Issue';
} else if (allStatuses.some(status => status === 'Degraded')) {
overallStatus = 'Degraded';
let isMaintenanceOngoing = false;
if (data.maintenanceAlerts && data.maintenanceAlerts.length > 0) {
const now = new Date();
data.maintenanceAlerts.forEach(alert => {
if (alert.start && alert.end) {
const startTime = new Date(alert.start);
const endTime = new Date(alert.end);
if (now >= startTime && now <= endTime) {
isMaintenanceOngoing = true;
}
}
});
}
if (isMaintenanceOngoing) {
overallStatusElement.innerHTML = `
<div class="status-icon">//</div>
Undergoing maintenance
`;
overallStatusElement.className = 'status-maintenance';
return;
}

let overallStatus = 'Operational';
if (data.OverallStatus && data.OverallStatus !== 'NoOverride') {
overallStatus = data.OverallStatus;
} else {
const allStatuses = Object.values(services).flatMap(group => Object.values(group));
if (allStatuses.some(status => status === 'Issue')) {
overallStatus = 'Issue';
} else if (allStatuses.some(status => status === 'Degraded')) {
overallStatus = 'Degraded';
}
}

let statusText = 'All systems operational';
Expand All @@ -140,6 +167,9 @@ function updateOverallStatus(services, RandomOperationalMessage) {
} else if (overallStatus === 'Issue') {
statusText = 'Major outage detected';
statusIcon = '✕';
} else {
statusText = overallStatus;
statusIcon = '?';
}

overallStatusElement.innerHTML = `
Expand Down Expand Up @@ -241,10 +271,19 @@ function createAlertElement(item, className) {
title.textContent = item.title;
element.appendChild(title);

const date = document.createElement('p');
date.className = 'date';
date.textContent = new Date(item.date).toLocaleString();
element.appendChild(date);
if (item.start && item.end) {
const date = document.createElement('p');
date.className = 'date';
const startTime = new Date(item.start).toLocaleString();
const endTime = new Date(item.end).toLocaleString();
date.textContent = `From ${startTime} to ${endTime}`;
element.appendChild(date);
} else if (item.date) {
const date = document.createElement('p');
date.className = 'date';
date.textContent = new Date(item.date).toLocaleString();
element.appendChild(date);
}

const message = document.createElement('p');
message.textContent = item.message;
Expand Down

0 comments on commit e1e5af2

Please sign in to comment.