Formatting and error handling

This commit is contained in:
2020-06-08 22:21:51 +02:00
committed by KevinMidboe
parent c5815e931f
commit 7cca05cbe7

View File

@@ -18,10 +18,11 @@ if (config.debug == false)
const dateString = new Date().getTime(); const dateString = new Date().getTime();
const pdfFilename = (config['pdfFilename'] || 'telenor-downtime') + `_${dateString}.pdf`; const pdfFilename = (config['pdfFilename'] || 'telenor-downtime') + `_${dateString}.pdf`;
const pdfPath = `pdfExports/${pdfFilename}`
const savePageToPDF = page => { const savePageToPDF = page => {
const pdfOptions = { const pdfOptions = {
path: `pdfExports/${pdfFilename}`, path: pdfPath,
format: "A4", format: "A4",
printBackground: true, printBackground: true,
displayHeaderFooter: true, displayHeaderFooter: true,
@@ -98,10 +99,11 @@ const notifyIfDown = serviceMessages => {
const servicesDown = serviceMessages.filter(message => message.isOk == false) const servicesDown = serviceMessages.filter(message => message.isOk == false)
if (servicesDown.length) { if (servicesDown.length) {
console.log("Following services are down:\n", servicesDown) console.log("Number of services down: ", servicesDown.length)
mail.sendAttachment('./telenor-downtime.pdf') return mail.sendAttachment(pdfPath, servicesDown[0].statusText)
.then(resp => console.log(`Message id: ${resp.messageId} sent.\nResponse content: ${resp}`)) .then(resp => console.log(`Message id: ${resp.messageId} sent.\nResponse content: ${resp}`))
.catch(err => console.error('Error from sendmail:', err))
} else { } else {
console.info("All service operational"); console.info("All service operational");
} }
@@ -118,6 +120,7 @@ const webscraper = async pageURL => {
} }
function closeBrowserAndExit(status=0) { function closeBrowserAndExit(status=0) {
console.log('✋ closing shop')
browser.close(); browser.close();
process.exit(status); process.exit(status);
} }