StalkMySite – FREE Script That Checks If Your Sites Are Up Using Google Docs [UPDATED]

EDIT (05/10/2012) – PLEASE READ:  The previous issue regarding the copying of Javascript appears to be resolved, although I have yet to figure out what was causing it.  I’ve tested that it works with multiple accounts with reliability, but since this seems to be a Google issue, I’m not willing to say it’s 100% resolved.  As such, I’m keeping a link to the Javascript (link here) so that you may still copy it if you need to.  As always if you need any help with this, let me know.

I came across this article from Lifehacker about how to use Google Docs and Javascript to monitor if your websites are currently up.  The article links to Amit Agarwal’s post on how to set up this Google Doc spreadsheet to handle the ever-so-tedious task of making sure that your sites are up before an upset customer or patron emails you and asks why they can’t read awesome posts like this one about WordPress. :-)

The only issue that I had with Amit’s script is that he only supports one website per spreadsheet.  So to keep track of ALL of your sites, you might end up making 15 spreadsheets.  Well, most of the people on his blog post were already clamoring for a multisite version and I figured I’d try my hand at making a script that would satisfy these requirements.

Enter StalkMySite.

StalkMySite is my heavily modified version that allows for keeping track of all of your sites’ uptime, no matter how many sites you need to keep tabs on.  My script reads all of the URLs that you enter, along with an email address for each site, then loops through all the data, checks each URL to see if it’s up and then if it encounters an error, it logs the error and reason into the spreadsheet, then shoots off an email.  All of this is automated by enabling script triggers that let you choose how often you need updates, from as often as every minute to every week.

Currently, my script only allows for 1 email address per URL, but in the future this might change.  Or even better yet, if you’re a savvy Javascript coder and want to modify it, knock yourself out!  It’s totally free under the GNU v2, so by all means, do what you want with it.  If you want me to assist, I’d be glad to do that.  Just email me at mike@fronterahouse.com and let me know what I can do or what questions I can answer.

How To Setup StalkMySite

It’s pretty easy.  If you haven’t already created a Google Docs account, you can do so here.  If you already have an account, then start by making a copy of the StalkMySite spreadsheet into your own Google Docs repository.  After that, you should be in your own repository, looking at the spreadsheet.

At this point, you should simply enter your URLs in the URL column on the ‘Enter Information’ worksheet, along with the corresponding email addresses that you want the notifications to be sent to.  After entering in this information, click on Tools > Script Editor to enter the Javascript Editor.  From here click Resources > Current script’s triggers…

Edit:  In doing some research on this script and through the Google Docs API, the sendMail function natively supports multiple recipients.  In your own spreadsheet, simply add your multiple email addresses, comma-separated and that is all you need to do.  Cool!

A new window will pop up where you can enter triggers that will fire at regular intervals and execute certain functions within your Javascript.  The function that you want to execute regularly in the StalkMySite sheet will be the get_user_data function.  Add this as a trigger by clicking on the link “No triggers set up.  Click here to add one now.”  This will allow you to select the get_user_data function.

Next, under the Events section, click on the dropdown and select “Time-driven”.  The next two dropdowns to the immediate right will let you select the interval of time.  Again those range from on the minute to by the week.  Go ahead and choose how often you want it to check your sites.  (NOTE:  I have mine currently set to every 5 minutes.  As this is still in the testing phase, I want to do it more frequently, but may dial my interval back in the future.)

Finally click on the save button here and that’s it!  Well, kind of.  You may receive a pop-up warning about not being the author of this script and the potential security hazard that poses.  This is a standard Google disclaimer to protect the user from doing something stupid.  Don’t worry though, this script is 100% legit and all you have to do is click through the prompt to allow access.

SMS Messages with StalkMySite

In today’s world of mobile technology, everybody is on the go and if you’re one of us “lowlifes” that doesn’t have push notification of email on your phone, you may have to wait an entire 5 (FIVE!!! *gasp*) minutes to get the email message saying your site is down.  Well, perhaps you want it faster than that?  As long as you have a cell phone and understand how sending SMS through email works, then you should be good to go.

I’ve included below a list of some of the most popular carriers and how their email-to-SMS addresses work.  For most of them, you simply put the phone number with no dashes ahead of the “@” symbol with the carriers default email domain afterwards.  Some require the use of the country code and some do not.  Have a look:

* This should go without saying, but replace “1234567890″ with your own phone number.

Alltel – 1234567890@message.alltel.com
AT&T
– 1234567890@txt.att.net
Boost – 1234567890@myboostmobile.com
iWireless – 1234567890@iwspcs.net
Nextel – 1234567890@messaging.nextel.com
Sprint – 1234567890@messaging.sprintpcs.com
T-Mobile – 1234567890@tmomail.net
Verizon – 1234567890@vtext.com
Virgin Mobile – 1234567890@vmobl.com
US Cellular – 1234567890@email.uscc.net

If you know of any other carriers that you’d like to list, post ‘em in the comments.

Potential Downside(s)

Personally, I think this script is great.  We no longer have to pay a third party site to ensure that our websites are up and running since this is 100% free.  However, I’m wondering what the Terms of Service of some shared hosting accounts would think about this or even what Google thinks about it.  It’s a simple request with a minimal packet size that is being sent to your server, but what if you’re a hosting company and everybody on their servers had multiple sites that they were doing this to?  Would that go noticed and then subsequently banned from being allowed by hosting providers?

Chances are, probably not (and I really hope not!).  I think that if StalkMySite is used properly it can be a useful preparedness tool that can keep you, the responsible webmaster, on their toes and ready to go.  One thing that I would recommend doing if you run a multisite install like we do here at Frontera, is only set this up on your primary domain.  Since all of the subsites that you run on a WP Multisite Network all point to the same IP address anyway, if your primary goes down, they should all go down.

As an example, say you run 10 sites all on one install of WordPress.  Your primary site has an IP address of 192.168.1.118 (yes I know that’s an internal IP, it’s just for educational purposes…) and you read my article on how to setup multisite domain mapping, so you currently have all 10 of those domains mapped.  If you notice in your hosting providers DNS management console, all of your domains should have an IP address of 192.168.1.118.  Don’t believe me?  Ping each site and see what IP the name translates to.  If it isn’t 192.168.1.118, then I have bad news; your multisite mapping isn’t setup properly.

So why ping 192.168.1.118 10 times every minute to check your sites when you know that if you lose one, you’ll lose them all?  The answer is, “don’t”.  Just ping your primary and call it a day.

Some Final Things To Note

I wrote this in an attempt to contribute back to the community and I felt it was a really good learning opportunity for me as far as Javascript is concerned.  I’m always striving to be better at jQuery and Javascript and for some reason, I find it difficult sometimes.  I know my code on this can be improved.  So if you want to improve it or have any tips or pointers for me, let me know in the comments and I’d be glad to upgrade the script to include them and give you credit for your contributions!

This entry was posted in Technology, Web and tagged , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post. Post a comment or leave a trackback: Trackback URL.

