Skip to content

Instantly share code, notes, and snippets.

@devesh2605
Created November 13, 2017 18:36
Show Gist options
  • Save devesh2605/a42ed5e98040732ee115fea18852ee12 to your computer and use it in GitHub Desktop.
Save devesh2605/a42ed5e98040732ee115fea18852ee12 to your computer and use it in GitHub Desktop.
const isReachable = require('is-reachable'),
nodemailer = require('nodemailer');
function checkStats() {
isReachable('api.example.com').then(reachable => {
if (reachable === true) {
console.log('Server is up');
} else {
console.log('Server is down');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'yourmail@gmail.com',
pass: 'yourpassword'
}
});
const mailOptions = {
from: 'yourmail@gmail.com',
to: 'recipient@example.com',
subject: 'Server stats',
html: '<b>Server is down</b>'
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log('Message failure: ' + error);
} else {
console.log('Message sent: ' + info.response);
}
});
}
});
setTimeout(checkStats, 5000);
}
checkStats();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment