Skip to content

Instantly share code, notes, and snippets.

@fu-sen
Last active January 4, 2016 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fu-sen/8591687 to your computer and use it in GitHub Desktop.
Save fu-sen/8591687 to your computer and use it in GitHub Desktop.
Google ドキュメント(表計算)を用いたサーバ情報の表示 | Use of Google Documents (spread sheet), server check | sample: https://docs.google.com/spreadsheet/ccc?key=0AsYX2dpcGiPkdHhGSXRleEhPcUQ4dDRUYlRQTkZhdkE&usp=sharing
function urlcheck() {
var servers = {
"openlab.jp": "openlab",
"www.ring.gr.jp": "Ring Server"
};
var sheet = SpreadsheetApp.getActiveSheet();
var y = 0;
for ( var url in servers ) {
var servername = servers[url];
var returncode = check_server(url);
y ++;
if (returncode == 200) {
var status = "正常";
var color = "#008000";
} else if (returncode == 0) {
var status = "接続不可";
var color = "#ff0000";
} else {
var status = "異常 " + returncode;
var color = "#ff0000";
}
sheet.getRange(y, 1).setValue(servername).setFontColor(color);
sheet.getRange(y, 2).setValue(status).setFontColor(color);
}
y ++;
var now = new Date();
sheet.getRange(y, 1).setValue(now);
sheet.getRange(y, 2).setValue("現在");
}
function check_server(url)
{
try {
var res = UrlFetchApp.fetch(url);
return res.getResponseCode();
} catch(e) {
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment