Monitoring VMware ESXi and vSphere with Nagios

By | 19/08/2013

Installation Requirements
Perl 5.8
Several supporting Perl modules:
Crypt-SSLeay (0.51) [Crypt::SSLeay]
Data-Dumper (2.102) [Data::Dumper]
MethodMaker (2.0.8) [Class::MethodMaker]
XML-LibXML (1.60) [XML::LibXML]
libwww-perl (5.805) [LWP]

Install all the dependencies of Perl SDK.

[root@nagios~]# perl -MCPAN -e shell

The above command shall bring you to the perl cpan install CLI. This will allow you to install requirements for Perl.

Example:

cpan> install Crypt::SSLeay

Installation

The prerequisite for the plugin to work is to install the VMWare Perl SDK.

Download the VMWare Perl SDK  from following url and untar it:

[root@nagios~]# https://my.vmware.com/web/vmware/details?productId=285&downloadGroup=VSP510-SDKPERL-510

[root@nagios~]# tar xvzf VMware-vSphere-Perl-SDK-5.0.0-422456.i386.tar

set http and ftp proxy to null before running the installer

[root@nagios~]# export http_proxy=

[root@nagios~]# export ftp_proxy=

[root@nagios~]# cd vmware-vsphere-cli-distrib/

[root@nagios~]#./vmware-install.pl

“Creating a new vSphere CLI installer database using the tar4 format.

Installing vSphere CLI.

You must read and accept the vSphere CLI End User License Agreement to continue.
Press enter to display it.”

“Read through the License Agreement”

“Do you accept? (yes/no)”
yes

“In which directory do you want to install the executable files?
[/usr/bin]”

“The following Perl modules were found on the system but may be too old to work
with vSphere CLI:

Crypt::SSLeay
Compress::Zlib

The installation of vSphere CLI 4.0.0 build-161974 for Linux mcompleted successfully. You can decide to remove this software from your system at any time
by invoking the following command:

“/usr/bin/vmware-uninstall-vSphere-CLI.pl”.

Now Download nagios check plugin check_esx.pl from op5.com

[root@nagios~]# git clone git://git.op5.org/nagios/op5plugins.git

Now make the plugin executable and run it

[root@nagios~]# cd op5plugins/

[root@nagios~]# chmod +x *.pl

Change the ownership to nagios for all plugins

[root@nagios~]# chown nagios:nagios *.pl

[root@nagios~]# ./check_vmware_api.pl

Note: sometimes it will give you error that perl-nagios plugin is not found. Install the required plugin and related dependencies.

Download the required rpms from the url given below

[root@nagios~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/perl-Nagios-Plugin-0.35-1.el6.noarch.rpm

[root@nagios~]# wget http://mirror.centos.org/centos/6/os/i386/Packages/perl-Config-Tiny-2.12-7.1.el6.noarch.rpm

[root@nagios~]# wget http://mirror.centos.org/centos/6/os/i386/Packages/perl-Params-Validate-0.92-3.el6.i686.rpm

[root@nagios~]# rpm -ivh perl-Nagios-Plugin-0.35-1.el6.noarch.rpm perl-Config-Tiny-2.12-7.1.el6.noarch.rpm perl-Params-Validate-0.92-3.el6.i686.rpm

Now try to run the check_vmware_api plugin

[root@nagios~]# ./check_vmware_api.pl

Copy all the plugins from vmware-vsphere-cli-distrib/ directory to /usr/local/nagios/libexec

[root@nagios~]# cd /root/vmware-vsphere-cli-distrib/

[root@nagios~]# cp -arv *.pl /usr/local/nagios/libexec/

Now its time to configure nagios so that it can monitor the esxi hosts.

First of all we’ll need a username and password to access the ESXi host,define those Nagios variables in /etc/nagios/resource.cfg

we’ll be monitoring these resources : CPU, memory usage, net usage, runtime status and IO/read/write.

create vmware definition (servers which you want to monitor)

# vim /usr/local/nagios/etc/objects/vmware.cfg

First define all your hosts as shown below

Similarly you can define all the hosts

# Now define a hostgroup for your Esxi Hosts:

# Now create the service definition as shown below

Define the commands related to ESXi in the /usr/local/nagios/etc/objects/command.cfg file

# vim /usr/local/nagios/etc/objects/commands.cfg

Now give the path of file in which you have defined your esxi hosts and hosts-group in nagios.cfg

vim /usr/local/nagios/etc/nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/vmware.cfg

That is it. Restart your nagios service and you are ready to monitor your esxi servers.

One thought on “Monitoring VMware ESXi and vSphere with Nagios

  1. Kateřina Bambušková

    For Debian Edit

    From:
    # check for e2fsprogs-devel installed
    if ( direct_command(“cat /etc/*release | grep -i ubuntu”) || direct_command(“cat /proc/version | grep -i ubuntu”) ) {

    To:
    # check for e2fsprogs-devel installed
    if ( direct_command(“cat /etc/issue | grep -i debian”) || direct_command(“cat /proc/version | grep -i debian”) ) {