Page 1 of 2

Could not stat() command file '/usr/local/nagios/var/

Posted: Wed Jun 11, 2014 7:48 pm
by paul.tyler1
Hello,

I am having the same error as in this post, but following the steps people have posted I am still not able to resolve the error and enable notifications for a service or make notes.

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.

Here is some of my system information, please advise what I can do next:

Linux i-2743-8087-VM 2.6.18-348.el5 #1 SMP Tue Jan 8 17:53:53 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

[root@i-2743-8087-VM tmp]# getenforce
Enforcing
[root@i-2743-8087-VM tmp]# setenforce 0
[root@i-2743-8087-VM tmp]# service nagios restart
Running configuration check...Stopping nagios: .done.
Starting nagios: done.
[root@i-2743-8087-VM tmp]# ps -auxww | grep nagios
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
nagios 4053 0.0 0.0 16112 1384 ? Ss 09:37 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
nagios 4054 0.0 0.0 9628 784 ? S 09:37 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
nagios 4055 0.0 0.0 9628 784 ? S 09:37 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
nagios 4056 0.0 0.0 9628 784 ? S 09:37 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
nagios 4057 0.0 0.0 9112 700 ? S 09:37 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
nagios 4059 0.0 0.0 15468 668 ? S 09:37 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
root 4073 0.0 0.0 61216 768 pts/1 S+ 09:39 0:00 grep nagios
[root@i-2743-8087-VM tmp]# ps -auxww | grep httpd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
apache 3570 0.0 0.2 236108 9596 ? S 09:08 0:00 /usr/sbin/httpd
apache 3686 0.0 0.2 236108 9600 ? S 09:19 0:00 /usr/sbin/httpd
root 4077 0.0 0.0 61216 764 pts/1 S+ 09:39 0:00 grep httpd
root 9428 0.0 0.3 235916 15668 ? Ss May28 0:00 /usr/sbin/httpd
apache 11301 0.0 0.2 236244 10396 ? S Jun08 0:00 /usr/sbin/httpd
apache 27779 0.0 0.3 237020 12576 ? S Jun08 0:00 /usr/sbin/httpd
apache 27781 0.0 0.2 236908 11888 ? S Jun08 0:00 /usr/sbin/httpd
apache 27782 0.0 0.2 236108 9656 ? S Jun08 0:00 /usr/sbin/httpd
apache 27783 0.0 0.2 236392 11496 ? S Jun08 0:00 /usr/sbin/httpd
apache 27784 0.0 0.2 236108 9648 ? S Jun08 0:00 /usr/sbin/httpd
apache 27786 0.0 0.2 236256 10408 ? S Jun08 0:00 /usr/sbin/httpd
apache 27787 0.0 0.2 236248 10404 ? S Jun08 0:00 /usr/sbin/httpd
apache 27788 0.0 0.2 237000 12028 ? S Jun08 0:00 /usr/sbin/httpd

Thank you in advance!

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Thu Jun 12, 2014 7:34 am
by Stuart Watts
What are the permissions on nagios.cmd, and the directories it sits in?

Code: Select all

ls -l /usr/local/nagios/var/rw/nagios.cmd
ls -ld /usr/local/nagios/var/rw
ls -ld /usr/local/nagios/var
ls -ld /usr/local/nagios
ls -ld /usr/local

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Thu Jun 12, 2014 4:14 pm
by Box293
I found this blog fixed the same problem (after trying lots of other similar sites).

http://linux.101hacks.com/unix/nagios-cmd-file-error/

I assume the group nagcmd already exists, so do the following:

Code: Select all

usermod -G nagcmd nagios
usermod -G nagcmd apache
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.

Code: Select all

service httpd restart
service nagios restart

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Thu Jun 12, 2014 6:33 pm
by paul.tyler1
Stuart Watts wrote:What are the permissions on nagios.cmd, and the directories it sits in?

Code: Select all

ls -l /usr/local/nagios/var/rw/nagios.cmd
ls -ld /usr/local/nagios/var/rw
ls -ld /usr/local/nagios/var
ls -ld /usr/local/nagios
ls -ld /usr/local

Here are the permissions:
[root@i-2743-8087-VM local]# ls -ld
drwxr-xr-x 14 root root 4096 Jun 12 12:20 .
[root@i-2743-8087-VM local]# cd nagios/
[root@i-2743-8087-VM nagios]# ls -ld
drwxrwxr-x 9 nagios nagios 4096 May 15 12:14 .
[root@i-2743-8087-VM nagios]# ls -lhart
total 72K
drwxrwxr-x 2 nagios nagios 4.0K May 15 12:05 bin
drwxrwxr-x 2 nagios nagios 4.0K May 15 12:05 sbin
drwxr-xr-x 2 root root 4.0K May 15 12:14 include
drwxrwxr-x 9 nagios nagios 4.0K May 15 12:14 .
drwxrwxr-x 11 nagios nagios 4.0K May 15 12:14 share
drwxrwxr-x 3 nagios nagios 4.0K May 15 12:14 libexec
drwxrwxr-x 3 nagios nagios 4.0K May 23 12:46 etc
drwxr-xr-x 14 root root 4.0K Jun 12 12:20 ..
drwxrwxr-x 5 nagios nagios 4.0K Jun 13 08:31 var
[root@i-2743-8087-VM nagios]# cd var/
[root@i-2743-8087-VM var]# ls -lhart
total 1.6M
drwxrwxr-x 3 nagios nagios 4.0K May 15 12:05 spool
drwxrwxr-x 9 nagios nagios 4.0K May 15 12:14 ..
drwxrwxr-x 2 nagios nagios 4.0K Jun 7 23:59 archives
-rw-r--r-- 1 nagios nagios 1.4M Jun 12 12:01 nagios.debug
-rw-r--r-- 1 nagios nagios 21K Jun 12 15:26 objects.precache
-rw-r--r-- 1 nagios nagios 6 Jun 12 15:26 nagios.lock
drwxrwsr-x 2 nagios nagcmd 4.0K Jun 12 15:26 rw
-rw-r--r-- 1 nagios nagios 21K Jun 12 15:26 objects.cache
-rw------- 1 nagios nagios 27K Jun 13 08:26 retention.dat
-rw-r--r-- 1 nagios nagios 41K Jun 13 08:26 nagios.log
-rw-rw-r-- 1 nagios nagios 28K Jun 13 08:31 status.dat
drwxrwxr-x 5 nagios nagios 4.0K Jun 13 08:31 .
[root@i-2743-8087-VM var]# cd rw/
[root@i-2743-8087-VM rw]# ls -lhart
total 24K
srw-rw---- 1 nagios nagcmd 0 Jun 12 15:26 nagios.qh
prw-rw---- 1 nagios nagcmd 0 Jun 12 15:26 nagios.cmd
drwxrwsr-x 2 nagios nagcmd 4.0K Jun 12 15:26 .
drwxrwxr-x 5 nagios nagios 4.0K Jun 13 08:32 ..

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Thu Jun 12, 2014 6:43 pm
by paul.tyler1
Box293 wrote:I found this blog fixed the same problem (after trying lots of other similar sites).

http://linux.101hacks.com/unix/nagios-cmd-file-error/

I assume the group nagcmd already exists, so do the following:

Code: Select all

usermod -G nagcmd nagios
usermod -G nagcmd apache
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.

Code: Select all

service httpd restart
service nagios restart
It looks like the correct permissions are in place already.
srw-rw---- 1 nagios nagcmd 0 Jun 12 15:26 nagios.qh
prw-rw---- 1 nagios nagcmd 0 Jun 12 15:26 nagios.cmd

I am stumped on this.

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Fri Jun 13, 2014 2:13 pm
by lmiltchev
Can you run the following command and show us the output?

Code: Select all

grep nag /etc/group

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Mon Jun 16, 2014 6:55 pm
by paul.tyler1
[root@i-2743-8087-VM ~]# grep nag /etc/group
nagios:x:500:apache
nagcmd:x:501:nagios

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Tue Jun 17, 2014 9:52 am
by sreinhardt
Looks like the usermod commands from above were not run. Could you run:

Code: Select all

usermod -G nagios nagios
usermod -G nagcmd apache
service nagios restart
service httpd restart
This is just so that both user account have proper access to the files they need.

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Tue Jun 17, 2014 7:28 pm
by paul.tyler1
I see now... Sorry, I was confused when I was looking at the permissions. Thank you, that did fix the notifications.

Re: Could not stat() command file '/usr/local/nagios/var/

Posted: Tue Jun 17, 2014 7:40 pm
by Box293
Happy days :D