Nagios, VMware/vSphere, VMware Perl SDK 6.5 on Gentoo Linux
Tutorials on how to install nagios to collect data from ESXi for Redhat/Ubuntu you can find plenty on internet. Unfortunately is not the case for Gentoo.
What you need to know that is not impossible and fairly easy (once you get it done).
Here the steps:
1) Download VMware-vSphere-Perl-SDK-6.5.0-xxxx.x86_64.tar.gz from VMware site.
2) Once you untar it you will have a perl script named vmware-install.pl which you can run but since it was not created for Gentoo it check prerequisite that you cannot form
Ex:
Creating a new vSphere CLI installer database using the tar4 format. Installing vSphere CLI 6.5.0 build-4566394 for Linux. You must read and accept the vSphere CLI End User License Agreement to continue. Press enter to display it. Do you accept? (yes/no) yes Thank you. Openssl-devel is not installed on the system. openssl-devel 0.9.7 is required for encrypted connections. Please install openssl-devel version 0.9.7 or greater. e2fsprogs is not installed on the system e2fsprogs 1.38 is required for UUID. Please install e2fsprogs 1.38 or greater.
3) So you will need to compile the whole thing manually, using perl Makefile.PL
4) It will give you a set of dependencies which will be needed, such:
perl Makefile.PL Warning: prerequisite Class::MethodMaker 2.08 not found. Warning: prerequisite Crypt::SSLeay 0.51 not found. Warning: prerequisite SOAP::Lite 0.67 not found. Warning: prerequisite UUID 0.03 not found. Warning: prerequisite XML::LibXML 1.58 not found. Generating a Unix-style Makefile Writing Makefile for VIPerlToolkit Writing MYMETA.yml and MYMETA.json
5) You will need:
emerge -pv dev-perl/Crypt-SSLeay dev-perl/Class-MethodMaker dev-perl/SOAP-Lite dev-perl/UUID app-text/xml2 dev-libs/libxml2 dev-perl/XML-LibXML dev-perl/libxml-perl
6) You might get errors when you compile dev-perl/XML-LibXML
Here is the trick:
You need to have dev-libs/libxml2, app-text/xml2 AND probably the most important one is net-libs/libnsl. Without the last one dev-perl/XML-LibXML will not be able be able to pass the prerequisite for xml2 :
"Checking for ability to link against xml2...yes"
7) Once all the perl modules are installed just compile the VMware-vSphere-Perl-SDK with perl Makefile.PL and make
8) Symlink or copy the VMware directory that was just created in /usr/local/lib64/perl5
9) You are ready to use the perl scripts present in SDK, in theory :))
10) In practice you might have self signed certificates and you need to tweak again some things.
The error :
apps/general/connect.pl --server 1.1.1.1 --username root --password xxxxx Server version unavailable at 'https://1.1.1.1:443/sdk/vimService.wsdl' at /usr/local/lib64/perl5/VMware/VICommon.pm line 735.
To find the real reason you can add before line 735 something like:
die $response->content . "\n";
Now the error will be :
Can't connect to 89.34.110.253:443 (certificate verify failed) SSL connect attempt failed error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed at /usr/lib64/perl5/vendor_perl/5.24.1/LWP/Protocol/http.pm line 49.
You will find on internet different solution like adding the fallowing:
$ENV{PERL_NET_HTTPS_SSL_SOCKET_CLASS} = 'Net::SSL'; $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
The problem with these commands is that either don’t work or are exposing you to man-in-the-middle attack.
A better solution is to download the certificates from the vCenter and use them. More exactly on the initial page of vCenter you have a link named: Download trusted root CA certificates. Download, unzip it and copy it to /etc/ssl/certs/.
An even better solution is to have/buy certificates but this will not be fallowed here. You can find plenty of tutorials on internet for this.
11) Finally we made it.
apps/general/connect.pl --server 1.1.1.1 --username root --password xxxxx Connection Successful Server Time : 2019-06-07T11:20:28.101016Z