error: could not stat() command file '/var/lib/nagios3/rw/nagios.cmd'!

Discussion in 'Linux' started by securityhope, Aug 28, 2016.

  1. securityhope

    securityhope Administrator Staff Member

    Joined:
    Aug 3, 2016
    Messages:
    1,241
    Likes Received:
    0
    Trophy Points:
    36
    Error: Could not stat() command file ‘/var/lib/nagios3/rw/nagios.cmd’!

    The external command file may be missing, Nagios may not be running, and/or Nagios may not be checking external commands. An error occurred while attempting to commit your command for processing.

    Code:
    service nagios3 stop
    dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
    dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
    service nagios3 start
    Nagiosis a network monitoring tool. I use it to track web servers, mail servers, and whatever else I have running on the LAN and on the Internet.

    One common configuration issue is getting theService Commandsmenu to work correctly. By default, it is visible in the UI, but disabled on the server backend. And on Debian, not all of the steps to enable it are particularly evident from the docs. Often, one will recieve the cryptic errorCould not stat() command filepointing to/var/lib/nagios3/rw/nagios.cmd. This can be fixed without too much fuss.

    <!--break-->I have run into this problem the last three times I have set up Nagios, and every time I fix it, I forget to document the process. So here's the documentation. The first few points are covered in the official Nagios documentation that comes with your package. The later points are not, and have more to do with OS configuration.

    Configure nagios.cfg
    Make sure you have something like this in/etc/nagios3/nagios.cfg:

    Code:
    # EXTERNAL COMMAND OPTION# Values: 0 = disable commands, 1 = enable commandscheck_external_commands=1# EXTERNAL COMMAND CHECK INTERVAL# NOTE: Setting this value to -1 causes Nagios to check the external# command file as often as possible.command_check_interval=15s#command_check_interval=-1# EXTERNAL COMMAND FILEcommand_file=/var/lib/nagios3/rw/nagios.cmd
    You will need to restart Nagios for these settings to be loaded.

    Configure cgi.cfg
    Next, edit the/etc/nagios3/cgi.cfgfile and check the following:

    Code:
    # SYSTEM/PROCESS COMMAND ACCESSauthorized_for_system_commands=nagiosadmin# ... Other stuff cut# GLOBAL HOST/SERVICE COMMAND ACCESSauthorized_for_all_service_commands=nagiosadminauthorized_for_all_host_commands=nagiosadmin
    This enables the usernagiosadminto submit commands. You can check out the in-file documentation for setting up multiple users.

    Restart Apache2 after you have done this.

    Add www-data to the Nagios Group
    Next, make sure that the userwww-datais in the groupnagios. You can check on this in/etc/group.

    Set the Permissions
    This last item is the tricky one. You need to set the correct permissions for the command pipe file (this is the file set innagios.cfg). Nagios uses this pipe to pass data from the CGI to the backend daemon.

    This file is located in/var/lib/nagios3/rw/nagios.cmd.

    By default, it should have the following permissions:

    Code:
    # ls -l /var/lib/nagios3/rw/nagios.cmd prw-rw---- 1 nagios nagios 0 2010-01-13 10:17 /var/lib/nagios3/rw/nagios.cmd
    Notice that the group ownership isnagios. That's why you addedwww-datato thenagiosgroup above.

    But even with these permissions, you may (will?) still get an error. The reason for this is that the parent directory,rw, does not allow any user butnagiosto access its contents:

    Code:
    # ls -lh /var/lib/nagios3total 92K-rw-r--r-- 1 nagios nagios    33K 2010-01-04 17:06 objects.precache-rw------- 1 nagios www-data  48K 2010-01-13 10:17 retention.datdrwx------ 2 nagios www-data 4.0K 2010-01-13 10:17 rwdrwxr-x--- 3 nagios nagios   4.0K 2010-01-04 16:00 spool
     

Share This Page

Share