Anthony Chung
Anthony Chung

Reputation: 1477

Slackbot making HTTP requests

I could be overthinking this, but I just wanted a sanity check:

I'd like my slackbot to ping my server every minute

On receiving a 404, it will stop pinging the server and message me to inform me that the server is down.

Would I just...have a setTimeOut func that makes a request and handle errors/success from there?

Or am I missing something...?

Thanks!

Upvotes: 2

Views: 1162

Answers (3)

Raghvendra Singh
Raghvendra Singh

Reputation: 31

You can also use Google Stack Driver (not sure if it's free). It pings your server in a given time interval from various location around the globe. You can integrate it with your slack work space too, and stack driver will post a message just like your custom slack bot whenever it doesn't receive 200 OK from your server. Hope this help!

Upvotes: 0

Erik Kalkoken
Erik Kalkoken

Reputation: 32737

Instead of using a custom script to ping and message you could also use a uptime service to monitor your bot. There are many to choose from, some are even free for small scale use like uptimerobot.com. I use it for all of my Slack bots and apps and it works pretty well.

Upvotes: 0

xShirase
xShirase

Reputation: 12399

Yes, this is called a healthcheck.

Typically what you want is to add a route to your server, say /healthcheck which just returns a 200 status and empty page. No need to overload your server by requesting a full set of assets every minute for no reason.

Then as you said, something like :

setInterval(()=>{
   checkStatus();
},60000);

function checkStatus(){
    request.get(options,(err,res,body)=>{
         if(res.statusCode!==200){
              //handle statuscode error
         }
    });
}

Upvotes: 2

Related Questions