- Oct 29, 2009
- 727
- 825
- Awards
- 8
- First Name
- Rick
Guys and Girls....
This past weekend I ran into an issue. A VPS (virtual private server) of mine went offline. It was a very simple easy fix. Simply, reboot the server and get it back online. The issue was, I had no idea it went offline. By looking at the stats it was down for a couple of hours. It was by a freak chance that I caught it. I called the provider I have the server setup with and ask them, "Do you guys not have a method or way of alerting me when the server goes offline???" The rep kindly replied, "no, we don't" ! She did say that there were scripts that I could place on the server that would alert me but they didn't have access to them because they were custom scripts written by other customers that have a VPS like mine. That got me thinking on how to go about getting alerts on when this thing decides to go offline again. Keep in mind, this is the first time this has happened to me. It's been running flawless for months now.
I'm sure there are programs and software that you can subscribe to and they will provide alerts, calls, charts and more data than you can shake a stick at. I get that. I need something simple, reliable, fast and Free!!!
I figured out a way to get the alerts now for my VPS but I started thinking, How many times have I ran into the issue of where I get a phone call from managers or sales reps at the dealership saying "Rick, our website is down or offline". It doesn't happen very often but I'm always one of the last people to know. I figure there's other people out there like me that have multiple websites who would like to be proactive instead of only reactive and know if the sites are down immediately so you can get on the phone with tech support to get them back up ASAP and not spend every waking moment surfing your own websites making sure they're up and running correctly.
I did a little searching on Google and I found a Google Apps script on Digital Inspiration that shows you how to send a SMS using Apps script and Twilio. Here's the link: https://ctrlq.org/code/20200-send-sms-google-script
A couple of steps that Digital Inspiration doesn't explain, I'll explain here for you.
Create a free account at www.twilio.com
Once you create your account, you will be prompted to give a cell number to receive a text message or call for a verification code.
Once you get your code and verify your account with twilio, login to twilio. At the Console Dashboard, click on the "Programmable SMS" link. With the free account, your allowed 1 twilio phone number that you can send SMS with. Get your free twilio phone number and it will be linked to your account!! Your done.
Now, you have your number, lets use Google Apps Script to ping your websites and get the response code from the header. If the response returned back isn't a 200 (200 meaning everything is working fine) then send you a SMS letting you know something was wrong and include the site name and the response that was returned back and include this in the text message.
Here you go!!
http://www.rickbuffkin.com/SMSnotifier.txt
Originally had the code posted here but, I had to edit my original post, DR kept altering the code!!!
Once you have your script, click on Run and you'll be prompted by google to allow the script to run. Simply select the GMail account your using and hit OK. If everything is working correctly, you shouldn't be getting any alerts at all. You can click on the View>Logs to see the response returned. The script is set to only send a text message if there is a response other than a 200.
Now that you have your code, and you've made your edits, the next thing you have to do is set your Script to run at a certain interval. In Scripts Apps click on Edit > Current Project's Triggers. Then click on the link to add a Trigger. In the next window you can set up the interval you want the script to run. I have mine running every min. You can set it to run as often as you want though. You can also set up an alert if for some reason that Google Apps Script errors and doesn't run your script. Just click on "notifications" and set your email address and when you want it sent. Mine is set to send immediately.
This was my solution and so far it seems to be working pretty well with no issues. Anyone else want to chime in with their solution??
This past weekend I ran into an issue. A VPS (virtual private server) of mine went offline. It was a very simple easy fix. Simply, reboot the server and get it back online. The issue was, I had no idea it went offline. By looking at the stats it was down for a couple of hours. It was by a freak chance that I caught it. I called the provider I have the server setup with and ask them, "Do you guys not have a method or way of alerting me when the server goes offline???" The rep kindly replied, "no, we don't" ! She did say that there were scripts that I could place on the server that would alert me but they didn't have access to them because they were custom scripts written by other customers that have a VPS like mine. That got me thinking on how to go about getting alerts on when this thing decides to go offline again. Keep in mind, this is the first time this has happened to me. It's been running flawless for months now.
I'm sure there are programs and software that you can subscribe to and they will provide alerts, calls, charts and more data than you can shake a stick at. I get that. I need something simple, reliable, fast and Free!!!
I figured out a way to get the alerts now for my VPS but I started thinking, How many times have I ran into the issue of where I get a phone call from managers or sales reps at the dealership saying "Rick, our website is down or offline". It doesn't happen very often but I'm always one of the last people to know. I figure there's other people out there like me that have multiple websites who would like to be proactive instead of only reactive and know if the sites are down immediately so you can get on the phone with tech support to get them back up ASAP and not spend every waking moment surfing your own websites making sure they're up and running correctly.
I did a little searching on Google and I found a Google Apps script on Digital Inspiration that shows you how to send a SMS using Apps script and Twilio. Here's the link: https://ctrlq.org/code/20200-send-sms-google-script
A couple of steps that Digital Inspiration doesn't explain, I'll explain here for you.
Create a free account at www.twilio.com
Once you create your account, you will be prompted to give a cell number to receive a text message or call for a verification code.
Once you get your code and verify your account with twilio, login to twilio. At the Console Dashboard, click on the "Programmable SMS" link. With the free account, your allowed 1 twilio phone number that you can send SMS with. Get your free twilio phone number and it will be linked to your account!! Your done.
Now, you have your number, lets use Google Apps Script to ping your websites and get the response code from the header. If the response returned back isn't a 200 (200 meaning everything is working fine) then send you a SMS letting you know something was wrong and include the site name and the response that was returned back and include this in the text message.
Here you go!!
http://www.rickbuffkin.com/SMSnotifier.txt
Originally had the code posted here but, I had to edit my original post, DR kept altering the code!!!
Once you have your script, click on Run and you'll be prompted by google to allow the script to run. Simply select the GMail account your using and hit OK. If everything is working correctly, you shouldn't be getting any alerts at all. You can click on the View>Logs to see the response returned. The script is set to only send a text message if there is a response other than a 200.
Now that you have your code, and you've made your edits, the next thing you have to do is set your Script to run at a certain interval. In Scripts Apps click on Edit > Current Project's Triggers. Then click on the link to add a Trigger. In the next window you can set up the interval you want the script to run. I have mine running every min. You can set it to run as often as you want though. You can also set up an alert if for some reason that Google Apps Script errors and doesn't run your script. Just click on "notifications" and set your email address and when you want it sent. Mine is set to send immediately.
This was my solution and so far it seems to be working pretty well with no issues. Anyone else want to chime in with their solution??
Last edited: