Skip to content

Instantly share code, notes, and snippets.

@twotix
Forked from yaph/sitemonitor.js
Created April 29, 2013 19:11
Show Gist options
  • Save twotix/5483941 to your computer and use it in GitHub Desktop.
Save twotix/5483941 to your computer and use it in GitHub Desktop.
function checkURLs() {
var errors = [];
var ss = SpreadsheetApp.getActiveSpreadsheet();
var rows = ss.getDataRange().getValues();
for (i in rows) {
var url = rows[i][0];
try {
UrlFetchApp.fetch(url);
} catch (e) {
// This error message parsing is gross, but it looks like
// http://productforums.google.com/forum/#!topic/apps-script/m_HOPHx64X8
// won't be fixed any time soon.
var parsedError = e.message.match(/returned code (\d+)\. Server response/)[1];
errors.push(parsedError + ' - '+ url);
}
}
if (errors.length) {
var emailTo = Session.getActiveUser().getEmail();
MailApp.sendEmail(emailTo, 'Sitemonitor Status', errors.join('\n'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment