Fixing “error: Could not stat() command file” Ubuntu 18.04

One common configuration issue with Nagios 3 running on Ubuntu is getting the Service Commands menu to work correctly.

By default, it is visible in the UI, but disabled on the server backend. In Ubuntu, you will recieve the cryptic error Could not stat() command file pointing to /var/lib/nagios3/rw/nagios.cmd. This can be fixed with the following steps:

sudo nano /etc/nagios3/nagios.cfg 

Ensure the check_external_commands=1

We now need to add the www-data user to the nagios group:

sudo usermod -a -G nagios www-data

We now need to grant execute permission to the nagios group to /var/lib/nagios3/rw

sudo chmod g+x /var/lib/nagios3/rw

We now need to restart Nagios and Apache

sudo systemctl restart nagios3.service 
sudo systemctl restart apache2.service