HaProxy

One of the best open source tools I have stumbled upon in the last 3-4 years is HaProxy. It is an awesome and powerful TCP load balancer that competes with the likes of F5, Zeus, and many other top vendors. The author of this software couldn’t be more helpful and seems to be available via the mailing list for support and provides patches/features on a regular basis. I’ll post up some example configurations soon.

Nexus 7

I’ve been thinking about getting a tablet for sometime, but I have found that there are only a small handful of decent tablets out there. I’ve contemplated an Ipad and some 10″ Androids from the likes of Samsung or Asus, but couldn’t justify the 400 dollar expense for a mere toy or at best a slightly useful mobile device. Also these devices, albeit smaller than a laptop, are still quite large and I really questioned whether I would actually want to tote the large square with me everywhere. So I put this purchase on the back burner for quite a while knowing that I didn’t really *need* the device.

As some of us may already know Google and Asus teamed up to deliver the newest Nexus device. In fact it is a brand new category for Nexus devices – a tablet. There are two models available – 8GB for $199 US and 16GB for $249 US. They both feature:

Quad core Tegra 3 processor rated at 1.3GHZ
1GB DDR3 RAM
1280×720 IPS Screen
GPS / Bluetooth / NFC Radios
Jelly bean 4.1.x
Probably a bunch of other stuff I don’t care to look up.

Typically Nexus receives the newest Android updates from Google which is huge perk to owning these branded devices. I have mixed feeling about most mobile operating systems so I was curious to see what the latest and greatest version of Android offered its users.

After another quick scan of the local stores to compare various tablets I went ahead and pulled the trigger on the 8GB Nexus 7 to keep the costs low. I ordered it off of Google Play since no local stores carried it at the time. I received my device in a non-discreet brown box roughly 3 days from purchase. The outer box is a little smaller than I would have liked and I start imagining just how minuscule the tablet inside was. After getting to the goods I discovered a nice shiny tablet with silver trim.

Just as I suspected the tablet was a little on the small side from first glance, but I went ahead plugged it in and powered it up. After about 30 seconds of various Google logos the home screen popped up and I was in business. I flipped between home screens and noticed the fluid movement between each screen with no noticeable lag. The screen is very detailed and has great color saturation with excellent viewing angles. +1 Google.

I performed the various account setup tasks and started poking around a little more. One of the first things I noticed is the Google voice search widget and I tested various commands and search phrases. Surprisingly it was 100% accurate. In the past I usually get quite irritated with voice dictation software due to the constant errors and end up typing on the even more infuriating virtual keyboard. Logically I would test out the virtual keyboard next. I wasn’t quite as overwhelmed with the keyboard as the voice dictation, but it was still decent as far as virtual keyboards go. I didn’t like the fact that you have to switch between on-screen keyboards to access numbers and symbols, but other than that it was accurate and responded well to the touch. Another feature that I would like is a Swype like system built into the stock keyboard. Not sure if there are any licensing or legal concerns, but it would be a nice to have. I should point out that several apps in the Play store provide this functionality quite well and should be an easy fix for anyone seeking Swype functionality.

Video playbook looks great. No stuttering or choppy display. Everything is smooth and plays as well as my desktop. Battery life has been excellent so far. With extreme usage I can go about 9-10 hours before having to recharge the device. With low to moderate usage I can go 2-3 days before needing a charge. Very impressive.

The new Google Now functionality in Jelly Bean is somewhat creepy and useful at the same time. With your permission, Google uses recent search data, your location, calender events, and other data to present helpful information to you such as weather conditions, sports scores, nearby restaurants, and traffic conditions. It doesn’t always correctly predict what I want and sometimes displays information I don’t need, but overall the functionality is cool and should only get better in time.

After having the tablet for a few days I purchased a bluetooth keyboard and leather case off of Amazon. I ended up going with the HP Touchpad keyboard ($21.50) and a off-brand leather case (7.00). I am very happy with both purchases and got them for a steal. The keyboard paired up easily and has a nice high quality feel. The case is very thin, durable, and has a nice solid front. As a bonus it offers a magnet embedded into the front cover that allows the device to go into a power saving mode and gives even better battery life.

Overall, I am quite please with my purchase and feel it was well worth the $199 dollars. Along with several installed applications it will be a great mobile tool to use for entertainment, quick web searches, and performing light system administration tasks. The combination of awesome performance and great battery life make this tablet a real winner.

Perl DNS Update

I created a little perl script to do some DNS updates to my name servers. It uses the Net::dns module and is ¬†pretty simple. I use it along with some of my other automation tools. Here’s the quick and dirty code:

#!/usr/bin/perl -U

use strict;
use Net::DNS;

sub dns_update {
my %args = @_;
my $update = Net::DNS::Update->new($args{domain});

if ($args{operation} eq "add") {
$update->push(update => rr_add("$args{hostname}.$args{domain}. 7200 A $args{ip_address}"));
} elsif ($args{operation} eq "delete") {
$update->push(update => rr_del("$args{hostname}.$args{domain} A"));
}

my $res = Net::DNS::Resolver->new;
$res->nameservers("$args{name_server}");
my $reply = $res->send($update);

# Successful?
if ($reply) {
my $rcode = $reply->header->rcode;
print 'Update ', $rcode eq 'NOERROR' ? "succeededn" : "failed: $rcoden";
} else {
print 'Update failed: ', $res->errorstring, "n";
}
}

There are two operations: add and delete. To call the code you would use the following:

dns_update(operation => “add”, hostname => “test”, domain => “example.com”, ip_address => “1.2.3.4″, name_server => “4.3.2.1″);

F5 Throttle Irule

Sometimes we need to protect our web servers from expected extra high loads. I threw together an irule to perform this task quickly and intelligently. So simply the irule will only allow so many sessions per a time window, and if the amount is exceeded it will display a 503 error page. One of the requirements is once a user accesses the back end site we no longer wish to throttle the user so we will issue a cookie that will bypass the throttle code. So on to the code:

when RULE_INIT {
set static::maxUsers 10
set static::windowSecs 20
set static::timeout 60
set static::table "throttle"
set static::cookiename "throttle"
}

when HTTP_REQUEST {
set cookie 0
set count 0

set currentTime [clock seconds]
set windowStart [expr {$currentTime - $static::windowSecs}]
 foreach { requestTime } [table keys -subtable $static::table] {
 if { $requestTime > $windowStart } {
 incr count 1
 } else {
 table delete -subtable $static::table $requestTime
 }
 }

if { [HTTP::cookie value $static::cookiename] ne "false" } {
 if { $count < $static::maxUsers } {
 table set -subtable $static::table $currentTime "ignored" $static::timeout
 set cookie 1
 } else {
 HTTP::respond 503 content "Sorry, but our servers are too busy. Please try again soon."
 return
 }
}
}

when HTTP_RESPONSE {
if { $cookie >= 1 } {
HTTP::cookie insert name $static::cookiename value "false" path "/"
}
}

Now just apply the irule to your VIP, adjust the maxUsers, the windowSecs variables and you should be good to go.

Cobbler XMLRPC API and Perl

I wanted to share some perl code I’ve been working on. I’m currently building some automation tools in perl and wanted to create some modules to perform various cobbler tasks. I’ve had to pick through the little amount of resources on the web along with inspecting some python tools to put this together. Its definitely not complete, but should get you on the right track. Now for the code:

#!/usr/bin/perl -U
use strict;
use warnings;
use XMLRPC::Lite;

sub cobbler {
# Argument List: cobbler_api, username, password, operation, name, profile, mac_address, ip_address, hostname
my %args = @_;
my $xmlrpc = XMLRPC::Lite -> proxy($args{cobbler_api});
my $token = $xmlrpc->login($args{username}, $args{password})->result();
my $return;
my @return;

my $object = $xmlrpc->new_system($token)->result();

if ($args{operation} eq "add") {
 $xmlrpc->modify_system($object, "name", $args{name}, $token)->result();
 $xmlrpc->modify_system($object, "profile", $args{profile}, $token)->result();
 $xmlrpc->modify_system($object, "hostname", $args{hostname}, $token)->result();
 $xmlrpc->modify_system($object, "gateway", $args{gateway}, $token)->result();
 my %network = ( 'macaddress-eth0'=>$args{mac_address}, 'subnet-eth0'=>$args{subnet}, 'static-eth0'=>'True', 'ipaddress-eth0' => $args{ip_address});
 $xmlrpc->modify_system($object, "modify_interface", %network, $token)->result();
 $xmlrpc->modify_system($object, "ks_meta", $args{ks_meta}, $token)->result();
 my $result = $xmlrpc->save_system($object, $token)->result();
} elsif ($args{operation} eq "delete") {
 $xmlrpc->remove_item("system", $args{name}, $token, "recursive")->result();
 my $result = $xmlrpc->save_system($object, $token)->result();
} elsif ($args{operation} eq "get_profiles") {
 my $list = $xmlrpc->get_profiles();
 my $params = $list->valueof('//params/param');
foreach my $value(@$params) {
 my $return = $value->{'name'};
 push (@return, $return);
 }
 return(@return);
} elsif ($args{operation} eq "get_distros") {
 my $list = $xmlrpc->get_distros();
 my $params = $list->valueof('//params/param');
 foreach my $value(@$params) {
 my $return = $value->{'name'};
 push (@return, $return);
 };
 return(@return);
};
}

You’ll see above that there are a few operations: add, delete, get_profiles, and get_distros. The options for add are somewhat limited currently. There is only 1 nic (eth0) configured. If you need to add additional nics you can add additional hashes into the %network array. (i.e. macaddress-eth1, ipaddress-eth1, etc).

get_profiles and get_distros both just return an array with the names of the profiles or distros.

Now to call the code:


cobbler(cobbler_api => 'http://127.0.0.1/cobbler_api', username => 'username', password => 'password', operation => 'get_profiles');

That’s about it for now. Hope this helps and feel free to post comments if you have any questions.