Sunday, January 15, 2012

Sending Prowl Notifications from Linux

More than a year ago, I set up my lovely Chumby alarm clock as a web server (go check it out!), which I find useful every now and again for quickly hosting small files.  Unfortunately, even after upgrading it to an 8GB internal SD card, between all the files I dump on it and my poor log rotation schedule on it, it sometimes manages to run out of file system space and gets kind of cranky.

I recently purchased a copy of Prowl, which is a growl notification app for iOS.  Growl is a universal notification system which I'm planning on building into some embedded hardware projects I'm working on, but I figured that while I had already bought the application, I would see how many other nails I can pound in with this hammer.  Turns out, this was a fairly simple application of said hammer to problem.
I wrote a simple shell script and installed it on my Chumby such that every morning at 8:30AM I wake up to a message on my iPod informing me on how my Chumby is doing.  This is done by generating the report via several lines of Bash, storing it in a temporary file, and then passing it along with my Prowl API key to one magic curl command, which you can see at the end of my code:

Shell code:


To get this working, you'll need to copy this shell script onto your Chumby, and then add a line to your Chumby's crontab to schedule it to run at the desired time.  You'll also need to replace my API key with one of your own.

Now, obviously since this is just using cURL to post the notifications, you can run this script in any environment which supports curl, be it almost any Linux environment, OSX, or pretty much anything else.

I found a forum thread on cocoaforge useful while putting this together.

This can also be done using wget instead of curl, if you prefer.  Note that the version of wget on the Chumby doesn't support SSL, so you'll need to drop back to http instead of the suggested https:
$ wget --post-data 'apikey=2541[snip]4d77&application=wget&event=Test message&description=I can use wget' -O - https://api.prowlapp.com/publicapi/add

5 comments:

  1. That's so nice and tempting!
    Gift my the prowl, please, I'll pay back compensation for it via paypal :-)

    ReplyDelete
  2. Okay, I've bought a gift card for the US iTunes AppStore and purchased the Prowl. Now, it turns out my old good dd-wrt uses a simplified version of wget: wget: unrecognized option `--post-data'
    DD-WRT VeryBusyBox v1.2.2 (2008.05.02-11:41+0000) multi-call binary

    Usage: wget [-c|--continue] [-q|--quiet] [-O|--output-document file]
    [--header 'header: value'] [-Y|--proxy on/off] [-P DIR] url

    That's a pity!

    ReplyDelete
  3. Yes. I'm currently working on getting my Tomato WRT54G(L)s to send prowl notifications. It's definitely possible; it's just that the wget in WRT systems is busybox-based, which is a very simplified, brain-dead, set of user space utilities (An easy way to tell is cd /usr/bin; ls -l and notice that everything is symlinks to busybox).

    Watch for another blog post if I figure out a solution better than having it remotely run the wget or curl command on another Linux box through ssh. I.e. this does in fact work in Tomato, but requires another Linux box (so I'm currently having my WRT54G post through my Chumby by running the command there):

    root@WRT54G # ssh username@otherhostrunningunix "wget blahblahblah"

    The Busybox SSH doesn't seem to support RSA login credentials, so this isn't even a good solution.

    ReplyDelete
  4. it smells like perversion ;-) I don't if this method is any better:
    http://wiki.birth-online.de/software/sh/http-post

    ReplyDelete
  5. Yeah, that seems pretty awful, and I couldn't get it to work. But, I did figure out how to encode the POST request into the URL itself and trick wget into handling it: http://kennethfinnegan.blogspot.com/2012/01/posting-prowl-messages-from-busybox.html

    ReplyDelete