How to Add the Linux Host to Nagios monitoring Server Using NRPE Plugin

Source: Internet
Author: User
Tags snmp string back unpack

In our first part of this article, we ' ve explained in detail on what to install and configure latest Nagios Core 4.2.0on Ce Ntos 7.2 server. In this article we'll show you how to add Remote Linux machine and it's services to Nagios monitoring host using NRPE AG Ent.

We hope you already have Nagios installed and running properly. If not, please use the following installation Guide to install it on the system.

    1. Nagios 4.2.0 Installation Guide on Rhel/centos 7.x/6.x/5.x & Fedora 24-19
    2. How to Add the Windows Host to Nagios monitoring Server

Once you ' ve installed, you can proceed further to install NRPE agent on your Remote Linux host. Before heading further, let us give to a short description about NRPE.

What is NRPE?

The NRPE (Nagios Remote Plugin Executor) Plugin allows you-to-monitor any Remote Linux/unix services or network devices. This NRPE add-on allows Nagios to monitor any local resources like CPU load, Swap, Memory usage, Online users, etc. on REM OTE Linux machines. After all, these local resources is not mostly exposed to external machines, a NRPE agent must be installed and Configur Ed on the remote machines.

Note:the NRPE addon requires that Nagios Plugins must is installed on the remote Linux machine. Without these, the NRPE daemon won't work and would not monitor anything.

Installation of NRPE Plugin

To use the NRPE, you'll need to does some additional tasks on both the Nagios monitoring host and Remote Linux host that T He NRPE installed on. We'll be covering both the installation parts separately.

We assume that is installing the NRPE on a host this supports TCP wrappers and xinted daemon installed on it. Today, the most of the modern Linux distributions has these and installed by default. If not, we'll install it later during the installation when required.

On Remote Linux Host

The below instructions to install Nagios Plugins and NRPE daemon on the Remote Linux Host.

Step 1:install Required Dependencies

We need to install required libraries like GCC, glibc, Glibc-common and GD and its development libraries before installing .

[Email protected]]# yum install-y gcc glibc glibc-common gd gd-devel make Net-snmp openssl-devel--------------on Fedora 22+ onwards--------------[[email protected]]# DNF install-y gcc glibc glibc-common gd gd-devel make Net-snmp openssl-de Vel
Step 2:create Nagios User

Create a new Nagios user account and set a password.

[Email protected]]# useradd nagios[[email protected]]# passwd Nagios
Step 3:install the Nagios Plugins

Create a directory for installation and all its future downloads.

[[Email protected]]# Cd/root/nagios

Now download latest Nagios Plugins 2.1.2 package with wget command.

[Email protected] nagios~]# wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
Step 4:extract Nagios Plugins

Run the following tar command to extract the source code tarball.

[Email protected] nagios~]# TAR-XVF nagios-plugins-2.1.2.tar.gz

After, extracting one new folder would appear in that directory.

[Email protected] Nagios ~]# ls-ltotal 2640drwxr-xr-x. Root root    4096  1 21:58 nagios-plugins-2.1.2-rw-r--r--.  1 root root 2695301  1 21:58 nagios-plugins-2.1.2.tar.gz
Step 5:compile and Install Nagios Plugins

Next, compile and install using following commands

[Email protected] nagios]# CD Nagios-plugins-2.1.2[[email protected] nagios-plugins-2.1.2]#./configure [[Email Protected] nagios-plugins-2.1.2]# Make[[email protected] nagios-plugins-2.1.2]# make install

Set the permissions on the plugin directory.

[Email protected] nagios-plugins-2.1.2]# chown Nagios.nagios/usr/local/nagios[[email protected] nagios-plugins-2.1.2]# Chown-r nagios.nagios/usr/local/nagios/libexec
Step 6:install Xinetd

Most of the systems, their by default installed. If not, the install XINETD package using following Yum command.

[email protected] nagios-plugins-2.1.2]# Yum install xinetd--------------on Fedora 22+ onwards--------------[[Email PR Otected] nagios-plugins-2.1.2]# DNF Install xinetd
Step 7:install NRPE Plugin

Download Latest NRPE Plugin 3.0 packages with wget command.

[Email protected] nagios-plugins-2.1.2]# cd/root/nagios[[email protected] nagios]# wget/http Liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.tar.gz

Unpack the NRPE source code tarball.

[[Email protected] nagios]# tar xzf nrpe-3.0.tar.gz[[email protected] nrpe-3.0]# CD nrpe-3.0

Compile and install the NRPE addon.

