From 354e735f10924dfd7adf9445526dbfe29ce4df33 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Fri, 24 Feb 2023 16:37:30 +0100 Subject: [PATCH] Re-added draftOutageEntries --- index.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 475cdc0..9dbeb07 100644 --- a/index.js +++ b/index.js @@ -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); + } + } } }