Friday, 8 August 2014

Monitoring Vyatta using Nagios

Monitoring Vyatta using Nagios


This tutorial will discuss the various ways using which you can effectively monitor your Switch/ Router using Nagios.

Before we begin, do note that the steps shown here are actually a continuation from my earlier series of tutorials based on Nagios:



Prerequisites:
  • Nagios Monitoring System: Installed and configured (Refer steps HERE)
  • Switch/ Router: Installed, configured and located on the same network as that of the Nagios Server. Here, I am using a Vyatta Virtual Router (192.168.50.1) as my client.

NOTE: We are going to monitor our Vyatta Router using two methods:


1) Using an agent (NRPE)
The NRPE add-on 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.
2) Agentless Monitoring (SNMP)
Agentless technologies like SNMP allow IT administrators to deploy monitoring solutions without having to install agent software on each monitored system, thus helping with reduced deployment time, reduced administrative overhead and centralized administration and configuration, etc.



1) Using an agent (NRPE)
Just to understand what NRPE actually is and how it works, check out this small excerpt from NRPE's Design overview Doc:

NRPE addon consists of two pieces:
– The check_nrpe plugin, which resides on the local monitoring machine
– The NRPE daemon, which runs on the remote Linux/Unix machine

When Nagios needs to monitor a resource of service from a remote Linux/Unix machine:
– Nagios will execute the check_nrpe plugin and tell it what service needs to be checked
– The check_nrpe plugin contacts the NRPE daemon on the remote host over an (optionally) SSL-protected connection
– The NRPE daemon runs the appropriate Nagios plugin to check the service or resource
– The results from the service check are passed from the NRPE daemon back to the check_nrpe plugin, which then returns the check results to the Nagios process.

NOTE: The NRPE daemon requires that Nagios plugins be installed on the remote Linux/Unix host. Without these, the daemon wouldn't be able to monitor anything. Hence we need to install NRPE as well as the Nagios Plugins in both the Nagios server as well as the Client that we will be monitoring.

a) Configuring Client
In the following steps, I'll be first installing Nagios Plugins as well as NRPE on my Vyatta box (192.168.50.1), then configuring NRPE to accept connections with my Nagios Server (192.168.50.150)

First, login to the Vyatta Router.

Next, switch to the configure mode by typing in configure as shown:
$ configure


Now the Vyatta that I'm using is a version 6.4. Vyatta basically runs a top of a customized Debian distribution, so we need to next add the Debian repository details as per follows:


NOTE: Execute the following commands in Configuration mode ONLY.

# set system package repository squeeze components 'main contrib non-free'

# set system package repository squeeze distribution 'squeeze'

# set system package repository squeeze url 'http://mirrors.kernel.org/debian'

# commit

# save

# exit


Once set, we can now go ahead and install any software we want on our Vyatta system.

NOTE: The following steps are to be carried out in the Operational Mode ONLY

$ sudo apt-get update


Next, install the NRPE as well as Nagios Plugins

$ sudo apt-get install nagios-nrpe-server nagios-plugins


Once the installation finishes, we need to edit the nrpe.cfg file at our client and add the Nagios Server IP in the allowed_hosts attribute

$ sudo vi /etc/nagios/nrpe.cfg


# Add the Nagios Server IP address (192.168.50.150). Remember that the IPs are comma separated.
allowed_hosts=127.0.0.1,192.16850.150

Save the file and exit the editor.

Restart the NRPE service
$ sudo service nagios-nrpe-server restart


b) Configure Nagios Server
Well, once your done with your Client setup, there actually nothing to configure at the Nagios Server side. However, I just wanted to show you some important things that you can indeed configure and use here as well.

First, lets take a look at what's exactly contained in a nrpe.cfg file. Here, I'll be using my Nagios Server's nrpe.cfg file.


Besides a lot of configurations and settings, you will find in each nrpe.cfg file a set of hard-coded nagios plugins with their commands and arguments (See pic below).

As you can see, there are a few Nagios plugins already defined here for use with nrpe. The first few commands have values already set into them, while the second set of commands have variable arguments that you can pass directly with NRPE

