Last active
November 19, 2024 07:20
-
-
Save fu-sen/8591687 to your computer and use it in GitHub Desktop.
Google ドキュメント(表計算)を用いたサーバ情報の表示 | Use of Google Documents (spread sheet), server check
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 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