?
Solved

how do i use nagios to check for disk space on a remote machine?

Posted on 2008-02-12
4
Medium Priority
?
28,220 Views
Last Modified: 2013-12-06
How can I use nagios to check for disk space on a remote machine?
I'm running 3RC2 on Fedora 8.  Been looking around and not getting too far.
I have hosts setup and disk checks...but I discovered that it is actually checking the local system, not the remote.  Here is the command:

define service{
        use                             local-service         ; Name of service template to use
        host_name                       myserver
        service_description             Root Partition
        check_command                   check_local_disk!20%!10%!/
        }

define service{
        use                             local-service         ; Name of service template to use
        host_name                       myserver
        service_description             boot
        check_command                   check_local_disk!20%!10%!/boot
        }

and so on for /usr /var etc...

in the commands.cfg, i have this for the command line:

# 'check_local_disk' command definition
define command{
        command_name    check_local_disk
        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
        }

I understand it's checking the local drive...need to check space on the remote drives.
Other remote checks like cpu, http are working fine remotely.
0
Comment
Question by:Seth Simmons
  • 2
3 Comments
 
LVL 1

Expert Comment

by:malcolm_logan_uk
ID: 20885460
On the remotehost - that is the one you want to check...

/usr/local/nagios/etc/nrpe.cfg

   command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda1

On the nagios host in the object file...

/usr/local/nagios/etc/objects/servers/remoteserver.cfg

   define service{
        use                     generic-service
        host_name               remoteserver
        service_description     /dev/sda1 Free Space
        check_command           check_nrpe!check_sda1
        }

Hope that helps - if you need anything more just ask.

M
0
 
LVL 36

Author Comment

by:Seth Simmons
ID: 20885800
on the remote host?  i need to install nagios there?  i found some things on google about nrpe but don't quite understand what it is or for.
0
 
LVL 1

Accepted Solution

by:
malcolm_logan_uk earned 200 total points
ID: 20891907
NRPE is a remote monitoring utility for Nagios...

"The NRPE addon is designed to allow you to execute Nagios plugins on remote Linux/Unix machines. The main reason for doing this is to allow Nagios to monitor "local" resources (like CPU load, memory usage, etc.) on remote machines. Since these public resources are not usually exposed to external machines, an agent like NRPE must be installed on the remote Linux/Unix machines."

Instructions are below

Good Luck

M

In order to use the NRPE addon, you'll need to perform some tasks on both the monitoring host and the remote Linux/Unix host that the NRPE daemon is installed on. I'll cover both of these tasks separately.

1. Remote Host Setup

These instructions should be completed on the remote Linux/Unix host that the NRPE daemon will be installed on. You'll be installing the Nagios plugins and the NRPE daemon...

i. Create Account Information

Become the root user.
   # su -
Create a new nagios user account and give it a password.
   # /usr/sbin/useradd nagios
   # passwd nagios

ii. Install the Nagios Plugins

Create a directory for storing the downloads.
   # mkdir ~/downloads
   # cd ~/downloads
