Re-added draftOutageEntries

This commit is contained in:
Romein van Buren 2023-02-24 16:37:30 +01:00
parent 9f28a8f30e
commit 354e735f10
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49

View File

@ -22,7 +22,7 @@ const icons = {
const servicesNotifiedAboutOutage = new Set();
let renderedDashboard = null;
async function processOutage({ outage, server, onDateUpdated }) {
async function processOutage({ outage, server, settings, onDateUpdated }) {
if (typeof onDateUpdated !== 'function') {
onDateUpdated = () => null;
}
@ -34,6 +34,12 @@ async function processOutage({ outage, server, onDateUpdated }) {
{ $set: { lastChecked: new Date() } }
).then(() => onDateUpdated(id));
// Get service entry
const service = await server
.storage
.store('smartyellow/webservice')
.findOne({ id });
// Get last heartbeat
const heartbeat = await server
.storage
@ -66,6 +72,34 @@ async function processOutage({ outage, server, onDateUpdated }) {
server.error('status: could not save web service heartbeat');
server.error(err);
}
// Draft outage entry
if (settings.draftOutageEntries) {
try {
server
.storage
.store('smartyellow/webserviceoutage')
.insert({
id: makeId(),
name: {
en: `[automatic] Outage for ${service.name.en}`,
},
state: 'concept',
resolved: false,
services: [ service.id ],
tags: [ 'automatically created' ],
notes: [ {
date: new Date(),
userId: 'system',
text: `Automatically created outage. Reason: ${JSON.stringify(testResult, null, 2)}`,
} ],
});
}
catch (err) {
server.warn('status: could not automatically draft outage entry');
server.warn(err);
}
}
}
}