Skip to content

Instantly share code, notes, and snippets.

@guilhermelimak
Created October 31, 2016 13:53
Show Gist options
  • Save guilhermelimak/0c798522b39b303862b7fe76bcd7ae53 to your computer and use it in GitHub Desktop.
Save guilhermelimak/0c798522b39b303862b7fe76bcd7ae53 to your computer and use it in GitHub Desktop.
unirest = require 'unirest'
URLS = [
'URLS_TO_CHECK_LIST'
]
ACCESS_TOKEN = '[PUSHBULLET_API_KEY]'
isError = (statusCode) ->
if statusCode >= 200 and statusCode <= 399 then return true else return false
sendPush = (title, message) ->
unirest
.post 'https://api.pushbullet.com/v2/pushes'
.headers { 'Access-token': ACCESS_TOKEN }
.send { type: 'note', title, body: message }
.end (res) ->
console.log res.statusCode
checkHealth = (url) ->
unirest
.get url
.end (res) ->
if isError res.statusCode
console.log "Everything is fine with #{url}"
else
console.log "Some error ocurred with #{url}", "Server returned: #{res.statusCode}"
sendPush "Some error ocurred with #{url}", "Server returned: #{res.statusCode}"
checkUrls = () ->
for url in URLS
checkHealth(url)
checkUrls()
setInterval checkUrls, 600000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment