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

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
hotriver
Posts: 8
Joined: Fri Feb 17, 2012 3:58 pm

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

Post by hotriver »

I tried to use Re-schedule the next check of this service, but I got

Error: Could not stat() command file '/usr/local/nagios/var/rw/nagios.cmd'!

I searched from google and ran the following command.

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

[root@localhost libexec]# ls -lah /usr/local/nagios/var/rw
total 8.0K
drwxrwsr-x. 2 nagios nagcmd 4.0K Feb 17 15:18 .
drwxrwxr-x. 5 nagios nagios 4.0K Feb 17 15:22 ..
prw-rw----. 1 nagios nagcmd 0 Feb 17 15:18 nagios.cmd

But it still have the same problem. I use Centos 6.2 and Nagios Core 3.31

I also tried to change SELinux Context for /usr/local/nagios/var/rw, it did not work either.

I noticed that the /usr/local/nagios/var/rw/nagios.cmd is 0 byte in size, is this correct?

HELP

Thanks in advance
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

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

Post by jsmurphy »

This is pretty much 100% of the time caused by a permissions issue, the .cmd file needs to be accessible by whatever you have defined as your command user/group and by the webserver. First of all take a peak at /etc/passwd and find the user account name for both nagios and your web server, then open /etc/group and locate your nagios group and your command group; nagios and nagcmd respectively for a default install. It should look something like this:

nagios:x:500:nagios,apache
nagcmd:x:501:nagios,apache

now check that rw and the .cmd file is owned by the nagios user and your nagios command group.
hotriver
Posts: 8
Joined: Fri Feb 17, 2012 3:58 pm

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

Post by hotriver »

Hi Jesmurphy,

Thank you very much for the help.

I checked etc/group and change nagios:x:500: to nagios:x:500:nagios,apache

But it did not work just after change. I had to change the SElinux Context for /usr/local/nagios/var/rw to httpd_user_rw_content_t, then it works.
User avatar
jsmurphy
Posts: 989
Joined: Wed Aug 18, 2010 9:46 pm

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

Post by jsmurphy »

Well on the plus side it was still a permissions issue :lol: ! What distro of Linux were you using? I've never seen SELinux interfere before... it would be good to know if it could be a distro specific thing.
hotriver
Posts: 8
Joined: Fri Feb 17, 2012 3:58 pm

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

Post by hotriver »

Hi Jsmerphy,

I use CentOS 6.2. It seems it added more oprions in the SELinux Context. I used 5.6 last year and did not need to change this option.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

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

Post by mguthrie »

Yeah, I've concluded that the purpose of SELinux is just to silently break things. There's currently a bug in CentOS 6 that makes SSH keys useless if you have SELinux enabled, so I'm sure that's not the only issue that exists because of it ; )
estefania.rabadan
Posts: 1
Joined: Fri Mar 09, 2012 8:09 am

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

Post by estefania.rabadan »

Hi all,

i have the same nagios.cmd problem. And i change the /et/group configuration, but i don't know where can i change SELinux Context from /usr/local/nagios/var/rw to httpd_user_rw_content_t. I'm using nagios 3.2.3 on Centos 6.2.

Thank you!
User avatar
Hinze57
Posts: 1
Joined: Thu May 24, 2012 8:27 am
Contact:

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

Post by Hinze57 »

Okay, following what hotriver did and it not working on my install I spent some time in the man pages...

Here is what I did to get things working so far under SELinux. BTW, I am running RHEL 6.2 and Nagios 3.4.1 core.

First I modified the nagios folder structure's SELinux labels to allow httpd read access:
# chcon -R --reference=/var/www/html /usr/local/nagios/share
# chcon -R --reference=/var/www/html /usr/local/nagios/var
# chcon -R --reference=/var/www/cgi-bin /usr/local/nagios/sbin

Next I changed the ~var/rw folder to allow write access via the httpd_sys_rw_content_t label:
# chcon -R -t httpd_sys_rw_content_t /usr/local/nagios/var/rw

So far it seems to be working for me.

Cheers,
xmuwolf
Posts: 2
Joined: Fri Aug 24, 2012 7:05 am

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

Post by xmuwolf »

Hinze57 wrote:Okay, following what hotriver did and it not working on my install I spent some time in the man pages...

Here is what I did to get things working so far under SELinux. BTW, I am running RHEL 6.2 and Nagios 3.4.1 core.

First I modified the nagios folder structure's SELinux labels to allow httpd read access:
# chcon -R --reference=/var/www/html /usr/local/nagios/share
# chcon -R --reference=/var/www/html /usr/local/nagios/var
# chcon -R --reference=/var/www/cgi-bin /usr/local/nagios/sbin

Next I changed the ~var/rw folder to allow write access via the httpd_sys_rw_content_t label:
# chcon -R -t httpd_sys_rw_content_t /usr/local/nagios/var/rw

So far it seems to be working for me.

Cheers,
Good job, well done!
Finnaly it worked when i did as you mentioned.
I have google for this case for a long time but it doesn't work always except setenforce=0.
Thanks a lot!
xmuwolf
Posts: 2
Joined: Fri Aug 24, 2012 7:05 am

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

Post by xmuwolf »

Hinze57 wrote:Okay, following what hotriver did and it not working on my install I spent some time in the man pages...

Here is what I did to get things working so far under SELinux. BTW, I am running RHEL 6.2 and Nagios 3.4.1 core.

First I modified the nagios folder structure's SELinux labels to allow httpd read access:
# chcon -R --reference=/var/www/html /usr/local/nagios/share
# chcon -R --reference=/var/www/html /usr/local/nagios/var
# chcon -R --reference=/var/www/cgi-bin /usr/local/nagios/sbin

Next I changed the ~var/rw folder to allow write access via the httpd_sys_rw_content_t label:
# chcon -R -t httpd_sys_rw_content_t /usr/local/nagios/var/rw

So far it seems to be working for me.

Cheers,
Thanks a lot , it worked finally!
Locked