Ticket ID #242 ‐ Configure NRPE for Remote Server Monitoring - GriffinKat/group-a GitHub Wiki

Remote Nagios Checks With NRPE

  1. Create a module for nrpe in the /etc/puppetlabs/code/modules directory with the following structure.

    image

  2. Edit the init.pp file with the following code.

    image

    Similarly, edit the install.pp, service.pp and config.pp file as shown below respectively:

    image

    image

    image

  3. Install the NRPE server on the database server using puppet module.

    Note: Make sure to comment out the config and service class in the init.pp file, as we will copy the nrpe.cfg file into the files directory of our nrpe module

    image

    Now, run the command on the db-a server sudo /opt/puppetlabs/puppet/bin/puppet agent --server=mgmt-a --no-daemonize --verbose --onetime

    image

    Verify that the nagios-nrpe-server is installed.

    image

  4. Now we will copy the default nrpe.cfg file to the files folder in the nrpe module on the management server. For this, we will first copy the file to the home directory of the management server and then move it to the files folder in the nrpe module, as I was getting permission denied error to copy directly.

    sudo scp /etc/nagios/nrpe.cfg group-a@mgmt-a:/home/group-a

    image

    sudo mv nrpe.cfg /etc/puppetlabs/code/modules/nrpe/files/

    image

  5. Edit the nrpe.cfg file in the files directory of the module.

    Edit the allowed hosts to accept requests from your server, e.g.:

    allowed_hosts=mgmt-a

    image

    Now we need to configure the NRPE server to perform the disk check. For security reasons, NRPE will only perform the checks it has been explicitly configured to do. There are some examples ones in the nrpe.cfg file, including one that is very close to what we want. Look for the line that reads:

    command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1

    This defines a command called check hda that checks the device /dev/hda1 and issues a warning when only 20% of it’s space remains free and a critical alert when only 10% remains free. The only problem is that our systems don’t have a dev/hda1 device. We can use the df command to see what device we do have mounted to provide the root filesystem and change that argument in this file. We probably want to change the command’s name as well.

    image

  6. Nagios Server Configuration

    First, Our base Nagios installation does not support performing remote checks with NRPE. We need to add that capability by installing the nagios-nrpe- plugin package.

    sudo apt update and sudo apt install -y nagios-nrpe-plugin

    image

    Next, create a new hostgroup with a name like “remote-disks” in the config.pp file in the nagios module. Place your db-a host in this new hostgroup. Also, add apps-a and backup-a after successfully testing on db-a.

    image

    Next, create a new service that performs the disk check via NRPE. The command to do this is check_nrpe!check_dev_root. This command is defined in the file /etc/nagios-plugins/config/check nrpe.cfg. The single argument, check_dev_root, is the name of the command we set up in the nrpe.cfg file on the remote system.

    image

    Apply the changes in the management server and restart the nagios.service.

    image

    image

  7. Apply the module in the apps-a and backup-a server.

    Note:Edit the site.pp file in the management server to include the nrpe module for db-a, backup-a and apps-a

    image

    image

  8. Verification

    image

    image