Whois for Stackstorm

I’ve been playing around with stackstorm for a little while now, and wanted to get back into it after a bit of distraction on other things. The idea of automating a lot of my daily repetetive tasks really appeals to me, so I started work on another module today.

The end result of today’s head-desking was st2-whois, a pack that does basic whois calls and saves me from having to find the website that works just right for it, or open a shell from a box with the right access.

It took about ten minutes to get the initial prototype working…

stackstorm prototype

… and then another eight hours or so of messing around before I could get a “proper” version working.

stackstorm "finished"

I know right, so different! So magic! Sarcasm aside, there was some serious swearing going on from my side, and it wasn’t until someone pointed out a key detail that I was able to solve it. Somehow, either stackstorm or jinja2 (I’m nearly certain it’s stackstorm) is incapable of dealing with certain variable types when parsing the responses. I knew I was handing back a dict, but it was being displayed as a string in the debug output. I thought it was just how it was shown in the output, not realising the conversion was going on.

stackstorm output

To make the requests I am using the rather handy python-whois package. What it (rather helpfully) does is convert the response data to a big dict full of unicode and converts dates to datetime.datetime objects where it can. Where multiple results for a field come back, it’ll also convert them to lists! You can see where this is going - stackstorm in the current version is running python 2.7 and the parser just doesn’t want to deal with anything but old-style strings or integers.

Once I’d figured out that the parser was having a fit, it didn’t take long to fix the issue - until I realised there were lists full of dates and unicode, which I also had to deal with. Thankfully, relatively easy to fix too. I’m sure there’s a better way of dealing with this, but given the fact this is dealing with small amounts of information infrequently, it should be fine. :)

Previously I wrote st2-pastebin which works with the Pastebin.com API to pull data from their stream. It’s pretty handy, and I’ve got a few things to use that for in the near future too.

On to more automation!



#automation #chatops #stackstorm #programming