Created
January 16, 2014 02:49
-
-
Save matsubo/8449027 to your computer and use it in GitHub Desktop.
Inspired by https://gist.github.com/mzdakr/8416983
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
var urls = [ | |
'http://www.example.com/', | |
'http://www.yahoo.com/', | |
]; | |
var to = '[email protected]'; | |
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