Monitor VMware vSphere from FreeBSD using the Perl SDK

VMware provides a CLI and a Perl SDK that allows managing and monitoring vSphere and ESXi environment from Windows and Linux. The Perl SDK is also available in the FreeBSD ports tree.

Here’s how to install and, basically, use the VMware Perl SDK on FreeBSD.

I’m using FreeBSD 8.3 but I guess what really matters in the ports tree. Use portsnap to get and/or update your ports tree. There is no binary package available as it is required to get the stuff from VMware’s website, creating an account and accepting the license.

Here’s what FreeBSD will tell you:

===> License check disabled, port has not defined LICENSE Due to licensing restrictions, certain files must be fetched manually. Please visit http://communities.vmware.com/community/vmtn/developer/forums/vsphere_sdk_perl and choose Download. Then, login using a VMware account and accept the license agreement. Choose the download for vSphere SDK for Perl - 32-bit Linux Installer (even if you are not on i386) After the download has completed, please place VMware-vSphere-Perl-SDK-5.0.0-422456.i386.tar.gz in /usr/ports/distfiles, then restart the build.

Download the archive, copy it where it shall be stored and run the installer:

# mkdir /usr/ports/distfiles # mv VMware/VMware-vSphere-Perl-SDK-5.0.0-422456.i386.tar.gz /usr/ports/distfiles/ # cd /usr/ports/net/vmware-vsphere-cli # make install clean ===> License check disabled, port has not defined LICENSE ===> Extracting for vmware-vsphere-cli-5.0.0 => SHA256 Checksum OK for VMware-vSphere-Perl-SDK-5.0.0-422456.i386.tar.gz. ===> vmware-vsphere-cli-5.0.0 depends on file: /usr/local/bin/perl5.12.4 - found (...) install -o root -g wheel -m 555 /usr/ports/net/vmware-vsphere-cli/work/VMware-vSphere-Perl-SDK-5.0.0-422456.i386/bin/viperl-support /usr/local/bin ======================================================================== Please note that, by default, an underlying Perl module does certificate verification when communicating with vSphere hosts. You must create a file that contains the public keys of all of your vSphere hosts and then configure your Perl scripts to have the following line: $ENV{HTTPS_CA_FILE} = "/path/to/file"; If you want to disable this important security feature, you may set the following variable to 0: $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} ======================================================================== ===> Compressing manual pages for vmware-vsphere-cli-5.0.0 ===> Registering installation for vmware-vsphere-cli-5.0.0

During the building process, I did “Enable national language support” for e2fsprogs-libuuid and “Enable https support” for p5-libwww.

Now, it’s time to test the API:

# /usr/local/share/examples/vmware-vsphere-cli/host/hostinfo.pl --server esxi --username 'admin' --password 'pass' Host Information Host Name: esxi.tumfatig.net Port Number: 902 BootTime: 2012-05-05T10:08:01.907061Z Cpu Model: Genuine Intel(R) CPU 0 @ 2.30GHz Cpu Speed: 9179149192 Cpu Usage: 281 File System: vmfs nfs vfat Host Status: The status is unknown Maintenance mode: 0 Physical Memory: 17087459328 bytes Memory Usage: 13068MB Network Adapters: 2 Reboot Required: 0 Software on host: VMware ESXi 5.0.0 build-623860 VMotion: 0

If you get errors like “Server version unavailable at 'https://esxi:443/sdk/vimService.wsdl' at /usr/local/lib/perl5/site_perl/5.12.4/VMware/VICommon.pm line 545“, this is because LWP is not accepting the self-signed certificate from the ESXi.
Just add the following line to any script you run:

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

So far so good, happy monitoring!

1 Comment

  • Monitor VMware vSphere from OpenBSD using the Perl SDK – TuM'Fatig Mon, 30 Jul 2012 10:23:56 +0000 Reply

    […] time, I had a look at how to monitor VMware vSphere from FreeBSD using the Perl SDK. Quite simple using the […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

%d bloggers like this: