===============
 WHAT
===============
This Nagios Plugin gets the size (Kb, Mb, Gb)  of the vmfs volumes (datastores) of a VMWare Server Esxi 4.

The VMWare VCLI must be installed and configured on the Nagios server (in my case, an Ubuntu server guest, inside the VMWare Server ESxi host), because we do use of the binary "vmkfstools" for getting the data.

Moreover, this version perl requires Nagios-Plugin installed too (http://search.cpan.org/dist/Nagios-Plugin/). Nagios Plugin is a family of perl modules to stremline writing Nagios plugins.


Warning and critical levels can be set, and plugin gives us perfdata output too, so it can be graphed with graphical tools as pnp4nagios,  besides the usual Nagios states (OK, WARNING and CRITICAL).

============================
PREREQUISITES & INSTALLATION
============================

1) For the check_vmfs.pl plugin to work, it needs VMWare VCLI installed. You can get it for free, after registration, here:

https://my.vmware.com/web/vmware/details?downloadGroup=VSP510-VCLI-510&productId=285

2) Because this perl script use Nagios::Plugin, we must install it automatically through CPAN or manually:
2.1) Installing Nagios::Plugin automatically:

# perl -MCPAN -e shell
# cpan> install Nagios::Plugin

2.2) Installing Nagios::Plugin manually:

Download last stable tar.gz from http://search.cpan.org/dist/Nagios-Plugin
tar xvfz Nagios-Plugin-0.36.tar.gz
cd Nagios-Plugin-0.36
perl Makefile.PL
make
make test
make install

3) To check into the server automatically, we need the credentials of the VMWare ESXi servers stored in a single config file.
By default it could be stored in nagios plugin path:

/usr/local/nagios/libexec/vmware_esxi_conf.txt

and this txt file should have, at least, these fields:

# VMWARE_SERVER1 USER1 PASSWORD1
# VMWARE_SERVER2 USER2 PASSWORD2

This file should be, by security, in 600 mode, and owner and group of Nagios user.

By Example:
chown vmware_esxi_conf.txt
chmod 600 vmware_esxi_conf.txt

4) check_vmfs.pl is placed in plugins Nagios path=>/usr/local/nagios/libexec

5) Checking if nagios default path is /usr/local/nagios/var. Script needs to create a file there called check_vmfs.err to handle errors.
If Nagios is installed in other place, just change this line in script:
ERR_LOG=/usr/local/nagios/var/check_vmfs.err
to your default nagios installation directory.


===============
EXAMPLES
===============

Command line:
 * Checking datastore1 of server with IP 10.71.8.70 volume using configuration file stored in current directory, with a warning level of 75%, a critical level of 90% and used space in Gb
	$ check_vmfs.pl -C vmware_esxi_conf.txt -S 10.71.8.70 -p /vmfs/volumes/datastore1 -w 75 -c 90 -u Gb

it could give us results similar to these ones:
VMFS OK - /vmfs/volumes/Sauron - total: 1519.75 Gb - used: 544.52 Gb (36%) - free: 975.23 Gb (64%) | /vmfs/volum
es/Sauron=36%;75;90

Nagios example:
 1) Add to commands.cfg file (by default in /usr/local/nagios/etc/objects path):

	 define command{
		command_name check_vmfs_pl
		command_line $USER1$/check_vmfs.pl -C $USER1$/$ARG1$ -S $ARG2$ -p $ARG3$ -w $ARG4$ -c $ARG5$ -u $ARG6$
	}

2) Add to vmware.cfg (or any other host with services, file):
	 define service{
          use                     generic-service
          host_name               svrvirtual
          service_description     datastore1 space 
          check_command           check_vmfs!vmware_esxi_conf.txt!10.71.8.70!/vmfs/volumes/Sauron!80!90!Gb
  }

3) Reload nagios service
sudo /etc/init.d/nagios reload

4) Check everything is working!

===============
 CONTACT
===============
jpcozar@notforadsyahoo.es
Remove the *notforads* substring from the address.

===============
 LICENSE
===============
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
