I do want a Kimsufi. But they’re in sold-out status since a month (about since someone made HackerNews notice they were renting dedicated servers for as low as 2,99€/month).
Well, that means that in order to get my own Kimsufi, I’ll have to smash competitors on time. That is, get to know when Kimsufis will be made available again before anyone else know and/or order one before anyone else.
This approach can be summarized into two steps.
Step one it’s easy, as I almost always have my laptop and cell phone with me (when I’m not home I’m in university).
Step two and three are somehow tricky, but I solved it.
Things I most frequently check are SMS on my cellphone, as many friends of mine tend to use SMS service and in I tend to check emails on my laptop and not on my cellphone.
So the best way to get notice is SMS, at least for me.
How do I send SMS from a computer? Several options are available:
Here are my considerations on the options:
Scripting Skype is easy using Skype4Py library.
How to continuously check OVH webpages? This is a typical watchdog problem.
Conceptually speaking, it simple:
Writing a quick&dirty solution that in Perl would be simple using WWW::Mechanize, but I wanted to monitor more that one page at the same time, notify to different people (a friend of mine wanted in Kimsufi too) and by the way I wanted to pratice object-oriented programming in Perl using Moose and experiment multi-threaded programming using Perl.
So, what did I do ?
First of all, I wrote a simple Python (using the aforementioned Skype4Py library) script to send SMS from the command line, called skype-sms-shooter. It takes only two parameters –body and –recipient, definitely self-explaining. Body must be shorter than 160 characters in length.
Then I proceeded in writing a watchdog program in Perl, maily made of two classes: Watchdog::Page and Watchdog::ThreadPool.
Watchdog::Page represent a page being monitored, stores its data and can invoke a function when action is triggered (change detected) and it can be specified by code (that is, you can tell to run your own code when change is detected) and pass parameters too.
My function was, of course, a piece of code that logs to console and runs skype-sms-shooter with appropriate parameters.
Full sources for this project are on my github page, in the ovh-watchdog repository.
Writing the code has been quite fun.
But here comes the really funny part: getting it to run 24/24h.
This isn’t a simple script that I can run in screen as I do typically.
Due to the skype instance running, we need some sort of X server running.
Does this mean I’ll have to run it on my laptop? No, that wouldn’t make that much sense as it would stop working when I suspend my laptop to ram (I rarely turn it off). Instead, this simply mean I have to run it on a computer which is 24/24h turned on. Like my Linode server or on dobby, my home server.
I’ve choosen to make it run on my Linode instance because the set-up process let me do some interesting things.
Of course, I won’t be running XOrg on my Linode. That requires a graphic card and a monitor, and I have none of them attached to my Linode.
Instead, I can use Xvfb, an headless X-compatible display server.
Ok, what’s the plan ?
Step one is easy, example from the Wikipedia page i’ve linked for Xvfb contain most of the things I needed. Additional information can be found in the Xvfb man page.
screen -S xvfb
This is how I set up a screen instance for Xvfb. I like using different instances of gnu screen for different topics. I have a “main” instance for irc client and mutt, and an “xvfb” instance for Xvfb.
Now, inside screen (you can attach to it using
screen -r xvfb)
Xvfb :1 -screen 0 1366x768x16 ## start xvfb &
x11vnc -display :1 -bg -nopw -listen localhost -xkb
I start an X server and let it go doing its things in the background.
Then I start fluxbox, which provides a basic and light yet comfortable desktop environment.
Then I start x11vnc, a simple vnc server so that I can control the graphic enviroment.
Now: you may have noticed that I used the -nopw arguments, that tells x11vnc anyone to log in and see/use what’s happening on my desktop.
This is NOT a safe choice at all, but works in case the firewall is configured not to allow connection on port 5900 (standard vnc port).
In my case I have a password for vnc, and my firewall is configured not to allow connection on port 5900. I use ssh tunnelling to reach my vnc server.
On our machine (at home) now I can type:
@santoro.tk -T -L 5900:localhost:5900
This creates an ssh tunnel, letting us reach localhost:5900 on my server.
Actually, on my server I run Xfce4, here is a screenshot:
In the image, skype is running in the Xvfb on my linode instance.
How to properly set up mechanize_ovh.pl ?
Simply open it into a text editor, reach the last part of the file, find part where pages are declared:
my $pag_k24g = Watchdog::Page->new(url => “http://www.ovh.it/server_dedicati/kimsufi_24g.xml”,title => “Kimsufi 24g”,change_detected => \¬ify_sms,change_detected_params => ["+39329xxxxxxx", "+39320xxxxxx"]) ;
in change_detected_params put your cell phone number, with international prefix.
I suggest you to try a custom page first, as Skype will ask for permission to let an application use its messaging service. Use a custom page, change it and let ovh_mechanize.pl recognize the change and allow programs to use Skype’s messaging capabilities.
You can now add al the pages you want.
Now I’m realizing I have to write a SETUP file for ovh-watchdog and a tl;dr section for this post.