Cannot Run Nagios Service Commands – Could not open command file Error
After installing Nagios, everything may appear to be up and running just fine until
you attempt to run a service command such as “Re-schedule the next check of this service”.
As soon as you get through the next page and hit the commit button, you get this nasty gram message from nagios saying that you cannot run nagios/var/rw/nagios.cmd:
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
Return from whence you came
As shown in the screenshot image below…
Grr! Nothing could be more aggravating then getting this error because your getting it when you actually have a real error on one of your servers that you need to work with and this becomes a distraction from resolving the real problem anyway.
What this Nagios Error is About
So, if we dissect this error, what it is saying is that somehow we don’t have permissions to run the /usr/local/nagios/var/rw/nagios.cmd file. So, our first reaction is to check the permission on the file:
|$ ls -l
prw-rw—- 1 nagios nagios 0 Nov 20 10:01 nagios.cmd
So, at this point, we are all tempted to just change the permissions on the cmd file, which will indeed resolve the problem until the nagios service is restarted again. Restarting will set the permissions to their original state again. So what we need is a real solution to the problem. So, the question goes to who or which user doesn’t have permissions. It looks like the nagios user does, isn’t that what nagios is running as. Nope! It is the webserver that is attempting to run the command and not the nagios service. So, the user that is running your webserver needs to have permissions to run this command file.
The solution is to add the userid that is running your webserver to the nagios group. In my case, I am using Apache httpd which is running using the apache userid. So, I need to add the apache user to the nagios group.
|# usermod -G nagios apache|
Now, we verify that the apache user is part of the nagios group:
|# grep nagios /etc/group
Now that is done, we need to restart the Apache service so that it can pick up the change in group membership.
|# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
With all of this done, try the nagios service command again, it should now be working.
Latest posts by Jeff Staten (see all)
- Configure Your HP Procurve Switch with SNTP - May 5, 2015
- Configuring HP Procurve 2920 Switches - May 1, 2015
- Troubleshooting Sendmail - November 28, 2014
usermod -a -G nagcmd apache
Works for the version of Nagios and CentOS I have
Worked for me. Awesome. Thanks!
also for me:
usermod -a -G nagcmd apache
Hi, your solutions works fine for me on Centos 6.5:
# usermod -G nagcmd apache
Thanks for this tip. helped me with nagios 4 on debian wheezy
I had that change the group, because I use Ubuntu
# usermod -G nagios www-data
# usermod -G nagcmd www-data