feat: Mise à jour des messages
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Simon 2024-09-09 18:14:09 +02:00
parent a576e01b17
commit bc4e7fbe91
1 changed files with 7 additions and 7 deletions

View File

@ -16,7 +16,7 @@ async function getLastUpdateTime(data) {
return data.overview.lastUpdateTime return data.overview.lastUpdateTime
} }
async function sendAlert() { async function sendAlert(msg) {
console.log("sendAlert start") console.log("sendAlert start")
const mailjet = Mailjet.apiConnect( const mailjet = Mailjet.apiConnect(
@ -35,12 +35,12 @@ async function sendAlert() {
}, },
To: [ To: [
{ {
Email: "simon@lestoitsduval.fr", Email: "alert@lestoitsduval.fr",
Name: "Conseil de gestion" Name: "Équipe pour les alertes"
} }
], ],
Subject: "😱 Alert sur la production", Subject: "😱 Alerte sur la production",
TextPart: "La production est de 0 watt !", TextPart: msg,
} }
] ]
}) })
@ -65,10 +65,10 @@ const currentPower = await getCurrentPower(data);
const lastUpdateTime = await getLastUpdateTime(data); const lastUpdateTime = await getLastUpdateTime(data);
console.log(`[${lastUpdateTime}] La salle Greyzollon Duluth produissait ${currentPower} watt${currentPower>0?'s':''} !`) console.log(`[${lastUpdateTime}] La salle Greyzollon Duluth produissait ${currentPower} watt${currentPower>0?'s':''} !`)
const secondDifference = Math.ceil(Math.abs(now.getTime() - new Date(lastUpdateTime).getTime()) / 1000); const secondDifference = Math.ceil(Math.abs(now.getTime() - new Date(lastUpdateTime).getTime()) / 1000);
if (secondDifference > (6 * 60)) { if (secondDifference > (6 * 60)) {
console.log(`❌ L'installation n'a pas répondu depuis '${lastUpdateTime}' ça fait ${secondDifference} secondes !`); console.log(`❌ L'installation n'a pas répondu depuis '${lastUpdateTime}' ça fait ${secondDifference} secondes !`);
await sendAlert(); await sendAlert(`❌ L'installation n'a pas répondu depuis '${lastUpdateTime}' ça fait ${secondDifference} secondes !`);
} else { } else {
console.log(`✅ L'installation répond correctement dernière mise à jour il y a ${secondDifference} secondes.`); console.log(`✅ L'installation répond correctement dernière mise à jour il y a ${secondDifference} secondes.`);
} }
await sendAlert();