Nagios3 on Ubuntu 14 server lts

What we are doing:

1 – Installing the nagios3 core onto a server running Ubunutu 14 lts. The purpose of this server is to monitor other servers.

2 – Install and configure a client server for the monitoring server to monitor.

3 – Setup and define a service

4 – Setup where the nagios monitoring server will send notifications to.

5 – Defining more services for your webserver

1  –  Installing and configuring the nagios3 core on the server used for monitoring others

First you need a full LAMP stack on your monitoring server:  Ubuntu LAMP

Second, unless you want to setup a full smtp server, you might want to quickly set up your server with sSMTP which will use someone elses SMTP server instead (ie gmail or something)

Install nagios3 on your server to monitor other servers

During the installation process you will be asked to configure a mail sever. By default nagios installs postfix, further on in this post we will override this with sSMTP, alternativ.

Choose the internet option:

Enter the mail name (this can be the default as we will override the postfix settings later

The default username for nagios is “nagiosadmin“, choose a password:

And confirm…

After nagios and nagios plugins installation, assign the permissions of www-data directory to nagios user, and set executable permission to the /var/lib/nagios3/ directory:

By default, Nagios won’t check for external commands, just to be on the cautious side.  If you want to be able to use the CGI command interface, you will have to enable this. To do that, edit file /etc/nagios3/nagios.cfg

Find the line,

Change it to

Save and close then restart nagios:


 

 You should now be able to access the nagios admin login page from:
http://< your ip or domain >/nagios3
username:  nagiosadmin
password:  whatever you set during the setup

Once logged your screen should look like:

You should be able to see the host (ie at the moment the only host will be the the server nagios is installed on) by clicking the host link on the left nav:

You can see more information about the host by click on the host:

2  –  Configuring a client for the nagios core to monitor

ssh into another machine, this machine will be monitored…
eg
ssh bob@www.mywebserver.com

Install the nrpe and nagios-plugins packages

Allow the nagios core server access to this server by editing the nrpe.cfg file:

Add your Nagios server ip address (ie the address of the server with nagios core installed). Find the “allowed_hosts=127.0.0.1” line, and add your nagios server’s IP (eg in this example I installed the nagios core onto a server with an IP of: 198.168.2.7) at end, eg:

Now just restart

 

3  –  Link the webserver to the nagios core

Now, go back to your Nagios server to add the clients to be monitored through nagios server. By default, Debian based systems uses a configuration directory called /etc/nagios3/conf.d/ where nagios3-common, other packages and the local admin can dump or link all object configuration files into.

In the object configuration files, you can define hosts, host groups, contacts, contact groups, services, etc. You can split your object definitions across several config files if you wish, or keep them all in a single config file.  EG:
Also, You can tell Nagios to process all config files (with a .cfg extension) in a particular directory by using the cfg_dir directive.
In this tutorial, I will tell Nagios to process client config files in a particular directory.
Edit /etc/nagios3/nagios.cfg file,

and uncomment the following line.

Create a directory called servers under /etc/nagios3/ location.

Create config file to the client to be monitored. In my case, I want to monitor my Ubuntu desktop which has IP address 192.168.1.100, and hostname as sk.

And add the following:

 

Save and close the file.  Here, sk is my Ubuntu 14.04 client host name, and 192.168.1.100 is the IP address of my client.  Restart nagios to see the new client in the nagios admin:

Now, open the nagios web console again in the browser and navigate to “Hosts” section in the left pane. You should see the newly added client will be visible there. Click on the host to see if there is anything wrong or alerts. Please note that you have to wait 90 seconds after any changes in your nagios server.

 Click the new host for more info:
Like this way, you can define more clients by creating a separate config files /etc/nagios3/servers directory for each client.

Define services on the nagios server:

We have defined the monitoring host before. Now let us add some services of the monitoring host. For example, to monitor the ssh service, add the following lines shown in red colour in the /etc/nagios3/servers/clients.cfg file.

And add to the end

 

Save and close the file. Restart Nagios.

 

Now log in to Nagios web console and check for the added services. Navigate to Services section, you should see the ssh service will be available there.

To know more about object definitions such as Host definitions, service definitions, contact definitions and more please do visit here. This page will describe you the description and format of all nagios object definitions.

4  –  Setting up email notifications from your nagios core server

Postfix is hard work and a little overkill for a nagios server. Instead we can use sSMTP to send the emails via a 3rd party email server.

Install sSMTP which will override postfix:

Configure sSMTP to use your gmail account (for example):

 

Remove all the contents and replace with:

 

Basic ntofication setup with Nagios:

The configuration file you will be using is /etc/nagios3/conf.d/contacts_nagios2.cfg. Although we are working with Nagios3, the “2” in the configuration file name is correct.

Within this file you will find a section that looks like:

 

The USERNAME you see above will be the text you need to configure for your alerts. If you need more than one email address to be alerted, you have to add a defined for each user.  Most of the definitions above will be pretty obvious. The service_notification flags are defined as such:
w = notify on warning states
c = critical states
r = recovery
f = start/stop of flapping
d = notify on down states
u = notify on unreachable states
s = notify on stopped states
You can pick and choose what states you want to be alerted for.
Once you have edited this file, save it, close it, and restart Nagios with the command:

 

You can go further with this to setup contact groups for different hosts and services etc ect. But for now, you should get an email when you webserver goes down.

5  –  Defining more than just an SSH service on your webservice

Back to your /etc/nagios3/servers/client.cfg file, at the moment we have just got the basic ssh service in there… lets add some more:

 

Gettting clever with your services:  http://geekpeek.net/nagios-configuration/

Leave a Reply

Your email address will not be published. Required fields are marked *