Created
November 13, 2017 18:36
-
-
Save devesh2605/a42ed5e98040732ee115fea18852ee12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]', | |
pass: 'yourpassword' | |
} | |
}); | |
const mailOptions = { | |
from: '[email protected]', | |
to: '[email protected]', | |
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