From bc4e7fbe91cb2add7101aaca3ea5670d90578490 Mon Sep 17 00:00:00 2001 From: Simon C Date: Mon, 9 Sep 2024 18:14:09 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Mise=20=C3=A0=20jour=20des=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index bae821a..4988088 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,7 @@ async function getLastUpdateTime(data) { return data.overview.lastUpdateTime } -async function sendAlert() { +async function sendAlert(msg) { console.log("sendAlert start") const mailjet = Mailjet.apiConnect( @@ -35,12 +35,12 @@ async function sendAlert() { }, To: [ { - Email: "simon@lestoitsduval.fr", - Name: "Conseil de gestion" + Email: "alert@lestoitsduval.fr", + Name: "Équipe pour les alertes" } ], - Subject: "😱 Alert sur la production", - TextPart: "La production est de 0 watt !", + Subject: "😱 Alerte sur la production", + TextPart: msg, } ] }) @@ -65,10 +65,10 @@ const currentPower = await getCurrentPower(data); const lastUpdateTime = await getLastUpdateTime(data); 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); + if (secondDifference > (6 * 60)) { 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 { console.log(`✅ L'installation répond correctement dernière mise à jour il y a ${secondDifference} secondes.`); } -await sendAlert();