How to monitor VMware ESXi using Nagios

Hello,

Final result

I wanted to monitor my VMware ESXi host using my Nagios monitor and used the check_vmware_api perl plugin for Nagios.
You can find the check_vmware_api perl script here.

In order to run this plugin you will need the VMware vSphere SDK for Perl, you will need to have it on the Nagios server.
I have written a pretty decent walkthrough guide on how to install this specifically for this plugin here.

1. First off we download the check_vmware_api from the link provided above (here).
Download it and place it in your nagios plugins folder, I’m using the name check_esx since it’s more comfortable.

cp check_vmware_api /usr/lib/nagios/plugins/check_esx
chmod +x /usr/lib/nagios/plugins/check_esx

2. Before we continue and define our Nagios command we should try it out, let’s do a basic test on CPU usage.

cd /usr/lib/nagios/plugins/
./check_esx -H 127.0.0.1 -u nagios -p test123 -l cpu -s usage -w 90 -c 95

Above is a simple check, here you specify the IP of the VMware host, username and password for the user to be used.
You can also specify when it should warn and when it should be considered critical.

What I did was create an additional user named nagios for the authentication (see below).
You should get a result similar to this:

CHECK_ESX OK - cpu usage=3.19 % | cpu_usage=3.19%;90;95

Here is a quick guide on how to add a VMware user.

  • Go to Inventory -> Local Users & Groups
  • Rightclick -> Add -> Fill in login, username and password
  • Go to Inventory -> Permissions
  • Rightclick -> Add Permission
  • You then select your newly created “nagios” user and assign it as Administrator (it’s required by VMware to be allowed to query for all the values)
  • 4. Continuing on, now we need to define Nagios commands for checking CPU, memory etc.
    I add the following to my /etc/nagios3/resource.cfg file to store the password for the VMware user, this way I dont have type it in several times.

    nano /etc/nagios3/resource.cfg
    

    Make sure there isn’t already a USER3 and USER4 declaration.
    Note that the variables must be defined like USERx else it won’t work (where x is a number)

    $USER3$=nagios
    $USER4$=test123
    

    I then continue on declaring the command in /etc/nagios3/commands.cfg

    nano /etc/nagios3/commands.cfg
    
    define command{
    command_name check_esx_cpu
    command_line /usr/bin/perl $USER1$/check_esx -H $HOSTADDRESS$ -u $USER3$ -p $USER4$ -l cpu -s usage -w $ARG1$ -c $ARG2$
    }
    
    define command{
    command_name check_esx_mem
    command_line /usr/bin/perl $USER1$/check_esx -H $HOSTADDRESS$ -u $USER3$ -p $USER4$ -l mem -s usage -w $ARG1$ -c $ARG2$
    }
    
    define command{
    command_name check_esx_net
    command_line /usr/bin/perl $USER1$/check_esx -H $HOSTADDRESS$ -u $USER3$ -p $USER4$ -l net -s usage -w $ARG1$ -c $ARG2$
    }
    
    define command{
    command_name check_esx_status
    command_line /usr/bin/perl $USER1$/check_esx -H $HOSTADDRESS$ -u $USER3$ -p $USER4$ -l runtime -s status
    }
    
    define command{
    command_name check_esx_ioread
    command_line /usr/bin/perl $USER1$/check_esx -H $HOSTADDRESS$ -u $USER3$ -p $USER4$ -l io -s read -w $ARG1$ -c $ARG2$
    }
    
    define command{
    command_name check_esx_iowrite
    command_line /usr/bin/perl $USER1$/check_esx -H $HOSTADDRESS$ -u $USER3$ -p $USER4$ -l io -s write -w $ARG1$ -c $ARG2$
    }
    

    Here you can see I’m specifying the USERx variable, make sure it’s correct

    I then add the service checks to the VMware host configuration in Nagios.
    A pretty much complete Nagios host configuration would look similar to this.

    define host{
            use                     generic-host
            host_name               vmware01
            alias                   vmware01.test.com
            address                 127.0.0.1
            notes                   VMware 01
            }
    
    define service{
            use                             generic-service
            host_name                       vmware01
            service_description             PING
            check_command                   check_ping!100.0,20%!500.0,60%
            }
    
    define service{
            use                             generic-service
            host_name                       vmware01
            service_description             VMware CPU
            check_command                   check_esx_cpu!80!90
    }
    
    define service{
            use                             generic-service
            host_name                       vmware01
            service_description             VMware Memory
            check_command                   check_esx_mem!80!90
    }
    
    define service{
            use                             generic-service
            host_name                       vmware01
            service_description             VMWare Network
            check_command                   check_esx_net!102400!204800
    }
    
    define service{
            use                             generic-service
            host_name                       vmware01
            service_description             VMWare Status
            check_command                   check_esx_status
    }
    
    define service{
            use                             generic-service
            host_name                       vmware01
            service_description             VMWare IO Read
            check_command                   check_esx_ioread!40!90
    }
    
    define service{
            use                             generic-service
            host_name                       vmware01
            service_description             VMWare IO Write
            check_command                   check_esx_iowrite!40!90
    }
    

    Then just restart your Nagios and your services should start popping up.

    service nagios3 restart
    

    Feel free to comment with questions or corrections
    /Trigger

    0 Comments

    Leave a Reply

    Your email address will not be published.