add nrpe for all ubuntu servers

1. Install Required NRPE Packages

bash
sudo apt update
sudo apt install -y xinetd monitoring-plugins nagios-nrpe-server

2. Verify NRPE Installation

bash
which nrpe

3. Update /etc/nagios/nrpe.cfg Configuration
Add or update the following lines:

bash
allowed_hosts=127.0.0.1,<Nagios_Server_IP>
dont_blame_nrpe=1
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_load]=/usr/lib/nagios/plugins/check_load -w 1.0,0.75,0.5 -c 2.0,1.5,1.0
command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_mem]=/usr/lib/nagios/plugins/check_mem.sh 80 90

4. Create and Set Permissions for check_mem.sh Script

bash
sudo vi /usr/lib/nagios/plugins/check_mem.sh

Paste the following code into the file:

bash
#!/bin/bash
USED_MEM=$(free | awk '/Mem:/ {print $3/$2 * 100.0}')
USED_MEM_INT=${USED_MEM%.*}
echo "MEMORY OK - $USED_MEM% used | mem=$USED_MEM%;$1;$2;0;100"
exit 0

Set the correct permissions:

bash
sudo chown nagios:nagios /usr/lib/nagios/plugins/check_mem.sh
sudo chmod 755 /usr/lib/nagios/plugins/check_mem.sh

5. Restart the NRPE Service

bash
sudo systemctl restart nrpe
sudo systemctl status nrpe

6. Test NRPE Commands Locally and from the Nagios Server

  • Local Test
    bash
    /usr/lib/nagios/plugins/check_nrpe -H localhost -c check_disk
    /usr/lib/nagios/plugins/check_nrpe -H localhost -c check_mem
  • Remote Test (Run from Nagios Server)
    bash
    /usr/local/nagios/libexec/check_nrpe -H <Remote_Server_IP> -c check_disk
    /usr/local/nagios/libexec/check_nrpe -H <Remote_Server_IP> -c check_mem
Posted in Uncategorized.