Subscribe:

Pages

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Thursday, September 20, 2012

Get a SMS When your Website is Down | Monitor Website With Google Docs

always use Google Docs for saving sharing my data. But now with Google Docs you can monitor your website’s up-time and down-time. The latest version of this Google Docs based website monitoring tool is even better:
  • Support multiple websites and blogs
  • It not only support E-mail but also SMS Alert

 How To Do:

  1. Click here and get a sheet.
  2. Now go to file and make copy of it.
  3. You’ll see a new Website Monitor menu in the toolbar. Click Initialize and you’ll get a pop-up asking for authorization. Just say Yes.
  4. Put your Website URL and email address
  5. You can put multiple URLs by adding comma.
  6. Go to the Website Monitor menu again and choose “Start Monitoring”.
Note: If you do not wish to receive SMS alerts, simply change the value of cell B4 from Yes to No.

Full Source Code:
function init() {  
  if (ScriptApp.getScriptTriggers().length == 0) {
    // Set up a monitor that triggers every 5 minutes
    ScriptApp.newTrigger("websiteMonitor")
      .timeBased().everyMinutes(5).create();
  }  
}
function websiteMonitor()
{
  var response, error, code, urls;
  // The script can monitor multiple website URLs (comma separated)
  urls = SpreadsheetApp.getActiveSheet().getRange("B2").getValue();
  urls = urls.replace(/\s/g, "").split(",");
  
  for (var i=0; ii++) {
    
    var url = urls[i];
      
    if (!ScriptProperties.getProperty(url)) {
        ScriptProperties.setProperty(url, 200);
    }
    
    // Trying to connect to the website URL
    try {    
      response = UrlFetchApp.fetch(url);
    } catch(error) {
      // If URLFetchApp fails, the site is probably down
      updateLog(url, -1);
      continue;
    }
    
    code = response.getResponseCode();
    updateLog(url, code);
    
  }
}
function updateLog(url, code) {  
  
  if (ScriptProperties.getProperty(url) == code)
    return;
  
  ScriptProperties.setProperty(url, code);
  
  var sheet = SpreadsheetApp.getActiveSheet();
  
  var row   = sheet.getLastRow() + 1;    
  var time  = new Date();  
  var msg = "Down";
  
  if (code == 200)
    msg = "Up";
  
  msg = "Website is " + msg + "  " + url;
  
  sheet.getRange(row,1).setValue(time);
  sheet.getRange(row,2).setValue(msg);
  
  // Send an email notification when the site status changes
  var email = sheet.getRange("B3").getValue();  
  MailApp.sendEmail(email, msg, url);
  
  var now   = new Date(time.getTime() + 10000);
  // Create an event in Google Calendar with an SMS reminder
  if (sheet.getRange("B4").getValue().toLowerCase() == "yes")
    CalendarApp.createEvent(msg, now, now).addSmsReminder(0);
}

No comments:

Post a Comment

Revolver map

Rank

Linked

 
ExactSeek.com