Monitoring VMware ESXi and vSphere with Nagios


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

$USER11$=username
$USER12$=password

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

# Host esx01
define host{
use                     vmware-server
host_name       esxi01
alias                   VMWare ESXi 01
address             IP Address
}
define host{
use                     vmware-server
host_name       esxi02
alias                   VMWare ESXi 02
address             IP Address
}
# Similarly you can define all the hosts

# Now define a hostgroup for your Esxi Hosts:

define hostgroup{
hostgroup_name  Esxi-Servers ; The name of the hostgroup

alias                        Vmware Servers ; Long name of the group

members                esxi01,esxi02
}

# Now create the service definition as shown below

# check cpu
define service{
use                                    generic-service
host_name                      esxi01
service_description       ESXi CPU Load
check_command            check_esx_cpu!80!90
}

# check memory usage
define service{
use                                    generic-service
host_name                      esxi01
service_description       ESXi Memory usage
check_command            check_esx_mem!80!90
}

# check net
define service{
use                                   generic-service
host_name                     esxi01
service_description      ESXi Network usage
check_command           check_esx_net!102400!204800
}

# check runtime status
define service{
use                                 generic-service
host_name                    esxi01
service_description     ESXi Runtime status
check_command          check_esx_runtime
}

# check io read
define service{
use                                 generic-service
host_name                   esxi01
service_description     ESXi IO read
check_command          check_esx_ioread!40!90
}

# check io write
define service{
use                                 generic-service
host_name                   esxi01
service_description    ESXi IO write
check_command         check_esx_iowrite!40!90
}

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

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

# check vmware esxi machine
# check cpu
define command{
command_name   check_esx_cpu
command_line      $USER1$/check_esx -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l cpu -s usage -w $ARG1$ -c $ARG2$
}

# check memory usage
define command{
command_name   check_esx_mem
command_line      $USER1$/check_esx -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l mem -s usage -w $ARG1$ -c $ARG2$
}

# check net usage
define command{
command_name   check_esx_net
command_line      $USER1$/check_esx -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l net -s usage -w $ARG1$ -c $ARG2$
}

# check runtime status
define command{
command_name   check_esx_runtime
command_line      $USER1$/check_esx -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l runtime -s status
}

# check io read
define command{
command_name   check_esx_ioread
command_line      $USER1$/check_esx -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l io -s read -w $ARG1$ -c $ARG2$
}

# check io write
define command{
command_name   check_esx_iowrite
command_line      $USER1$/check_esx -H $HOSTADDRESS$ -u $USER11$ -p $USER12$ -l io -s write -w $ARG1$ -c $ARG2$
}

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.

About Alex Hunt

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Vmware. Bookmark the permalink.

One Response to Monitoring VMware ESXi and vSphere with Nagios

  1. 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”) ) {

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s