Download the source code tarball of the Nagios plugins (visit http://www.nagios.org/download/ for links to the latestversions). At the time of writing, the latest stable version of the Nagios plugins was 1.4.6.
   # wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.6.tar.gz
Extract the Nagios plugins source code tarball.
   # tar xzf nagios-plugins-1.4.6.tar.gz
   # cd nagios-plugins-1.4.6
Compile and install the plugins.
   # ./configure
   # make
   # make install
The permissions on the plugin directory and the plugins will need to be fixed at this point, so run the following commands.
   # chown nagios.nagios /usr/local/nagios
   # chown -R nagios.nagios /usr/local/nagios/libexec

iii. Install the NRPE daemon

Download the source code tarball of the NRPE addon (visit http://www.nagios.org/download/ for links to the latest versions). At the time of writing, the latest version of NRPE was 2.8.
   # cd ~/downloads
   # wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
Extract the NRPE source code tarball.
   # tar xzf nrpe-2.8.tar.gz
   # cd nrpe-2.8
Compile the NRPE addon.
   # ./configure
   # make all
Install the NRPE plugin (for testing), daemon, and sample daemon config file.
   # make install-plugin
   # make install-daemon
   # make install-daemon-config
Install the NRPE daemon as a service under xinetd.
   # make install-xinetd
Edit the /etc/xinetd.d/nrpe file and add the IP address of the monitoring server to the only_from directive.
   only_from            = 127.0.0.1 <nagios_ip_address>
Add the following entry for the NRPE daemon to the /etc/services file.
   nrpe                 5666/tcp             # NRPE
Restart the xinetd service.
   # service xinetd restart

iv. Test the NRPE daemon locally

Its time to see if things are working properly...
Make sure the nrpe daemon is running under xinetd.
   # netstat -at | grep nrpe
The output out this command should show something like this:
   tcp             0            0 *:nrpe     *:*           LISTEN
If it does, great! If it doesn't, make sure of the following:
You added the nrpe entry to your /etc/services file
The only_from directive in the /etc/xinetd.d/nrpe file contains an entry for "127.0.0.1"
xinetd is installed and started
Check the system log files for references about xinetd or nrpe and fix any problems that are reported
Next, check to make sure the NRPE daemon is functioning properly. To do this, run the check_nrpe plugin that was installed for testing purposes.
   # /usr/local/nagios/libexec/check_nrpe -H localhost
You should get a string back that tells you what version of NRPE is installed, like this:
   NRPE v2.8

v. Open firewall rules

Make sure that the local firewall on the machine will allow the NRPE daemon to be accessed from remote servers.
To do this, run the following iptables command. Note that the RH-Firewall-1-INPUT chain name is Fedora-specific, so it will be different on other Linux distributions.
   # iptables -I RH-Firewall-1-INPUT -p tcp -m tcp dport 5666 -j ACCEPT
Save the new iptables rule so it will survive machine reboots.
   # service iptables save

2. Monitoring Host Setup

On the monitoring host (the machine that runs Nagios), you'll need to do just a few things:
Install the check_nrpe plugin
Create a Nagios command definition for using the check_nrpe plugin
Create Nagios host and service definitions for monitoring the remote host

These instructions assume that you have already installed Nagios on this machine according to the quickstart installation guide. The configuration examples that are given reference templates that are defined in the sample localhost.cfg and commands.cfg files that get installed if you follow the quickstart.

i. Install the check_nrpe plugin

Become the root user. You may have to use sudo -s on Ubuntu and other distros.
   # su -
Create a directory for storing the downloads.
   # mkdir ~/downloads
   # cd ~/downloads
Download the source code tarball of the NRPE addon (visit http://www.nagios.org/download/ for links to the latestversions). At the time of writing, the latest version of NRPE was 2.8.
   # wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.8.tar.gz
Extract the NRPE source code tarball.
   # tar xzf nrpe-2.8.tar.gz
   # cd nrpe-2.8
Compile the NRPE addon.
   # ./configure
   # make all
Install the NRPE plugin.
   # make install-plugin

ii. Test communication with the NRPE daemon

Make sure the check_nrpe plugin can talk to the NRPE daemon on the remote host. Replace "192.168.0.1" in the command below with the IP address of the remote host that has NRPE installed.
   # /usr/local/nagios/libexec/check_nrpe -H 192.168.0.1
You should get a string back that tells you what version of NRPE is installed on the remote host, like this:
   NRPE v2.8
If the plugin returns a timeout error, check the following:
Make sure there isn't a firewall between the remote host and the monitoring server that is blocking communication
Make sure that the NRPE daemon is installed properly under xinetd
Make sure the remote host doesn't have local (iptables) firewall rules that prevent the monitoring server from talking to the NRPE daemon

iii. Create a command definition

You'll need to create a command definition in one of your Nagios object configuration files in order to use the check_nrpe plugin. Open the sample commands.cfg file for editing...
   # vi /usr/local/nagios/etc/commands.cfg
and add the following definition to the file:
   define command{
            command_name         check_nrpe
            command_line         $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
            }
You are now ready to start adding services that should be monitored on the remote machine to the Nagios configuration...

iv. Create host and service definitions

You'll need to create some object definitions in order to monitor the remote Linux/Unix machine. These definitions can be placed in their own file or added to an already exiting object configuration file.
First, its best practice to create a new template for each different type of host you'll be monitoring. Let's create a new template for linux boxes.
   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
               }
Notice that the linux-box template definition is inheriting default values from the generic-host template, which is defined in the sample localhost.cfg file that gets installed when you follow the Nagios quickstart installation guide.
Next, define a new host for the remote Linux/Unix box that references the newly created linux-box host template.
   define host{
               use                        linux-box                  ;  Inherit default values from a template
               host_name                  remotehost                 ;  The name we're giving to this server
               alias                      Fedora Core 6              ;  A longer name for the server
               address                    192.168.0.1                ;  IP address of the server
               }
Next, define some services for monitoring the remote Linux/Unix box. These example service definitions will use the sample commands that have been defined in the nrpe.cfg file on the remote host.
The following service will monitor the CPU load on the remote host. The "check_load" argument that is passed to the check_nrpe command definition tells the NRPE daemon to run the "check_load" command as defined in the nrpe.cfg file.
   define service{
               use                        generic-service
               host_name                  remotehost
               service_description        CPU Load
               check_command              check_nrpe!check_load
               }
The following service will monitor the the number of currently logged in users on the remote host.
   define service{
               use                        generic-service
               host_name                  remotehost
               service_description        Current Users
               check_command              check_nrpe!check_users
               }
The following service will monitor the free drive space on /dev/hda1 on the remote host.
   define service{
               use   generic-service
               host_name   remotehost
               service_description   /dev/hda1 Free Space
               check_command   check_nrpe!check_hda1
               }

The following service will monitor the total number of processes on the remote host.
   define service{
             use                        generic-service
             host_name                  remotehost
             service_description        Total Processes
             check_command              check_nrpe!check_total_procs
             }
The following service will monitor the number of zombie processes on the remote host.
   define service{
             use                        generic-service
             host_name                  remotehost
             service_description        Zombie Processes
             check_command              check_nrpe!check_zombie_procs
             }
Those are the basic service definitions for monitoring the remote host.

v. Restart Nagios

At this point you've installed the check_nrpe plugin and addon host and service definitions for monitoring the remote Linux/Unix machine. Now its time to make those changes live...
Verify your Nagios configuration files.
   # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are errors, fix them. If everything is fine, restart Nagios.
   # service nagios restart
That's it! You should see the host and service definitions you created in the Nagios web interface. In a few minutes Nagios should have the current status information for the remote Linux/Unix machine.



0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
Virtualization software lets you run different versions of Windows, Ubuntu Linux and other versions of Linux all at the same time, rather than running each one directly from your computer's hard drive.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question