Last active
December 31, 2017 03:07
-
-
Save yaph/3724237 to your computer and use it in GitHub Desktop.
Google Apps Script Site Monitor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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