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

0 Comments

Leave a Reply

Your email address will not be published.