# Nagios NRPE

### **Downloading Nagios Core:**

[https://www.nagios.org/downloads/nagios-core/thanks/?t=1500128149](https://www.nagios.org/downloads/nagios-core/thanks/?t=1500128149)

### **Installing Nagios Core:**

<p class="callout info">Installation is really easy just follow the guide:</p>

[https://assets.nagios.com/downloads/nagioscore/docs/Installing\_Nagios\_Core\_From\_Source.pdf#\_ga=2.210947287.396962911.1500126138-104828703.1500126138](https://assets.nagios.com/downloads/nagioscore/docs/Installing_Nagios_Core_From_Source.pdf#_ga=2.210947287.396962911.1500126138-104828703.1500126138)

<p class="callout info">When installing nagios on an ubuntu 17.04 server i had to cp /usr/lib/nagios/plugins/check\_nrpe /usr/local/nagios/libexec/check\_nrpe and apt-get install nagios-nrpe-plugin</p>

Once it's installed, create a host and a service and the commands.

Lets start by making sure nagios sees the files we are going to create for our hosts and services.

```
vi /usr/local/nagios/etc/nagios.cfg
```

> cfg\_file=/usr/local/nagios/etc/servers/hosts.cfg   
> cfg\_file=/usr/local/nagios/etc/servers/services.cfg

```
mkdir /usr/local/nagios/etc/servers/
```

We will start by creating a template we can use for our hosts, then below we will create the host and then create the services for that host.

```
vim /usr/local/nagios/etc/servers/hosts.cfg
```

```
define host{
name                            linux-box               ; Name of this template
use                             generic-host            ; Inherit default values
check_period                    24x7        
check_interval                  5       
retry_interval                  1       
max_check_attempts              10      
check_command                   check-host-alive
notification_period             24x7    
notification_interval           30      
notification_options            d,r     
contact_groups                  admins  
register                        0                       ; DONT REGISTER THIS - ITS A TEMPLATE
}

define host{
use                             linux-box                ; Inherit default values from a template
host_name                       linux-server-01		 ; The name we're giving to this server
alias                           Linux Server 01          ; A longer name for the server
address                         192.168.1.100            ; IP address of Remote Linux host
}
```

```
vim /usr/local/nagios/etc/servers/services.cfg
```

```
define service{
use                     generic-service
host_name               linux-server-01
service_description     CPU Load
check_command           check_nrpe!check_load
}
```

```
vi /usr/local/nagios/etc/objects/commands.cfg
```

<p class="callout info">The -H will be for the host it will connect to (192.168.1.100) defined in the host.cfg, the -c will be the name specified on the remote host inside the /etc/nrpe.cfg</p>

```
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
```

<p class="callout warning">Verify nagios config for errors before restarting.</p>

```
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
```

Restart the service

```
service nagios restart
```

#### **Remote host:**

now lets install the NRPE plugins and add a few plugins to the config file.

**On Ubuntu:**

```
apt-get install nagios-nrpe-server nagios-plugins-basic
```

**For CentOS:**

To view the list of plugins you can install:

```
yum --enablerepo=epel -y list nagios-plugins*
```

```
yum install nrpe nagios-plugins-dns nagios-plugins-load nagios-plugins-swap nagios-plugins-disk nagios-plugins-procs
```

<p class="callout info">Now we need to add the nagios server (192.168.1.101) and the commands it can execute</p>

```
vim /etc/nagios/nrpe.cfg
```

> command\[check\_load\]=/usr/local/nagios/libexec/check\_load -w 15,10,5 -c 30,25,20

> allowed\_hosts=127.0.0.1,192.168.1.101

On Ubuntu:

```
systemctl enable nagios-nrpe-server
systemctl restart nagios-nrpe-server
```

On Centos:

```
systemctl enable nrpe
systemctl restart nrpe 
```

**Check in CLI**

```shell
/usr/local/nagios/libexec/check_nrpe -n -H 10.1.1.1
```

Or on older versions

```shell
/usr/lib/nagios/plugins/check_nrpe
```

##### **Other NRPE commands:**

> command\[check\_ping\]=/usr/local/nagios/libexec/check\_ping 8.8.8.8 -w 50,50% -c 100,90%  
> command\[check\_vda\]=/usr/lib64/nagios/plugins/check\_disk -w 20% -c 10% -p /dev/vda1  
> command\[check\_swap\]=/usr/local/nagios/libexec/check\_swap -w 10% -c 5%  
> command\[check\_raid\]=/usr/local/nagios/libexec/check\_raid

##### **tcp\_check**

> define service{  
> use generic-service  
> host\_name media-server  
> service\_description Check Emby  
> check\_command check\_tcp!8096  
> }