Workers are great, one thing you can do is check if a website is online using a ping test and if it is not online send a email to your account with only a few lines. Just replace where you see APIKEY in the url with your API key you can find under your account settings.

As you can see we return the ping results to the page so it will show under the worker history, but we also if the ping failed (can't reach host) send a notification via the panel email system.

v.ping=s.ping("www.nodehost.ca")
if v.ping >= 500
s.echo("Yikes, the ping test to the server took v.ping MS.")
else
s.echo("Hey the server had a ping of v.ping MS. That is great!")
end

if v.ping false
v.title=s.string_url_encode("Website down")
v.message=s.string_url_encode("We are unable to reach your website, the ping test returned v.ping MS. Might want to take a look.")
v.alert=s.http_request_get("https://api.nodehost.cloud/post_account_email_create?api_key=APIKEY&subject=v.title&message=v.message&type=alert")
v.response=s.json_decode_reverse(v.alert)
if notset v.response[data][error]
s.echo("Alert sent via email")
else
s.echo("Was not able to send alert")
end
end
Was this article helpful?
Cancel
Thank you!