[[email protected] nrpe-3.0]#/configure[[email protected] nrpe-3.0]# make all

Next, install the NRPE plugin daemon, and Sample daemon config file.

[[email protected] nrpe-3.0]# make Install-plugin[[email protected] nrpe-3.0]# make Install-daemon[[email protected] nrpe-3.0]# make Install-daemon-config

Install the NRPE daemon under xinetd as a service.

[[email protected] nrpe-3.0]# make Install-xinetdor[[email protected] nrpe-3.0]# make install-inetd

Now Open/etc/xinetd.d/nrpe file and add the localhost and IP address of the Nagios monitoring Server.

Only_from = 127.0.0.1 localhost <nagios_ip_address>

Next, open/etc/services file add the following entry for the NRPE daemon at the bottom of the file.

Nrpe            5666/tcp                 Nrpe

Restart the XINETD service.

[[Email protected]]# service xinetd Restart
Step 8:verify NRPE Daemon locally

Run the following command to verify the NRPE daemon working correctly under XINETD.

[[Email protected]]# netstat-at | grep nrpetcp        0      0 *:nrpe                      *:*                         LISTEN

If you get the output similar to above, means it working correctly. If not, make sure to check the following things.

    1. Check you ' ve added Nrpe entry correctly in/etc/services file
    2. The Only_from contains an entry for ' nagios_ip_address ' in The/etc/xinetd.d/nrpe file.
    3. The xinetd is installed and started.
    4. Check for the errors of the system log files for about xinetd or Nrpe and fix those problems.

Next, verify the NRPE daemon is functioning properly. Run the "Check_nrpe" command that is installed earlier for testing purposes.

[Email protected]]#/usr/local/nagios/libexec/check_nrpe-h localhost

You'll get a following string on the screens, it shows you-what version of NRPE is installed:

NRPE v3.0
Step 9:configure Firewall Rules

Make sure, the Firewall on the local machine would allow the NRPE daemon to being accessed from remote servers. To does this, run the following iptables command.

--------------on Rhel/centos 6/5 and Fedora--------------[[email protected]]# iptables-a input-p tcp-m TCP--dport 56 66-j ACCEPT--------------on Rhel/centos 7 and Fedora onwards--------------[[email protected]]# firewall-cmd--perman ENT--zone=public--add-port=5666/tcp

Run the following command to Save the new iptables rule so it'll survive at system reboots.

--------------on Rhel/centos 6/5 and Fedora--------------[[Email protected]]# service Iptables Save
Step 10:customize NRPE Commands

The default NRPE configuration file that got installed have several command definitions that'll be used to monitor this m Achine. The sample configuration file located at.

[[Email protected]]# vi/usr/local/nagios/etc/nrpe.cfg

The following is the default command definitions that is located at the bottom of the configuration file. For the time being, we assume is using these commands. You can check them by using the following commands.

#/usr/local/nagios/libexec/check_nrpe-h Localhost-c check_usersusers OK-1 users currently logged in |users=1;5;10;0
#/usr/local/nagios/libexec/check_nrpe-h localhost-c check_loadok-load average:3.90, 4.37, 3.94|load1=3.900;15.000;3 0.000;0; load5=4.370;10.000;25.000;0; load15=3.940;5.000;20.000;0;
#/usr/local/nagios/libexec/check_nrpe-h Localhost-c check_hda1disk ok-free space:/boot 154 MB (84% inode=99%); |/boo t=29mb;154;173;0;193
#/usr/local/nagios/libexec/check_nrpe-h localhost-c Check_total_procsprocs critical:297 processes
#/usr/local/nagios/libexec/check_nrpe-h localhost-c Check_zombie_procsprocs ok:0 processes with state = Z

You can edit and add new command definitions by editing the NRPE config file. Finally, you ' ve successfully installed and configured NRPE agent on the Remote Linux Host. Now it's time to install a NRPE component and add some services on your Nagios monitoring Server ...

On Nagios monitoring Server

Now login to into your Nagios monitoring Server. Here you'll need to do following things:

    1. Install the Check_nrpe plugin.
    2. Create a Nagios command definition using the Check_nrpe plugin.
    3. Create Nagios Host and add service definitions for monitoring the remote Linux host.
Step 1:install NRPE Plugin

Go to the Nagios download directory and download latest NRPE Plugin with wget command.

[Email protected]]# cd/root/nagios[[email protected]]# wget Http://liquidtelecom.dl.sourceforge.net/project/nagios /nrpe-3.x/nrpe-3.0.tar.gz

Unpack the NRPE source code tarball.

