We’ll be back soon!
Sorry for the inconvenience but we’re performing some maintenance at the moment. We’ll be back online shortly!
— Instapush Team
Sorry for the inconvenience but we’re performing some maintenance at the moment. We’ll be back online shortly!
— Instapush Team
Tweet |
Instapush allows you to receive notifications on your smartphone for your critical transactions within your app or service.
In this example we will use nodejs module http-monitor along with Instapush to monitor a specific URL/server and get notified immediatly if it's down and another notification when it has recovered under few minutes. This comes pretty handy for system adminstrators and enterpreneurs on the go.
Assuming you are ready lets start.
Navigate to your dashboard and click add app button
Instapush is event based so we need to create 2 events to fire notifications to your smartphone: one on server down and one when it has recovered.
Now the fun part we will use your terminal and code editor. Before we create our index.js file We will need to install 2 npm modules http-monitor and instapush
$ npm install instapush http-monitor
Now lets create our index.js file. First we set some variables and require modules
var monitor = require('http-monitor'), instapush = require('instapush'), last_downtime;
We create the notification function with instapush. instapush.notify accepts an object with two items "event" and "trackers". Event is the event name (recovery or error) and the only "tracker"/parameter we have is the last_downtime
var notify = function(event, last_downtime){ instapush.notify({"event":event,"trackers":{"last_downtime":last_downtime}},function(err,response){ console.log(response); }) }
Then we set settings for Instapush by adding our appID and secret
instapush.settings({ id:'5321ac79a4c48axxxxxxxx', secret:'c7e2ee2645b4aecxxxxxxxx', });
monitor the server and generate a notification on error
monitor('mywebsite.com').on('error',function(){ last_downtime = new Date(); notify("error", last_downtime); })
Finally generate a notification on recovery
.on('recovery',function(){ notify("recovery", last_downtime); });
Full code of index.js:
var monitor = require('http-monitor'), instapush = require('instapush'), last_downtime; var notify = function(event, last_downtime){ instapush.notify({"event":event,"trackers":{"last_downtime":last_downtime}},function(err,response){ console.log(response); }) } instapush.settings({ id: 'xxx', secret: 'xxx' }); monitor('myurlsadsadasdasdas.com').on('error',function(){ last_downtime = new Date(); notify("error", last_downtime); }).on('recovery',function(){ notify("recovery", last_downtime); });
That's it! deploy your node app to a separate server (heroku, Appfog or nodijust) and enjoy instant notifications if something goes wrong on your app server.
$ node index.js
Instapush is a product by PushBots, © 2013.