Various fixes

This commit is contained in:
Romein van Buren 2022-07-13 13:42:37 +02:00
parent 0aa3ce6e2a
commit 7f1d1dc90e
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
7 changed files with 28 additions and 18 deletions

View File

@ -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;

View File

@ -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) {

Binary file not shown.

View File

@ -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 });
}
});

View File

@ -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 };

View File

@ -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));
}

View File

@ -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);
}