feat: Mise à jour des messages
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a576e01b17
commit
bc4e7fbe91
14
index.js
14
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();
|
||||
|
|
Loading…
Reference in New Issue