Skip to content

Instantly share code, notes, and snippets.

@matsubo
Created January 16, 2014 02:49
Show Gist options
  • Save matsubo/8449027 to your computer and use it in GitHub Desktop.
Save matsubo/8449027 to your computer and use it in GitHub Desktop.
var urls = [
'http://www.example.com/',
'http://www.yahoo.com/',
];
var to = 'foo@example.com';
var sub = 'HTTP check failure';
var body = "The server seems to be down. Please check the server status.\n" ;
function myFunction()
{
for (var i in urls) {
if(check_server(urls[i]) == 200){
continue;
}
MailApp.sendEmail(to, urls[i] + ':' + sub, body + urls[i]);
}
}
function check_server(url)
{
try{
var res = UrlFetchApp.fetch(url);
return res.getResponseCode();
} catch(e){
return 999;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment