Developers these days have to do everything. We used to just develop, now some of us (me) design have become designers and we operate our own servers.
That’s all good. And with automation it becomes remarkably do-able too. If we do it well, we can actually enjoy our lives and let the robots do all the work in the background.
But robots make mistakes. Or well, our code usually makes mistakes. How do we figure out when things go wrong? Let the robots tell us.
Pushover
Pushover lets you send push messages from inside your apps, shell or scripts to your iPhone, Android or any web device. Simply with one HTTP POST request. This means opening this URL:
…with this POST data:
token=wMpQqm7iYCKGvhoTu4YjaPKDn21ZfE
message=Hello World
Becomes a push message on ALL my devices saying “Hello World”.
What do I use it for
Every day Nomad List gets data from lots of sources, including APIs but also regular websites it scrapes. This goes fine, but when it detects it doesn’t understand the data it gets, I’ve programmed it to message me through Pushover.
In shell scripts I do this:
curl -s –form-string “token=aS8whNNHSXS4niSJ” –form-string “user=udjCGMmQ5qCzW” –form-string “message=Something went totally wrong with getting the weather data, please check LOL” https://api.pushover.net/1/messages.json
In PHP, I run a shell_exec (I know not so safe, watch out and don’t put user data in this for obvious reasons, they’ll hack your shell):
shell_exec(‘curl -s –form-string “token=aS8whNNHSXS4niSJ” –form-string “user=udjCGMmQ5qCzW” –form-string “message=Something went totally wrong with getting the weather data, please check LOL” https://api.pushover.net/1/messages.json’);
You can even monitor server error logs. I do it through PHP but you can probably script something yourself:
$result=shell_exec(‘tail /var/log/nginx/error.log’);
$hash=file_get_contents(DIR.’/tailLogToPushover.md5′);
// don’t update, if log hasn’t changed since last push
if($hash==md5($result)) exit;
$lines=explode(“\n”,$result);
foreach($lines as $line) {
shell_exec(‘curl -s –form-string “token=aS8whNNHSXS4niSJ” –form-string “user=udjCGMmQ5qCzW” –form-string “message=’. escapeshellarg($line).'” https://api.pushover.net/1/messages.json’);
echo $line;
echo “\n”;
}
This tails the last few log entries. Then uses a hash to check if they haven’t been sent before to Pushover. Then it sends them to your phone. That means you get server errors on your phone (in this case from NGINX).
Watch out: this is slightly risky as you put the error in a shell command. Hopefully escapeshellarg cleans it up (I think it does).
Zapier
Now to go next level, you can also push notices from other services using API-connector tool Zapier:
I’ve connected my PayPal and Stripe to tell me when I get new transactions. These push notices work BETTER than PayPal and Stripe’s own actually, that sometimes somehow don’t even show up.
I’ve also connected MailChimp to Pushover. That means I can see when scheduled campaigns are sent out.
To give you an idea of what my phone looks like every day:
Conclusion
I know there’s WAY more advanced ways of logging errors etc. But this simple approach works for me. I can fill my scripts with notices any time anything goes wrong.
Where before I felt kinda blind knowing my robot scripts would be working and had to constantly check if they actually did things properly. Now I know they do! And I can sleep relaxed.
This is all fund and games until your robot takes over though.
Eeeeekkkkkkkkk!
P.S. I'm on Twitter too if you'd like to follow more of my stories. And I wrote a book called MAKE about building startups without funding. See a list of my stories or contact me. To get an alert when I write a new blog post, you can subscribe below: