Forum Discussion
Sean_29304
Mar 23, 2012Nimbostratus
Geolocation data auto-update
Hello, Is there a way to automate Geolocation data updates? Thank you, Sean
David_Burley_20
Nimbostratus
I wrote this last night, and it works for us -- feel free to use it -- though I recommend you test it in your environment first.
!/usr/bin/perl -w
Download the latest GeoIP files for F5 LTM and install them. This script runs
from a supporting host.
Requires:
* perl (WWW::Mechanize and its dependencies)
* A ssh suite with passwordless authentication via key to the load balancers
* unzip
* md5sum
This script will be fragile, since it relies upon minimal changes to the F5
website. It should be reasonably safe, given it checks the md5sum of the
downloaded file, but use at your own risk.
Configure the $user and $pass variables for your login to the F5 site.
Configure the @servers list for the servers to SSH to and update the DBs on
use WWW::Mechanize;
Configuration section - Update these
my $user = 'F5_LOGIN_USERNAME';
my $pass = 'F5_PASSWORD';
my $uri = 'https://downloads.f5.com/esd/ecc.sv?sw=BIG-IP&pro=big-ip_v11.x&ver=11.6.0&container=GeoLocationUpdates';
my @servers = qw(SERVER1 SERVER2);
my $dir = '/tmp/f5geoip';
End configuration - changes shouldn't be necessary below unless the F5 site changes.
die "\$dir needs set to something that doesn't exist\n" if($dir eq '' || $dir eq '/' || -e $dir); Sanity check....
mkdir($dir);
Login to F5, download the GeoIP update and md5sum
my $mech = WWW::Mechanize->new( cookie_jar => {} );
$mech->get($uri);
$mech->submit_form(
form_name => 'login',
fields => {
userid => $user,
passwd => $pass
}
);
$mech->submit_form(
form_name => 'LicenseAgreement'
);
$mech->follow_link(url_regex => qr/\.zip$/);
$mech->follow_link(url_regex => qr/\.zip/);
$mech->save_content("$dir/f5geoip.zip");
$mech->get($uri);
$mech->follow_link(url_regex => qr/\.zip\.md5$/);
$mech->follow_link(url_regex => qr/\.zip\.md5/);
$mech->save_content("$dir/f5geoip.zip.md5");
Validate the file contents against md5sum and extract
my $sum = `cat $dir/f5geoip.zip.md5 | cut -d ' ' -f 1`;
my $filesum = `md5sum $dir/f5geoip.zip | cut -d ' ' -f 1`;
chomp $sum;
chomp $filesum;
die "Invalid checksum on GeoIP Database\n" if ($sum ne $filesum);
my $ret = system("unzip $dir/f5geoip.zip -d $dir >/dev/null") >> 8;
die "zip didn't properly extract\n" if($ret != 0);
Generate a list of the RPMs
my @files = split("\n", `ls -1 $dir | grep rpm`);
Copy the files to the LB via SCP and then run the updater
foreach my $server (@servers) {
foreach my $file (@files) {
system("scp $dir/$file $server:/shared/tmp > /dev/null");
system("ssh $server 'geoip_update_data -f /shared/tmp/$file; rm -f /shared/tmp/$file'");
}
}
Cleanup
system("rm -f $dir/*; rmdir $dir");
johnnypizzy
Dec 21, 2015Nimbostratus
Thanks for the script David. Works great!
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects