Category: VMware

How to fix Nagios “error: Could not stat() command file” on Debian GNU Linux

Hello,

If you are recieving this problem in Nagios it’s probably because of faulty permissions
or erroneous Nagios configuration.

1. Make sure the following is set in the Nagios configuration in /etc/nagios3/nagios.cfg

nano /etc/nagios3/nagios.cfg
# EXTERNAL COMMAND OPTION
# Values: 0 = disable commands, 1 = enable commands
check_external_commands=1

# EXTERNAL COMMAND FILE
command_file=/var/lib/nagios3/rw/nagios.cmd
</code>

Also make sure the /var/lib/nagios3/rw/nagios.cmd file does exist.

file /var/lib/nagios3/rw/nagios.cmd
/var/lib/nagios3/rw/nagios.cmd: fifo (named pipe)

2. Make sure your Nagios user has the permissions to execute the commands, check in /etc/nagios3/cgi.cfg

nano /etc/nagios3/cgi.cfg
# SYSTEM/PROCESS COMMAND ACCESS
authorized_for_system_commands=nagiosadmin

# GLOBAL HOST/SERVICE COMMAND ACCESS
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin

Default is the nagiosadmin user

3. Make sure the www-data user (the user running Apache) is in the Nagios user group.

id www-data

Output:

uid=33(www-data) gid=33(www-data) groups=33(www-data)

Adding the www-data user to the Nagios group.

usermod -a -G nagios www-data
</code>

Check again.

id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data),106(nagios)

5. Check the permissions for the nagios.cmd file like this

ls -l /var/lib/nagios3/rw/nagios.cmd 
prw-rw---- 1 nagios nagios 0 Jun 24 11:39 /var/lib/nagios3/rw/nagios.cmd

And then make sure there is execute permission for groups on the /var/lib/nagios3/rw directory.

ls -l /var/lib/nagios3/
total 132
-rw-r--r-- 1 nagios nagios      572 Jun 13 08:14 host-perfdata.out
-rw------- 1 nagios www-data 115362 Jun 24 11:18 retention.dat
drwx------ 2 nagios www-data   4096 Jun 24 11:18 rw
-rw-r--r-- 1 nagios nagios     2162 Jun 13 08:16 service-perfdata.out
drwxr-x--- 3 nagios nagios     4096 Jun 11 23:15 spool

Add execute permissions for group like this.

chmod g+x /var/lib/nagios3/rw/
ls -l /var/lib/nagios3/
total 132
-rw-r--r-- 1 nagios nagios      572 Jun 13 08:14 host-perfdata.out
-rw------- 1 nagios www-data 115362 Jun 24 11:18 retention.dat
drwx--x--- 2 nagios www-data   4096 Jun 24 11:18 rw
-rw-r--r-- 1 nagios nagios     2162 Jun 13 08:16 service-perfdata.out
drwxr-x--- 3 nagios nagios     4096 Jun 11 23:15 spool

6. Now all you have to do is to restart Apache (and possibly Nagios too) and it should be working with external commands.

service apache2 restart
service nagios3 restart

/Trigger

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

    How to install VMware vSphere SDK on Debian GNU Linux

    Hello,

    I wanted to setup Nagios monitoring for my VMware host and found this nifty little Perl plugin check_vmware_api (you can find it here).

    In order to run this plugin you will need the VMware vSphere SDK for Perl.
    You can search for it on VMware’s download page here.

    I searched for “vsphere sdk” and choose the first result VMware vSphere SDK for Perl 5.5 and downloaded the x64 Linux version.
    The problem here is that it’s not originally for Debian but for Ubuntu so we’ll have to do some adjustments later on.

    1. We need to make sure we have the following packages.

    apt-get install build-essential gcc uuid uuid-dev perl libssl-dev perl-doc liburi-perl libxml-libxml-perl libcrypt-ssleay-perl
    

    2. When you have downloaded the vSphere SDK for Perl we need to untar it, do some modifications then install.

    tar xvf VMware-vSphere-Perl-SDK-5.5.0-1384587.x86_64.tar.gz
    cd vmware-vsphere-cli-distrib
    

    3. Do the following changes, open vmware-install.pl in your favored text editor (I’m using nano)

    nano vmware-install.pl
    

    Change this line

    if ( direct_command("cat /etc/*-release | grep -i ubuntu") || direct_command("cat /proc/version | grep -i ubuntu") ) {
    

    to

    if ( direct_command("cat /etc/*-release | grep -i debian") || direct_command("cat /proc/version | grep -i debian") ) {
    

    4. This step is pretty much optional but to prevent recieving some warnings because of undefined exportvariables you can set the following or just ignore this step.

    export http_proxy=
    export ftp_proxy=
    

    5. Now you should be good to go, so go on and execute the installation.

    ./vmware-install.pl
    

    Thanks for reading and please comment if you have any corrections or questions
    /Trigger