Created
January 3, 2018 09:03
-
-
Save rikumi/01daa31825834ca9ddcec670b34df191 to your computer and use it in GitHub Desktop.
Slacklet for Monitoring Herald API
This file contains 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
monitoring = true | |
main = -> | |
send '监控程序已上线' | |
loop | |
if not monitoring | |
send '监控程序已退出' | |
break | |
downCount = 0 | |
res = await (axios.get 'https://www.heraldstudio.com/api/').catch (e) -> | |
res = data: e.message | |
unless (parseInt res?.statusCode) is 404 | |
downCount += 1 | |
test = (count) -> | |
return false if count == 1 | |
while count % 10 == 0 | |
count /= 10 | |
return count in [1, 2, 5] | |
if test downCount | |
send "(发生#{ downCount }次) 到 Herald API 的定期请求不符合预期:" + | |
res?.statusCode + ' ' + JSON.stringify res?.data ? '' | |
else | |
if downCount > 1 | |
send 'Herald API 的定期请求已恢复正常。' | |
downCount = 0 | |
await sleep 10000 | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment