Skip to content

Instantly share code, notes, and snippets.

@rikumi
Created January 3, 2018 09:03
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 rikumi/01daa31825834ca9ddcec670b34df191 to your computer and use it in GitHub Desktop.
Save rikumi/01daa31825834ca9ddcec670b34df191 to your computer and use it in GitHub Desktop.
Slacklet for Monitoring Herald API
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