function sitesCheck(){
var urls = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("site").getRange("A:A").getValues();
for(var i=0; i < urls.length; i++) {
var url = urls[i][0];
if(0 < url.length) {
var res = UrlFetchApp.fetch(url);
Logger.log(res.getResponseCode());
Logger.log(res.getHeaders());
var code = res.getResponseCode();
if(code !== 200) {
var channel = "#company";
pushSlack("<!everyone> 落ちてると思うので確認してください。 code:" + code + " " + url,"サイトチェックくん",channel);
}
}
}
}
function pushSlack(msg,username,channel){
var options = {"method":"POST"};
var payload = {};
payload.text = msg;
payload.username = username;
payload.channel = channel;
options.payload = JSON.stringify(payload);
Logger.log(payload);
var slackUrl = "https://hooks.slack.com/services/" + "keyなど";
UrlFetchApp.fetch(slackUrl, options);
}
More than 5 years have passed since last update.
GASで既存のサイトの表示確認し、200以外のコードが返ってきたらslackに通知する
Last updated at Posted at 2018-01-19
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme