Solved: Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

Solved: Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

When you perform some activities in Nagios UI (for example: Re-schedule the next check of this service), you might get the following error message in the browser:

Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

The permissions on the external command file and/or directory may be incorrect.
Read the FAQs on how to setup proper permissions.

An error occurred while attempting to commit your command for processing.

As you can imagine, this is a permission issue. Let us look at the current permission of rw directory, and nagios.cmd file.

As you see below, rw directory and nagios.cmd file have nagios as the group. Make sure the group has “rwxs” permission for the /usr/local/nagios/var/rw folder.

# ls -ld /usr/local/nagios/var/rw
drwxrwsr-x. 2 nagios nagios 4096 Jul 1 10:47 /usr/local/nagios/var/rw

# ls -l /usr/local/nagios/var/rw
prw-rw—-. 1 nagios nagios 0 Jul 1 10:21 nagios.cmd
srw-rw—-. 1 nagios nagios 0 Jul 1 10:47 nagios.qh

The “rw” folder and nagios.cmd file should be owned by the nagioscmd group.

First, create the nagioscmd group, and nagios and apache user to this group as shown below.

groupadd nagcmd

usermod -G nagcmd nagios

usermod -G nagcmd apache

Next, change the group using chown command to fix the issue.

chown nagios:nagcmd /usr/local/nagios/var/rw

chown nagios:nagcmd /usr/local/nagios/var/rw/nagios.cmd

Finally, restart the Apache and Nagios, you should not get that nagios.cmd error message anymore.

But, the correct way to solve this problem is to specify the nagioscmd group when you do the ./configure during installation itself.

During Nagios installation, instead of just specifying “./configure”, you should create the nagioscmd group, assign it to apache and nagios user, and specify the following “./configure”, which will set the permission for the “rw” directory, and nagios.cmd file correctly when you do make install.

 

./configure –with-command-group=nagcmd

 

 

If you’re updating Nagios, and/or you are trying to reschedule checks manually, and you get the error below:

Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

Then it means that the permissions on the folder are messed up. Don’t bother setting up the permissions on the file itself, nagios.cmd, since that file gets recreated very often, so:

chown nagios.nagcmd /usr/local/nagios/var/rw
chmod g+rwx /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

This should get you up and running without problems.

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.