Skip to content

Instantly share code, notes, and snippets.

@yaph
Last active December 31, 2017 03:07
Show Gist options
  • Save yaph/3724237 to your computer and use it in GitHub Desktop.
Save yaph/3724237 to your computer and use it in GitHub Desktop.
Google Apps Script Site Monitor
function checkURLs() {
var errors = [];
var ss = SpreadsheetApp.getActiveSpreadsheet();
var rows = ss.getDataRange().getValues();
for (i in rows) {
var url = rows[i][0];
var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
var status = response.getResponseCode();
if (status !== 200)
errors.push(status + ' - '+ 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