diff --git a/entities/webserviceheartbeat.js b/entities/webserviceheartbeat.js index 06a7e22..3dbbb5f 100644 --- a/entities/webserviceheartbeat.js +++ b/entities/webserviceheartbeat.js @@ -17,10 +17,10 @@ module.exports = { trim: true, filter: { title: 'id', - match: '^[a-zA-Z0-9]{6}$', + match: '^[a-zA-Z0-9]{10}$', order: 999, }, - default: () => makeId(6), + default: () => makeId(10), validate: async ({ newValues, oldValues, newEntity, storage }) => { if (newEntity) { const r = storage ? await storage.store('smartyellow/webserviceheartbeat').get(newValues.id) : null; diff --git a/gui/dashboard/lib.js b/gui/dashboard/lib.js index 4dea8d5..21aa52e 100644 --- a/gui/dashboard/lib.js +++ b/gui/dashboard/lib.js @@ -46,7 +46,7 @@ export const shuffle = crossfade({ const transform = style.transform === 'none' ? '' : style.transform; return { - duration: 400, + duration: 100, easing: quintOut, css: t => ` transform: ${transform} scale(${t}); @@ -58,7 +58,9 @@ export const shuffle = crossfade({ export function ringBell() { const bell = new Audio(window.location.href + '/sound'); + bell.loop = true; bell.addEventListener('canplaythrough', () => bell.play()); + window.addEventListener('keydown', () => bell.pause()); } export function formatDuration(ms) { diff --git a/gui/sounds/bell.wav b/gui/sounds/bell.wav index 00dff80..d89b28c 100644 Binary files a/gui/sounds/bell.wav and b/gui/sounds/bell.wav differ diff --git a/index.js b/index.js index 3d01a5b..f73905c 100644 --- a/index.js +++ b/index.js @@ -179,7 +179,7 @@ module.exports = { const services = await server .storage .store('smartyellow/webservice') - .find({ autotestEnabled: true }) + .find() .toArray(); if (!services.length) { @@ -194,6 +194,7 @@ module.exports = { server.error(message.error); } else if (message.outage) { + console.log('outage', message.outage); processOutage({ outage: message.outage, server, settings }); } }); diff --git a/lib/processoutage.js b/lib/processoutage.js index 9fb6f6d..88006a4 100644 --- a/lib/processoutage.js +++ b/lib/processoutage.js @@ -5,7 +5,7 @@ const { makeId } = require('core/makeid'); async function processOutage({ outage, server, settings }) { for (const [ id, testResult ] of Object.entries(outage)) { // Update check date - await server.storage.store('smartyellow/webservice').update( + server.storage.store('smartyellow/webservice').update( { id }, { $set: { lastChecked: new Date() } } ); @@ -24,6 +24,8 @@ async function processOutage({ outage, server, settings }) { .toArray(); const lastBeat = heartbeat[heartbeat.length - 1]; + console.log('lastbeat', lastBeat); + // Encountered an error while checking status if (testResult.error) { server.error('Error while checking status of ' + id); @@ -36,8 +38,8 @@ async function processOutage({ outage, server, settings }) { if ((lastBeat && lastBeat.down == false) || !lastBeat) { // Insert heartbeat if last one is not valid anymore try { - await server.storage.store('smartyellow/webserviceheartbeat').insert({ - id: makeId(6), + server.storage.store('smartyellow/webserviceheartbeat').insert({ + id: makeId(10), down: true, webservice: id, testResult, @@ -45,14 +47,14 @@ async function processOutage({ outage, server, settings }) { }); } catch (err) { - server.error(err); server.error('could not save web service heartbeat'); + server.error(err); } // Send e-mail notification if (server.sendEmail && settings.emailSender && settings.emailRecipient) { try { - await server.sendEmail({ + server.sendEmail({ sender: settings.emailSender, to: settings.emailRecipient, subject: `[outage] ${service.name} is down`, @@ -64,19 +66,19 @@ async function processOutage({ outage, server, settings }) { }); } catch (err) { - server.error(err); server.error('could not send endpoint status notification e-mail'); + server.error(err); } } // Draft outage entry if (settings.draftOutageEntries) { try { - await server + server .storage .store('smartyellow/webserviceoutage') .insert({ - id: makeId(6), + id: makeId(), name: { en: `[automatic] Outage for ${service.name.en}`, }, @@ -92,8 +94,8 @@ async function processOutage({ outage, server, settings }) { }); } catch (err) { - server.error(err); server.error('could not automatically draft outage entry'); + server.error(err); } } } @@ -106,7 +108,7 @@ async function processOutage({ outage, server, settings }) { // Insert heartbeat if last one is not valid anymore try { await server.storage.store('smartyellow/webserviceheartbeat').insert({ - id: makeId(6), + id: makeId(10), down: false, webservice: id, testResult, @@ -114,12 +116,14 @@ async function processOutage({ outage, server, settings }) { }); } catch (err) { - server.error(err); server.error('could not save web service heartbeat'); + server.error(err); } } } } + + return; } module.exports = { processOutage }; diff --git a/lib/runtime.js b/lib/runtime.js index 692014a..45bef88 100644 --- a/lib/runtime.js +++ b/lib/runtime.js @@ -19,7 +19,7 @@ process.on('message', async message => { const interval = service.autotestInterval; const needsCheck = timePassed >= interval; - if (service.autotestEnabled && needsCheck) { + if (needsCheck) { ids.push(service.id); promises.push(testEndpoints(service.autotest)); } diff --git a/lib/testendpoints.js b/lib/testendpoints.js index bbcca17..4cf6961 100644 --- a/lib/testendpoints.js +++ b/lib/testendpoints.js @@ -6,7 +6,7 @@ const { realValues } = require('./realvalues'); async function testEndpoints(endpoints) { const output = { - serviceUp: true, + serviceUp: undefined, success: true, error: false, requirement: undefined, @@ -46,15 +46,18 @@ async function testEndpoints(endpoints) { } if (!result) { - output.success = true; output.serviceUp = false; output.requirement = requirement; output.realValue = realValue; } + else { + output.serviceUp = true; + } }); } catch (err) { output.success = false; + output.serviceUp = false; output.error = err; console.error(err); }