[Email protected]]# tar xzf nrpe-3.0.tar.gz[[email protected]]# CD nrpe-3.0

Compile and install the NRPE addon.

[[Email protected]]#./configure[[email protected]]# make All[[email protected]]# make Install-daemon
Step 2:verify NRPE Daemon remotely

Make sure, the Check_nrpe plugin can communicate with the Nrpe daemon on the remote Linux host. ADD the IP address in the command below with the IP address of your Remote Linux host.

[Email protected]]#/usr/local/nagios/libexec/check_nrpe-h <remote_linux_ip_address>

You'll get a string back to that shows your what version of NRPE was installed on the remote host and like this:

NRPE v3.0

If your receive a plugin time-out error, then check the following things.

    1. Make sure your firewall isn ' t blocking the communication between the remote host and the monitoring host.
    2. Make sure, the NRPE daemon is installed correctly under XINETD.
    3. Make sure, the remote Linux host firewall rules blocking the monitoring server from communicating to the NRPE daemon.
Adding Remote Linux Host to Nagios monitoring Server

To add a remote host need to create a new files "hosts.cfg" and "Services.cfg" under "/usr/local/nagios/etc/" Loca tion.

[[Email protected]]# cd/usr/local/nagios/etc/[[email protected]]# Touch hosts.cfg[[email protected]]# Touch Services.cfg

Now add these the files to main Nagios configuration file. Open nagios.cfg file with any editor.

[[Email protected]]# vi/usr/local/nagios/etc/nagios.cfg

Now add the newly created files as shown below.

# You can specify individual object config files as shown below:cfg_file=/usr/local/nagios/etc/hosts.cfgcfg_file=/usr/ Local/nagios/etc/services.cfg

Now open hosts.cfg file and add the default host template name and define remote hosts as shown below. Make sure to replace Host_name, alias and address with your remote host server details.

[[Email protected]]# vi/usr/local/nagios/etc/hosts.cfg
# # Default Linux Host Template # # #define HOST{NAME Linux-box; Name of this templateuse generic-host;                  Inherit default Valuescheck_period 24x7 check_interval 5 Retry_interval 1 max_check_attempts Check_command Check-host-alivenotificati On_period 24x7 Notification_interval notification_options d,r Contact_grou PS Admins register 0; DONT REGISTER this-its A template}## defaultdefine host{use linux-box; Inherit default values from a Templatehost_name tecmint; The name we ' re giving to this serveralias CentOS 6; A longer name for the serveraddress 5.175.142.66; IP address of Remote Linux host}

Next Open services.cfg File Add the following services to be monitored.

[[Email protected]]# vi/usr/local/nagios/etc/services.cfg
Define Service{use                     generic-servicehost_name               tecmintservice_description     CPU loadcheck_command           Check_nrpe!check_load}define service{use                     generic-servicehost_name               tecmintservice_description     Total Processescheck_command           check_nrpe!check_total_procs}define service{use                     generic-servicehost_name               Tecmintservice_description current     userscheck_command           check_nrpe!check_users}define service{use                     Generic-servicehost_name               tecmintservice_description     SSH monitoringcheck_command           Check_nrpe!check _ssh}define service{use                     generic-servicehost_name               tecmintservice_description     FTP monitoringcheck_ Command           Check_nrpe!check_ftp}

Now NRPE command definition needs to being created in Commands.cfg file.

[[Email protected]]# vi/usr/local/nagios/etc/objects/commands.cfg

ADD the following NRPE command definition at the bottom of the file.

################################################################################ NRPE CHECK COMMAND## COMMAND to use NRPE to check remote host systems############################################################################### Define Command{command_name check_nrpecommand_line $USER 1$/check_nrpe-h $HOSTADDRESS $-C $ARG 1$}

Finally, verify Nagios Configuration files for any errors.

[Email protected]]#/usr/local/nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfgtotal warnings:0total Errors:   0

Restart Nagios:

[[Email protected]]# service Nagios Restart

That ' s it. Now go-to-Nagios monitoring Web interface at "Http://Your-server-IP-address/nagios" or "Http://FQDN/nagios" and provide th E username "nagiosadmin" and password. Check the Remote Linux Host was added and is being monitored.

Nagios Remote Host Monitoring

That ' s it! For now, in our my up-coming article I'll show you what to add Windows host to Nagios monitoring Server. If you ' re facing any difficulties while adding remote host to Nagios. Please do comment your queries or problem via comment sections, till then stay tuned to tecmint.com for more such valuable Articles.

How to Add the Linux Host to Nagios monitoring Server Using NRPE Plugin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.