For e.g. check_users plugin is configured to raise a WARNING if there are 5 users logged into the Client system or a CRITICAL if the user logged in count exceeds 10

So if you want to add or use another plugin thats not listed here, you know just where to put it. Simply add new command definitions in both of your nrpe.cfg files (Server and Clients) and you are ready to go. 


c) Configuring Plugins
This section is going to show you how to use NRPE along with few Nagios plugins to monitor remote hosts and Clients.

1) check_load

This plugin checks the current systems Load Average.


Syntax for use with nrpe: 



check_nrpe -H <HOSTADDRESS> -c check_load 

Example:
# ./check_nrpe -H 192.168.50.1 -c check_load 

Since we have not provided any arguments to this example, it will use the default check_load arguments specified in the nrpe.cfg file (Refer the above screenshot). 

The following example will generate a warning status if the load average exceeds the values: 15 for Load1, 10 for Load5 and 5 for Load15. Similarly, it will generate critical status if the load average exceeds the values: 30 for Load1, 25 for Load5 and 20 for Load15. 


To monitor the Client using the Nagios UI, simply add the Host Definition first to the clients.cfg file

define host {
    use                          linux-server
    host_name               vyatta
    alias                         vyatta
    address                   192.168.50.1
max_check_attempts   5
check_period               24x7
notification_interval      10
notification_period        24x7
}




Define the corresponding Service as well:


define service {

use                         generic-service

host_name              vyatta
service_description  Current Load of System
check_command     check_nrpe!check_load
}


Save and exit the editor.


Restart the Nagios service and check the Nagios UI. You should see your Plugin generating alerts as shown below:


2) check_users
This plugin checks the current number of logged in users.



Syntax for use with nrpe: 



check_nrpe -H <HOSTADDRESS> -c check_users

Example:
# ./check_nrpe -H 192.168.50.1 -c check_users

Since we have not provided any arguments to this example, it will use the default check_users arguments specified in the nrpe.cfg file. The following example will raise a warning if the current number of logged in users is 5 or a critical alert if the users exceed the count of 10.

You can even define the corresponding Service for the Plugin in the clients.cfg file as shown:


define service {

use                         generic-service

host_name              vyatta
service_description  Logged in Users
check_command     check_nrpe!check_users
}


Restart the Nagios service and check the Nagios UI. You should see your Plugin generating alerts as shown below:





2) Agentless Monitoring (SNMP)
If agents and NRPE is not your thing and you still want to monitor your remote hosts and clients, then using something like SNMP is a very viable and simple option. Simply enable SNMP on your Client and provide it a unique SNMP string (a.k.a Community String) and there you have it!! 

You can easily monitor your Vyatta Router using SNMP using the following steps:

a) Configure Client
First, enable SNMP on Vyatta and provide a suitable Community String (here, I'm using MyCommunity

NOTE: The following commands need to be executed in Configuration mode ONLY

# set service snmp community MyCommunity authorization ro

# set service snmp community MyCommunity client 192.168.50.150


b) Configure Nagios Server
Use the in-built check_snmp plugin and test your remote host monitoring:

Syntax for use with nrpe

check_snmp -H <HOSTADDRESS> -C <COMMUNITY_STRING> -0 <OID>

Here, <OID> stands for Object Identifiers. 

Example:
# ./check_nrpe -H 192.168.50.1 -C MyCommunity -o sysUpTime.0

The following command simply returns the remote host's Uptime.


You can even define the corresponding Service for the Plugin in the clients.cfg file as shown:


define service {

use                           generic-service

host_name                vyatta
service_description    Router Uptime
check_command  check_snmp! -C MyCommunty -o sysUpTime.0
}


Restart the Nagios service and check the Nagios UI. You should see your Plugin generating alerts as shown below:




And there you have it, simply and easy steps to monitor Vyatta's Virtual Router. So stay tuned as in my next post, I'll be covering Monitoring Xenserver with Nagios!!





No comments :

Post a Comment