Automatic Server-Down Emails
Step 1. Set up your Linux Box with your gmail address, smtp.google.com, and password generated here: https://security.google.com/settings/security/apppasswords
Step 2. Open crontab -e
Step 3. Enter this line:
59 * * * * whoToEmail="adamoutler@gmail.com" serverToCheck="adamoutler.com"; curl -m 5 $serverToCheck || $(curl http://google.com && echo "At $(date) it was detected the $serverToCheck server is down" |mail -s "$serverToCheck is down" $whoToEmail)
Step 4. Change whoToEmail and serverToCheck to your own values.
Step 5. Do happy dance.
Step 1. Set up your Linux Box with your gmail address, smtp.google.com, and password generated here: https://security.google.com/settings/security/apppasswords
Step 2. Open crontab -e
Step 3. Enter this line:
59 * * * * whoToEmail="adamoutler@gmail.com" serverToCheck="adamoutler.com"; curl -m 5 $serverToCheck || $(curl http://google.com && echo "At $(date) it was detected the $serverToCheck server is down" |mail -s "$serverToCheck is down" $whoToEmail)
Step 4. Change whoToEmail and serverToCheck to your own values.
Step 5. Do happy dance.
Shared to my Google keep45w
Now to spoof some false alarms45w
👍👍👏👏45w
+Keith I Myers I'm pretty sure the rickroll server is uncrashable.45w
+Marty Ballard I have a dedicated infrastructure setup for that45w
+Keith I Myers obviously.45w
As someone who a few jobs ago was responsible for detecting down systems and bringing them back to function, I'd have to say the utility of any detection and reporting/alerting system is about proportional to its complexity. That is to say, this is far better than nothing , but it helps to know why a site went down (is it the host itself? the network connectivity to it? power? etc.) as well as having some state knowledge (basically, transition detection) so that you don't get notified over and over about something you know is down. Granted, this formula is set to run only once per hour, so one would hope inaccessibility lasts less than an hour. But still...if you're like me, my email notifications are silent overnight, so if inaccessiblity starts at say 2:30 am, I don't need 4 or 5 messages about my site being so when I wake up.
Just saying, this is defininely good, with a lot of things that can be learned from it.45w
This does a very rudimentary internet connection check before it sends an email. If a connection to your site fails and http://Google.com passes, it will send the email. So you at least don't get false positives from the Linux box's internet going down.45w
Add a comment...
Related Collections