Check ISP website & send mail if services are down

Scrape, navigate and print ISP's status page for a given address. This
only works with telenor and the URL must be a search for a given
address.
If any services are found to be down a mail is sent from and to accounts
set in config.js.
This commit is contained in:
2020-05-27 19:58:12 +02:00
parent 216a2bb106
commit 12a039930b
2 changed files with 168 additions and 0 deletions

40
src/mail.js Normal file
View File

@@ -0,0 +1,40 @@
const nodemailer = require( 'nodemailer')
const config = require('../config.js')
class Mail {
constructor(sender=undefined, password=undefined, recipient=undefined) {
this.sender = sender || config.senderEmail;
this.password = password || config.senderPassword;
this.recipient = recipient || config.recipientEmail;
this.transporter = this.setupTransporter();
}
setupTransporter() {
return nodemailer.createTransport({
service: 'gmail',
auth: {
user: this.sender,
pass: this.password
}
})
}
sendMail = message => this.transporter.sendMail(message);
sendAttachment = fileRef => {
const message = {
from: `"Fred Foo 👻" <${this.sender}>`,
to: this.recipient,
subject: 'Telenor nedetid',
text: "hello wordl",
html: "<p>hello wordl</p>",
attachments: [{
path: fileRef
}]
}
return this.sendMail(message)
}
}
module.exports = Mail