17 Comments

  1. Mike Posted March 30, 2012 at 8:52 am | Permalink

    Nice work. I also caught wind of the original design from lifehacker, and like many others wanted multisite support. So way to go!

    The one other thing I would like to see is thresholding. For whatever reason, my site will occasionally miss one check. Well I really don’t care if it misses one because it comes back 98% of the time. I just want to be notified via email if it misses say 2 or 3 in a row. I think you could just add a variable that counts the consecutive misses, but I am not a really skilled programmer.

    Just a suggestion. Thanks for your efforts!

    • Electronic Media Director Posted March 30, 2012 at 9:16 am | Permalink

      Thanks Mike! I’m glad you like the script.

      As for thresholding, I don’t believe you can do that given the nature of how Google Docs is setup. I’m pretty sure that these scripts are always going to be state-less and you’d have to have a way to pass the value of a variable to the script itself each time it ran and the only way that I know how to do that is with a server side session. For security reasons, among many others, I doubt they’ll ever let users modify anything server related.

  2. Mike Posted April 3, 2012 at 10:17 am | Permalink

    Appreciate the response, Could you simply add a column to the spreadsheet next to each site that increments if the test failes, resets to 0 if it succeeds?

    So each time the test passes column C would be set to 0, then if it fails once it would be incremented to 1, if it fails again incremented to 2, etc..

    The place the alarming portion of the code in an if block that checks that value for 2 or 3 or however many failures.

    Then when it passes again the first time, just set the value back to 0.

    I don’t know if that would really work, but just my thoughts on it. If I had the know how I would attempt to implement it, but no time for the learning curve at the moment. :) Regardless, nice work!

    • Electronic Media Director Posted April 3, 2012 at 10:31 am | Permalink

      Wow, I can’t believe I missed that. Of course the spreadsheet itself has state. Good call!

      I’ll have to take a look at the code and see if I can modify it to work that way. Maybe even have a field in the spreadsheet that asks the user how many failures in a row should occur before they want to be notified?

  3. Mike Posted April 11, 2012 at 9:09 am | Permalink

    That would be awesome. Either 1 setting for all sites, or an additional column on the sheet where you define the sites that allows you to define a value for each site. Hope you can add this improvement, it would be killer!

  4. Scott Posted April 13, 2012 at 11:02 am | Permalink

    Thanks for this version. I was also trying to use the first version and this is what I wanted. 1 quick question though I know in Amit’s version, well according to people in comments. That his version of checking the site would not affect Google Analytics. It appears yours checks the site in the same way. Is this correct or do you know if it would affect Google Analytics counts?
    Thank you very much for this great script.

    • Electronic Media Director Posted April 13, 2012 at 11:22 am | Permalink

      Glad you enjoy it Scott! The mechanism by which my script “pings” the target site is actually a built in command for the library that Google Docs uses (UrlFetchApp.fetch) and is the exact same method that Amit used as well.

      While I can’t be 100% certain that it’s not affecting analytics (as I haven’t truly checked that deeply yet), I haven’t noticed any spikes on our own analytics that isn’t a direct result of organic search traffic.

  5. Andrew Hughes Posted April 14, 2012 at 1:25 pm | Permalink

    Good article!!! I just tried this out and it works GREAT!!! I love the sms option as well.

    • Electronic Media Director Posted April 14, 2012 at 1:47 pm | Permalink

      Thanks Andrew! Glad to hear it works for you. At some time in the future I’m going to try adding some other features to it so stay tuned!

  6. Mike Kennedy Posted April 20, 2012 at 7:10 am | Permalink

    Hi, Mike,

    Many thanks, indeed, for these major mods to Amit’s script. I just found this site, and “copied” in the spreadsheet using the link you supplied above.

    I have a small, strange, problem: The two sheets copied in just fine, but there’s no sign of any scripts, or any triggers, etc… Under Tools, Scripts Manager/Editor, there’s… nothing!! I’m probably doing something very silly!!

    Thank you,
    – Mike

    • Electronic Media Director Posted April 20, 2012 at 8:45 am | Permalink

      Hello Mike and thanks for bringing this to my attention. I just attempted to copy this script myself by using a different account and within the same account and both failed to copy over the necessary scripts as well. I’ll try and find out what’s going on with this and get back with you.

      In the meantime, I’ll be updating this article with the necessary script code so that you can copy and paste it into your spreadsheet. That should do the trick to at least get you by until this is sorted out.

      • Mike Kennedy Posted April 20, 2012 at 11:21 am | Permalink

        Thanks, Mike. Let me know if I can help in any way (maybe by email). -Mike.

  7. John McLearran Posted May 10, 2012 at 9:26 am | Permalink

    I love the simplicity of your script. I am wondering how I get this to run. I have followed all the steps outlined above but am I missing something? Do I need to Publish as a Service or Run anything?

    When I do get it to work the response is “undefined”.

    Thanks!

    • Electronic Media Director Posted May 10, 2012 at 10:58 am | Permalink

      Glad you like the script John! There should be no need to publish anything. Usually if it throws an “undefined” error it means that a function or a variable is empty or, quite literally, undefined. However, everything in the script is defined as it should be, so here’s a couple of things to check to verify it’s setup correctly:

      1. Make sure the URL is correct in the spreadsheet. Use ‘http://’ before your domain and don’t encase the URL in any quotes or anything like that.
      2. If you’re using multiple email addresses as targets, make sure that they are separated by a comma and not a semi-colon or other character.
      3. Check to be sure that the Javascript code copied over correctly. Do this by opening up the doc, then clicking on “Tools” > “Script editor”. You should see code in this window. If not, the code DID NOT copy and you will need to copy it manually using the link in the editor note at the top of this post.
      4. Make sure that your event triggers are set correctly. Do this by going into the script editor, then click “Resources” > “Current script triggers…”. If this says “No triggers set up. Click here to add one now.” then this means that you have no scheduled events to record the data. To resolve that, click on “No triggers set up. Click here to add one now.” then from the first drop-down select the function “get_user_data”, set the “Events” drop-down to “Time-driven”, then select your time interval.
      5. Finally, if you’ve done all of this and verified that it is setup correctly, you should see NO activity until your site is offline for any reason. The script only records data and sends emails in the event that the site is offline.
      6. I hope this helps out!

  8. Ryan Paul Posted September 25, 2012 at 11:00 am | Permalink

    Hi there…

    I’ve noticed that if this script finds a 404 site on one line, it won’t send alerts for any 404 sites below that (until you remove the first down site). It just keeps sending an email error for the first one found.

    Any idea how to fix this?

    Regards,
    Ryan

  9. David Posted October 11, 2012 at 7:58 pm | Permalink

    Great article and script. The current version of the javascript either from google docs or your download is StalkMySite – v1.1a. What happened to 1.1b and 1.2? The extra functionality that is in 1.2 makes the script really worth while.
    Thanks for good work.

  10. Electronic Media Director Posted December 18, 2012 at 7:14 pm | Permalink

    Hey guys. Sorry I haven’t been around to do much on this script lately. I hope to be updating it very soon. Look for some big changes in 2013!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>